Qt 4.8
Public Functions | Friends | List of all members
QMacPrintEngine Class Reference

#include <qprintengine_mac_p.h>

Inheritance diagram for QMacPrintEngine:
QPaintEngine QPrintEngine

Public Functions

bool abort ()
 Instructs the print engine to abort the printing process. More...
 
bool begin (QPaintDevice *dev)
 Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. More...
 
virtual void drawEllipse (const QRectF &r)
 Reimplement this function to draw the largest ellipse that can be contained within rectangle rect. More...
 
virtual void drawImage (const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
 Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap. More...
 
virtual void drawLines (const QLineF *lines, int lineCount)
 The default implementation splits the list of lines in lines into lineCount separate calls to drawPath() or drawPolygon() depending on the feature set of the paint engine. More...
 
virtual void drawPath (const QPainterPath &)
 The default implementation ignores the path and does nothing. More...
 
virtual void drawPixmap (const QRectF &r, const QPixmap &pm, const QRectF &sr)
 Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r. More...
 
virtual void drawPoints (const QPointF *p, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
virtual void drawPolygon (const QPointF *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
virtual void drawRects (const QRectF *r, int num)
 Draws the first rectCount rectangles in the buffer rects. More...
 
virtual void drawTextItem (const QPointF &p, const QTextItem &ti)
 This function draws the text item textItem at position p. More...
 
virtual void drawTiledPixmap (const QRectF &r, const QPixmap &pixmap, const QPointF &s)
 Reimplement this function to draw the pixmap in the given rect, starting at the given p. More...
 
bool end ()
 Reimplement this function to finish painting on the current paint device. More...
 
Qt::HANDLE handle () const
 
int metric (QPaintDevice::PaintDeviceMetric) const
 Returns the metric for the given id. More...
 
bool newPage ()
 Instructs the print engine to start a new page. More...
 
QPaintEnginepaintEngine () const
 
QPrinter::PrinterState printerState () const
 Returns the current state of the printer being used by the print engine. More...
 
QVariant property (PrintEnginePropertyKey key) const
 Returns the print engine's property specified by key. More...
 
 QMacPrintEngine (QPrinter::PrinterMode mode)
 
void setProperty (PrintEnginePropertyKey key, const QVariant &value)
 Sets the print engine's property specified by key to the given value. More...
 
virtual QPaintEngine::Type type () const
 Reimplement this function to return the paint engine Type. More...
 
void updateState (const QPaintEngineState &state)
 Reimplement this function to update the state of a paint engine. More...
 
- Public Functions inherited from QPaintEngine
void clearDirty (DirtyFlags df)
 
virtual QPoint coordinateOffset () const
 Returns the offset from the painters origo to the engines origo. More...
 
virtual void drawEllipse (const QRect &r)
 The default implementation of this function calls the floating point version of this function. More...
 
virtual void drawLines (const QLine *lines, int lineCount)
 The default implementation converts the first lineCount lines in lines to a QLineF and calls the floating point version of this function. More...
 
virtual void drawPoints (const QPoint *points, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
virtual void drawPolygon (const QPoint *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
virtual void drawRects (const QRect *rects, int rectCount)
 The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF and calls the floating point version of this function. More...
 
void fix_neg_rect (int *x, int *y, int *w, int *h)
 
virtual HDC getDC () const
 Empty default implementation. More...
 
bool hasFeature (PaintEngineFeatures feature) const
 Returns true if the paint engine supports the specified feature; otherwise returns false. More...
 
bool isActive () const
 Returns true if the paint engine is actively drawing; otherwise returns false. More...
 
bool isExtended () const
 Returns true if the paint engine is a QPaintEngineEx derivative. More...
 
QPaintDevicepaintDevice () const
 Returns the device that this engine is painting on, if painting is active; otherwise returns 0. More...
 
QPainterpainter () const
 Returns the paint engine's painter. More...
 
 QPaintEngine (PaintEngineFeatures features=0)
 Creates a paint engine with the featureset specified by caps. More...
 
virtual void releaseDC (HDC hdc) const
 Empty default implementation. More...
 
void setActive (bool newState)
 Sets the active state of the paint engine to state. More...
 
void setDirty (DirtyFlags df)
 
void setPaintDevice (QPaintDevice *device)
 
void setSystemClip (const QRegion &baseClip)
 Sets the system clip for this engine. More...
 
void setSystemRect (const QRect &rect)
 Sets the target rect for drawing within the backing store. More...
 
void syncState ()
 Updates all dirty states in this engine. More...
 
QRegion systemClip () const
 Returns the system clip. More...
 
QRect systemRect () const
 Retrieves the rect for drawing within the backing store. More...
 
bool testDirty (DirtyFlags df)
 
virtual ~QPaintEngine ()
 Destroys the paint engine. More...
 
- Public Functions inherited from QPrintEngine
virtual HDC getPrinterDC () const
 
virtual void releasePrinterDC (HDC) const
 
virtual ~QPrintEngine ()
 Destroys the print engine. More...
 

Friends

class QPageSetupDialog
 
class QPrintDialog
 

Additional Inherited Members

- Public Types inherited from QPaintEngine
enum  DirtyFlag {
  DirtyPen = 0x0001, DirtyBrush = 0x0002, DirtyBrushOrigin = 0x0004, DirtyFont = 0x0008,
  DirtyBackground = 0x0010, DirtyBackgroundMode = 0x0020, DirtyTransform = 0x0040, DirtyClipRegion = 0x0080,
  DirtyClipPath = 0x0100, DirtyHints = 0x0200, DirtyCompositionMode = 0x0400, DirtyClipEnabled = 0x0800,
  DirtyOpacity = 0x1000, AllDirty = 0xffff
}
 QPaintEngine::updateState(). More...
 
enum  PaintEngineFeature {
  PrimitiveTransform = 0x00000001, PatternTransform = 0x00000002, PixmapTransform = 0x00000004, PatternBrush = 0x00000008,
  LinearGradientFill = 0x00000010, RadialGradientFill = 0x00000020, ConicalGradientFill = 0x00000040, AlphaBlend = 0x00000080,
  PorterDuff = 0x00000100, PainterPaths = 0x00000200, Antialiasing = 0x00000400, BrushStroke = 0x00000800,
  ConstantOpacity = 0x00001000, MaskedBrush = 0x00002000, PerspectiveTransform = 0x00004000, BlendModes = 0x00008000,
  ObjectBoundingModeGradients = 0x00010000, RasterOpModes = 0x00020000, PaintOutsidePaintEvent = 0x20000000, AllFeatures = 0xffffffff
}
 This enum is used to describe the features or capabilities that the paint engine has. More...
 
enum  PolygonDrawMode { OddEvenMode, WindingMode, ConvexMode, PolylineMode }
 
enum  Type {
  X11, Windows, QuickDraw, CoreGraphics,
  MacPrinter, QWindowSystem, PostScript, OpenGL,
  Picture, SVG, Raster, Direct3D,
  Pdf, OpenVG, OpenGL2, PaintBuffer,
  Blitter, User = 50, MaxUser = 100
}
 
- Public Types inherited from QPrintEngine
enum  PrintEnginePropertyKey {
  PPK_CollateCopies, PPK_ColorMode, PPK_Creator, PPK_DocumentName,
  PPK_FullPage, PPK_NumberOfCopies, PPK_Orientation, PPK_OutputFileName,
  PPK_PageOrder, PPK_PageRect, PPK_PageSize, PPK_PaperRect,
  PPK_PaperSource, PPK_PrinterName, PPK_PrinterProgram, PPK_Resolution,
  PPK_SelectionOption, PPK_SupportedResolutions, PPK_WindowsPageSize, PPK_FontEmbedding,
  PPK_SuppressSystemPrintStatus, PPK_Duplex, PPK_PaperSources, PPK_CustomPaperSize,
  PPK_PageMargins, PPK_CopyCount, PPK_SupportsMultipleCopies, PPK_PaperSize = PPK_PageSize,
  PPK_CustomBase = 0xff00
}
 This enum is used to communicate properties between the print engine and QPrinter. More...
 
- Protected Functions inherited from QPaintEngine
 QPaintEngine (QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0)
 
- Protected Variables inherited from QPaintEngine
uint active: 1
 
QScopedPointer< QPaintEnginePrivated_ptr
 
uint extended: 1
 
PaintEngineFeatures gccaps
 
uint selfDestruct: 1
 
QPaintEngineStatestate
 

Detailed Description

Definition at line 73 of file qprintengine_mac_p.h.

Constructors and Destructors

◆ QMacPrintEngine()

QMacPrintEngine::QMacPrintEngine ( QPrinter::PrinterMode  mode)

Definition at line 53 of file qprintengine_mac.mm.

54 {
56  d->mode = mode;
57  d->initialize();
58 }
double d
Definition: qnumeric_p.h:62
QPaintEngine(PaintEngineFeatures features=0)
Creates a paint engine with the featureset specified by caps.
#define Q_D(Class)
Definition: qglobal.h:2482

Functions

◆ abort()

bool QMacPrintEngine::abort ( )
virtual

Instructs the print engine to abort the printing process.

Returns true if successful; otherwise returns false.

Implements QPrintEngine.

Definition at line 297 of file qprintengine_mac.mm.

Referenced by newPage(), and type().

298 {
300  if (d->state != QPrinter::Active)
301  return false;
302  bool ret = end();
303  d->state = QPrinter::Aborted;
304  return ret;
305 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool end()
Reimplement this function to finish painting on the current paint device.

◆ begin()

bool QMacPrintEngine::begin ( QPaintDevice pdev)
virtual

Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev.

Return true if the initialization was successful; otherwise return false.

See also
end() isActive()

Implements QPaintEngine.

Definition at line 60 of file qprintengine_mac.mm.

61 {
63 
64  Q_ASSERT(dev && dev->devType() == QInternal::Printer);
65  if (!static_cast<QPrinter *>(dev)->isValid())
66  return false;
67 
68  if (d->state == QPrinter::Idle && !d->isPrintSessionInitialized()) // Need to reinitialize
69  d->initialize();
70 
71  d->paintEngine->state = state;
72  d->paintEngine->begin(dev);
73  Q_ASSERT_X(d->state == QPrinter::Idle, "QMacPrintEngine", "printer already active");
74 
75  if (PMSessionValidatePrintSettings(d->session, d->settings, kPMDontWantBoolean) != noErr
76  || PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean) != noErr) {
77  d->state = QPrinter::Error;
78  return false;
79  }
80 
81  if (!d->outputFilename.isEmpty()) {
82  QCFType<CFURLRef> outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault,
83  QCFString(d->outputFilename),
84  kCFURLPOSIXPathStyle,
85  false);
86  if (PMSessionSetDestination(d->session, d->settings, kPMDestinationFile,
87  kPMDocumentFormatPDF, outFile) != noErr) {
88  qWarning("QMacPrintEngine::begin: Problem setting file [%s]", d->outputFilename.toUtf8().constData());
89  return false;
90  }
91  }
92  OSStatus status = noErr;
93 #ifndef QT_MAC_USE_COCOA
94  status = d->shouldSuppressStatus() ? PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format)
95  : PMSessionBeginCGDocument(d->session, d->settings, d->format);
96 #else
97  status = PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format);
98 #endif
99 
100  if (status != noErr) {
101  d->state = QPrinter::Error;
102  return false;
103  }
104 
105  d->state = QPrinter::Active;
106  setActive(true);
107  d->newPage_helper();
108  return true;
109 }
double d
Definition: qnumeric_p.h:62
QPaintEngineState * state
Definition: qpaintengine.h:239
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void setActive(bool newState)
Sets the active state of the paint engine to state.
Definition: qpaintengine.h:155
Q_CORE_EXPORT void qWarning(const char *,...)
signed long OSStatus
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static const char * outFile
Definition: qtestlog.cpp:93

◆ drawEllipse()

void QMacPrintEngine::drawEllipse ( const QRectF rect)
virtual

Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.

The default implementation calls drawPolygon().

Reimplemented from QPaintEngine.

Definition at line 604 of file qprintengine_mac.mm.

Referenced by type().

605 {
607  Q_ASSERT(d->state == QPrinter::Active);
608  d->paintEngine->drawEllipse(r);
609 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawImage()

void QMacPrintEngine::drawImage ( const QRectF r,
const QImage pm,
const QRectF sr,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap.

Reimplemented from QPaintEngine.

Definition at line 632 of file qprintengine_mac.mm.

Referenced by type().

633 {
635  Q_ASSERT(d->state == QPrinter::Active);
636  d->paintEngine->drawImage(r, pm, sr, flags);
637 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawLines()

void QMacPrintEngine::drawLines ( const QLineF lines,
int  lineCount 
)
virtual

The default implementation splits the list of lines in lines into lineCount separate calls to drawPath() or drawPolygon() depending on the feature set of the paint engine.

Reimplemented from QPaintEngine.

Definition at line 611 of file qprintengine_mac.mm.

Referenced by type().

612 {
614  Q_ASSERT(d->state == QPrinter::Active);
615  d->paintEngine->drawLines(lines, lineCount);
616 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawPath()

void QMacPrintEngine::drawPath ( const QPainterPath path)
virtual

The default implementation ignores the path and does nothing.

Reimplemented from QPaintEngine.

Definition at line 653 of file qprintengine_mac.mm.

Referenced by type().

654 {
656  Q_ASSERT(d->state == QPrinter::Active);
657  d->paintEngine->drawPath(path);
658 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawPixmap()

void QMacPrintEngine::drawPixmap ( const QRectF r,
const QPixmap pm,
const QRectF sr 
)
virtual

Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.

Implements QPaintEngine.

Definition at line 625 of file qprintengine_mac.mm.

Referenced by type().

626 {
628  Q_ASSERT(d->state == QPrinter::Active);
629  d->paintEngine->drawPixmap(r, pm, sr);
630 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawPoints()

void QMacPrintEngine::drawPoints ( const QPointF points,
int  pointCount 
)
virtual

Draws the first pointCount points in the buffer points.

Reimplemented from QPaintEngine.

Definition at line 597 of file qprintengine_mac.mm.

Referenced by type().

598 {
600  Q_ASSERT(d->state == QPrinter::Active);
601  d->paintEngine->drawPoints(points, pointCount);
602 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawPolygon()

void QMacPrintEngine::drawPolygon ( const QPointF points,
int  pointCount,
PolygonDrawMode  mode 
)
virtual

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

Note
At least one of the drawPolygon() functions must be reimplemented.

Reimplemented from QPaintEngine.

Definition at line 618 of file qprintengine_mac.mm.

Referenced by type().

619 {
621  Q_ASSERT(d->state == QPrinter::Active);
622  d->paintEngine->drawPolygon(points, pointCount, mode);
623 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawRects()

void QMacPrintEngine::drawRects ( const QRectF rects,
int  rectCount 
)
virtual

Draws the first rectCount rectangles in the buffer rects.

The default implementation of this function calls drawPath() or drawPolygon() depending on the feature set of the paint engine.

Reimplemented from QPaintEngine.

Definition at line 590 of file qprintengine_mac.mm.

Referenced by type().

591 {
593  Q_ASSERT(d->state == QPrinter::Active);
594  d->paintEngine->drawRects(r, num);
595 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawTextItem()

void QMacPrintEngine::drawTextItem ( const QPointF p,
const QTextItem textItem 
)
virtual

This function draws the text item textItem at position p.

The default implementation of this function converts the text to a QPainterPath and paints the resulting path.

Reimplemented from QPaintEngine.

Definition at line 639 of file qprintengine_mac.mm.

Referenced by type().

640 {
642  Q_ASSERT(d->state == QPrinter::Active);
643  d->paintEngine->drawTextItem(p, ti);
644 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ drawTiledPixmap()

void QMacPrintEngine::drawTiledPixmap ( const QRectF rect,
const QPixmap pixmap,
const QPointF p 
)
virtual

Reimplement this function to draw the pixmap in the given rect, starting at the given p.

The pixmap will be drawn repeatedly until the rect is filled.

Reimplemented from QPaintEngine.

Definition at line 646 of file qprintengine_mac.mm.

Referenced by type().

647 {
649  Q_ASSERT(d->state == QPrinter::Active);
650  d->paintEngine->drawTiledPixmap(dr, pixmap, sr);
651 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482

◆ end()

bool QMacPrintEngine::end ( )
virtual

Reimplement this function to finish painting on the current paint device.

Return true if painting was finished successfully; otherwise return false.

See also
begin() isActive()

Implements QPaintEngine.

Definition at line 111 of file qprintengine_mac.mm.

Referenced by abort().

112 {
114  if (d->state == QPrinter::Aborted)
115  return true; // I was just here a function call ago :)
116  if(d->paintEngine->type() == QPaintEngine::CoreGraphics) {
117  // We dont need the paint engine to call restoreGraphicsState()
118  static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->stackCount = 0;
119  static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->hd = 0;
120  }
121  d->paintEngine->end();
122  if (d->state != QPrinter::Idle)
123  d->releaseSession();
124  d->state = QPrinter::Idle;
125  return true;
126 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ handle()

Qt::HANDLE QMacPrintEngine::handle ( ) const

Definition at line 134 of file qprintengine_mac.mm.

135 {
137  return cgEngine->d_func()->hd;
138 }
QPaintEngine * paintEngine() const

◆ metric()

int QMacPrintEngine::metric ( QPaintDevice::PaintDeviceMetric  id) const
virtual

Returns the metric for the given id.

Implements QPrintEngine.

Definition at line 340 of file qprintengine_mac.mm.

Referenced by type().

341 {
342  Q_D(const QMacPrintEngine);
343  int val = 1;
344  switch (m) {
346  if (d->hasCustomPaperSize) {
347  val = qRound(d->customSize.width());
348  if (d->hasCustomPageMargins) {
349  val -= qRound(d->leftMargin + d->rightMargin);
350  } else {
352  val -= qRound(margins.at(0).toDouble() + margins.at(2).toDouble());
353  }
354  } else {
355  val = qt_get_PDMWidth(d->format, property(PPK_FullPage).toBool(), d->resolution);
356  }
357  break;
359  if (d->hasCustomPaperSize) {
360  val = qRound(d->customSize.height());
361  if (d->hasCustomPageMargins) {
362  val -= qRound(d->topMargin + d->bottomMargin);
363  } else {
365  val -= qRound(margins.at(1).toDouble() + margins.at(3).toDouble());
366  }
367  } else {
368  val = qt_get_PDMHeight(d->format, property(PPK_FullPage).toBool(), d->resolution);
369  }
370  break;
373  val = int((val * 254 + 5 * d->resolution.hRes) / (10 * d->resolution.hRes));
374  break;
377  val = int((val * 254 + 5 * d->resolution.vRes) / (10 * d->resolution.vRes));
378  break;
381  PMPrinter printer;
382  if(PMSessionGetCurrentPrinter(d->session, &printer) == noErr) {
383  PMResolution resolution;
384 #ifndef QT_MAC_USE_COCOA
385 # if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
387  PMPrinterGetOutputResolution(printer, d->settings, &resolution);
388  } else
389 # endif
390  {
391  PMPrinterGetPrinterResolution(printer, kPMCurrentValue, &resolution);
392  }
393 #else
394  PMPrinterGetOutputResolution(printer, d->settings, &resolution);
395 #endif
396  val = (int)resolution.vRes;
397  break;
398  }
399  //otherwise fall through
400  }
402  val = (int)d->resolution.vRes;
403  break;
405  val = (int)d->resolution.hRes;
406  break;
408  val = (1 << metric(QPaintDevice::PdmDepth));
409  break;
411  val = 24;
412  break;
413  default:
414  val = 0;
415  qWarning("QPrinter::metric: Invalid metric command");
416  }
417  return val;
418 }
double d
Definition: qnumeric_p.h:62
static int qt_get_PDMWidth(PMPageFormat pformat, bool fullPage, const PMResolution &resolution)
static int qt_get_PDMHeight(PMPageFormat pformat, bool fullPage, const PMResolution &resolution)
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
#define Q_D(Class)
Definition: qglobal.h:2482
static bool toBool(Register *reg, int type, bool *ok=0)
QVariant property(PrintEnginePropertyKey key) const
Returns the print engine&#39;s property specified by key.
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 *,...)
int metric(QPaintDevice::PaintDeviceMetric) const
Returns the metric for the given id.
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ newPage()

bool QMacPrintEngine::newPage ( )
virtual

Instructs the print engine to start a new page.

Returns true if the printer was able to create the new page; otherwise returns false.

Implements QPrintEngine.

Definition at line 272 of file qprintengine_mac.mm.

Referenced by type().

273 {
275  Q_ASSERT(d->state == QPrinter::Active);
276  OSStatus err =
277 #ifndef QT_MAC_USE_COCOA
278  d->shouldSuppressStatus() ? PMSessionEndPageNoDialog(d->session)
279  : PMSessionEndPage(d->session);
280 #else
281  PMSessionEndPageNoDialog(d->session);
282 #endif
283  if (err != noErr) {
284  if (err == kPMCancel) {
285  // User canceled, we need to abort!
286  abort();
287  } else {
288  // Not sure what the problem is...
289  qWarning("QMacPrintEngine::newPage: Cannot end current page. %ld", long(err));
290  d->state = QPrinter::Error;
291  }
292  return false;
293  }
294  return d->newPage_helper();
295 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
signed long OSStatus
bool abort()
Instructs the print engine to abort the printing process.

◆ paintEngine()

QPaintEngine * QMacPrintEngine::paintEngine ( ) const

Definition at line 129 of file qprintengine_mac.mm.

Referenced by handle(), QMacPrintEnginePrivate::initialize(), QMacPrintEnginePrivate::newPage_helper(), type(), and QMacPrintEnginePrivate::~QMacPrintEnginePrivate().

130 {
131  return d_func()->paintEngine;
132 }

◆ printerState()

QPrinter::PrinterState QMacPrintEngine::printerState ( ) const
virtual

Returns the current state of the printer being used by the print engine.

Implements QPrintEngine.

Definition at line 267 of file qprintengine_mac.mm.

Referenced by type().

268 {
269  return d_func()->state;
270 }

◆ property()

QVariant QMacPrintEngine::property ( PrintEnginePropertyKey  key) const
virtual

Returns the print engine's property specified by key.

See also
setProperty()

Implements QPrintEngine.

Definition at line 794 of file qprintengine_mac.mm.

Referenced by metric(), and type().

795 {
796  Q_D(const QMacPrintEngine);
797  QVariant ret;
798 
799  if (!d->session && d->valueCache.contains(key))
800  return *d->valueCache.find(key);
801 
802  switch (key) {
803  case PPK_CollateCopies:
804  ret = false;
805  break;
806  case PPK_ColorMode:
807  ret = QPrinter::Color;
808  break;
809  case PPK_Creator:
810  break;
811  case PPK_DocumentName:
812  break;
813  case PPK_FullPage:
814  ret = d->fullPage;
815  break;
816  case PPK_NumberOfCopies:
817  ret = 1;
818  break;
819  case PPK_CopyCount: {
820  UInt32 copies = 1;
821  PMGetCopies(d->settings, &copies);
822  ret = (uint) copies;
823  break;
824  }
826  ret = true;
827  break;
828  case PPK_Orientation:
829  PMOrientation orientation;
830  PMGetOrientation(d->format, &orientation);
831  ret = orientation == kPMPortrait ? QPrinter::Portrait : QPrinter::Landscape;
832  break;
833  case PPK_OutputFileName:
834  ret = d->outputFilename;
835  break;
836  case PPK_PageOrder:
837  break;
838  case PPK_PaperSource:
839  break;
840  case PPK_PageRect: {
841  // PageRect is returned in device pixels
842  QRect r;
843  PMRect macrect, macpaper;
844  qreal hRatio = d->resolution.hRes / 72;
845  qreal vRatio = d->resolution.vRes / 72;
846  if (d->hasCustomPaperSize) {
847  r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio));
848  if (d->hasCustomPageMargins) {
849  r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio),
850  -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio));
851  } else {
853  r.adjust(qRound(margins.at(0).toDouble() * hRatio),
854  qRound(margins.at(1).toDouble() * vRatio),
855  -qRound(margins.at(2).toDouble() * hRatio),
856  -qRound(margins.at(3).toDouble()) * vRatio);
857  }
858  } else if (PMGetAdjustedPageRect(d->format, &macrect) == noErr
859  && PMGetAdjustedPaperRect(d->format, &macpaper) == noErr)
860  {
861  if (d->fullPage || d->hasCustomPageMargins) {
862  r.setCoords(int(macpaper.left * hRatio), int(macpaper.top * vRatio),
863  int(macpaper.right * hRatio), int(macpaper.bottom * vRatio));
864  r.translate(-r.x(), -r.y());
865  if (d->hasCustomPageMargins) {
866  r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio),
867  -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio));
868  }
869  } else {
870  r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio),
871  int(macrect.right * hRatio), int(macrect.bottom * vRatio));
872  r.translate(int(-macpaper.left * hRatio), int(-macpaper.top * vRatio));
873  }
874  }
875  ret = r;
876  break; }
877  case PPK_PaperSize:
878  ret = d->paperSize();
879  break;
880  case PPK_PaperRect: {
881  QRect r;
882  PMRect macrect;
883  qreal hRatio = d->resolution.hRes / 72;
884  qreal vRatio = d->resolution.vRes / 72;
885  if (d->hasCustomPaperSize) {
886  r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio));
887  } else if (PMGetAdjustedPaperRect(d->format, &macrect) == noErr) {
888  r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio),
889  int(macrect.right * hRatio), int(macrect.bottom * vRatio));
890  r.translate(-r.x(), -r.y());
891  }
892  ret = r;
893  break; }
894  case PPK_PrinterName: {
895  PMPrinter printer;
896  OSStatus status = PMSessionGetCurrentPrinter(d->session, &printer);
897  if (status != noErr)
898  qWarning("QMacPrintEngine::printerName: Failed getting current PMPrinter: %ld", long(status));
899  if (printer)
900  ret = QCFString::toQString(PMPrinterGetName(printer));
901  break; }
902  case PPK_Resolution: {
903  ret = d->resolution.hRes;
904  break;
905  }
907  ret = d->supportedResolutions();
908  break;
909  case PPK_CustomPaperSize:
910  ret = d->customSize;
911  break;
912  case PPK_PageMargins:
913  {
914  QList<QVariant> margins;
915  if (d->hasCustomPageMargins) {
916  margins << d->leftMargin << d->topMargin
917  << d->rightMargin << d->bottomMargin;
918  } else {
919  PMPaperMargins paperMargins;
920  PMPaper paper;
921  PMGetPageFormatPaper(d->format, &paper);
922  PMPaperGetMargins(paper, &paperMargins);
923  margins << paperMargins.left << paperMargins.top
924  << paperMargins.right << paperMargins.bottom;
925  }
926  ret = margins;
927  break;
928  }
929  default:
930  break;
931  }
932  return ret;
933 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
#define Q_D(Class)
Definition: qglobal.h:2482
QVariant property(PrintEnginePropertyKey key) const
Returns the print engine&#39;s property specified by key.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
void setCoords(int x1, int y1, int x2, int y2)
Sets the coordinates of the rectangle&#39;s top-left corner to (x1, y1), and the coordinates of its botto...
Definition: qrect.h:416
signed long OSStatus
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
int key
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setProperty()

void QMacPrintEngine::setProperty ( PrintEnginePropertyKey  key,
const QVariant value 
)
virtual

Sets the print engine's property specified by key to the given value.

See also
property()

Implements QPrintEngine.

Definition at line 661 of file qprintengine_mac.mm.

Referenced by type().

662 {
664 
665  d->valueCache.insert(key, value);
666  if (!d->session)
667  return;
668 
669  switch (key) {
670  case PPK_CollateCopies:
671  break;
672  case PPK_ColorMode:
673  break;
674  case PPK_Creator:
675  break;
676  case PPK_DocumentName:
677  break;
678  case PPK_PageOrder:
679  break;
680  case PPK_PaperSource:
681  break;
682  case PPK_SelectionOption:
683  break;
684  case PPK_Resolution: {
685  PMPrinter printer;
686  UInt32 count;
687  if (PMSessionGetCurrentPrinter(d->session, &printer) != noErr)
688  break;
689  if (PMPrinterGetPrinterResolutionCount(printer, &count) != noErr)
690  break;
691  PMResolution resolution = { 0.0, 0.0 };
692  PMResolution bestResolution = { 0.0, 0.0 };
693  int dpi = value.toInt();
694  int bestDistance = INT_MAX;
695  for (UInt32 i = 1; i <= count; ++i) { // Yes, it starts at 1
696  if (PMPrinterGetIndexedPrinterResolution(printer, i, &resolution) == noErr) {
697  if (dpi == int(resolution.hRes)) {
698  bestResolution = resolution;
699  break;
700  } else {
701  int distance = qAbs(dpi - int(resolution.hRes));
702  if (distance < bestDistance) {
703  bestDistance = distance;
704  bestResolution = resolution;
705  }
706  }
707  }
708  }
709  PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean);
710  break;
711  }
712 
713  case PPK_FullPage:
714  d->fullPage = value.toBool();
715  break;
716  case PPK_CopyCount: // fallthrough
717  case PPK_NumberOfCopies:
718  PMSetCopies(d->settings, value.toInt(), false);
719  break;
720  case PPK_Orientation: {
721  if (d->state == QPrinter::Active) {
722  qWarning("QMacPrintEngine::setOrientation: Orientation cannot be changed during a print job, ignoring change");
723  } else {
724  QPrinter::Orientation newOrientation = QPrinter::Orientation(value.toInt());
725  if (d->hasCustomPaperSize && (d->orient != newOrientation))
726  d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
727  d->orient = newOrientation;
728  PMOrientation o = d->orient == QPrinter::Portrait ? kPMPortrait : kPMLandscape;
729  PMSetOrientation(d->format, o, false);
730  PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean);
731  }
732  break; }
733  case PPK_OutputFileName:
734  d->outputFilename = value.toString();
735  break;
736  case PPK_PaperSize:
737  d->setPaperSize(QPrinter::PaperSize(value.toInt()));
738  break;
739  case PPK_PrinterName: {
740  bool printerNameSet = false;
741  OSStatus status = noErr;
742  QCFType<CFArrayRef> printerList;
743  status = PMServerCreatePrinterList(kPMServerLocal, &printerList);
744  if (status == noErr) {
745  CFIndex count = CFArrayGetCount(printerList);
746  for (CFIndex i=0; i<count; ++i) {
747  PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
748  QString name = QCFString::toQString(PMPrinterGetName(printer));
749  if (name == value.toString()) {
750  status = PMSessionSetCurrentPMPrinter(d->session, printer);
751  printerNameSet = true;
752  break;
753  }
754  }
755  }
756  if (status != noErr)
757  qWarning("QMacPrintEngine::setPrinterName: Error setting printer: %ld", long(status));
758  if (!printerNameSet) {
759  qWarning("QMacPrintEngine::setPrinterName: Failed to set printer named '%s'.", qPrintable(value.toString()));
760  d->releaseSession();
761  d->state = QPrinter::Idle;
762  }
763  break; }
765  d->suppressStatus = value.toBool();
766  break;
767  case PPK_CustomPaperSize:
768  {
769  PMOrientation orientation;
770  PMGetOrientation(d->format, &orientation);
771  d->customSize = value.toSizeF();
772  if (orientation != kPMPortrait)
773  d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
774  d->setPaperSize(QPrinter::Custom);
775  break;
776  }
777  case PPK_PageMargins:
778  {
779  QList<QVariant> margins(value.toList());
780  Q_ASSERT(margins.size() == 4);
781  d->leftMargin = margins.at(0).toDouble();
782  d->topMargin = margins.at(1).toDouble();
783  d->rightMargin = margins.at(2).toDouble();
784  d->bottomMargin = margins.at(3).toDouble();
785  d->hasCustomPageMargins = true;
786  break;
787  }
788 
789  default:
790  break;
791  }
792 }
double d
Definition: qnumeric_p.h:62
Orientation
This enum type (not to be confused with Orientation) is used to specify each page&#39;s orientation...
Definition: qprinter.h:78
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
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
const char * name
Q_CORE_EXPORT void qWarning(const char *,...)
static int distance(QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
signed long OSStatus
QSizeF toSizeF() const
Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF...
Definition: qvariant.cpp:2447
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
int key
#define qPrintable(string)
Definition: qglobal.h:1750
#define INT_MAX

◆ type()

virtual QPaintEngine::Type QMacPrintEngine::type ( ) const
inlinevirtual

Reimplement this function to return the paint engine Type.

Implements QPaintEngine.

Definition at line 83 of file qprintengine_mac_p.h.

◆ updateState()

void QMacPrintEngine::updateState ( const QPaintEngineState state)
virtual

Reimplement this function to update the state of a paint engine.

When implemented, this function is responsible for checking the paint engine's current state and update the properties that are changed. Use the QPaintEngineState::state() function to find out which properties that must be updated, then use the corresponding GetFunction{get function} to retrieve the current values for the given properties.

See also
QPaintEngineState

Implements QPaintEngine.

Definition at line 585 of file qprintengine_mac.mm.

Referenced by type().

586 {
587  d_func()->paintEngine->updateState(state);
588 }

Friends and Related Functions

◆ QPageSetupDialog

friend class QPageSetupDialog
friend

Definition at line 113 of file qprintengine_mac_p.h.

◆ QPrintDialog

friend class QPrintDialog
friend

Definition at line 112 of file qprintengine_mac_p.h.


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