src/gui/painting/qprinter.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
   156     const qreal multiplier = qt_multiplierForUnit(unit, resolution);
   156     const qreal multiplier = qt_multiplierForUnit(unit, resolution);
   157     return QSizeF((qt_paperSizes[paperSize][width_index] * 72 / 25.4) / multiplier,
   157     return QSizeF((qt_paperSizes[paperSize][width_index] * 72 / 25.4) / multiplier,
   158                   (qt_paperSizes[paperSize][height_index] * 72 / 25.4) / multiplier);
   158                   (qt_paperSizes[paperSize][height_index] * 72 / 25.4) / multiplier);
   159 }
   159 }
   160 
   160 
   161 
       
   162 // returns the actual num copies set on a printer, not
       
   163 // the number that is documented in QPrinter::numCopies()
       
   164 int qt_printerRealNumCopies(QPaintEngine *engine)
       
   165 {
       
   166     int numCopies = 1;
       
   167     if (engine->type() == QPaintEngine::PostScript
       
   168         || engine->type() == QPaintEngine::Pdf)
       
   169     {
       
   170         QPdfBaseEngine *base = static_cast<QPdfBaseEngine *>(engine);
       
   171         numCopies = base->d_func()->copies;
       
   172     }
       
   173 #ifdef Q_WS_WIN
       
   174     else if (engine->type() == QPaintEngine::Windows) {
       
   175         QWin32PrintEngine *base = static_cast<QWin32PrintEngine *>(engine);
       
   176         numCopies = base->d_func()->num_copies;
       
   177     }
       
   178 #endif
       
   179     return numCopies;
       
   180 }
       
   181 
       
   182 void QPrinterPrivate::createDefaultEngines()
   161 void QPrinterPrivate::createDefaultEngines()
   183 {
   162 {
   184     QPrinter::OutputFormat realOutputFormat = outputFormat;
   163     QPrinter::OutputFormat realOutputFormat = outputFormat;
   185 #if !defined (QTOPIA_PRINTENGINE)
   164 #if !defined (QTOPIA_PRINTENGINE)
   186 #if defined (Q_OS_UNIX) && ! defined (Q_WS_MAC)
   165 #if defined (Q_OS_UNIX) && ! defined (Q_WS_MAC)
   300   printer.
   279   printer.
   301   \i setResolution() tells QPrinter what resolution you wish the
   280   \i setResolution() tells QPrinter what resolution you wish the
   302   printer to provide, in dots per inch (DPI).
   281   printer to provide, in dots per inch (DPI).
   303   \i setFullPage() tells QPrinter whether you want to deal with the
   282   \i setFullPage() tells QPrinter whether you want to deal with the
   304   full page or just with the part the printer can draw on.
   283   full page or just with the part the printer can draw on.
   305   \i setNumCopies() tells QPrinter how many copies of the document
   284   \i setCopyCount() tells QPrinter how many copies of the document
   306   it should print.
   285   it should print.
   307   \endlist
   286   \endlist
   308 
   287 
   309   Many of these functions can only be called before the actual printing
   288   Many of these functions can only be called before the actual printing
   310   begins (i.e., before QPainter::begin() is called). This usually makes
   289   begins (i.e., before QPainter::begin() is called). This usually makes
   401     Used to specify the print range selection option.
   380     Used to specify the print range selection option.
   402 
   381 
   403     \value AllPages All pages should be printed.
   382     \value AllPages All pages should be printed.
   404     \value Selection Only the selection should be printed.
   383     \value Selection Only the selection should be printed.
   405     \value PageRange The specified page range should be printed.
   384     \value PageRange The specified page range should be printed.
       
   385     \value CurrentPage Only the current page should be printed.
   406 
   386 
   407     \sa QAbstractPrintDialog::PrintRange
   387     \sa QAbstractPrintDialog::PrintRange
   408 */
   388 */
   409 
   389 
   410 /*!
   390 /*!
   590   should use to print.
   570   should use to print.
   591 
   571 
   592   \value AllPages All the pages should be printed.
   572   \value AllPages All the pages should be printed.
   593   \value Selection Only the selection should be printed.
   573   \value Selection Only the selection should be printed.
   594   \value PageRange Print according to the from page and to page options.
   574   \value PageRange Print according to the from page and to page options.
       
   575   \value CurrentPage Only the current page should be printed.
   595 
   576 
   596   \sa setPrintRange(), printRange()
   577   \sa setPrintRange(), printRange()
   597 */
   578 */
   598 
   579 
   599 /*
   580 /*
   605 
   586 
   606   \value PrintToFile Describes if print to file should be enabled.
   587   \value PrintToFile Describes if print to file should be enabled.
   607   \value PrintSelection Describes if printing selections should be enabled.
   588   \value PrintSelection Describes if printing selections should be enabled.
   608   \value PrintPageRange Describes if printing page ranges (from, to) should
   589   \value PrintPageRange Describes if printing page ranges (from, to) should
   609   be enabled
   590   be enabled
       
   591   \value PrintCurrentPage if Print Current Page option should be enabled
   610 
   592 
   611   \sa setOptionEnabled(), isOptionEnabled()
   593   \sa setOptionEnabled(), isOptionEnabled()
   612 */
   594 */
   613 
   595 
   614 /*!
   596 /*!
   746     if (d->validPrinter && d->outputFormat == format)
   728     if (d->validPrinter && d->outputFormat == format)
   747         return;
   729         return;
   748     d->outputFormat = format;
   730     d->outputFormat = format;
   749 
   731 
   750     QPrintEngine *oldPrintEngine = d->printEngine;
   732     QPrintEngine *oldPrintEngine = d->printEngine;
   751     QPaintEngine *oldPaintEngine = d->paintEngine; // same as the above - shouldn't be deleted
       
   752     const bool def_engine = d->use_default_engine;
   733     const bool def_engine = d->use_default_engine;
   753     d->printEngine = 0;
   734     d->printEngine = 0;
   754 
   735 
   755     d->createDefaultEngines();
   736     d->createDefaultEngines();
   756 
   737 
   759             QPrintEngine::PrintEnginePropertyKey key = d->manualSetList[i];
   740             QPrintEngine::PrintEnginePropertyKey key = d->manualSetList[i];
   760             QVariant prop;
   741             QVariant prop;
   761             // PPK_NumberOfCopies need special treatmeant since it in most cases
   742             // PPK_NumberOfCopies need special treatmeant since it in most cases
   762             // will return 1, disregarding the actual value that was set
   743             // will return 1, disregarding the actual value that was set
   763             if (key == QPrintEngine::PPK_NumberOfCopies)
   744             if (key == QPrintEngine::PPK_NumberOfCopies)
   764                 prop = QVariant(qt_printerRealNumCopies(oldPaintEngine));
   745                 prop = QVariant(copyCount());
   765             else
   746             else
   766                 prop = oldPrintEngine->property(key);
   747                 prop = oldPrintEngine->property(key);
   767             if (prop.isValid())
   748             if (prop.isValid())
   768                 d->printEngine->setProperty(key, prop);
   749                 d->printEngine->setProperty(key, prop);
   769         }
   750         }
  1261     return QPrinter::ColorMode(d->printEngine->property(QPrintEngine::PPK_ColorMode).toInt());
  1242     return QPrinter::ColorMode(d->printEngine->property(QPrintEngine::PPK_ColorMode).toInt());
  1262 }
  1243 }
  1263 
  1244 
  1264 
  1245 
  1265 /*!
  1246 /*!
       
  1247   \obsolete
  1266   Returns the number of copies to be printed. The default value is 1.
  1248   Returns the number of copies to be printed. The default value is 1.
  1267 
  1249 
  1268   On Windows, Mac OS X and X11 systems that support CUPS, this will always
  1250   On Windows, Mac OS X and X11 systems that support CUPS, this will always
  1269   return 1 as these operating systems can internally handle the number
  1251   return 1 as these operating systems can internally handle the number
  1270   of copies.
  1252   of copies.
  1273   required to print in order to match the number specified in the printer setup
  1255   required to print in order to match the number specified in the printer setup
  1274   dialog. This has been done since some printer drivers are not capable of
  1256   dialog. This has been done since some printer drivers are not capable of
  1275   buffering up the copies and in those cases the application must make an
  1257   buffering up the copies and in those cases the application must make an
  1276   explicit call to the print code for each copy.
  1258   explicit call to the print code for each copy.
  1277 
  1259 
       
  1260   Use copyCount() in conjunction with supportsMultipleCopies() instead.
       
  1261 
  1278   \sa setNumCopies(), actualNumCopies()
  1262   \sa setNumCopies(), actualNumCopies()
  1279 */
  1263 */
  1280 
  1264 
  1281 int QPrinter::numCopies() const
  1265 int QPrinter::numCopies() const
  1282 {
  1266 {
  1284    return d->printEngine->property(QPrintEngine::PPK_NumberOfCopies).toInt();
  1268    return d->printEngine->property(QPrintEngine::PPK_NumberOfCopies).toInt();
  1285 }
  1269 }
  1286 
  1270 
  1287 
  1271 
  1288 /*!
  1272 /*!
       
  1273     \obsolete
  1289     \since 4.6
  1274     \since 4.6
  1290 
  1275 
  1291     Returns the number of copies that will be printed. The default
  1276     Returns the number of copies that will be printed. The default
  1292     value is 1.
  1277     value is 1.
  1293 
  1278 
  1294     This function always returns the actual value specified in the print
  1279     This function always returns the actual value specified in the print
  1295     dialog or using setNumCopies().
  1280     dialog or using setNumCopies().
  1296 
  1281 
       
  1282     Use copyCount() instead.
       
  1283 
  1297     \sa setNumCopies(), numCopies()
  1284     \sa setNumCopies(), numCopies()
  1298 */
  1285 */
  1299 int QPrinter::actualNumCopies() const
  1286 int QPrinter::actualNumCopies() const
  1300 {
  1287 {
  1301     Q_D(const QPrinter);
  1288     return copyCount();
  1302     return qt_printerRealNumCopies(d->paintEngine);
  1289 }
  1303 }
  1290 
  1304 
  1291 
  1305 
  1292 
  1306 
  1293 /*!
  1307 /*!
  1294   \obsolete
  1308   Sets the number of copies to be printed to \a numCopies.
  1295   Sets the number of copies to be printed to \a numCopies.
  1309 
  1296 
  1310   The printer driver reads this setting and prints the specified
  1297   The printer driver reads this setting and prints the specified
  1311   number of copies.
  1298   number of copies.
       
  1299 
       
  1300   Use setCopyCount() instead.
  1312 
  1301 
  1313   \sa numCopies()
  1302   \sa numCopies()
  1314 */
  1303 */
  1315 
  1304 
  1316 void QPrinter::setNumCopies(int numCopies)
  1305 void QPrinter::setNumCopies(int numCopies)
  1319     ABORT_IF_ACTIVE("QPrinter::setNumCopies");
  1308     ABORT_IF_ACTIVE("QPrinter::setNumCopies");
  1320     d->printEngine->setProperty(QPrintEngine::PPK_NumberOfCopies, numCopies);
  1309     d->printEngine->setProperty(QPrintEngine::PPK_NumberOfCopies, numCopies);
  1321     d->addToManualSetList(QPrintEngine::PPK_NumberOfCopies);
  1310     d->addToManualSetList(QPrintEngine::PPK_NumberOfCopies);
  1322 }
  1311 }
  1323 
  1312 
       
  1313 /*!
       
  1314     \since 4.7
       
  1315 
       
  1316     Sets the number of copies to be printed to \a count.
       
  1317 
       
  1318     The printer driver reads this setting and prints the specified number of
       
  1319     copies.
       
  1320 
       
  1321     \sa copyCount(), supportsMultipleCopies()
       
  1322 */
       
  1323 
       
  1324 void QPrinter::setCopyCount(int count)
       
  1325 {
       
  1326     Q_D(QPrinter);
       
  1327     ABORT_IF_ACTIVE("QPrinter::setCopyCount;");
       
  1328     d->printEngine->setProperty(QPrintEngine::PPK_CopyCount, count);
       
  1329     d->addToManualSetList(QPrintEngine::PPK_CopyCount);
       
  1330 }
       
  1331 
       
  1332 /*!
       
  1333     \since 4.7
       
  1334 
       
  1335     Returns the number of copies that will be printed. The default value is 1.
       
  1336 
       
  1337     \sa setCopyCount(), supportsMultipleCopies()
       
  1338 */
       
  1339 
       
  1340 int QPrinter::copyCount() const
       
  1341 {
       
  1342     Q_D(const QPrinter);
       
  1343     return d->printEngine->property(QPrintEngine::PPK_CopyCount).toInt();
       
  1344 }
       
  1345 
       
  1346 /*!
       
  1347     \since 4.7
       
  1348 
       
  1349     Returns true if the printer supports printing multiple copies of the same
       
  1350     document in one job; otherwise false is returned.
       
  1351 
       
  1352     On most systems this function will return true. However, on X11 systems
       
  1353     that do not support CUPS, this function will return false. That means the
       
  1354     application has to handle the number of copies by printing the same
       
  1355     document the required number of times.
       
  1356 
       
  1357     \sa setCopyCount(), copyCount()
       
  1358 */
       
  1359 
       
  1360 bool QPrinter::supportsMultipleCopies() const
       
  1361 {
       
  1362     Q_D(const QPrinter);
       
  1363     return d->printEngine->property(QPrintEngine::PPK_SupportsMultipleCopies).toBool();
       
  1364 }
  1324 
  1365 
  1325 /*!
  1366 /*!
  1326     \since 4.1
  1367     \since 4.1
  1327 
  1368 
  1328     Returns true if collation is turned on when multiple copies is selected.
  1369     Returns true if collation is turned on when multiple copies is selected.
  2260     printer.
  2301     printer.
  2261 
  2302 
  2262     \value PPK_FullPage A boolean describing if the printer should be
  2303     \value PPK_FullPage A boolean describing if the printer should be
  2263     full page or not.
  2304     full page or not.
  2264 
  2305 
  2265     \value PPK_NumberOfCopies An integer specifying the number of
  2306     \value PPK_NumberOfCopies Obsolete. An integer specifying the number of
  2266     copies
  2307     copies. Use PPK_CopyCount instead.
  2267 
  2308 
  2268     \value PPK_Orientation Specifies a QPrinter::Orientation value.
  2309     \value PPK_Orientation Specifies a QPrinter::Orientation value.
  2269 
  2310 
  2270     \value PPK_OutputFileName The output file name as a string. An
  2311     \value PPK_OutputFileName The output file name as a string. An
  2271     empty file name indicates that the printer should not print to a file.
  2312     empty file name indicates that the printer should not print to a file.
  2307     \value PPK_CustomPaperSize A QSizeF specifying a custom paper size
  2348     \value PPK_CustomPaperSize A QSizeF specifying a custom paper size
  2308     in the QPrinter::Point unit.
  2349     in the QPrinter::Point unit.
  2309 
  2350 
  2310     \value PPK_PageMargins A QList<QVariant> containing the left, top,
  2351     \value PPK_PageMargins A QList<QVariant> containing the left, top,
  2311     right and bottom margin values.
  2352     right and bottom margin values.
       
  2353 
       
  2354     \value PPK_CopyCount An integer specifying the number of copies to print.
       
  2355 
       
  2356     \value PPK_SupportsMultipleCopies A boolean value indicating whether or not
       
  2357     the printer supports printing multiple copies in one job.
  2312 
  2358 
  2313     \value PPK_CustomBase Basis for extension.
  2359     \value PPK_CustomBase Basis for extension.
  2314 */
  2360 */
  2315 
  2361 
  2316 /*!
  2362 /*!