diff options
Diffstat (limited to 'src/gui/painting/qcoregraphics.mm')
-rw-r--r-- | src/gui/painting/qcoregraphics.mm | 93 |
1 files changed, 41 insertions, 52 deletions
diff --git a/src/gui/painting/qcoregraphics.mm b/src/gui/painting/qcoregraphics.mm index ef29f4a490..27b46202f5 100644 --- a/src/gui/painting/qcoregraphics.mm +++ b/src/gui/painting/qcoregraphics.mm @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qcoregraphics_p.h" @@ -58,22 +22,22 @@ CGBitmapInfo qt_mac_bitmapInfoForImage(const QImage &image) CGBitmapInfo bitmapInfo = kCGImageAlphaNone; switch (image.format()) { case QImage::Format_ARGB32: - bitmapInfo = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; + bitmapInfo = CGBitmapInfo(kCGImageAlphaFirst) | kCGBitmapByteOrder32Host; break; case QImage::Format_RGB32: - bitmapInfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; + bitmapInfo = CGBitmapInfo(kCGImageAlphaNoneSkipFirst) | kCGBitmapByteOrder32Host; break; case QImage::Format_RGBA8888_Premultiplied: - bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big; + bitmapInfo = CGBitmapInfo(kCGImageAlphaPremultipliedLast) | kCGBitmapByteOrder32Big; break; case QImage::Format_RGBA8888: - bitmapInfo = kCGImageAlphaLast | kCGBitmapByteOrder32Big; + bitmapInfo = CGBitmapInfo(kCGImageAlphaLast) | kCGBitmapByteOrder32Big; break; case QImage::Format_RGBX8888: - bitmapInfo = kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big; + bitmapInfo = CGBitmapInfo(kCGImageAlphaNoneSkipLast) | kCGBitmapByteOrder32Big; break; case QImage::Format_ARGB32_Premultiplied: - bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; + bitmapInfo = CGBitmapInfo(kCGImageAlphaPremultipliedFirst) | kCGBitmapByteOrder32Host; break; default: break; } @@ -145,7 +109,7 @@ QT_END_NAMESPACE // NSImage. auto nsImage = [[NSImage alloc] initWithSize:NSZeroSize]; auto *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; - imageRep.size = (image.size() / image.devicePixelRatio()).toCGSize(); + imageRep.size = image.deviceIndependentSize().toCGSize(); [nsImage addRepresentation:[imageRep autorelease]]; Q_ASSERT(CGSizeEqualToSize(nsImage.size, imageRep.size)); @@ -168,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; @@ -178,7 +142,7 @@ QT_END_NAMESPACE continue; auto *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; - imageRep.size = (image.size() / image.devicePixelRatio()).toCGSize(); + imageRep.size = image.deviceIndependentSize().toCGSize(); [nsImage addRepresentation:[imageRep autorelease]]; } @@ -198,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); @@ -218,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) @@ -422,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: |