Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgsquickprint.cpp 00003 A class to quickly print a map with minimal effort. 00004 ------------------- 00005 begin : Jan 2008 00006 copyright : (c) Tim Sutton, 2008 00007 email : tim@linfiniti.com 00008 00009 *************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 /* $Id: plugin.cpp 7796 2007-12-16 22:11:38Z homann $ */ 00018 00019 // 00020 // QGIS Specific includes 00021 // 00022 00023 #include <qgisinterface.h> 00024 #include <qgisgui.h> 00025 #include "qgsquickprint.h" 00026 #include <qgsapplication.h> 00027 #include <qgsmaplayerregistry.h> 00028 #include <qgsvectorlayer.h> 00029 #include <qgssymbol.h> 00030 #include <qgsmapcanvas.h> 00031 #include <qgsrenderer.h> 00032 #include <qgslogger.h> 00033 #include <qgslabelattributes.h> 00034 #include <qgslabel.h> 00035 00036 // 00037 // Qt4 Related Includes 00038 // 00039 00040 #include <QAction> 00041 #include <QToolBar> 00042 #include <QColor> 00043 #include <QPainter> 00044 #include <QDate> 00045 #include <QPixmap> 00046 #include <QString> 00047 #include <QSettings> 00048 #include <QSvgRenderer> 00049 #include <QLinearGradient> 00050 00051 //other includes 00052 #include <cmath> 00053 00054 #ifdef _MSC_VER 00055 #define round(x) ((x) >= 0 ? floor((x)+0.5) : floor((x)-0.5)) 00056 #endif 00057 00058 QgsQuickPrint::QgsQuickPrint() 00059 { 00060 mPageSize = QPrinter::A4; 00061 } 00062 00063 QgsQuickPrint::~QgsQuickPrint() 00064 { 00065 00066 } 00067 void QgsQuickPrint::setTitle( QString theText ) 00068 { 00069 mTitleText = theText; 00070 } 00071 void QgsQuickPrint::setName( QString theText ) 00072 { 00073 mNameText = theText; 00074 } 00075 void QgsQuickPrint::setCopyright( QString theText ) 00076 { 00077 mCopyrightText = theText; 00078 } 00079 void QgsQuickPrint::setNorthArrow( QString theFileName ) 00080 { 00081 mNorthArrowFile = theFileName; 00082 } 00083 void QgsQuickPrint::setLogo1( QString theFileName ) 00084 { 00085 mLogo1File = theFileName; 00086 QgsDebugMsg( QString( "Logo1 set to: %1" ).arg( mLogo1File ) ); 00087 } 00088 void QgsQuickPrint::setLogo2( QString theFileName ) 00089 { 00090 mLogo2File = theFileName; 00091 QgsDebugMsg( QString( "Logo2 set to: %1" ).arg( mLogo2File ) ); 00092 } 00093 void QgsQuickPrint::setOutputPdf( QString theFileName ) 00094 { 00095 mOutputFileName = theFileName; 00096 } 00097 void QgsQuickPrint::setMapCanvas( QgsMapCanvas * thepMapCanvas ) 00098 { 00099 mpMapRenderer = thepMapCanvas->mapRenderer(); 00100 mMapBackgroundColor = thepMapCanvas->canvasColor(); 00101 } 00102 void QgsQuickPrint::setMapRenderer( QgsMapRenderer * thepMapRenderer ) 00103 { 00104 mpMapRenderer = thepMapRenderer; 00105 } 00106 void QgsQuickPrint::setMapBackgroundColor( QColor theColor ) 00107 { 00108 mMapBackgroundColor = theColor; 00109 } 00110 void QgsQuickPrint::setPageSize( QPrinter::PageSize theSize ) 00111 { 00112 mPageSize = theSize; 00113 } 00114 00115 void QgsQuickPrint::printMap() 00116 { 00117 if ( mOutputFileName.isEmpty() ) 00118 { 00119 return; 00120 } 00121 if ( mpMapRenderer == NULL ) 00122 { 00123 return; 00124 } 00125 //ensure the user never omitted the extension from the file name 00126 if ( !mOutputFileName.toUpper().endsWith( ".PDF" ) ) 00127 { 00128 mOutputFileName += ".pdf"; 00129 } 00130 00131 // Initialising the printer this way lets us find out what 00132 // the screen resolution is which we store and then 00133 // reset the resolution of the printer after that... 00134 QPrinter myPrinter( QPrinter::ScreenResolution ); 00135 00136 // Try to force the printer resolution to 300dpi 00137 // to get past platform specific defaults in printer 00138 // resolution... 00139 // 00140 int myPrintResolutionDpi = 300; 00141 myPrinter.setResolution( myPrintResolutionDpi ); 00142 myPrinter.setOutputFormat( QPrinter::PdfFormat ); 00143 QgsDebugMsg( QString( "Printing to page size %1" ).arg( pageSizeToString( mPageSize ) ) ); 00144 myPrinter.setPageSize( mPageSize ); 00145 myPrinter.setOutputFileName( mOutputFileName ); 00146 myPrinter.setOrientation( QPrinter::Landscape ); 00147 myPrinter.setDocName( "quickprint Report" ); 00148 QPainter myPrintPainter( &myPrinter ); 00149 myPrintPainter.setPen( Qt::gray ); 00150 myPrintPainter.setBrush( Qt::white ); 00151 // This is what we are aiming for: 00152 // a 00153 // +-(1)------ Acme Maps (2) --------------------------------------+ 00154 // |b 12/01/2007 (3) | 00155 // | Earthquakes (4) | 00156 // | +--(5)--------------------------------------------------------+ | 00157 // | |c | | 00158 // | | +-(6)---------------------------------------+ +~(7)~~~~~~+ | | 00159 // | | | | | | | | 00160 // | | | | | | | | 00161 // | | | | | | | | 00162 // | | | | | | | | 00163 // | | | | | | | | 00164 // | | | | | | | | 00165 // | | | | | | | | 00166 // | | | | | | | | 00167 // | | | | | | | | 00168 // | | | | | | | | 00169 // | | | | | | | | 00170 // | | +-------------------------------------------+ +~~~~~~~~~~+ | | 00171 // | | | | 00172 // | +-------------------------------------------------------------+ | 00173 // | | 00174 // | +-(8)-----+ +-(9-)----+ +-(10)----+ /|\ | 00175 // | | | |Copyright| | | / | \ | 00176 // | | | | 2008 | | | |(11) | 00177 // | +---------+ +---------+ +---------+ | 00178 // | +~(12)~~~~~~+ | 00179 // +-----------------------------------------------------------------+ 00180 // 00181 // 1) PageBorder 8) Logo1 00182 // 2) PageTitle 9) CopyrightText 00183 // 3) MapDate 10) Logo2 00184 // 4) MapTitle 11) NorthArrow 00185 // 5) MapFrame 12) ScaleBar 00186 // 6) MapPixmap 00187 // 7) LegendPixmap 00188 // a OriginXY 00189 // b HorizontalSpacing 00190 // c VerticalSpacing 00191 00192 // 00193 // Note: Different operating systems will use different 00194 // page resolutions for QPrinter::HighResolution so I'm 00195 // working all coordinates out as percentages of page 00196 // size so that we can hopefully get comarable print 00197 // results on all platforms. 00198 // 00199 00200 // 00201 // Note #2: Im defining all measurements here as my plan 00202 // is to later support templates with different page 00203 // layouts and paper sizes etc. 00204 // 00205 00206 00207 //set the top left origin for the print layout 00208 int myOriginX = myPrinter.pageRect().left(); 00209 int myOriginY = myPrinter.pageRect().top(); 00210 int myDrawableWidth = myPrinter.pageRect().width() - myOriginX; 00211 int myDrawableHeight = myPrinter.pageRect().height() - myOriginY; 00212 00213 //define the spacing between layout elements 00214 int myHorizontalSpacing = myDrawableWidth / 100; // 1% 00215 int myVerticalSpacing = myDrawableHeight / 100; // 1% 00216 00217 //define the proportions for the page layout 00218 int myMapWidthPercent = 65; 00219 int myMapHeightPercent = 71; 00220 int myLegendWidthPercent = 25; 00221 int myLegendHeightPercent = 65; 00222 int myLogoWidthPercent = 23; 00223 int myLogoHeightPercent = 17; 00224 // 00225 // Remember the size and dpi of the maprender 00226 // so we can restore it properly 00227 // 00228 int myOriginalDpi = mpMapRenderer->outputDpi(); 00229 //sensible default to prevent divide by zero 00230 if ( 0 == myOriginalDpi ) myOriginalDpi = 96; 00231 QSize myOriginalSize = mpMapRenderer->outputSize(); 00232 00233 //define the font sizes and family 00234 int myMapTitleFontSize = 24; 00235 int myMapDateFontSize = 16; 00236 int myMapNameFontSize = 32; 00237 int myLegendFontSize = 12; 00238 #ifdef Q_OS_LINUX//this sucks... 00239 myLegendFontSize -= 2; 00240 #endif 00241 00242 #ifdef WIN32 //this sucks too... 00243 myMapTitleFontSize /= 2; 00244 myMapDateFontSize /= 2; 00245 myMapNameFontSize /= 2; 00246 myLegendFontSize /= 2; 00247 #endif 00248 QString myFontFamily = "Arial"; 00249 00250 // 00251 // Draw the PageBorder 00252 // 00253 myPrintPainter.drawRect( 00254 myOriginX, myOriginY, myDrawableWidth, myDrawableHeight ); 00255 // 00256 // Draw the PageTitle 00257 // 00258 QFont myTitleFont( myFontFamily, myMapTitleFontSize ); 00259 myPrintPainter.setFont( myTitleFont ); 00260 QFontMetrics myTitleMetrics( myTitleFont, &myPrinter ); 00261 int myPageTitleHeight = myTitleMetrics.height(); 00262 int myPageTitleWidth = myTitleMetrics.width( mTitleText ); 00263 myOriginX += myHorizontalSpacing; 00264 myOriginY -= ( myPageTitleHeight / 2 ); 00265 QRect myPageTitleRect( myOriginX, 00266 myOriginY, 00267 myPageTitleWidth, 00268 myPageTitleHeight ); 00269 // make sure the title goes onto a white background 00270 myPrintPainter.setPen( Qt::white ); 00271 myPrintPainter.drawRect( myPageTitleRect ); 00272 myPrintPainter.setPen( Qt::black ); 00273 myPrintPainter.drawText( myPageTitleRect, Qt::AlignCenter, mTitleText ); 00274 00275 // 00276 // Draw the MapDate 00277 // 00278 QFont myDateFont( myFontFamily, myMapDateFontSize ); 00279 QString myDateText( QDate::currentDate().toString( Qt::LocalDate ) ); 00280 myPrintPainter.setFont( myDateFont ); 00281 QFontMetrics myDateMetrics( myDateFont, &myPrinter ); 00282 int myDateHeight = myDateMetrics.height(); 00283 //int myDateWidth = myDateMetrics.width(myDateText); 00284 myOriginX += myHorizontalSpacing; 00285 myOriginY += myPageTitleHeight + myVerticalSpacing ; 00286 QRect myDateRect( myOriginX, 00287 myOriginY, 00288 myPageTitleWidth, //use same width as page title for centering 00289 myDateHeight ); 00290 // make sure the title goes onto a white background 00291 myPrintPainter.setPen( Qt::white ); 00292 myPrintPainter.drawRect( myDateRect ); 00293 myPrintPainter.setPen( Qt::black ); 00294 myPrintPainter.drawText( myDateRect, Qt::AlignCenter, myDateText ); 00295 00296 // 00297 // Draw the MapName 00298 // 00299 QFont myNameFont( myFontFamily, myMapNameFontSize ); 00300 myPrintPainter.setFont( myNameFont ); 00301 QFontMetrics myNameMetrics( myNameFont, &myPrinter ); 00302 int myNameHeight = myNameMetrics.height(); 00303 int myNameWidth = myNameMetrics.width( mNameText ); 00304 myOriginX = myPrinter.pageRect().left() + myDrawableWidth / 2; //page center 00305 myOriginX -= myNameWidth / 2; 00306 myOriginY = myPrinter.pageRect().top() + ( myPageTitleHeight / 2 ) + myVerticalSpacing ; 00307 QRect myNameRect( myOriginX, 00308 myOriginY, 00309 myNameWidth, 00310 myNameHeight ); 00311 // make sure the title goes onto a white background 00312 myPrintPainter.setPen( Qt::white ); 00313 myPrintPainter.drawRect( myNameRect ); 00314 myPrintPainter.setPen( Qt::black ); 00315 myPrintPainter.drawText( myNameRect, Qt::AlignCenter, mNameText ); 00316 00317 // 00318 // Draw the MapFrame (top) 00319 // 00320 int myMapFrameWidth = myDrawableWidth ; 00321 myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; 00322 myOriginY += myNameHeight + myVerticalSpacing; 00323 QLine myMapFrameTopLine( myOriginX, 00324 myOriginY, 00325 myMapFrameWidth, 00326 myOriginY ); 00327 myPrintPainter.setPen( Qt::black ); 00328 myPrintPainter.drawLine( myMapFrameTopLine ); 00329 00330 00331 // Draw the map onto a pixmap 00332 // @TODO: we need to save teh extent of the screen map and 00333 // then set them again for the print map so that the map scales 00334 // properly in the print 00335 int myMapDimensionX = ( myDrawableWidth / 100 ) * myMapHeightPercent; 00336 int myMapDimensionY = ( myDrawableHeight / 100 ) * myMapWidthPercent; 00337 00338 QImage myMapImage( QSize( myMapDimensionX, myMapDimensionY ), QImage::Format_ARGB32 ); 00339 myMapImage.setDotsPerMeterX(( double )( myPrinter.logicalDpiX() ) / 25.4 * 1000.0 ); 00340 myMapImage.setDotsPerMeterY(( double )( myPrinter.logicalDpiY() ) / 25.4 * 1000.0 ); 00341 myMapImage.fill( 0 ); 00342 QPainter myMapPainter; 00343 myMapPainter.begin( &myMapImage ); 00344 // Now resize for print 00345 mpMapRenderer->setOutputSize( QSize( myMapDimensionX, myMapDimensionY ), ( myPrinter.logicalDpiX() + myPrinter.logicalDpiY() ) / 2 ); 00346 mpMapRenderer->render( &myMapPainter ); 00347 00348 myMapPainter.end(); 00349 //draw the map pixmap onto our pdf print device 00350 myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; 00351 myOriginY += myVerticalSpacing * 2; 00352 00353 myPrintPainter.drawImage( myOriginX, myOriginY, myMapImage ); 00354 00355 // 00356 // Draw the legend 00357 // 00358 QFont myLegendFont( myFontFamily, myLegendFontSize ); 00359 //myPrintPainter.setFont(myLegendFont); 00360 int myLegendDimensionX = ( myDrawableWidth / 100 ) * myLegendWidthPercent; 00361 int myLegendDimensionY = ( myDrawableHeight / 100 ) * myLegendHeightPercent; 00362 00363 00364 // Create a viewport to make coordinate conversions easier 00365 // The viewport has the same dimensions as the page(otherwise items 00366 // drawn into it will appear squashed), but a different origin. 00367 QRect myOriginalViewport = myPrintPainter.viewport(); //for restoring later 00368 myOriginX += myMapDimensionX + myHorizontalSpacing; 00369 myPrintPainter.setViewport( myOriginX, 00370 myOriginY, 00371 myOriginalViewport.width(), 00372 myOriginalViewport.height() ); 00373 //draw a rectangale around the legend frame 00374 //@TODO make this user settable 00375 if ( 0 == 1 ) //put some real logic here 00376 { 00377 myPrintPainter.drawRect( 0, 0, myLegendDimensionX, myLegendDimensionY ); 00378 } 00379 //get font metric and other vars needed 00380 QFontMetrics myLegendFontMetrics( myLegendFont, &myPrinter ); 00381 int myLegendFontHeight = myLegendFontMetrics.height(); 00382 int myLegendXPos = 0; 00383 int myLegendYPos = 0; 00384 int myLegendSpacer = myLegendFontHeight / 2; //for vertical and horizontal spacing 00385 int myLegendVerticalSpacer = myLegendFontHeight / 3; //for vertical between rows 00386 int myIconWidth = myLegendFontHeight; 00387 myPrintPainter.setFont( myLegendFont ); 00388 QStringList myLayerSet = mpMapRenderer->layerSet(); 00389 QStringListIterator myLayerIterator( myLayerSet ); 00390 //second clause below is to prevent legend spilling out the bottom 00391 while ( myLayerIterator.hasNext() && 00392 myLegendYPos < myLegendDimensionY ) 00393 { 00394 QString myLayerId = myLayerIterator.next(); 00395 QgsMapLayer * mypLayer = 00396 QgsMapLayerRegistry::instance()->mapLayer( myLayerId ); 00397 if ( mypLayer ) 00398 { 00399 QgsVectorLayer *mypVectorLayer = 00400 qobject_cast<QgsVectorLayer *>( mypLayer ); 00401 // TODO: add support for symbology-ng renderers 00402 if ( mypVectorLayer && mypVectorLayer->renderer() ) 00403 { 00404 QString myLayerName = mypVectorLayer->name(); 00405 QIcon myIcon; 00406 QPixmap myPixmap( QSize( myIconWidth, myIconWidth ) ); //square 00407 //based on code from qgslegendlayer.cpp - see that file for more info 00408 const QgsRenderer* mypRenderer = mypVectorLayer->renderer(); 00409 const QList<QgsSymbol*> mySymbolList = mypRenderer->symbols(); 00410 // 00411 // Single symbol 00412 // 00413 double widthScale = ( myPrinter.logicalDpiX() + myPrinter.logicalDpiY() ) / 2.0 / 25.4; 00414 00415 if ( 1 == mySymbolList.size() ) 00416 { 00417 QgsSymbol * mypSymbol = mySymbolList.at( 0 ); 00418 myPrintPainter.setPen( mypSymbol->pen() ); 00419 myPrintPainter.setBrush( mypSymbol->brush() ); 00420 myLegendXPos = 0 ; 00421 if ( mypSymbol->type() == QGis::Point ) 00422 { 00423 QImage myImage; 00424 myImage = mypSymbol->getPointSymbolAsImage( widthScale ); 00425 myPrintPainter.drawImage( myLegendXPos, myLegendYPos, myImage ); 00426 } 00427 else if ( mypSymbol->type() == QGis::Line ) 00428 { 00429 myPrintPainter.drawLine( myLegendXPos, myLegendYPos, 00430 myLegendXPos + myIconWidth, 00431 myLegendYPos + myIconWidth ); 00432 } 00433 else //polygon 00434 { 00435 myPrintPainter.drawRect( myLegendXPos, myLegendYPos, myIconWidth, myIconWidth ); 00436 } 00437 myLegendXPos += myIconWidth + myLegendSpacer; 00438 myPrintPainter.setPen( Qt::black ); 00439 QStringList myWrappedLayerNameList = wordWrap( myLayerName, 00440 myLegendFontMetrics, 00441 myLegendDimensionX - myIconWidth ); 00442 // 00443 // Loop through wrapped legend label lines 00444 // 00445 QStringListIterator myLineWrapIterator( myWrappedLayerNameList ); 00446 while ( myLineWrapIterator.hasNext() ) 00447 { 00448 QString myLine = myLineWrapIterator.next(); 00449 QRect myLegendItemRect( myLegendXPos, 00450 myLegendYPos, 00451 myLegendDimensionX - myIconWidth, 00452 myLegendFontHeight ); 00453 myPrintPainter.drawText( myLegendItemRect, Qt::AlignLeft, myLine ); 00454 myLegendYPos += myLegendVerticalSpacer + myLegendFontHeight; 00455 } 00456 } 00457 else //class breaks 00458 { 00459 // draw in the layer name first, after we loop for the class breaks 00460 QStringList myWrappedLayerNameList = wordWrap( myLayerName, 00461 myLegendFontMetrics, 00462 myLegendDimensionX - myIconWidth ); 00463 // Check the wrapped layer name wont overrun the space we have 00464 // for the legend ... 00465 int myLabelHeight = myLegendFontHeight * 00466 myWrappedLayerNameList.count(); 00467 if ( myLegendYPos + myLabelHeight > myLegendDimensionY ) 00468 { 00469 continue; 00470 } 00471 00472 // 00473 // Loop through wrapped legend label lines 00474 // 00475 QStringListIterator myLineWrapIterator( myWrappedLayerNameList ); 00476 while ( myLineWrapIterator.hasNext() ) 00477 { 00478 QString myLine = myLineWrapIterator.next(); 00479 myLegendXPos = myIconWidth; 00480 QRect myLegendItemRect( myLegendXPos, 00481 myLegendYPos, 00482 myLegendFontMetrics.width( myLine ), 00483 myLegendFontHeight ); 00484 myPrintPainter.setPen( Qt::black ); 00485 myPrintPainter.drawText( myLegendItemRect, Qt::AlignLeft, myLine ); 00486 myLegendYPos += myLegendVerticalSpacer + myLegendFontHeight; 00487 } 00488 // 00489 // Loop through the class breaks 00490 // 00491 QListIterator<QgsSymbol *> myIterator( mySymbolList ); 00492 while ( myIterator.hasNext() && myLegendYPos < myLegendDimensionY ) 00493 { 00494 QgsSymbol * mypSymbol = myIterator.next(); 00495 myPrintPainter.setPen( mypSymbol->pen() ); 00496 myPrintPainter.setBrush( mypSymbol->brush() ); 00497 myLegendXPos = myLegendSpacer * 3; //extra indent for class breaks 00498 if ( mypSymbol->type() == QGis::Point ) 00499 { 00500 QImage myImage; 00501 myImage = mypSymbol->getPointSymbolAsImage( widthScale ); 00502 myPrintPainter.drawImage( myLegendXPos, myLegendYPos, myImage ); 00503 } 00504 else if ( mypSymbol->type() == QGis::Line ) 00505 { 00506 myPrintPainter.drawLine( myLegendXPos, myLegendYPos, 00507 myLegendXPos + myIconWidth, 00508 myLegendYPos + myIconWidth ); 00509 } 00510 else //polygon 00511 { 00512 myPrintPainter.drawRect( 00513 myLegendXPos, myLegendYPos, myIconWidth, myIconWidth ); 00514 } 00515 // 00516 // Now work out the class break label 00517 // 00518 QString myLabel; 00519 QString myLower = mypSymbol->lowerValue(); 00520 if ( !myLower.isEmpty() ) 00521 { 00522 myLabel = myLower; 00523 } 00524 QString myUpper = mypSymbol->upperValue(); 00525 if ( !myUpper.isEmpty() ) 00526 { 00527 myLabel += " - "; 00528 myLabel += myUpper; 00529 } 00530 QString myText = mypSymbol->label(); 00531 if ( !myText.isEmpty() ) 00532 { 00533 myLabel += " "; 00534 myLabel += myText; 00535 } 00536 myLabel = myLabel.trimmed(); 00537 myLegendXPos += myIconWidth + myLegendSpacer; 00538 myPrintPainter.setPen( Qt::black ); 00539 00540 QStringList myWrappedLayerNameList = wordWrap( myLabel, 00541 myLegendFontMetrics, 00542 myLegendDimensionX - myLegendXPos ); 00543 // 00544 // Loop through wrapped legend label lines 00545 // 00546 QStringListIterator myLineWrapIterator( myWrappedLayerNameList ); 00547 while ( myLineWrapIterator.hasNext() ) 00548 { 00549 QString myLine = myLineWrapIterator.next(); 00550 // check if the text will overflow the space we have 00551 QRect myLegendItemRect( myLegendXPos, 00552 myLegendYPos, 00553 myLegendDimensionX - myIconWidth, 00554 myLegendFontHeight ); 00555 myPrintPainter.drawText( myLegendItemRect, Qt::AlignLeft, myLine ); 00556 myLegendYPos += myLegendVerticalSpacer + myLegendFontHeight; 00557 } //wordwrap loop 00558 } //symbol loop 00559 } //class breaks 00560 } //if vectorlayer 00561 } //if maplayer 00562 } //layer iterator 00563 00564 //reinstate the viewport 00565 myPrintPainter.setViewport( myOriginalViewport ); 00566 00567 00568 // 00569 // Draw the MapFrame (bottom) 00570 // 00571 myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; 00572 myOriginY += myMapDimensionY + ( myVerticalSpacing * 2 ); 00573 QLine myMapFrameBottomLine( myOriginX, 00574 myOriginY, 00575 myMapFrameWidth, 00576 myOriginY ); 00577 myPrintPainter.setPen( Qt::black ); 00578 myPrintPainter.drawLine( myMapFrameBottomLine ); 00579 00580 00581 // 00582 // Draw logo 1 00583 // 00584 int myLogoXDim = ( myDrawableWidth / 100 ) * myLogoWidthPercent; 00585 int myLogoYDim = ( myDrawableHeight / 100 ) * myLogoHeightPercent; 00586 QPixmap myLogo1; 00587 QgsDebugMsg( QString( "Logo1: %1" ).arg( mLogo1File ) ); 00588 myLogo1.fill( Qt::white ); 00589 myLogo1.load( mLogo1File ); 00590 myLogo1 = myLogo1.scaled( myLogoXDim, myLogoYDim, Qt::KeepAspectRatio ); 00591 myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; 00592 myOriginY += myVerticalSpacing ; 00593 myPrintPainter.drawPixmap( myOriginX, 00594 myOriginY, 00595 myLogo1 ); 00596 00597 // 00598 // Draw Copyright Text 00599 // 00600 myOriginX += myHorizontalSpacing + myLogoXDim; 00601 QRect myCopyrightRect( myOriginX, myOriginY, myLogoXDim, myLogoYDim ); 00602 myPrintPainter.setPen( Qt::black ); 00603 QFont myCopyrightFont( myFontFamily, myMapDateFontSize ); 00604 myPrintPainter.setFont( myCopyrightFont ); 00605 //myPrintPainter.drawRect( myCopyrightRect ); 00606 myPrintPainter.drawText( myCopyrightRect, Qt::AlignCenter | Qt::TextWordWrap, mCopyrightText ); 00607 00608 // 00609 // Draw logo 2 00610 // 00611 QPixmap myLogo2; 00612 myLogo2.fill( Qt::white ); 00613 myLogo2.load( mLogo2File ); 00614 myLogo2 = myLogo2.scaled( myLogoXDim, myLogoYDim, Qt::KeepAspectRatio ); 00615 myOriginX += myHorizontalSpacing + myLogoXDim; 00616 myPrintPainter.drawPixmap( myOriginX, 00617 myOriginY, 00618 myLogo2 ); 00619 00620 // 00621 // Draw the north arrow 00622 // 00623 myOriginX += myHorizontalSpacing + myLogoXDim; 00624 // use half the available space for the n.arrow 00625 // and the rest for the scale bar (see below) 00626 QPixmap myNorthArrow( myLogoYDim / 2, myLogoYDim / 2 ); 00627 myNorthArrow.fill( Qt::white ); 00628 QPainter myNorthPainter( &myNorthArrow ); 00629 QSvgRenderer mySvgRenderer( mNorthArrowFile ); 00630 mySvgRenderer.render( &myNorthPainter ); 00631 myPrintPainter.drawPixmap( myOriginX + (( myLogoXDim / 2 ) ), 00632 myOriginY, 00633 myNorthArrow ); 00634 00635 // 00636 // Draw the scale bar 00637 // 00638 myOriginY += myLogoYDim / 2 + myVerticalSpacing; 00639 myPrintPainter.setViewport( myOriginX, 00640 myOriginY, 00641 myOriginalViewport.width(), 00642 myOriginalViewport.height() ); 00643 renderPrintScaleBar( &myPrintPainter, mpMapRenderer, myLogoXDim ); 00644 myPrintPainter.setViewport( myOriginalViewport ); 00645 00646 // 00647 // Finish up 00648 // 00649 00650 00651 myPrintPainter.end(); 00652 #if 0 00653 mProgressDialog.setValue( 0 ); 00654 mProgressDialog.setLabelText( tr( "Please wait while your report is generated", "COMMENTED OUT" ) ); 00655 mProgressDialog.show(); 00656 mProgressDialog.setWindowModality( Qt::WindowModal ); 00657 mProgressDialog.setAutoClose( true ); 00658 #endif 00659 // 00660 // Restore the map render to its former glory 00661 // 00662 mpMapRenderer->setOutputSize( myOriginalSize, myOriginalDpi ); 00663 } 00664 00665 void QgsQuickPrint::scaleTextLabels( int theScaleFactor, SymbolScalingType theDirection ) 00666 { 00667 if ( 0 >= theScaleFactor ) 00668 { 00669 QgsDebugMsg( "invalid scale factor" ); 00670 return; 00671 } 00672 QStringList myLayerSet = mpMapRenderer->layerSet(); 00673 QStringListIterator myLayerIterator( myLayerSet ); 00674 while ( myLayerIterator.hasNext() ) 00675 { 00676 QString myLayerId = myLayerIterator.next(); 00677 QgsDebugMsg( "Scaling text labels for print for " + myLayerId ); 00678 QgsMapLayer * mypLayer = 00679 QgsMapLayerRegistry::instance()->mapLayer( myLayerId ); 00680 if ( mypLayer ) 00681 { 00682 QgsVectorLayer *mypVectorLayer = 00683 qobject_cast<QgsVectorLayer *>( mypLayer ); 00684 if ( mypVectorLayer ) 00685 { 00686 QgsLabel * mypLabel = mypVectorLayer->label(); 00687 QgsLabelAttributes * mypLabelAttributes = mypLabel->labelAttributes(); 00688 if ( theDirection == ScaleUp ) 00689 { 00690 mypLabelAttributes->setSize( 00691 mypLabelAttributes->size() * theScaleFactor, 00692 mypLabelAttributes->sizeType() ); 00693 } 00694 else //scale down 00695 { 00696 mypLabelAttributes->setSize( 00697 mypLabelAttributes->size() / theScaleFactor, 00698 mypLabelAttributes->sizeType() ); 00699 } 00700 } //if vectorlayer 00701 } //if maplayer 00702 } //layer iterator 00703 } 00704 00705 void QgsQuickPrint::scalePointSymbols( int theScaleFactor, SymbolScalingType theDirection ) 00706 { 00707 if ( 0 >= theScaleFactor ) 00708 { 00709 QgsDebugMsg( "invalid scale factor" ); 00710 return; 00711 } 00712 QStringList myLayerSet = mpMapRenderer->layerSet(); 00713 QStringListIterator myLayerIterator( myLayerSet ); 00714 while ( myLayerIterator.hasNext() ) 00715 { 00716 QString myLayerId = myLayerIterator.next(); 00717 QgsDebugMsg( "Scaling point symbols for print for " + myLayerId ); 00718 QgsMapLayer * mypLayer = 00719 QgsMapLayerRegistry::instance()->mapLayer( myLayerId ); 00720 if ( mypLayer ) 00721 { 00722 QgsVectorLayer *mypVectorLayer = 00723 qobject_cast<QgsVectorLayer *>( mypLayer ); 00724 if ( mypVectorLayer ) 00725 { 00726 const QgsRenderer* mypRenderer = mypVectorLayer->renderer(); 00727 const QList<QgsSymbol*> mySymbolList = mypRenderer->symbols(); 00728 // 00729 // Single symbol 00730 // 00731 if ( 1 == mySymbolList.size() ) 00732 { 00733 QgsSymbol * mypSymbol = mySymbolList.at( 0 ); 00734 if ( mypSymbol->type() == QGis::Point ) 00735 { 00736 if ( theDirection == ScaleUp ) 00737 { 00738 mypSymbol->setPointSize( mypSymbol->pointSize() * theScaleFactor ); 00739 } 00740 else //Scale Down 00741 { 00742 mypSymbol->setPointSize( mypSymbol->pointSize() / theScaleFactor ); 00743 } 00744 } 00745 } 00746 else //class breaks 00747 { 00748 QListIterator<QgsSymbol *> myIterator( mySymbolList ); 00749 while ( myIterator.hasNext() ) 00750 { 00751 QgsSymbol * mypSymbol = myIterator.next(); 00752 if ( mypSymbol->type() == QGis::Point ) 00753 { 00754 if ( theDirection == ScaleUp ) 00755 { 00756 mypSymbol->setPointSize( mypSymbol->pointSize() * theScaleFactor ); 00757 } 00758 else //Scale Down 00759 { 00760 mypSymbol->setPointSize( mypSymbol->pointSize() / theScaleFactor ); 00761 } 00762 } 00763 } //symbol loop 00764 } //class breaks 00765 } //if vectorlayer 00766 } //if maplayer 00767 } //layer iterator 00768 } 00769 00770 00771 00772 void QgsQuickPrint::renderPrintScaleBar( QPainter * thepPainter, 00773 QgsMapRenderer * thepMapRenderer, 00774 int theMaximumWidth ) 00775 { 00776 //hard coding some options for now 00777 bool mySnappingFlag = true; 00778 QColor mColor = Qt::black; 00779 // Hard coded sizes 00780 int myTextOffsetX = 0; 00781 int myTextOffsetY = 5; 00782 int myXMargin = 20; 00783 int myYMargin = 20; 00784 int myPreferredSize = theMaximumWidth - ( myXMargin * 2 ); 00785 double myActualSize = 0; 00786 int myBufferSize = 1; //softcode this later 00787 QColor myBackColor = Qt::white; //used for text 00788 QColor myForeColor = Qt::black; //used for text 00789 00790 //Get canvas dimensions 00791 //int myCanvasHeight = thepMapCanvas->height(); 00792 00793 //Get map units per pixel. This can be negative at times (to do with 00794 //projections) and that just confuses the rest of the code in this 00795 //function, so force to a positive number. 00796 double myMapUnitsPerPixelDouble = qAbs( thepMapRenderer->mapUnitsPerPixel() ); 00797 // 00798 // Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze 00799 int myLayerCount = thepMapRenderer->layerSet().count(); 00800 if ( !myLayerCount || !myMapUnitsPerPixelDouble ) return; 00801 00802 //Calculate size of scale bar for preferred number of map units 00803 double myScaleBarWidth = myPreferredSize; 00804 myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble; 00805 00806 00807 // Work out the exponent for the number - e.g, 1234 will give 3, 00808 // and .001234 will give -3 00809 double myPowerOf10 = floor( log10( myActualSize ) ); 00810 00811 // snap to integer < 10 times power of 10 00812 if ( mySnappingFlag ) 00813 { 00814 double scaler = pow( 10.0, myPowerOf10 ); 00815 myActualSize = round( myActualSize / scaler ) * scaler; 00816 myScaleBarWidth = myActualSize / myMapUnitsPerPixelDouble; 00817 } 00818 00819 //Get type of map units and set scale bar unit label text 00820 QGis::UnitType myMapUnits = thepMapRenderer->mapUnits(); 00821 QString myScaleBarUnitLabel; 00822 switch ( myMapUnits ) 00823 { 00824 case QGis::Meters: 00825 if ( myActualSize > 1000.0 ) 00826 { 00827 myScaleBarUnitLabel = tr( " km" ); 00828 myActualSize = myActualSize / 1000; 00829 } 00830 else if ( myActualSize < 0.01 ) 00831 { 00832 myScaleBarUnitLabel = tr( " mm" ); 00833 myActualSize = myActualSize * 1000; 00834 } 00835 else if ( myActualSize < 0.1 ) 00836 { 00837 myScaleBarUnitLabel = tr( " cm" ); 00838 myActualSize = myActualSize * 100; 00839 } 00840 else 00841 myScaleBarUnitLabel = tr( " m" ); 00842 break; 00843 case QGis::Feet: 00844 if ( myActualSize > 5280.0 ) //5280 feet to the mile 00845 { 00846 myScaleBarUnitLabel = tr( " miles" ); 00847 myActualSize = myActualSize / 5280; 00848 } 00849 else if ( myActualSize == 5280.0 ) //5280 feet to the mile 00850 { 00851 myScaleBarUnitLabel = tr( " mile" ); 00852 myActualSize = myActualSize / 5280; 00853 } 00854 else if ( myActualSize < 1 ) 00855 { 00856 myScaleBarUnitLabel = tr( " inches" ); 00857 myActualSize = myActualSize * 12; 00858 } 00859 else if ( myActualSize == 1.0 ) 00860 { 00861 myScaleBarUnitLabel = tr( " foot" ); 00862 } 00863 else 00864 { 00865 myScaleBarUnitLabel = tr( " feet" ); 00866 } 00867 break; 00868 case QGis::Degrees: 00869 if ( myActualSize == 1.0 ) 00870 myScaleBarUnitLabel = tr( " degree" ); 00871 else 00872 myScaleBarUnitLabel = tr( " degrees" ); 00873 break; 00874 case QGis::UnknownUnit: 00875 myScaleBarUnitLabel = tr( " unknown" ); 00876 default: 00877 QgsDebugMsg( "Error: not picked up map units - actual value = " 00878 + QString::number( myMapUnits ) ); 00879 }; 00880 00881 //Set font and calculate width of unit label 00882 int myFontSize = 10; //we use this later for buffering 00883 QFont myFont( "helvetica", myFontSize ); 00884 thepPainter->setFont( myFont ); 00885 QFontMetrics myFontMetrics( myFont ); 00886 double myFontWidth = myFontMetrics.width( myScaleBarUnitLabel ); 00887 double myFontHeight = myFontMetrics.height(); 00888 00889 //Set the maximum label 00890 QString myScaleBarMaxLabel = QString::number( myActualSize ); 00891 00892 //Calculate total width of scale bar and label 00893 //we divide by 2 because the max scale label 00894 //will be centered over the endpoint of the scale bar 00895 double myTotalScaleBarWidth = myScaleBarWidth + ( myFontWidth / 2 ); 00896 00897 //determine the origin of scale bar (bottom right) 00898 //for x origin set things up so the scalebar is centered 00899 int myOriginX = ( theMaximumWidth - myTotalScaleBarWidth ) / 2; 00900 int myOriginY = myYMargin; 00901 00902 //Set pen to draw with 00903 QPen myForegroundPen( mColor, 2 ); 00904 QPen myBackgroundPen( Qt::white, 3 ); 00905 00906 //Cast myScaleBarWidth to int for drawing 00907 int myScaleBarWidthInt = ( int ) myScaleBarWidth; 00908 00909 //now draw the bar itself in user selected color 00910 thepPainter->setPen( myForegroundPen ); 00911 //make a glossygradient for the background 00912 QGradientStops myStops; 00913 myStops << QGradientStop( 0.0, QColor( "#616161" ) ); 00914 myStops << QGradientStop( 0.5, QColor( "#505050" ) ); 00915 myStops << QGradientStop( 0.6, QColor( "#434343" ) ); 00916 myStops << QGradientStop( 1.0, QColor( "#656565" ) ); 00917 //draw again with the brush in the revers direction to complete teh glossiness 00918 QLinearGradient myReverseGlossyBrush( 00919 QPointF( myOriginX, myOriginY + myFontHeight*3 ), 00920 QPointF( myOriginX, myOriginY ) ); 00921 thepPainter->setBrush( myReverseGlossyBrush ); 00922 thepPainter->drawRect( 00923 myOriginX, 00924 myOriginY, 00925 myOriginX + myScaleBarWidthInt, 00926 myOriginY + myFontHeight 00927 ); 00928 00929 // 00930 //Do drawing of scale bar text 00931 // 00932 00933 00934 //Draw the minimum label buffer 00935 thepPainter->setPen( myBackColor ); 00936 myFontWidth = myFontMetrics.width( "0" ); 00937 00938 for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) 00939 { 00940 for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) 00941 { 00942 thepPainter->drawText( int( i + ( myOriginX - ( myFontWidth / 2 ) ) ), 00943 int( j + ( myOriginY - ( myFontHeight / 4 ) ) ) - myTextOffsetY, 00944 "0" ); 00945 } 00946 } 00947 00948 //Draw minimum label 00949 thepPainter->setPen( myForeColor ); 00950 00951 thepPainter->drawText( 00952 int( myOriginX - ( myFontWidth / 2 ) ), 00953 int( myOriginY - ( myFontHeight / 4 ) ) - myTextOffsetY, 00954 "0" 00955 ); 00956 00957 // 00958 //Draw maximum label 00959 // 00960 thepPainter->setPen( myBackColor ); 00961 myFontWidth = myFontMetrics.width( myScaleBarMaxLabel ); 00962 myFontHeight = myFontMetrics.height(); 00963 //first the buffer 00964 for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) 00965 { 00966 for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) 00967 { 00968 thepPainter->drawText( int( i + ( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ) ), 00969 int( j + ( myOriginY - ( myFontHeight / 4 ) ) ) - myTextOffsetY, 00970 myScaleBarMaxLabel ); 00971 } 00972 } 00973 //then the text itself 00974 thepPainter->setPen( myForeColor ); 00975 thepPainter->drawText( 00976 int( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ), 00977 int( myOriginY - ( myFontHeight / 4 ) ) - myTextOffsetY, 00978 myScaleBarMaxLabel 00979 ); 00980 00981 // 00982 //Draw unit label 00983 // 00984 thepPainter->setPen( myBackColor ); 00985 myFontWidth = myFontMetrics.width( myScaleBarUnitLabel ); 00986 //first the buffer 00987 for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) 00988 { 00989 for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) 00990 { 00991 thepPainter->drawText( i + ( myOriginX + myScaleBarWidthInt + myTextOffsetX ), 00992 j + myOriginY + myFontHeight + ( myFontHeight*2.5 ) + myTextOffsetY, 00993 myScaleBarUnitLabel ); 00994 } 00995 } 00996 //then the text itself 00997 thepPainter->setPen( myForeColor ); 00998 thepPainter->drawText( 00999 myOriginX + myScaleBarWidthInt + myTextOffsetX, 01000 myOriginY + myFontHeight + ( myFontHeight*2.5 ) + myTextOffsetY, 01001 myScaleBarUnitLabel 01002 ); 01003 } 01004 01005 QStringList QgsQuickPrint::wordWrap( QString theString, 01006 QFontMetrics theMetrics, 01007 int theWidth ) 01008 { 01009 //iterate the string 01010 QStringList myList; 01011 QString myCumulativeLine = ""; 01012 QString myStringToPreviousSpace = ""; 01013 int myPreviousSpacePos = 0; 01014 for ( int i = 0; i < theString.count(); ++i ) 01015 { 01016 QChar myChar = theString.at( i ); 01017 if ( myChar == QChar( ' ' ) ) 01018 { 01019 myStringToPreviousSpace = myCumulativeLine; 01020 myPreviousSpacePos = i; 01021 } 01022 myCumulativeLine += myChar; 01023 if ( theMetrics.width( myCumulativeLine ) >= theWidth ) 01024 { 01025 //time to wrap 01026 //@todo deal with long strings that have no spaces 01027 //forcing a break at current pos... 01028 myList << myStringToPreviousSpace.trimmed(); 01029 i = myPreviousSpacePos; 01030 myStringToPreviousSpace = ""; 01031 myCumulativeLine = ""; 01032 } 01033 }//end of i loop 01034 //add whatever is left in the string to the list 01035 if ( !myCumulativeLine.trimmed().isEmpty() ) 01036 { 01037 myList << myCumulativeLine.trimmed(); 01038 } 01039 01040 //qDebug("Wrapped legend entry: %s\n%s", theString, myList.join("\n").toLocal8Bit().constData() ); 01041 return myList; 01042 01043 } 01044 QString QgsQuickPrint::pageSizeToString( QPrinter::PageSize theSize ) 01045 { 01046 if ( theSize == QPrinter::A0 ) return "QPrinter::A0"; 01047 if ( theSize == QPrinter::A1 ) return "QPrinter::A1"; 01048 if ( theSize == QPrinter::A2 ) return "QPrinter::A2"; 01049 if ( theSize == QPrinter::A3 ) return "QPrinter::A3"; 01050 if ( theSize == QPrinter::A4 ) return "QPrinter::A4"; 01051 if ( theSize == QPrinter::A5 ) return "QPrinter::A5"; 01052 if ( theSize == QPrinter::A6 ) return "QPrinter::A6"; 01053 if ( theSize == QPrinter::A7 ) return "QPrinter::A7"; 01054 if ( theSize == QPrinter::A8 ) return "QPrinter::A8"; 01055 if ( theSize == QPrinter::A9 ) return "QPrinter::A9"; 01056 if ( theSize == QPrinter::B0 ) return "QPrinter::B0"; 01057 if ( theSize == QPrinter::B1 ) return "QPrinter::B1"; 01058 if ( theSize == QPrinter::B10 ) return "QPrinter::B10"; 01059 if ( theSize == QPrinter::B2 ) return "QPrinter::B2"; 01060 if ( theSize == QPrinter::B3 ) return "QPrinter::B3"; 01061 if ( theSize == QPrinter::B4 ) return "QPrinter::B4"; 01062 if ( theSize == QPrinter::B5 ) return "QPrinter::B5"; 01063 if ( theSize == QPrinter::B6 ) return "QPrinter::B6"; 01064 if ( theSize == QPrinter::B7 ) return "QPrinter::B7"; 01065 if ( theSize == QPrinter::B8 ) return "QPrinter::B8"; 01066 if ( theSize == QPrinter::B9 ) return "QPrinter::B9"; 01067 if ( theSize == QPrinter::C5E ) return "QPrinter::C5E"; 01068 if ( theSize == QPrinter::Comm10E ) return "QPrinter::Comm10E"; 01069 if ( theSize == QPrinter::DLE ) return "QPrinter::DLE"; 01070 if ( theSize == QPrinter::Executive ) return "QPrinter::Executive"; 01071 if ( theSize == QPrinter::Folio ) return "QPrinter::Folio"; 01072 if ( theSize == QPrinter::Ledger ) return "QPrinter::Ledger"; 01073 if ( theSize == QPrinter::Legal ) return "QPrinter::Legal"; 01074 if ( theSize == QPrinter::Letter ) return "QPrinter::Letter"; 01075 //falback 01076 return "QPrinter::A4"; 01077 01078 } 01079 01080 QPrinter::PageSize QgsQuickPrint::stringToPageSize( QString theSize ) 01081 { 01082 if ( theSize == "QPrinter::A0" ) return QPrinter::A0; 01083 if ( theSize == "QPrinter::A1" ) return QPrinter::A1; 01084 if ( theSize == "QPrinter::A2" ) return QPrinter::A2; 01085 if ( theSize == "QPrinter::A3" ) return QPrinter::A3; 01086 if ( theSize == "QPrinter::A4" ) return QPrinter::A4; 01087 if ( theSize == "QPrinter::A5" ) return QPrinter::A5; 01088 if ( theSize == "QPrinter::A6" ) return QPrinter::A6; 01089 if ( theSize == "QPrinter::A7" ) return QPrinter::A7; 01090 if ( theSize == "QPrinter::A8" ) return QPrinter::A8; 01091 if ( theSize == "QPrinter::A9" ) return QPrinter::A9; 01092 if ( theSize == "QPrinter::B0" ) return QPrinter::B0; 01093 if ( theSize == "QPrinter::B1" ) return QPrinter::B1; 01094 if ( theSize == "QPrinter::B10" ) return QPrinter::B10; 01095 if ( theSize == "QPrinter::B2" ) return QPrinter::B2; 01096 if ( theSize == "QPrinter::B3" ) return QPrinter::B3; 01097 if ( theSize == "QPrinter::B4" ) return QPrinter::B4; 01098 if ( theSize == "QPrinter::B5" ) return QPrinter::B5; 01099 if ( theSize == "QPrinter::B6" ) return QPrinter::B6; 01100 if ( theSize == "QPrinter::B7" ) return QPrinter::B7; 01101 if ( theSize == "QPrinter::B8" ) return QPrinter::B8; 01102 if ( theSize == "QPrinter::B9" ) return QPrinter::B9; 01103 if ( theSize == "QPrinter::C5E" ) return QPrinter::C5E; 01104 if ( theSize == "QPrinter::Comm10E" ) return QPrinter::Comm10E; 01105 if ( theSize == "QPrinter::DLE" ) return QPrinter::DLE; 01106 if ( theSize == "QPrinter::Executive" ) return QPrinter::Executive; 01107 if ( theSize == "QPrinter::Folio" ) return QPrinter::Folio; 01108 if ( theSize == "QPrinter::Ledger" ) return QPrinter::Ledger; 01109 if ( theSize == "QPrinter::Legal" ) return QPrinter::Legal; 01110 if ( theSize == "QPrinter::Letter" ) return QPrinter::Letter; 01111 //falback 01112 return QPrinter::A4; 01113 01114 } 01115 01116 01117