diff options
Diffstat (limited to 'src/gui/painting/qcoregraphics.mm')
-rw-r--r-- | src/gui/painting/qcoregraphics.mm | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/gui/painting/qcoregraphics.mm b/src/gui/painting/qcoregraphics.mm index ed44efc5ec..27b46202f5 100644 --- a/src/gui/painting/qcoregraphics.mm +++ b/src/gui/painting/qcoregraphics.mm @@ -132,7 +132,7 @@ QT_END_NAMESPACE auto nsImage = [[[NSImage alloc] initWithSize:NSZeroSize] autorelease]; - for (QSize size : qAsConst(availableSizes)) { + for (QSize size : std::as_const(availableSizes)) { QImage image = icon.pixmap(size).toImage(); if (image.isNull()) continue; @@ -162,6 +162,9 @@ QT_BEGIN_NAMESPACE QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size) { + // ### TODO: add parameter so that we can decide whether to maintain the aspect + // ratio of the image (positioning the image inside the pixmap of size \a size), + // or whether we want to fill the resulting pixmap by stretching the image. const NSSize pixmapSize = NSMakeSize(size.width(), size.height()); QPixmap pixmap(pixmapSize.width, pixmapSize.height); pixmap.fill(Qt::transparent); @@ -182,6 +185,25 @@ QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size) #endif // Q_OS_MACOS +#ifdef QT_PLATFORM_UIKIT + +QImage qt_mac_toQImage(const UIImage *image, QSizeF size) +{ + // ### TODO: same as above + QImage ret(size.width(), size.height(), QImage::Format_ARGB32_Premultiplied); + ret.fill(Qt::transparent); + QMacCGContext ctx(&ret); + if (!ctx) + return QImage(); + UIGraphicsPushContext(ctx); + const CGRect rect = CGRectMake(0, 0, size.width(), size.height()); + [image drawInRect:rect]; + UIGraphicsPopContext(); + return ret; +} + +#endif // QT_PLATFORM_UIKIT + // ---------------------- Colors and Brushes ---------------------- QColor qt_mac_toQColor(CGColorRef color) @@ -386,11 +408,14 @@ void QMacCGContext::initialize(QPaintDevice *paintDevice) // Find the underlying QImage of the paint device switch (int deviceType = paintDevice->devType()) { case QInternal::Pixmap: { - auto *platformPixmap = static_cast<QPixmap*>(paintDevice)->handle(); - if (platformPixmap && platformPixmap->classId() == QPlatformPixmap::RasterClass) - initialize(platformPixmap->buffer()); - else - qWarning() << "QMacCGContext: Unsupported pixmap class" << platformPixmap->classId(); + if (auto *platformPixmap = static_cast<QPixmap*>(paintDevice)->handle()) { + if (platformPixmap->classId() == QPlatformPixmap::RasterClass) + initialize(platformPixmap->buffer()); + else + qWarning() << "QMacCGContext: Unsupported pixmap class" << platformPixmap->classId(); + } else { + qWarning() << "QMacCGContext: Empty platformPixmap"; + } break; } case QInternal::Image: |