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); };
60 QCFType<CGDataProviderRef> dataProvider =
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
101 QCFType<CGImageRef> cgImage =
image.toCGImage();
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];
140 QCFType<CGImageRef> cgImage =
image.toCGImage();
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);
168 const NSSize pixmapSize = NSMakeSize(
size.width(),
size.height());
171 [image setSize:pixmapSize];
172 const NSRect iconRect = NSMakeRect(0, 0, pixmapSize.width, pixmapSize.height);
176 NSGraphicsContext *
gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
179 [NSGraphicsContext saveGraphicsState];
180 [NSGraphicsContext setCurrentContext:gc];
181 [image drawInRect:iconRect fromRect:iconRect operation:NSCompositingOperationSourceOver fraction:1.0 respectFlipped:YES hints:nil];
182 [NSGraphicsContext restoreGraphicsState];
188#ifdef QT_PLATFORM_UIKIT
198 UIGraphicsPushContext(
ctx);
199 const CGRect
rect = CGRectMake(0, 0,
size.width(),
size.height());
200 [image drawInRect:rect];
201 UIGraphicsPopContext();
212 CGColorSpaceModel
model = CGColorSpaceGetModel(CGColorGetColorSpace(
color));
214 if (
model == kCGColorSpaceModelRGB) {
216 }
else if (
model == kCGColorSpaceModelCMYK) {
218 }
else if (
model == kCGColorSpaceModelMonochrome) {
222 qWarning(
"Qt: qt_mac_toQColor: cannot convert from colorspace model: %d",
model);
232 switch (
color.type) {
233 case NSColorTypeComponentBased: {
234 const NSColorSpace *colorSpace = [color colorSpace];
235 if (colorSpace == NSColorSpace.genericRGBColorSpace
236 &&
color.numberOfComponents == 4) {
238 [color getComponents:components];
241 }
else if (colorSpace == NSColorSpace.genericCMYKColorSpace
242 &&
color.numberOfComponents == 5) {
244 [color getComponents:components];
251 const NSColor *tmpColor = [color colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
253 [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
266 CGColorSpaceModel
model = CGColorSpaceGetModel(CGColorGetColorSpace(
color));
267 if (
model == kCGColorSpaceModelPattern) {
269 qWarning(
"Qt: qt_mac_toQBrush: cannot convert from colorspace model: %d",
model);
279static bool qt_mac_isSystemColorOrInstance(
const NSColor *
color, NSString *colorNameComponent, NSString *
className)
284 if (
color.type == NSColorTypeCatalog &&
285 [
color.catalogNameComponent isEqualToString:
@"System"] &&
286 [
color.colorNameComponent isEqualToString:colorNameComponent])
296 if ([
color.className isEqualToString:
@"NSMenuItemHighlightColor"]) {
297 qWarning(
"Qt: qt_mac_toQBrush: cannot convert from NSMenuItemHighlightColor");
303 if ([
color.className isEqualToString:
@"NSMetalPatternColor"]) {
309 qWarning(
"Qt: qt_mac_toQBrush: cannot convert from NSMetalPatternColor");
316 if (qt_mac_isSystemColorOrInstance(
color,
@"_sourceListBackgroundColor",
@"NSSourceListBackgroundColor")) {
335 if (qt_mac_isSystemColorOrInstance(
color,
@"controlColor",
@"NSGradientPatternColor") ||
336 qt_mac_isSystemColorOrInstance(
color,
@"windowBackgroundColor",
@"NSGradientPatternColor")) {
342 if (
color.type == NSColorTypePattern) {
343 NSImage *patternImage =
color.patternImage;
344 const QSizeF sz(patternImage.size.width, patternImage.size.height);
346 qtBrush.setTexture(qt_mac_toQPixmap(patternImage, sz));
359 CGAffineTransform old_xform = CGAffineTransformIdentity;
361 old_xform = CGContextGetCTM(hd);
362 CGContextConcatCTM(hd, CGAffineTransformInvert(old_xform));
363 CGContextConcatCTM(hd, *orig_xform);
367 CGContextBeginPath(hd);
369 CGContextAddRect(hd, CGRectMake(0, 0, 0, 0));
371 for (
const QRect &
r : rgn) {
372 CGRect mac_r = CGRectMake(
r.x(),
r.y(),
r.width(),
r.height());
373 CGContextAddRect(hd, mac_r);
379 CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
380 CGContextConcatCTM(hd, old_xform);
390 QVector<QRect> scaledRects;
391 scaledRects.reserve(region->
rectCount());
394 scaledRects.append(
QRect(
rect.topLeft() * scaleFactor,
rect.size() * scaleFactor));
396 region->
setRects(&scaledRects[0], scaledRects.count());
406void QMacCGContext::initialize(
QPaintDevice *paintDevice)
417 qWarning() <<
"QMacCGContext: Empty platformPixmap";
425 qWarning() <<
"QMacCGContext: not implemented: Widget class";
438 paintEngine = aggregateEngine;
448 qWarning() <<
"QMacCGContext:: Unsupported paint engine type" << paintEngine->
type();
462 qWarning() <<
"QMacCGContext:: Unsupported paint device type" << painterDeviceType;
473 QCFType<CGColorSpaceRef> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
479 CGContextScaleCTM(
context, 1, -1);
481 const qreal devicePixelRatio =
image->devicePixelRatio();
508 CGContextScaleCTM(
context, devicePixelRatio, devicePixelRatio);
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 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
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 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
void gc(QV4::ExecutionEngine &engine, GCFlags flags)
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