diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoacursor.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoacursor.mm | 119 |
1 files changed, 50 insertions, 69 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoacursor.mm b/src/plugins/platforms/cocoa/qcocoacursor.mm index e0d623fc4c..aaa35a91ef 100644 --- a/src/plugins/platforms/cocoa/qcocoacursor.mm +++ b/src/plugins/platforms/cocoa/qcocoacursor.mm @@ -1,41 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins 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) 2016 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 <AppKit/AppKit.h> #include "qcocoacursor.h" #include "qcocoawindow.h" @@ -45,8 +11,19 @@ #include <QtGui/QBitmap> +#if !defined(QT_APPLE_NO_PRIVATE_APIS) +@interface NSCursor() ++ (id)_windowResizeNorthWestSouthEastCursor; ++ (id)_windowResizeNorthEastSouthWestCursor; ++ (id)_windowResizeNorthSouthCursor; ++ (id)_windowResizeEastWestCursor; +@end +#endif // QT_APPLE_NO_PRIVATE_APIS + QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QCocoaCursor::QCocoaCursor() { } @@ -116,7 +93,7 @@ NSCursor *QCocoaCursor::convertCursor(QCursor *cursor) return nil; const Qt::CursorShape newShape = cursor->shape(); - NSCursor *cocoaCursor; + NSCursor *cocoaCursor = nil; // Check for a suitable built-in NSCursor first: switch (newShape) { @@ -157,7 +134,29 @@ NSCursor *QCocoaCursor::convertCursor(QCursor *cursor) case Qt::DragLinkCursor: cocoaCursor = [NSCursor dragLinkCursor]; break; - default : { +#if !defined(QT_APPLE_NO_PRIVATE_APIS) + case Qt::SizeVerCursor: + if ([NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)]) + cocoaCursor = [NSCursor _windowResizeNorthSouthCursor]; + break; + case Qt::SizeHorCursor: + if ([NSCursor respondsToSelector:@selector(_windowResizeEastWestCursor)]) + cocoaCursor = [NSCursor _windowResizeEastWestCursor]; + break; + case Qt::SizeBDiagCursor: + if ([NSCursor respondsToSelector:@selector(_windowResizeNorthEastSouthWestCursor)]) + cocoaCursor = [NSCursor _windowResizeNorthEastSouthWestCursor]; + break; + case Qt::SizeFDiagCursor: + if ([NSCursor respondsToSelector:@selector(_windowResizeNorthWestSouthEastCursor)]) + cocoaCursor = [NSCursor _windowResizeNorthWestSouthEastCursor]; + break; +#endif // QT_APPLE_NO_PRIVATE_APIS + default: + break; + } + + if (!cocoaCursor) { // No suitable OS cursor exist, use cursors provided // by Qt for the rest. Check for a cached cursor: cocoaCursor = m_cursors.value(newShape); @@ -172,8 +171,6 @@ NSCursor *QCocoaCursor::convertCursor(QCursor *cursor) m_cursors.insert(newShape, cocoaCursor); } - - break; } } return cocoaCursor; } @@ -253,15 +250,15 @@ NSCursor *QCocoaCursor::createCursorData(QCursor *cursor) return createCursorFromPixmap(pixmap); break; } case Qt::WaitCursor: { - QPixmap pixmap = QPixmap(QLatin1String(":/qt-project.org/mac/cursors/images/spincursor.png")); + QPixmap pixmap = QPixmap(":/qt-project.org/mac/cursors/images/spincursor.png"_L1); return createCursorFromPixmap(pixmap, hotspot); break; } case Qt::SizeAllCursor: { - QPixmap pixmap = QPixmap(QLatin1String(":/qt-project.org/mac/cursors/images/sizeallcursor.png")); + QPixmap pixmap = QPixmap(":/qt-project.org/mac/cursors/images/sizeallcursor.png"_L1); return createCursorFromPixmap(pixmap, QPoint(8, 8)); break; } case Qt::BusyCursor: { - QPixmap pixmap = QPixmap(QLatin1String(":/qt-project.org/mac/cursors/images/waitcursor.png")); + QPixmap pixmap = QPixmap(":/qt-project.org/mac/cursors/images/waitcursor.png"_L1); return createCursorFromPixmap(pixmap, hotspot); break; } #define QT_USE_APPROXIMATE_CURSORS @@ -301,17 +298,17 @@ NSCursor *QCocoaCursor::createCursorData(QCursor *cursor) if (cursorData) { QBitmap bitmap(QBitmap::fromData(QSize(16, 16), cursorData, QImage::Format_Mono)); QBitmap mask(QBitmap::fromData(QSize(16, 16), cursorMaskData, QImage::Format_Mono)); - return (createCursorFromBitmap(&bitmap, &mask, hotspot)); + return (createCursorFromBitmap(bitmap, mask, hotspot)); } return nil; // should not happen, all cases covered above } -NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap *bitmap, const QBitmap *mask, const QPoint hotspot) +NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap &bitmap, const QBitmap &mask, const QPoint hotspot) { - QImage finalCursor(bitmap->size(), QImage::Format_ARGB32); - QImage bmi = bitmap->toImage().convertToFormat(QImage::Format_RGB32); - QImage bmmi = mask->toImage().convertToFormat(QImage::Format_RGB32); + QImage finalCursor(bitmap.size(), QImage::Format_ARGB32); + QImage bmi = bitmap.toImage().convertToFormat(QImage::Format_RGB32); + QImage bmmi = mask.toImage().convertToFormat(QImage::Format_RGB32); for (int row = 0; row < finalCursor.height(); ++row) { QRgb *bmData = reinterpret_cast<QRgb *>(bmi.scanLine(row)); QRgb *bmmData = reinterpret_cast<QRgb *>(bmmi.scanLine(row)); @@ -332,27 +329,11 @@ NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap *bitmap, const QBit return createCursorFromPixmap(QPixmap::fromImage(finalCursor), hotspot); } -NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap pixmap, const QPoint hotspot) +NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap &pixmap, const QPoint hotspot) { NSPoint hotSpot = NSMakePoint(hotspot.x(), hotspot.y()); - NSImage *nsimage; - if (pixmap.devicePixelRatio() > 1.0) { - QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio(); - QPixmap scaledPixmap = pixmap.scaled(layoutSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - scaledPixmap.setDevicePixelRatio(1.0); - nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(scaledPixmap)); - CGImageRef cgImage = qt_mac_toCGImage(pixmap.toImage()); - NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; - [nsimage addRepresentation:imageRep]; - [imageRep release]; - CGImageRelease(cgImage); - } else { - nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap)); - } - - NSCursor *nsCursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot]; - [nsimage release]; - return nsCursor; + auto *image = [NSImage imageFromQImage:pixmap.toImage()]; + return [[NSCursor alloc] initWithImage:image hotSpot:hotSpot]; } QT_END_NAMESPACE |