Qt 4.8
Functions
qpaintdevice_mac.cpp File Reference
#include "qpaintdevice.h"
#include "qpainter.h"
#include "qwidget.h"
#include "qbitmap.h"
#include "qapplication.h"
#include "qprinter.h"
#include <qdebug.h>
#include <private/qt_mac_p.h>
#include <private/qprintengine_mac_p.h>
#include <private/qpixmap_mac_p.h>
#include <private/qpixmap_raster_p.h>

Go to the source code of this file.

Functions

Q_GUI_EXPORT CGContextRef qt_mac_cg_context (const QPaintDevice *pdev)
 Returns the CoreGraphics CGContextRef of the paint device. More...
 
CGColorSpaceRef qt_mac_colorSpaceForDeviceType (const QPaintDevice *pdev)
 
float qt_mac_defaultDpi_x ()
 
float qt_mac_defaultDpi_y ()
 
Q_GUI_EXPORT GrafPtr qt_mac_qd_context (const QPaintDevice *device)
 Returns the QuickDraw CGrafPtr of the paint device. More...
 

Function Documentation

◆ qt_mac_cg_context()

Q_GUI_EXPORT CGContextRef qt_mac_cg_context ( const QPaintDevice pdev)

Returns the CoreGraphics CGContextRef of the paint device.

Warning
This function is not part of the public interface.

0 is returned if it can't be obtained. It is the caller's responsiblity to CGContextRelease the context when finished using it.

Warning
This function is only available on Mac OS X.

Definition at line 118 of file qpaintdevice_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::begin(), getTabDirection(), QMacStyle::polish(), QMacCGContext::QMacCGContext(), qt_mac_convert_iconref(), qt_mac_draw_pattern(), qt_mac_fill_background(), and QMacWindowSurface::scroll().

119 {
120  if (pdev->devType() == QInternal::Pixmap) {
121  const QPixmap *pm = static_cast<const QPixmap*>(pdev);
123  uint flags = kCGImageAlphaPremultipliedFirst;
124 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
125  flags |= kCGBitmapByteOrder32Host;
126 #endif
127  CGContextRef ret = 0;
128 
129  // It would make sense to put this into a mac #ifdef'ed
130  // virtual function in the QPixmapData at some point
131  if (pm->data->classId() == QPixmapData::MacClass) {
132  const QMacPixmapData *pmData = static_cast<const QMacPixmapData*>(pm->data.data());
133  ret = CGBitmapContextCreate(pmData->pixels, pmData->w, pmData->h,
134  8, pmData->bytesPerRow, colorspace,
135  flags);
136  if(!ret)
137  qWarning("QPaintDevice: Unable to create context for pixmap (%d/%d/%d)",
138  pmData->w, pmData->h, (pmData->bytesPerRow * pmData->h));
139  } else if (pm->data->classId() == QPixmapData::RasterClass) {
140  QImage *image = pm->data->buffer();
141  ret = CGBitmapContextCreate(image->bits(), image->width(), image->height(),
142  8, image->bytesPerLine(), colorspace, flags);
143  }
144 
145  CGContextTranslateCTM(ret, 0, pm->height());
146  CGContextScaleCTM(ret, 1, -1);
147  return ret;
148  } else if (pdev->devType() == QInternal::Widget) {
149  CGContextRef ret = static_cast<CGContextRef>(static_cast<const QWidget *>(pdev)->macCGHandle());
150  CGContextRetain(ret);
151  return ret;
152  } else if (pdev->devType() == QInternal::MacQuartz) {
153  return static_cast<const QMacQuartzPaintDevice *>(pdev)->cgContext();
154  }
155  return 0;
156 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *pdev)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
virtual int devType() const
Definition: qpaintdevice.h:167
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
ClassId classId() const
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
struct CGColorSpace * CGColorSpaceRef
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual QImage * buffer()
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
struct CGContext * CGContextRef
quint32 * pixels

◆ qt_mac_colorSpaceForDeviceType()

CGColorSpaceRef qt_mac_colorSpaceForDeviceType ( const QPaintDevice pdev)

Definition at line 153 of file qpaintengine_mac.cpp.

Referenced by cgColorForQColor(), QMacCGContext::QMacCGContext(), qt_mac_cg_context(), qt_mac_qd_context(), and QCoreGraphicsPaintEnginePrivate::setFillBrush().

154 {
155  bool isWidget = (paintDevice->devType() == QInternal::Widget);
156  return QCoreGraphicsPaintEngine::macDisplayColorSpace(isWidget ? static_cast<const QWidget *>(paintDevice)
157  : 0);
158 }
static CGColorSpaceRef macDisplayColorSpace(const QWidget *widget=0)

◆ qt_mac_defaultDpi_x()

float qt_mac_defaultDpi_x ( )
Warning
This function is not part of the public interface.

Definition at line 61 of file qpaintdevice_mac.cpp.

Referenced by QMacPixmapData::metric(), QWidget::metric(), qt_defaultDpiX(), qt_mac_pixelsize(), and qt_mac_pointsize().

62 {
63  // Mac OS X currently assumes things to be 72 dpi.
64  // (see http://developer.apple.com/releasenotes/GraphicsImaging/RN-ResolutionIndependentUI/)
65  // This may need to be re-worked as we go further in the resolution-independence stuff.
66  return 72;
67 }

◆ qt_mac_defaultDpi_y()

float qt_mac_defaultDpi_y ( )
Warning
This function is not part of the public interface.

Definition at line 70 of file qpaintdevice_mac.cpp.

Referenced by QMacPixmapData::metric(), QWidget::metric(), and qt_defaultDpiY().

71 {
72  // Mac OS X currently assumes things to be 72 dpi.
73  // (see http://developer.apple.com/releasenotes/GraphicsImaging/RN-ResolutionIndependentUI/)
74  // This may need to be re-worked as we go further in the resolution-independence stuff.
75  return 72;
76 }

◆ qt_mac_qd_context()

Q_GUI_EXPORT GrafPtr qt_mac_qd_context ( const QPaintDevice device)

Returns the QuickDraw CGrafPtr of the paint device.

Warning
This function is not part of the public interface.

0 is returned if it can't be obtained. Do not hold the pointer around for long as it can be relocated.

Warning
This function is only available on Mac OS X.

Definition at line 91 of file qpaintdevice_mac.cpp.

92 {
93  if (device->devType() == QInternal::Pixmap) {
94  return static_cast<GrafPtr>(static_cast<const QPixmap *>(device)->macQDHandle());
95  } else if(device->devType() == QInternal::Widget) {
96  return static_cast<GrafPtr>(static_cast<const QWidget *>(device)->macQDHandle());
97  } else if(device->devType() == QInternal::Printer) {
98  QPaintEngine *engine = static_cast<const QPrinter *>(device)->paintEngine();
99  return static_cast<GrafPtr>(static_cast<const QMacPrintEngine *>(engine)->handle());
100  }
101  return 0;
102 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual int devType() const
Definition: qpaintdevice.h:167
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71