Qt 4.8
Classes | Macros | Enumerations | Functions | Variables
qpaintengine_mac.cpp File Reference
#include <qbitmap.h>
#include <qpaintdevice.h>
#include <private/qpaintengine_mac_p.h>
#include <qpainterpath.h>
#include <qpixmapcache.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qprintengine_mac_p.h>
#include <qprinter.h>
#include <qstack.h>
#include <qtextcodec.h>
#include <qwidget.h>
#include <qvarlengtharray.h>
#include <qdebug.h>
#include <qcoreapplication.h>
#include <qmath.h>
#include <private/qfont_p.h>
#include <private/qfontengine_p.h>
#include <private/qfontengine_coretext_p.h>
#include <private/qfontengine_mac_p.h>
#include <private/qnumeric_p.h>
#include <private/qpainter_p.h>
#include <private/qpainterpath_p.h>
#include <private/qpixmap_mac_p.h>
#include <private/qt_mac_p.h>
#include <private/qtextengine_p.h>
#include <private/qwidget_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
#include <string.h>

Go to the source code of this file.

Classes

class  QMacPattern
 
struct  qt_mac_cg_transform_path
 

Macros

#define QMACPATTERN_MASK_MULTIPLIER   32
 

Enumerations

enum  CGCompositeMode {
  kCGCompositeModeClear = 0, kCGCompositeModeCopy = 1, kCGCompositeModeSourceOver = 2, kCGCompositeModeSourceIn = 3,
  kCGCompositeModeSourceOut = 4, kCGCompositeModeSourceAtop = 5, kCGCompositeModeDestinationOver = 6, kCGCompositeModeDestinationIn = 7,
  kCGCompositeModeDestinationOut = 8, kCGCompositeModeDestinationAtop = 9, kCGCompositeModeXOR = 10, kCGCompositeModePlusDarker = 11,
  kCGCompositeModePlusLighter = 12
}
 

Functions

static QCFType< CGColorRef > cgColorForQColor (const QColor &col, QPaintDevice *pdev)
 
void CGContextSetCompositeOperation (CGContextRef, int)
 
static void drawImageReleaseData (void *info, const void *, size_t)
 
CGContextRef qt_mac_cg_context (const QPaintDevice *)
 Returns the CoreGraphics CGContextRef of the paint device. More...
 
static QPaintEngine::PaintEngineFeatures qt_mac_cg_features ()
 
void qt_mac_cg_transform_path_apply (void *info, const CGPathElement *element)
 
void qt_mac_clip_cg (CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig_xform)
 
CGColorSpaceRef qt_mac_colorSpaceForDeviceType (const QPaintDevice *paintDevice)
 
static CGMutablePathRef qt_mac_compose_path (const QPainterPath &p, float off=0)
 
static CGRect qt_mac_compose_rect (const QRectF &r, float off=0)
 
static int qt_mac_convert_color_from_cg (float c)
 
static float qt_mac_convert_color_to_cg (int c)
 
CGAffineTransform qt_mac_convert_transform_to_cg (const QTransform &t)
 
CGImageRef qt_mac_create_imagemask (const QPixmap &px, const QRectF &sr)
 
CGImageRef qt_mac_createCGImageFromQImage (const QImage &img, const QImage **imagePtr=0)
 
static void qt_mac_dispose_pattern (void *info)
 
void qt_mac_dispose_rgn (RgnHandle r)
 
static void qt_mac_draw_pattern (void *info, CGContextRef c)
 
static const ucharqt_mac_patternForBrush (int brushStyle)
 
QPoint qt_mac_posInWindow (const QWidget *w)
 
OSWindowRef qt_mac_window_for (const QWidget *)
 
QPixmap qt_pixmapForBrush (int, bool)
 

Variables

int qt_antialiasing_threshold
 

Macro Definition Documentation

◆ QMACPATTERN_MASK_MULTIPLIER

#define QMACPATTERN_MASK_MULTIPLIER   32

Enumeration Type Documentation

◆ CGCompositeMode

Enumerator
kCGCompositeModeClear 
kCGCompositeModeCopy 
kCGCompositeModeSourceOver 
kCGCompositeModeSourceIn 
kCGCompositeModeSourceOut 
kCGCompositeModeSourceAtop 
kCGCompositeModeDestinationOver 
kCGCompositeModeDestinationIn 
kCGCompositeModeDestinationOut 
kCGCompositeModeDestinationAtop 
kCGCompositeModeXOR 
kCGCompositeModePlusDarker 
kCGCompositeModePlusLighter 

Definition at line 1187 of file qpaintengine_mac.cpp.

Function Documentation

◆ cgColorForQColor()

static QCFType<CGColorRef> cgColorForQColor ( const QColor col,
QPaintDevice pdev 
)
inlinestatic

Definition at line 160 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawPixmap(), qt_mac_draw_pattern(), QCoreGraphicsPaintEnginePrivate::setFillBrush(), and QCoreGraphicsPaintEnginePrivate::setStrokePen().

161 {
162  CGFloat components[] = {
167  };
168  return CGColorCreate(qt_mac_colorSpaceForDeviceType(pdev), components);
169 }
CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice)
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
static float qt_mac_convert_color_to_cg(int c)
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
float CGFloat

◆ CGContextSetCompositeOperation()

void CGContextSetCompositeOperation ( CGContextRef  ,
int   
)

◆ drawImageReleaseData()

static void drawImageReleaseData ( void *  info,
const void *  ,
size_t   
)
static

Definition at line 1001 of file qpaintengine_mac.cpp.

Referenced by qt_mac_createCGImageFromQImage().

1002 {
1003  delete static_cast<QImage *>(info);
1004 }
static mach_timebase_info_data_t info
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87

◆ qt_mac_cg_context()

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(), and qt_mac_draw_pattern().

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_cg_features()

static QPaintEngine::PaintEngineFeatures qt_mac_cg_features ( )
inlinestatic

◆ qt_mac_cg_transform_path_apply()

void qt_mac_cg_transform_path_apply ( void *  info,
const CGPathElement *  element 
)

Definition at line 1640 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEnginePrivate::drawPath().

1641 {
1642  Q_ASSERT(info && element);
1644  switch(element->type) {
1645  case kCGPathElementMoveToPoint:
1646  CGPathMoveToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y);
1647  break;
1648  case kCGPathElementAddLineToPoint:
1649  CGPathAddLineToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y);
1650  break;
1651  case kCGPathElementAddQuadCurveToPoint:
1652  CGPathAddQuadCurveToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y,
1653  element->points[1].x, element->points[1].y);
1654  break;
1655  case kCGPathElementAddCurveToPoint:
1656  CGPathAddCurveToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y,
1657  element->points[1].x, element->points[1].y,
1658  element->points[2].x, element->points[2].y);
1659  break;
1660  case kCGPathElementCloseSubpath:
1661  CGPathCloseSubpath(t->path);
1662  break;
1663  default:
1664  qDebug() << "Unhandled path transform type: " << element->type;
1665  }
1666 }
static mach_timebase_info_data_t info
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)

◆ qt_mac_clip_cg()

void qt_mac_clip_cg ( CGContextRef  hd,
const QRegion rgn,
CGAffineTransform *  orig_xform 
)

Definition at line 381 of file qpaintengine_mac.cpp.

Referenced by QMacCGContext::QMacCGContext(), and QCoreGraphicsPaintEnginePrivate::setClip().

382 {
383  CGAffineTransform old_xform = CGAffineTransformIdentity;
384  if(orig_xform) { //setup xforms
385  old_xform = CGContextGetCTM(hd);
386  CGContextConcatCTM(hd, CGAffineTransformInvert(old_xform));
387  CGContextConcatCTM(hd, *orig_xform);
388  }
389 
390  //do the clipping
391  CGContextBeginPath(hd);
392  if(rgn.isEmpty()) {
393  CGContextAddRect(hd, CGRectMake(0, 0, 0, 0));
394  } else {
395 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
397  QCFType<HIMutableShapeRef> shape = rgn.toHIMutableShape();
398  Q_ASSERT(!HIShapeIsEmpty(shape));
399  HIShapeReplacePathInCGContext(shape, hd);
400  } else
401 #endif
402  {
403  QVector<QRect> rects = rgn.rects();
404  const int count = rects.size();
405  for(int i = 0; i < count; i++) {
406  const QRect &r = rects[i];
407  CGRect mac_r = CGRectMake(r.x(), r.y(), r.width(), r.height());
408  CGContextAddRect(hd, mac_r);
409  }
410  }
411 
412  }
413  CGContextClip(hd);
414 
415  if(orig_xform) {//reset xforms
416  CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
417  CGContextConcatCTM(hd, old_xform);
418  }
419 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
struct CGRect CGRect
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
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ qt_mac_colorSpaceForDeviceType()

CGColorSpaceRef qt_mac_colorSpaceForDeviceType ( const QPaintDevice paintDevice)

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)
virtual int devType() const
Definition: qpaintdevice.h:167

◆ qt_mac_compose_path()

static CGMutablePathRef qt_mac_compose_path ( const QPainterPath p,
float  off = 0 
)
static

Definition at line 252 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawPath(), and QCoreGraphicsPaintEngine::updateClipPath().

253 {
254  CGMutablePathRef ret = CGPathCreateMutable();
255  QPointF startPt;
256  for (int i=0; i<p.elementCount(); ++i) {
257  const QPainterPath::Element &elm = p.elementAt(i);
258  switch (elm.type) {
260  if(i > 0
261  && p.elementAt(i - 1).x == startPt.x()
262  && p.elementAt(i - 1).y == startPt.y())
263  CGPathCloseSubpath(ret);
264  startPt = QPointF(elm.x, elm.y);
265  CGPathMoveToPoint(ret, 0, elm.x+off, elm.y+off);
266  break;
268  CGPathAddLineToPoint(ret, 0, elm.x+off, elm.y+off);
269  break;
273  CGPathAddCurveToPoint(ret, 0,
274  elm.x+off, elm.y+off,
275  p.elementAt(i+1).x+off, p.elementAt(i+1).y+off,
276  p.elementAt(i+2).x+off, p.elementAt(i+2).y+off);
277  i+=2;
278  break;
279  default:
280  qFatal("QCoreGraphicsPaintEngine::drawPath(), unhandled type: %d", elm.type);
281  break;
282  }
283  }
284  if(!p.isEmpty()
285  && p.elementAt(p.elementCount() - 1).x == startPt.x()
286  && p.elementAt(p.elementCount() - 1).y == startPt.y())
287  CGPathCloseSubpath(ret);
288  return ret;
289 }
ElementType type
the type of element
Definition: qpainterpath.h:81
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
Q_CORE_EXPORT void qFatal(const char *,...)
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ qt_mac_compose_rect()

static CGRect qt_mac_compose_rect ( const QRectF r,
float  off = 0 
)
static

Definition at line 247 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawRects().

248 {
249  return CGRectMake(r.x()+off, r.y()+off, r.width(), r.height());
250 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664

◆ qt_mac_convert_color_from_cg()

static int qt_mac_convert_color_from_cg ( float  c)
inlinestatic

Definition at line 148 of file qpaintengine_mac.cpp.

148 { return qRound(c * 255); }
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ qt_mac_convert_color_to_cg()

static float qt_mac_convert_color_to_cg ( int  c)
inlinestatic

Definition at line 147 of file qpaintengine_mac.cpp.

Referenced by cgColorForQColor(), and QCoreGraphicsPaintEnginePrivate::setFillBrush().

147 { return ((float)c * 1000 / 255) / 1000; }
unsigned char c[8]
Definition: qnumeric_p.h:62

◆ qt_mac_convert_transform_to_cg()

CGAffineTransform qt_mac_convert_transform_to_cg ( const QTransform t)

Definition at line 149 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEnginePrivate::drawPath(), QCoreGraphicsPaintEnginePrivate::setFillBrush(), and QCoreGraphicsPaintEnginePrivate::setTransform().

149  {
150  return CGAffineTransformMake(t.m11(), t.m12(), t.m21(), t.m22(), t.dx(), t.dy());
151 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ qt_mac_create_imagemask()

CGImageRef qt_mac_create_imagemask ( const QPixmap px,
const QRectF sr 
)

Definition at line 1077 of file qpixmap_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawPixmap(), and qt_mac_draw_pattern().

1078 {
1079  QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
1080  if (px->cg_mask) {
1081  if (px->cg_mask_rect == sr) {
1082  CGImageRetain(px->cg_mask); //reference for the caller
1083  return px->cg_mask;
1084  }
1085  CGImageRelease(px->cg_mask);
1086  px->cg_mask = 0;
1087  }
1088 
1089  const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height());
1090  const int sbpr = px->bytesPerRow;
1091  const uint nbytes = sw * sh;
1092  // alpha is always 255 for bitmaps, ignore it in this case.
1093  const quint32 mask = px->depth() == 1 ? 0x00ffffff : 0xffffffff;
1094  quint8 *dptr = static_cast<quint8 *>(malloc(nbytes));
1095  quint32 *sptr = px->pixels, *srow;
1096  for(int y = sy, offset=0; y < sh; ++y) {
1097  srow = sptr + (y * (sbpr / 4));
1098  for(int x = sx; x < sw; ++x)
1099  *(dptr+(offset++)) = (*(srow+x) & mask) ? 255 : 0;
1100  }
1101  QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, dptr, nbytes, qt_mac_cgimage_data_free);
1102  px->cg_mask = CGImageMaskCreate(sw, sh, 8, 8, nbytes / sh, provider, 0, 0);
1103  px->cg_mask_rect = sr;
1104  CGImageRetain(px->cg_mask); //reference for the caller
1105  return px->cg_mask;
1106 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
unsigned char quint8
Definition: qglobal.h:934
CGImageRef cg_mask
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
unsigned int uint
Definition: qglobal.h:996
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
int depth() const
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
Definition: qpixmap_mac.cpp:91
unsigned int quint32
Definition: qglobal.h:938
quint32 * pixels
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ qt_mac_createCGImageFromQImage()

CGImageRef qt_mac_createCGImageFromQImage ( const QImage img,
const QImage **  imagePtr = 0 
)

Definition at line 1006 of file qpaintengine_mac.cpp.

Referenced by QMacPasteboardMimeHTMLText::convertFromMime(), QMacPasteboardMimeTiff::convertFromMime(), and QCoreGraphicsPaintEngine::drawImage().

1007 {
1008  QImage *image;
1009  if (img.depth() != 32)
1011  else
1012  image = new QImage(img);
1013 
1014  uint cgflags = kCGImageAlphaNone;
1015  switch (image->format()) {
1017  cgflags = kCGImageAlphaPremultipliedFirst;
1018  break;
1019  case QImage::Format_ARGB32:
1020  cgflags = kCGImageAlphaFirst;
1021  break;
1022  case QImage::Format_RGB32:
1023  cgflags = kCGImageAlphaNoneSkipFirst;
1024  default:
1025  break;
1026  }
1027 #if defined(kCGBitmapByteOrder32Host) //only needed because CGImage.h added symbols in the minor version
1028  cgflags |= kCGBitmapByteOrder32Host;
1029 #endif
1030  QCFType<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(image,
1031  static_cast<const QImage *>(image)->bits(),
1032  image->byteCount(),
1034  if (imagePtr)
1035  *imagePtr = image;
1036  return CGImageCreate(image->width(), image->height(), 8, 32,
1037  image->bytesPerLine(),
1039  cgflags, dataProvider, 0, false, kCGRenderingIntentDefault);
1040 
1041 }
static CGColorSpaceRef macGenericColorSpace()
int byteCount() const
Returns the number of bytes occupied by the image data.
Definition: qimage.cpp:1800
static void drawImageReleaseData(void *info, const void *, size_t)
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
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
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ qt_mac_dispose_pattern()

static void qt_mac_dispose_pattern ( void *  info)
static

Definition at line 524 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawTiledPixmap(), and QCoreGraphicsPaintEnginePrivate::setFillBrush().

525 {
526  QMacPattern *pat = (QMacPattern*)info;
527  delete pat;
528 }
static mach_timebase_info_data_t info

◆ qt_mac_dispose_rgn()

void qt_mac_dispose_rgn ( RgnHandle  r)

◆ qt_mac_draw_pattern()

static void qt_mac_draw_pattern ( void *  info,
CGContextRef  c 
)
static

Definition at line 459 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawTiledPixmap(), and QCoreGraphicsPaintEnginePrivate::setFillBrush().

460 {
461  QMacPattern *pat = (QMacPattern*)info;
462  int w = 0, h = 0;
463  bool isBitmap = (pat->data.pixmap.depth() == 1);
464  if(!pat->image) { //lazy cache
465  if(pat->as_mask) {
466  Q_ASSERT(pat->data.bytes);
467  w = h = 8;
468 #if (QMACPATTERN_MASK_MULTIPLIER == 1)
469  CGDataProviderRef provider = CGDataProviderCreateWithData(0, pat->data.bytes, w*h, 0);
470  pat->image = CGImageMaskCreate(w, h, 1, 1, 1, provider, 0, false);
471  CGDataProviderRelease(provider);
472 #else
473  const int numBytes = (w*h)/sizeof(uchar);
474  uchar xor_bytes[numBytes];
475  for(int i = 0; i < numBytes; ++i)
476  xor_bytes[i] = pat->data.bytes[i] ^ 0xFF;
477  CGDataProviderRef provider = CGDataProviderCreateWithData(0, xor_bytes, w*h, 0);
478  CGImageRef swatch = CGImageMaskCreate(w, h, 1, 1, 1, provider, 0, false);
479  CGDataProviderRelease(provider);
480 
481  const QColor c0(0, 0, 0, 0), c1(255, 255, 255, 255);
482  QPixmap pm(w*QMACPATTERN_MASK_MULTIPLIER, h*QMACPATTERN_MASK_MULTIPLIER);
483  pm.fill(c0);
484  CGContextRef pm_ctx = qt_mac_cg_context(&pm);
485  CGContextSetFillColorWithColor(c, cgColorForQColor(c1, pat->pdev));
486  CGRect rect = CGRectMake(0, 0, w, h);
487  for(int x = 0; x < QMACPATTERN_MASK_MULTIPLIER; ++x) {
488  rect.origin.x = x * w;
489  for(int y = 0; y < QMACPATTERN_MASK_MULTIPLIER; ++y) {
490  rect.origin.y = y * h;
491  qt_mac_drawCGImage(pm_ctx, &rect, swatch);
492  }
493  }
494  pat->image = qt_mac_create_imagemask(pm, pm.rect());
495  CGImageRelease(swatch);
496  CGContextRelease(pm_ctx);
499 #endif
500  } else {
501  w = pat->data.pixmap.width();
502  h = pat->data.pixmap.height();
503  if (isBitmap)
504  pat->image = qt_mac_create_imagemask(pat->data.pixmap, pat->data.pixmap.rect());
505  else
506  pat->image = (CGImageRef)pat->data.pixmap.macCGHandle();
507  }
508  } else {
509  w = CGImageGetWidth(pat->image);
510  h = CGImageGetHeight(pat->image);
511  }
512 
513  //draw
514  bool needRestore = false;
515  if (CGImageIsMask(pat->image)) {
516  CGContextSaveGState(c);
517  CGContextSetFillColorWithColor(c, cgColorForQColor(pat->foreground, pat->pdev));
518  }
519  CGRect rect = CGRectMake(0, 0, w, h);
520  qt_mac_drawCGImage(c, &rect, pat->image);
521  if(needRestore)
522  CGContextRestoreGState(c);
523 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
static QCFType< CGColorRef > cgColorForQColor(const QColor &col, QPaintDevice *pdev)
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
struct CGImage * CGImageRef
#define QMACPATTERN_MASK_MULTIPLIER
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
struct QMacPattern::@240 data
CGImageRef qt_mac_create_imagemask(const QPixmap &px, const QRectF &sr)
unsigned char uchar
Definition: qglobal.h:994
CGContextRef qt_mac_cg_context(const QPaintDevice *)
Returns the CoreGraphics CGContextRef of the paint device.
const uchar * bytes
QPaintDevice * pdev
struct CGRect CGRect
OSStatus qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage)
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
CGImageRef image
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
struct CGContext * CGContextRef

◆ qt_mac_patternForBrush()

static const uchar* qt_mac_patternForBrush ( int  brushStyle)
static

Definition at line 1506 of file qpaintengine_mac.cpp.

Referenced by QCoreGraphicsPaintEnginePrivate::setFillBrush().

1507 {
1508  Q_ASSERT(brushStyle > Qt::SolidPattern && brushStyle < Qt::LinearGradientPattern);
1509  static const uchar dense1_pat[] = { 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00 };
1510  static const uchar dense2_pat[] = { 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00, 0x88 };
1511  static const uchar dense3_pat[] = { 0x11, 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa };
1512  static const uchar dense4_pat[] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 };
1513  static const uchar dense5_pat[] = { 0xee, 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55 };
1514  static const uchar dense6_pat[] = { 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff, 0x77 };
1515  static const uchar dense7_pat[] = { 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff };
1516  static const uchar hor_pat[] = { 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff };
1517  static const uchar ver_pat[] = { 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef };
1518  static const uchar cross_pat[] = { 0xef, 0xef, 0xef, 0xef, 0x00, 0xef, 0xef, 0xef };
1519  static const uchar fdiag_pat[] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe };
1520  static const uchar bdiag_pat[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f };
1521  static const uchar dcross_pat[] = { 0x7e, 0xbd, 0xdb, 0xe7, 0xe7, 0xdb, 0xbd, 0x7e };
1522  static const uchar *const pat_tbl[] = {
1523  dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat,
1524  dense6_pat, dense7_pat,
1525  hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat };
1526  return pat_tbl[brushStyle - Qt::Dense1Pattern];
1527 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned char uchar
Definition: qglobal.h:994

◆ qt_mac_posInWindow()

QPoint qt_mac_posInWindow ( const QWidget w)

Definition at line 380 of file qwidget_mac.mm.

Referenced by make_widget_eventUPP(), and qt_mac_get_widget_rgn().

381 {
382  QPoint ret = w->data->wrect.topLeft();
383  while(w && !w->isWindow()) {
384  ret += w->pos();
385  w = w->parentWidget();
386  }
387  return ret;
388 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
QWidgetData * data
Definition: qwidget.h:815
QRect wrect
Definition: qwidget.h:145
QPoint pos
the position of the widget within its parent widget
Definition: qwidget.h:163
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ qt_mac_window_for()

OSWindowRef qt_mac_window_for ( const QWidget )

Definition at line 484 of file qwidget_mac.mm.

Referenced by QCoreGraphicsPaintEngine::end().

485 {
486  if (OSViewRef hiview = qt_mac_effectiveview_for(w)) {
488  if (window)
489  return window;
490 
491  if (qt_isGenuineQWidget(hiview)) {
492  // This is a workaround for NSToolbar. When a widget is hidden
493  // by clicking the toolbar button, Cocoa reparents the widgets
494  // to another window (but Qt doesn't know about it).
495  // When we start showing them, it reparents back,
496  // but at this point it's window is nil, but the window it's being brought
497  // into (the Qt one) is for sure created.
498  // This stops the hierarchy moving under our feet.
499  QWidget *toplevel = w->window();
500  if (toplevel != w) {
501  hiview = qt_mac_nativeview_for(toplevel);
502  if (OSWindowRef w = qt_mac_window_for(hiview))
503  return w;
504  }
505 
506  toplevel->d_func()->createWindow_sys();
507  // Reget the hiview since "create window" could potentially move the view (I guess).
508  hiview = qt_mac_nativeview_for(toplevel);
509  return qt_mac_window_for(hiview);
510  }
511  }
512  return 0;
513 }
Q_GUI_EXPORT OSWindowRef qt_mac_window_for(OSViewRef view)
Definition: qwidget_mac.mm:453
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
NSWindow * window
static bool qt_isGenuineQWidget(OSViewRef ref)
Definition: qwidget_mac.mm:464
WindowRef OSWindowRef
Q_GUI_EXPORT OSViewRef qt_mac_nativeview_for(const QWidget *w)
Definition: qwidget_mac.mm:419
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
HIViewRef OSViewRef
Q_GUI_EXPORT OSViewRef qt_mac_effectiveview_for(const QWidget *w)
Definition: qwidget_mac.mm:424

◆ qt_pixmapForBrush()

QPixmap qt_pixmapForBrush ( int  ,
bool   
)

Definition at line 99 of file qbrush.cpp.

100 {
101 
102  QPixmap pm;
103  QString key = QLatin1Literal("$qt-brush$")
104  % HexString<uint>(brushStyle)
105  % QLatin1Char(invert ? '1' : '0');
106  if (!QPixmapCache::find(key, pm)) {
107  pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert),
109  QPixmapCache::insert(key, pm);
110  }
111 
112  return pm;
113 }
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
Definition: qbitmap.cpp:318
const uchar * qt_patternForBrush(int brushStyle, bool invert)
Definition: qbrush.cpp:56
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QPixmap * find(const QString &key)
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Variable Documentation

◆ qt_antialiasing_threshold

int qt_antialiasing_threshold

Definition at line 495 of file qapplication.cpp.

Referenced by QCoreGraphicsPaintEngine::drawTextItem().