From d8857f21ac2640215177b9cb7bb681b74bc66068 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 22 Nov 2016 09:46:14 +0100 Subject: If there are no available sizes, then fallback to the requested size In a case like the SVG iconengine there is no available sizes implementation. However in that case we don't need to provide different sizes as we can have SVG scale it for us to the one requested. So it is assumed that with no available sizes implementation that the icon engine will take care of this for us. This ensures that SVG files can be used as icons inside the menu on macOS. Task-number: QTBUG-40225 Task-number: QTBUG-55932 Change-Id: If01ca582c4c07834e6de16652924e0b7e118c87c Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoahelpers.h | 2 +- src/plugins/platforms/cocoa/qcocoahelpers.mm | 7 +++++-- src/plugins/platforms/cocoa/qcocoamenuitem.mm | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index c2abe4e245..bbb37937d2 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -64,7 +64,7 @@ inline NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &qst NSImage *qt_mac_cgimage_to_nsimage(CGImageRef iamge); NSImage *qt_mac_create_nsimage(const QPixmap &pm); -NSImage *qt_mac_create_nsimage(const QIcon &icon); +NSImage *qt_mac_create_nsimage(const QIcon &icon, int defaultSize = 0); CGImageRef qt_mac_toCGImage(const QImage &qImage); CGImageRef qt_mac_toCGImageMask(const QImage &qImage); QImage qt_mac_toQImage(CGImageRef image); diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 058209da7e..cd73148752 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -152,13 +152,16 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm) return nsImage; } -NSImage *qt_mac_create_nsimage(const QIcon &icon) +NSImage *qt_mac_create_nsimage(const QIcon &icon, int defaultSize) { if (icon.isNull()) return nil; NSImage *nsImage = [[NSImage alloc] init]; - foreach (QSize size, icon.availableSizes()) { + QList availableSizes = icon.availableSizes(); + if (availableSizes.isEmpty() && defaultSize > 0) + availableSizes << QSize(defaultSize, defaultSize); + foreach (QSize size, availableSizes) { QPixmap pm = icon.pixmap(size); QImage image = pm.toImage(); CGImageRef cgImage = qt_mac_toCGImage(image); diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 2d4073956a..fa8eb22569 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -348,7 +348,7 @@ NSMenuItem *QCocoaMenuItem::sync() NSImage *img = nil; if (!m_icon.isNull()) { - img = qt_mac_create_nsimage(m_icon); + img = qt_mac_create_nsimage(m_icon, m_iconSize); [img setSize:NSMakeSize(m_iconSize, m_iconSize)]; } [m_native setImage:img]; -- cgit v1.2.3 From 600c5a7e1bb59f97205e0a50ccc05937a31b9480 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 15 Nov 2016 14:43:45 +0100 Subject: Document third-party code in Cocoa QPA plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2c30f5da25c83d6129403cb9b745a2f17fd6fd9e Reviewed-by: Topi Reiniƶ --- src/plugins/platforms/cocoa/COCOA_LICENSE.txt | 29 +++++++++++++++++++++++++ src/plugins/platforms/cocoa/qt_attribution.json | 13 +++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/plugins/platforms/cocoa/COCOA_LICENSE.txt create mode 100644 src/plugins/platforms/cocoa/qt_attribution.json (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/COCOA_LICENSE.txt b/src/plugins/platforms/cocoa/COCOA_LICENSE.txt new file mode 100644 index 0000000000..8c08f48528 --- /dev/null +++ b/src/plugins/platforms/cocoa/COCOA_LICENSE.txt @@ -0,0 +1,29 @@ +Copyright (c) 2007-2008, Apple, Inc. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of Apple, Inc. nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/plugins/platforms/cocoa/qt_attribution.json b/src/plugins/platforms/cocoa/qt_attribution.json new file mode 100644 index 0000000000..37c0937f29 --- /dev/null +++ b/src/plugins/platforms/cocoa/qt_attribution.json @@ -0,0 +1,13 @@ +{ + "Id": "cocoa-platform-plugin", + "Name": "Cocoa Platform Plugin", + "QDocModule": "qtgui", + "QtUsage": "Code used in the Qt Platform Abstraction (QPA) for macOS.", + "Files": "qcocoaapplication.h qcocoaapplication.mm qcocoaapplicationdelegate.h qcocoaapplicationdelegate.mm qcocoaeventdispatcher.h qcocoaeventdispatcher.mm qcocoaintrospection.h qcocoaintrospection.mm qcocoasystemtrayicon.mm qmacdefines_mac.h", + + "Description": "Allows Qt to integrate into Apple's Cocoa API.", + "LicenseId": "BSD-3-Clause", + "License": "BSD 3-clause \"New\" or \"Revised\" License", + "LicenseFile": "COCOA_LICENSE.txt", + "Copyright": "Copyright (c) 2007-2008, Apple, Inc." +} -- cgit v1.2.3 From 2c9dc93696f32b798b872f931c102329d0ba7155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 2 Dec 2016 12:03:02 +0100 Subject: Cocoa: Unbreak app activation on macOS Sierra Previously, we would activate the application during QCocoaIntegration construction, which means at QApplication creation time. This now seems to interfere with application startup on macOS Sierra, where the application window ends up in an unfocused state. Move application activation to applicationDidFinishLaunching, at which point the Cocoa runtime should be completely initialized. Do this for 10.12+ only to avoid regressions/ test failures on previous versions. Change-Id: Ic5f150d53f06a302b53a3ba86a4a9b18bb2a1783 Task-number: QTBUG-57044 Reviewed-by: Timur Pocheptsov Reviewed-by: Qt CI Bot --- src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 14 +++++++++----- src/plugins/platforms/cocoa/qcocoaintegration.mm | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index da755aa189..7368aabf7d 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -282,14 +282,18 @@ QT_END_NAMESPACE { Q_UNUSED(aNotification); inLaunch = false; - // qt_release_apple_event_handler(); - - // Insert code here to initialize your application + if (qEnvironmentVariableIsEmpty("QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM")) { + if (QSysInfo::macVersion() >= QSysInfo::MV_10_12) { + // Move the application window to front to avoid launching behind the terminal. + // Ignoring other apps is neccessary (we must ignore the terminal), but makes + // Qt apps play slightly less nice with other apps when lanching from Finder + // (See the activateIgnoringOtherApps docs.) + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; + } + } } - - - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames { Q_UNUSED(filenames); diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 92fffb4d15..18340f4ee1 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -312,11 +312,15 @@ QCocoaIntegration::QCocoaIntegration(const QStringList ¶mList) // see the function implementation for exceptions.) qt_mac_transformProccessToForegroundApplication(); - // Move the application window to front to avoid launching behind the terminal. - // Ignoring other apps is neccessary (we must ignore the terminal), but makes - // Qt apps play slightly less nice with other apps when lanching from Finder - // (See the activateIgnoringOtherApps docs.) - [cocoaApplication activateIgnoringOtherApps : YES]; + // Move the application window to front to make it take focus, also when launching + // from the terminal. On 10.12+ this call has been moved to applicationDidFinishLauching + // to work around issues with loss of focus at startup. + if (QSysInfo::macVersion() < QSysInfo::MV_10_12) { + // Ignoring other apps is neccessary (we must ignore the terminal), but makes + // Qt apps play slightly less nice with other apps when lanching from Finder + // (See the activateIgnoringOtherApps docs.) + [cocoaApplication activateIgnoringOtherApps : YES]; + } } // ### For AA_MacPluginApplication we don't want to load the menu nib. -- cgit v1.2.3