Qt 4.8
Public Functions | Public Variables | List of all members
QMacPrintEnginePrivate Class Reference

#include <qprintengine_mac_p.h>

Inheritance diagram for QMacPrintEnginePrivate:
QPaintEnginePrivate

Public Functions

void initialize ()
 
bool isPrintSessionInitialized () const
 
bool newPage_helper ()
 
QPrinter::PaperSize paperSize () const
 
 QMacPrintEnginePrivate ()
 
void releaseSession ()
 
void setPaperSize (QPrinter::PaperSize ps)
 
bool shouldSuppressStatus () const
 
QList< QVariantsupportedResolutions () const
 
 ~QMacPrintEnginePrivate ()
 
- Public Functions inherited from QPaintEnginePrivate
void drawBoxTextItem (const QPointF &p, const QTextItemInt &ti)
 
 QPaintEnginePrivate ()
 
void setSystemTransform (const QTransform &xform)
 
void setSystemViewport (const QRegion &region)
 
virtual void systemStateChanged ()
 
void transformSystemClip ()
 
virtual ~QPaintEnginePrivate ()
 

Public Variables

qreal bottomMargin
 
PMPaper customPaper
 
QSizeF customSize
 
PMPageFormat format
 
bool fullPage
 
bool hasCustomPageMargins
 
bool hasCustomPaperSize
 
qreal leftMargin
 
QPrinter::PrinterMode mode
 
QPrinter::Orientation orient
 
QString outputFilename
 
QPaintEnginepaintEngine
 
NSPrintInfoprintInfo
 
PMResolution resolution
 
qreal rightMargin
 
PMPrintSession session
 
PMPrintSettings settings
 
QPrinter::PrinterState state
 
bool suppressStatus
 
qreal topMargin
 
QHash< QMacPrintEngine::PrintEnginePropertyKey, QVariantvalueCache
 
- Public Variables inherited from QPaintEnginePrivate
QWidgetcurrentClipWidget
 
uint hasSystemTransform: 1
 
uint hasSystemViewport: 1
 
QPaintDevicepdev
 
QPaintEngineq_ptr
 
QRegion systemClip
 
QRect systemRect
 
QTransform systemTransform
 
QRegion systemViewport
 

Detailed Description

Definition at line 116 of file qprintengine_mac_p.h.

Constructors and Destructors

◆ QMacPrintEnginePrivate()

QMacPrintEnginePrivate::QMacPrintEnginePrivate ( )
inline

◆ ~QMacPrintEnginePrivate()

QMacPrintEnginePrivate::~QMacPrintEnginePrivate ( )

Definition at line 140 of file qprintengine_mac.mm.

141 {
142 #ifdef QT_MAC_USE_COCOA
143  [printInfo release];
144 #endif
145  delete paintEngine;
146 }

Functions

◆ initialize()

void QMacPrintEnginePrivate::initialize ( )

Definition at line 420 of file qprintengine_mac.mm.

Referenced by QPrintDialogPrivate::initBeforeRun().

421 {
423 
424 #ifndef QT_MAC_USE_COCOA
425  Q_ASSERT(!session);
426 #else
428 #endif
429 
430  if (!paintEngine)
432 
433  q->gccaps = paintEngine->gccaps;
434 
435  fullPage = false;
436 
437 #ifndef QT_MAC_USE_COCOA
438  if (PMCreateSession(&session) != 0)
439  session = 0;
440 #else
442  printInfo = [[NSPrintInfo alloc] initWithDictionary:[NSDictionary dictionary]];
443  session = static_cast<PMPrintSession>([printInfo PMPrintSession]);
444 #endif
445 
446  PMPrinter printer;
447  if (session && PMSessionGetCurrentPrinter(session, &printer) == noErr) {
448  QList<QVariant> resolutions = supportedResolutions();
449  if (!resolutions.isEmpty() && mode != QPrinter::ScreenResolution) {
450  if (resolutions.count() > 1 && mode == QPrinter::HighResolution) {
451  int max = 0;
452  for (int i = 0; i < resolutions.count(); ++i) {
453  int value = resolutions.at(i).toInt();
454  if (value > max)
455  max = value;
456  }
457  resolution.hRes = resolution.vRes = max;
458  } else {
459  resolution.hRes = resolution.vRes = resolutions.at(0).toInt();
460  }
461  if(resolution.hRes == 0)
462  resolution.hRes = resolution.vRes = 600;
463  } else {
464  resolution.hRes = resolution.vRes = qt_defaultDpi();
465  }
466  }
467 
468 #ifndef QT_MAC_USE_COCOA
469  bool settingsInitialized = (settings != 0);
470  bool settingsOK = !settingsInitialized ? PMCreatePrintSettings(&settings) == noErr : true;
471  if (settingsOK && !settingsInitialized)
472  settingsOK = PMSessionDefaultPrintSettings(session, settings) == noErr;
473 
474 
475  bool formatInitialized = (format != 0);
476  bool formatOK = !formatInitialized ? PMCreatePageFormat(&format) == noErr : true;
477  if (formatOK) {
478  if (!formatInitialized) {
479  formatOK = PMSessionDefaultPageFormat(session, format) == noErr;
480  }
481  formatOK = PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) == noErr;
482  }
483 #else
484  settings = static_cast<PMPrintSettings>([printInfo PMPrintSettings]);
485  format = static_cast<PMPageFormat>([printInfo PMPageFormat]);
486 #endif
487 
488 #ifndef QT_MAC_USE_COCOA
489  if (!settingsOK || !formatOK) {
490  qWarning("QMacPrintEngine::initialize: Unable to initialize QPainter");
492  }
493 #endif
494 
496  for (propC = valueCache.constBegin(); propC != valueCache.constEnd(); propC++) {
497  q->setProperty(propC.key(), propC.value());
498  }
499 }
PaintEngineFeatures gccaps
Definition: qpaintengine.h:240
QHash< QMacPrintEngine::PrintEnginePropertyKey, QVariant > valueCache
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void NSPrintInfo
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
QPrinter::PrinterMode mode
QPrinter::PrinterState state
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
Q_GUI_EXPORT int qt_defaultDpi()
Definition: qfont.cpp:240
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
QList< QVariant > supportedResolutions() const

◆ isPrintSessionInitialized()

bool QMacPrintEnginePrivate::isPrintSessionInitialized ( ) const
inline

Definition at line 152 of file qprintengine_mac_p.h.

153  {
154 #ifndef QT_MAC_USE_COCOA
155  return session != 0;
156 #else
157  return printInfo != 0;
158 #endif
159  }

◆ newPage_helper()

bool QMacPrintEnginePrivate::newPage_helper ( )

Definition at line 523 of file qprintengine_mac.mm.

524 {
527 
528  if (PMSessionError(session) != noErr) {
529  q->abort();
530  return false;
531  }
532 
533  // pop the stack of saved graphic states, in case we get the same
534  // context back - either way, the stack count should be 0 when we
535  // get the new one
537  while (cgEngine->d_func()->stackCount > 0)
538  cgEngine->d_func()->restoreGraphicsState();
539 
540  OSStatus status =
541 #ifndef QT_MAC_USE_COCOA
542  shouldSuppressStatus() ? PMSessionBeginPageNoDialog(session, format, 0)
543  : PMSessionBeginPage(session, format, 0);
544 #else
545  PMSessionBeginPageNoDialog(session, format, 0);
546 #endif
547  if(status != noErr) {
549  return false;
550  }
551 
552  QRect page = q->property(QPrintEngine::PPK_PageRect).toRect();
553  QRect paper = q->property(QPrintEngine::PPK_PaperRect).toRect();
554 
555  CGContextRef cgContext;
556  OSStatus err = noErr;
557  err = PMSessionGetCGGraphicsContext(session, &cgContext);
558  if(err != noErr) {
559  qWarning("QMacPrintEngine::newPage: Cannot retrieve CoreGraphics context: %ld", long(err));
561  return false;
562  }
563  cgEngine->d_func()->hd = cgContext;
564 
565  // Set the resolution as a scaling ration of 72 (the default).
566  CGContextScaleCTM(cgContext, 72 / resolution.hRes, 72 / resolution.vRes);
567 
568  CGContextScaleCTM(cgContext, 1, -1);
569  CGContextTranslateCTM(cgContext, 0, -paper.height());
570  if (!fullPage)
571  CGContextTranslateCTM(cgContext, page.x() - paper.x(), page.y() - paper.y());
572  cgEngine->d_func()->orig_xform = CGContextGetCTM(cgContext);
573  cgEngine->d_func()->setClip(0);
578  if (cgEngine->painter()->hasClipping())
580  cgEngine->syncState();
581  return true;
582 }
void syncState()
Updates all dirty states in this engine.
QPaintEngineState * state
Definition: qpaintengine.h:239
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
QPaintEngine::DirtyFlags dirtyFlags
Definition: qpaintengine.h:325
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
DirtyFlag
QPaintEngine::updateState().
Definition: qpaintengine.h:125
#define Q_Q(Class)
Definition: qglobal.h:2483
QPainter * painter() const
Returns the paint engine&#39;s painter.
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
Definition: qpainter.cpp:2499
Q_CORE_EXPORT void qWarning(const char *,...)
signed long OSStatus
QPrinter::PrinterState state
bool shouldSuppressStatus() const
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
struct CGContext * CGContextRef

◆ paperSize()

QPrinter::PaperSize QMacPrintEnginePrivate::paperSize ( ) const

Definition at line 202 of file qprintengine_mac.mm.

203 {
204  if (hasCustomPaperSize)
205  return QPrinter::Custom;
206  PMRect paper;
207  PMGetUnadjustedPaperRect(format, &paper);
208  int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
209  int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
210  for (int i = QPrinter::A4; i < QPrinter::NPaperSize; ++i) {
212  if (s.width() == wMM && s.height() == hMM)
213  return (QPrinter::PaperSize)i;
214  }
215  return QPrinter::Custom;
216 }
QSize toSize() const
Returns an integer based copy of this size.
Definition: qsize.h:355
int width() const
Returns the width.
Definition: qsize.h:126
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
int height() const
Returns the height.
Definition: qsize.h:129
QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size)
Definition: qprinter.cpp:2615
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ releaseSession()

void QMacPrintEnginePrivate::releaseSession ( )

Definition at line 501 of file qprintengine_mac.mm.

502 {
503 #ifndef QT_MAC_USE_COCOA
504  if (shouldSuppressStatus()) {
505  PMSessionEndPageNoDialog(session);
506  PMSessionEndDocumentNoDialog(session);
507  } else {
508  PMSessionEndPage(session);
509  PMSessionEndDocument(session);
510  }
511  PMRelease(session);
512 #else
513  PMSessionEndPageNoDialog(session);
514  PMSessionEndDocumentNoDialog(session);
515  [printInfo release];
516 #endif
517  if (hasCustomPaperSize)
518  PMRelease(customPaper);
519  printInfo = 0;
520  session = 0;
521 }
bool shouldSuppressStatus() const

◆ setPaperSize()

void QMacPrintEnginePrivate::setPaperSize ( QPrinter::PaperSize  ps)

Definition at line 148 of file qprintengine_mac.mm.

149 {
151  if (hasCustomPaperSize) {
152  PMRelease(customPaper);
153  customPaper = 0;
154  }
156  PMPrinter printer;
157 
158  if (PMSessionGetCurrentPrinter(session, &printer) == noErr) {
159  if (ps != QPrinter::Custom) {
160  QSize newSize = qt_paperSizeToQSizeF(ps).toSize();
161  QCFType<CFArrayRef> formats;
162  if (PMSessionCreatePageFormatList(session, printer, &formats) == noErr) {
163  CFIndex total = CFArrayGetCount(formats);
164  PMPageFormat tmp;
165  PMRect paper;
166  for (CFIndex idx = 0; idx < total; ++idx) {
167  tmp = static_cast<PMPageFormat>(const_cast<void *>(CFArrayGetValueAtIndex(formats, idx)));
168  PMGetUnadjustedPaperRect(tmp, &paper);
169  int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
170  int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
171  if (newSize.width() == wMM && newSize.height() == hMM) {
172  PMCopyPageFormat(tmp, format);
173  // reset the orientation and resolution as they are lost in the copy.
174  q->setProperty(QPrintEngine::PPK_Orientation, orient);
175  if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) {
176  // Don't know, warn for the moment.
177  qWarning("QMacPrintEngine, problem setting format and resolution for this page size");
178  }
179  break;
180  }
181  }
182  }
183  } else {
185  PMPaperMargins paperMargins;
186  paperMargins.left = leftMargin;
187  paperMargins.top = topMargin;
188  paperMargins.right = rightMargin;
189  paperMargins.bottom = bottomMargin;
190  PMPaperCreateCustom(printer, paperId, QCFString("Custom size"), customSize.width(), customSize.height(), &paperMargins, &customPaper);
191  PMPageFormat tmp;
192  PMCreatePageFormatWithPMPaper(&tmp, customPaper);
193  PMCopyPageFormat(tmp, format);
194  if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) {
195  // Don't know, warn for the moment.
196  qWarning("QMacPrintEngine, problem setting paper name");
197  }
198  }
199  }
200 }
QSize toSize() const
Returns an integer based copy of this size.
Definition: qsize.h:355
static QUuid createUuid()
On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and vers...
Definition: quuid.cpp:897
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
#define Q_Q(Class)
Definition: qglobal.h:2483
int width() const
Returns the width.
Definition: qsize.h:126
static QString toString(Register *reg, int type, bool *ok=0)
Q_CORE_EXPORT void qWarning(const char *,...)
int height() const
Returns the height.
Definition: qsize.h:129
QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size)
Definition: qprinter.cpp:2615
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QPrinter::Orientation orient

◆ shouldSuppressStatus()

bool QMacPrintEnginePrivate::shouldSuppressStatus ( ) const

Definition at line 257 of file qprintengine_mac.mm.

258 {
259  if (suppressStatus == true)
260  return true;
261 
262  // Supress displaying the automatic progress dialog if we are printing
263  // from a non-gui thread.
264  return (qApp->thread() != QThread::currentThread());
265 }
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
#define qApp

◆ supportedResolutions()

QList< QVariant > QMacPrintEnginePrivate::supportedResolutions ( ) const

Definition at line 218 of file qprintengine_mac.mm.

219 {
220  Q_ASSERT_X(session, "QMacPrinterEngine::supportedResolutions",
221  "must have a valid printer session");
222  UInt32 resCount;
223  QList<QVariant> resolutions;
224  PMPrinter printer;
225  if (PMSessionGetCurrentPrinter(session, &printer) == noErr) {
226  PMResolution res;
227  OSStatus status = PMPrinterGetPrinterResolutionCount(printer, &resCount);
228  if (status == kPMNotImplemented) {
229 #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
230  // *Sigh* we have to use the non-indexed version.
231  if (PMPrinterGetPrinterResolution(printer, kPMMinSquareResolution, &res) == noErr)
232  resolutions.append(int(res.hRes));
233  if (PMPrinterGetPrinterResolution(printer, kPMMaxSquareResolution, &res) == noErr) {
234  QVariant var(int(res.hRes));
235  if (!resolutions.contains(var))
236  resolutions.append(var);
237  }
238  if (PMPrinterGetPrinterResolution(printer, kPMDefaultResolution, &res) == noErr) {
239  QVariant var(int(res.hRes));
240  if (!resolutions.contains(var))
241  resolutions.append(var);
242  }
243 #endif
244  } else if (status == noErr) {
245  // According to the docs, index start at 1.
246  for (UInt32 i = 1; i <= resCount; ++i) {
247  if (PMPrinterGetIndexedPrinterResolution(printer, i, &res) == noErr)
248  resolutions.append(QVariant(int(res.hRes)));
249  }
250  } else {
251  qWarning("QMacPrintEngine::supportedResolutions: Unexpected error: %ld", long(status));
252  }
253  }
254  return resolutions;
255 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
Q_CORE_EXPORT void qWarning(const char *,...)
signed long OSStatus
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

Properties

◆ bottomMargin

qreal QMacPrintEnginePrivate::bottomMargin

Definition at line 138 of file qprintengine_mac_p.h.

◆ customPaper

PMPaper QMacPrintEnginePrivate::customPaper

Definition at line 140 of file qprintengine_mac_p.h.

◆ customSize

QSizeF QMacPrintEnginePrivate::customSize

Definition at line 133 of file qprintengine_mac_p.h.

◆ format

PMPageFormat QMacPrintEnginePrivate::format

Definition at line 124 of file qprintengine_mac_p.h.

Referenced by QPrintDialogPrivate::openCarbonPrintPanel().

◆ fullPage

bool QMacPrintEnginePrivate::fullPage

Definition at line 129 of file qprintengine_mac_p.h.

◆ hasCustomPageMargins

bool QMacPrintEnginePrivate::hasCustomPageMargins

Definition at line 134 of file qprintengine_mac_p.h.

◆ hasCustomPaperSize

bool QMacPrintEnginePrivate::hasCustomPaperSize

Definition at line 132 of file qprintengine_mac_p.h.

◆ leftMargin

qreal QMacPrintEnginePrivate::leftMargin

Definition at line 135 of file qprintengine_mac_p.h.

◆ mode

QPrinter::PrinterMode QMacPrintEnginePrivate::mode

Definition at line 120 of file qprintengine_mac_p.h.

◆ orient

QPrinter::Orientation QMacPrintEnginePrivate::orient

Definition at line 122 of file qprintengine_mac_p.h.

◆ outputFilename

QString QMacPrintEnginePrivate::outputFilename

Definition at line 128 of file qprintengine_mac_p.h.

Referenced by QPrintDialogPrivate::closeCarbonPrintPanel().

◆ paintEngine

QPaintEngine* QMacPrintEnginePrivate::paintEngine

Definition at line 130 of file qprintengine_mac_p.h.

◆ printInfo

NSPrintInfo* QMacPrintEnginePrivate::printInfo

Definition at line 123 of file qprintengine_mac_p.h.

◆ resolution

PMResolution QMacPrintEnginePrivate::resolution

Definition at line 127 of file qprintengine_mac_p.h.

◆ rightMargin

qreal QMacPrintEnginePrivate::rightMargin

Definition at line 137 of file qprintengine_mac_p.h.

◆ session

PMPrintSession QMacPrintEnginePrivate::session

◆ settings

PMPrintSettings QMacPrintEnginePrivate::settings

◆ state

QPrinter::PrinterState QMacPrintEnginePrivate::state

◆ suppressStatus

bool QMacPrintEnginePrivate::suppressStatus

Definition at line 131 of file qprintengine_mac_p.h.

◆ topMargin

qreal QMacPrintEnginePrivate::topMargin

Definition at line 136 of file qprintengine_mac_p.h.

◆ valueCache

QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant> QMacPrintEnginePrivate::valueCache

Definition at line 139 of file qprintengine_mac_p.h.


The documentation for this class was generated from the following files: