6#include <private/qcore_mac_p.h>
7#include <qpa/qplatformpixmap.h>
8#include <QtGui/qicon.h>
9#include <QtGui/private/qpaintengine_p.h>
10#include <QtCore/qdebug.h>
11#include <QtCore/qcoreapplication.h>
12#include <QtCore/qoperatingsystemversion.h>
22 CGBitmapInfo bitmapInfo = kCGImageAlphaNone;
23 switch (
image.format()) {
25 bitmapInfo = CGBitmapInfo(kCGImageAlphaFirst) | kCGBitmapByteOrder32Host;
28 bitmapInfo = CGBitmapInfo(kCGImageAlphaNoneSkipFirst) | kCGBitmapByteOrder32Host;
31 bitmapInfo = CGBitmapInfo(kCGImageAlphaPremultipliedLast) | kCGBitmapByteOrder32Big;
34 bitmapInfo = CGBitmapInfo(kCGImageAlphaLast) | kCGBitmapByteOrder32Big;
37 bitmapInfo = CGBitmapInfo(kCGImageAlphaNoneSkipLast) | kCGBitmapByteOrder32Big;
40 bitmapInfo = CGBitmapInfo(kCGImageAlphaPremultipliedFirst) | kCGBitmapByteOrder32Host;
49 CGImageRef cgImage = inImage.toCGImage();
59 static const auto deleter = [](
void *
image,
const void *, size_t) {
delete static_cast<QImage *
>(
image); };
62 image.sizeInBytes(), deleter);
64 return CGImageMaskCreate(
image.width(),
image.height(), 8,
image.depth(),
65 image.bytesPerLine(), dataProvider, NULL,
false);
70 CGContextSaveGState( inContext );
71 CGContextTranslateCTM (inContext, 0, inBounds->origin.y + CGRectGetMaxY(*inBounds));
72 CGContextScaleCTM(inContext, 1, -1);
74 CGContextDrawImage(inContext, *inBounds, inImage);
76 CGContextRestoreGState(inContext);
81 const size_t w = CGImageGetWidth(
image),
82 h = CGImageGetHeight(
image);
85 CGRect
rect = CGRectMake(0, 0,
w,
h);
95@implementation NSImage (QtExtras)
96+ (instancetype)imageFromQImage:(const
QImage &)image
110 auto nsImage = [[NSImage alloc] initWithSize:NSZeroSize];
111 auto *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
112 imageRep.size =
image.deviceIndependentSize().toCGSize();
113 [nsImage addRepresentation:[imageRep autorelease]];
114 Q_ASSERT(CGSizeEqualToSize(nsImage.size, imageRep.size));
116 return [nsImage autorelease];
119+ (instancetype)imageFromQIcon:(const
QIcon &)icon
121 return [NSImage imageFromQIcon:icon withSize:0];
124+ (instancetype)imageFromQIcon:(const
QIcon &)icon withSize:(
int)size
130 if (availableSizes.isEmpty() &&
size > 0)
133 auto nsImage = [[[NSImage alloc] initWithSize:NSZeroSize] autorelease];
144 auto *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
145 imageRep.size =
image.deviceIndependentSize().toCGSize();
146 [nsImage addRepresentation:[imageRep autorelease]];
149 if (!nsImage.representations.count)
152 [nsImage setTemplate:icon.isMask()];
155 nsImage.size = CGSizeMake(
size,
size);
165 const NSSize pixmapSize = NSMakeSize(
size.width(),
size.height());
168 [image setSize:pixmapSize];
169 const NSRect iconRect = NSMakeRect(0, 0, pixmapSize.width, pixmapSize.height);
173 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
176 [NSGraphicsContext saveGraphicsState];
177 [NSGraphicsContext setCurrentContext:gc];
178 [image drawInRect:iconRect fromRect:iconRect operation:NSCompositingOperationSourceOver fraction:1.0 respectFlipped:YES hints:nil];
179 [NSGraphicsContext restoreGraphicsState];
190 CGColorSpaceModel
model = CGColorSpaceGetModel(CGColorGetColorSpace(
color));
192 if (
model == kCGColorSpaceModelRGB) {
194 }
else if (
model == kCGColorSpaceModelCMYK) {
196 }
else if (
model == kCGColorSpaceModelMonochrome) {
200 qWarning(
"Qt: qt_mac_toQColor: cannot convert from colorspace model: %d",
model);
210 switch (
color.type) {
211 case NSColorTypeComponentBased: {
212 const NSColorSpace *colorSpace = [color colorSpace];
213 if (colorSpace == NSColorSpace.genericRGBColorSpace
214 &&
color.numberOfComponents == 4) {
216 [color getComponents:components];
219 }
else if (colorSpace == NSColorSpace.genericCMYKColorSpace
220 &&
color.numberOfComponents == 5) {
222 [color getComponents:components];
229 const NSColor *tmpColor = [color colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
231 [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
244 CGColorSpaceModel
model = CGColorSpaceGetModel(CGColorGetColorSpace(
color));
245 if (
model == kCGColorSpaceModelPattern) {
247 qWarning(
"Qt: qt_mac_toQBrush: cannot convert from colorspace model: %d",
model);
257static bool qt_mac_isSystemColorOrInstance(
const NSColor *
color, NSString *colorNameComponent, NSString *
className)
262 if (
color.type == NSColorTypeCatalog &&
263 [
color.catalogNameComponent isEqualToString:
@"System"] &&
264 [
color.colorNameComponent isEqualToString:colorNameComponent])
274 if ([
color.className isEqualToString:
@"NSMenuItemHighlightColor"]) {
275 qWarning(
"Qt: qt_mac_toQBrush: cannot convert from NSMenuItemHighlightColor");
281 if ([
color.className isEqualToString:
@"NSMetalPatternColor"]) {
287 qWarning(
"Qt: qt_mac_toQBrush: cannot convert from NSMetalPatternColor");
294 if (qt_mac_isSystemColorOrInstance(
color,
@"_sourceListBackgroundColor",
@"NSSourceListBackgroundColor")) {
313 if (qt_mac_isSystemColorOrInstance(
color,
@"controlColor",
@"NSGradientPatternColor") ||
314 qt_mac_isSystemColorOrInstance(
color,
@"windowBackgroundColor",
@"NSGradientPatternColor")) {
320 if (
color.type == NSColorTypePattern) {
321 NSImage *patternImage =
color.patternImage;
322 const QSizeF sz(patternImage.size.width, patternImage.size.height);
324 qtBrush.
setTexture(qt_mac_toQPixmap(patternImage, sz));
337 CGAffineTransform old_xform = CGAffineTransformIdentity;
339 old_xform = CGContextGetCTM(hd);
340 CGContextConcatCTM(hd, CGAffineTransformInvert(old_xform));
341 CGContextConcatCTM(hd, *orig_xform);
345 CGContextBeginPath(hd);
347 CGContextAddRect(hd, CGRectMake(0, 0, 0, 0));
349 for (
const QRect &
r : rgn) {
350 CGRect mac_r = CGRectMake(
r.x(),
r.y(),
r.width(),
r.height());
351 CGContextAddRect(hd, mac_r);
357 CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
358 CGContextConcatCTM(hd, old_xform);
384void QMacCGContext::initialize(
QPaintDevice *paintDevice)
395 qWarning() <<
"QMacCGContext: Empty platformPixmap";
403 qWarning() <<
"QMacCGContext: not implemented: Widget class";
416 paintEngine = aggregateEngine;
426 qWarning() <<
"QMacCGContext:: Unsupported paint engine type" << paintEngine->
type();
440 qWarning() <<
"QMacCGContext:: Unsupported paint device type" << painterDeviceType;
457 CGContextScaleCTM(
context, 1, -1);
459 const qreal devicePixelRatio =
image->devicePixelRatio();
486 CGContextScaleCTM(
context, devicePixelRatio, devicePixelRatio);
void setColor(const QColor &color)
Sets the brush color to the given color.
void setStyle(Qt::BrushStyle)
Sets the brush style to style.
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
The QColor class provides colors based on RGB, HSV or CMYK values.
void setRgbF(float r, float g, float b, float a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha,...
void setCmykF(float c, float m, float y, float k, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
The QIcon class provides scalable icons in different modes and states.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
QList< QSize > availableSizes(Mode mode=Normal, State state=Off) const
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
@ Format_RGBA8888_Premultiplied
@ Format_ARGB32_Premultiplied
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
qsizetype count() const noexcept
void reserve(qsizetype size)
void append(parameter_type t)
virtual int devType() const
static QPaintEnginePrivate * get(QPaintEngine *paintEngine)
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
QRegion systemClip() const
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns \nullptr...
The QPainter class performs low-level painting on widgets and other paint devices.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
QRegion clipRegion() const
Returns the currently set clip region.
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
ColorGroup
\value Disabled \value Active \value Inactive \value Normal synonym for Active
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
QImage toImage() const
Converts the pixmap to a QImage.
\inmodule QtCore\reentrant
The QRegion class specifies a clip region for a painter.
int rectCount() const noexcept
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
void setRects(const QRect *rect, int num)
Sets the region using the array of rectangles specified by rects and number.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Combined button and popup list for selecting options.
void qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage)
QBrush qt_mac_toQBrush(CGColorRef color)
void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig_xform)
QColor qt_mac_toQColor(CGColorRef color)
QImage qt_mac_toQImage(CGImageRef image)
void qt_mac_scale_region(QRegion *region, qreal scaleFactor)
CGImageRef qt_mac_toCGImage(const QImage &inImage)
QT_USE_NAMESPACE QT_BEGIN_NAMESPACE CGBitmapInfo qt_mac_bitmapInfoForImage(const QImage &image)
CGImageRef qt_mac_toCGImageMask(const QImage &image)
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLint GLenum GLint components
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat GLfloat GLfloat h
GLfloat GLfloat GLfloat alpha
struct CGContext * CGContextRef
static QWindowsDirect2DPlatformPixmap * platformPixmap(QPixmap *p)
static QInputDevice::DeviceType deviceType(const UINT cursorType)
const char className[16]
[1]
QSqlQueryModel * model
[16]
rect deviceTransform(view->viewportTransform()).map(QPointF(0