diff options
author | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-08-22 11:30:00 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-08-22 11:30:01 +0200 |
commit | d314819fc02139e05e16c56657898c704f7fb48f (patch) | |
tree | a61ba968233634948401c8339f9613844de1c2b5 /src/plugins/platforms/cocoa | |
parent | 9f888d2fde9c5413e5519e0914e9b13638760985 (diff) | |
parent | e0e9e196a72ffe5457034894eaaadc90ed0d34ef (diff) |
Merge dev into 5.8
Change-Id: I41ee7b50534b01cf042bed8bb8824ba2e5026a29
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r-- | src/plugins/platforms/cocoa/cocoa.pro | 2 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoadrag.mm | 16 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm | 9 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 1 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 64 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoatheme.mm | 3 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 33 |
7 files changed, 61 insertions, 67 deletions
diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 02d8b16110..d9d3cb1627 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -71,7 +71,7 @@ HEADERS += qcocoaintegration.h \ messages.h \ qcocoamimetypes.h -contains(QT_CONFIG, opengl.*) { +qtConfig(opengl.*) { OBJECTIVE_SOURCES += qcocoaglcontext.mm HEADERS += qcocoaglcontext.h diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm index 1ebcde0584..13ae0382ab 100644 --- a/src/plugins/platforms/cocoa/qcocoadrag.mm +++ b/src/plugins/platforms/cocoa/qcocoadrag.mm @@ -40,6 +40,9 @@ #include "qcocoadrag.h" #include "qmacclipboard.h" #include "qcocoahelpers.h" +#ifndef QT_NO_WIDGETS +#include <QtWidgets/qwidget.h> +#endif QT_BEGIN_NAMESPACE @@ -187,7 +190,18 @@ QPixmap QCocoaDrag::dragPixmap(QDrag *drag, QPoint &hotSpot) const const int width = fm.width(s); const int height = fm.height(); if (width > 0 && height > 0) { - pm = QPixmap(width, height); + qreal dpr = 1.0; + if (const QWindow *sourceWindow = qobject_cast<QWindow *>(drag->source())) { + dpr = sourceWindow->devicePixelRatio(); + } +#ifndef QT_NO_WIDGETS + else if (const QWidget *sourceWidget = qobject_cast<QWidget *>(drag->source())) { + if (const QWindow *sourceWindow = sourceWidget->window()->windowHandle()) + dpr = sourceWindow->devicePixelRatio(); + } +#endif + pm = QPixmap(width * dpr, height * dpr); + pm.setDevicePixelRatio(dpr); QPainter p(&pm); p.fillRect(0, 0, pm.width(), pm.height(), Qt::color0); p.setPen(Qt::color1); diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 0375dd85f2..31a0a3d600 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -589,6 +589,15 @@ void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_panelClosed(bool accepted) QCocoaMenuBar::resetKnownMenuItemsToQt(); if (accepted) { emit accept(); + + QString filter = selectedNameFilter(); + if (filter.isEmpty()) + emit filterSelected(filter); + + QList<QUrl> files = selectedFiles(); + emit filesSelected(files); + if (files.count() == 1) + emit fileSelected(files.first()); } else { emit reject(); } diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index dc7dfb788f..dfda22d376 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -365,6 +365,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); emit mHelper->reject(); } else { emit mHelper->accept(); + emit mHelper->fontSelected(mHelper->currentFont()); } } } diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 9b4055d92d..6920f75887 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -101,65 +101,23 @@ void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list) return result; } -static void qt_mac_deleteImage(void *image, const void *, size_t) -{ - delete static_cast<QImage *>(image); -} - -// Creates a CGDataProvider with the data from the given image. -// The data provider retains a copy of the image. -CGDataProviderRef qt_mac_CGDataProvider(const QImage &image) -{ - return CGDataProviderCreateWithData(new QImage(image), image.bits(), - image.byteCount(), qt_mac_deleteImage); -} - CGImageRef qt_mac_toCGImage(const QImage &inImage) { - if (inImage.isNull()) - return 0; + CGImageRef cgImage = inImage.toCGImage(); + if (cgImage) + return cgImage; - QImage image = inImage; - - uint cgflags = kCGImageAlphaNone; - switch (image.format()) { - case QImage::Format_ARGB32: - cgflags = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; - break; - case QImage::Format_RGB32: - cgflags = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; - break; - case QImage::Format_RGB888: - cgflags = kCGImageAlphaNone | kCGBitmapByteOrder32Big; - break; - case QImage::Format_RGBA8888_Premultiplied: - cgflags = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big; - break; - case QImage::Format_RGBA8888: - cgflags = kCGImageAlphaLast | kCGBitmapByteOrder32Big; - break; - case QImage::Format_RGBX8888: - cgflags = kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big; - break; - default: - // Everything not recognized explicitly is converted to ARGB32_Premultiplied. - image = inImage.convertToFormat(QImage::Format_ARGB32_Premultiplied); - // no break; - case QImage::Format_ARGB32_Premultiplied: - cgflags = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; - break; - } - - QCFType<CGDataProviderRef> dataProvider = qt_mac_CGDataProvider(image); - return CGImageCreate(image.width(), image.height(), 8, 32, - image.bytesPerLine(), - qt_mac_genericColorSpace(), - cgflags, dataProvider, 0, false, kCGRenderingIntentDefault); + // Convert image data to a known-good format if the fast conversion fails. + return inImage.convertToFormat(QImage::Format_ARGB32_Premultiplied).toCGImage(); } CGImageRef qt_mac_toCGImageMask(const QImage &image) { - QCFType<CGDataProviderRef> dataProvider = qt_mac_CGDataProvider(image); + static const auto deleter = [](void *image, const void *, size_t) { delete static_cast<QImage *>(image); }; + QCFType<CGDataProviderRef> dataProvider = + CGDataProviderCreateWithData(new QImage(image), image.bits(), + image.byteCount(), deleter); + return CGImageMaskCreate(image.width(), image.height(), 8, image.depth(), image.bytesPerLine(), dataProvider, NULL, false); } @@ -647,7 +605,7 @@ QString qt_mac_removeAmpersandEscapes(QString s) returned if it can't be obtained. It is the caller's responsibility to CGContextRelease the context when finished using it. - \warning This function is only available on OS X. + \warning This function is only available on \macos. \warning This function is duplicated in qmacstyle_mac.mm */ CGContextRef qt_mac_cg_context(QPaintDevice *pdev) diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 3a3d634f5a..cb8ffee556 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -287,7 +287,8 @@ public: const qreal devicePixelRatio = qGuiApp->devicePixelRatio(); const int sizes[] = { qRound(16 * devicePixelRatio), qRound(32 * devicePixelRatio), - qRound(64 * devicePixelRatio), qRound(128 * devicePixelRatio) + qRound(64 * devicePixelRatio), qRound(128 * devicePixelRatio), + qRound(256 * devicePixelRatio) }; return QAbstractFileIconEngine::toSizeList(sizes, sizes + sizeof(sizes) / sizeof(sizes[0])); } diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 500049a504..af324c07ff 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -1999,16 +1999,27 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin return target->mapFromGlobal(source->mapToGlobal(point)); } -- (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL)isLocal +- (NSDragOperation)draggingSession:(NSDraggingSession *)session + sourceOperationMaskForDraggingContext:(NSDraggingContext)context { - Q_UNUSED(isLocal); + Q_UNUSED(session); + Q_UNUSED(context); QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); return qt_mac_mapDropActions(nativeDrag->currentDrag()->supportedActions()); } -- (BOOL) ignoreModifierKeysWhileDragging +- (BOOL)ignoreModifierKeysForDraggingSession:(NSDraggingSession *)session { - return NO; + Q_UNUSED(session); + // According to the "Dragging Sources" chapter on Cocoa DnD Programming + // (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DragandDrop/Concepts/dragsource.html), + // if the control, option, or command key is pressed, the source’s + // operation mask is filtered to only contain a reduced set of operations. + // + // Since Qt already takes care of tracking the keyboard modifiers, we + // don't need (or want) Cocoa to filter anything. Instead, we'll let + // the application do the actual filtering. + return YES; } - (BOOL)wantsPeriodicDraggingUpdates @@ -2165,27 +2176,27 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin return response.isAccepted(); } -- (void)draggedImage:(NSImage*) img endedAt:(NSPoint) point operation:(NSDragOperation) operation +- (void)draggingSession:(NSDraggingSession *)session + endedAtPoint:(NSPoint)screenPoint + operation:(NSDragOperation)operation { - Q_UNUSED(img); + Q_UNUSED(session); Q_UNUSED(operation); QWindow *target = findEventTargetWindow(m_window); if (!target) return; -// keep our state, and QGuiApplication state (buttons member) in-sync, -// or future mouse events will be processed incorrectly + // keep our state, and QGuiApplication state (buttons member) in-sync, + // or future mouse events will be processed incorrectly NSUInteger pmb = [NSEvent pressedMouseButtons]; for (int buttonNumber = 0; buttonNumber < 32; buttonNumber++) { // see cocoaButton2QtButton() for the 32 value if (!(pmb & (1 << buttonNumber))) m_buttons &= ~cocoaButton2QtButton(buttonNumber); } - NSPoint windowPoint = [self convertPoint: point fromView: nil]; + NSPoint windowPoint = [self.window convertRectFromScreen:NSMakeRect(screenPoint.x, screenPoint.y, 1, 1)].origin; QPoint qtWindowPoint(windowPoint.x, windowPoint.y); - NSWindow *window = [self window]; - NSPoint screenPoint = [window convertRectToScreen:NSMakeRect(point.x, point.y, 0, 0)].origin; QPoint qtScreenPoint = QPoint(screenPoint.x, qt_mac_flipYCoordinate(screenPoint.y)); QWindowSystemInterface::handleMouseEvent(target, mapWindowCoordinates(m_window, target, qtWindowPoint), qtScreenPoint, m_buttons); |