From 9899c29daf3f867f02f4b5f920d50e877ec3f3c3 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Sat, 24 Mar 2018 01:05:17 +0100 Subject: Don't ignore the shortcut when the QMenuBar is parentless With Cocoa it is possible to have a parentless QMenuBar so that the same one can be used for multiple windows. Therefore if the top level window is the QMenuBar when checking for the context then we can let it carry on as if the top level window is the same as the active window. Task-number: QTBUG-45453 Change-Id: Ifacf2111d5f9973afe8af30c6338918f130e51a4 Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qshortcut.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index 32600d4152..fde039c75e 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -187,8 +187,15 @@ static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidge active_window = active_window->parentWidget()->window(); } - if (active_window != tlw) + if (active_window != tlw) { +#if QT_CONFIG(menubar) + // If the tlw is a QMenuBar then we allow it to proceed as this indicates that + // the QMenuBar is a parentless one and is therefore used for multiple top level + // windows in the application. This is common on macOS platforms for example. + if (!qobject_cast(tlw)) +#endif return false; + } /* if we live in a MDI subwindow, ignore the event if we are not the active document window */ -- cgit v1.2.3 From 99e52d89fec67e353e3ad8ac065268cd4c76e853 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 5 Apr 2018 13:05:15 +0200 Subject: Compile when using -no-feature-networkinterface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I12a808599dd1fecaebc2e85a96da27a044666009 Reviewed-by: Mårten Nordheim Reviewed-by: Timur Pocheptsov --- src/network/kernel/qnetworkinterface_linux.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/network/kernel/qnetworkinterface_linux.cpp b/src/network/kernel/qnetworkinterface_linux.cpp index 5dc62bf7bb..23ed2e0e15 100644 --- a/src/network/kernel/qnetworkinterface_linux.cpp +++ b/src/network/kernel/qnetworkinterface_linux.cpp @@ -41,6 +41,8 @@ #include "qnetworkinterface_p.h" #include "qnetworkinterface_unix_p.h" +#ifndef QT_NO_NETWORKINTERFACE + #include #include #include @@ -448,3 +450,5 @@ QList QNetworkInterfaceManager::scan() } QT_END_NAMESPACE + +#endif // QT_NO_NETWORKINTERFACE -- cgit v1.2.3 From 3697366642f05dd9239f730b48feea165f411ce6 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 10 Apr 2018 12:39:29 +0300 Subject: QSplitter: fix doc for widget() and handle() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7b8a0ba9f6b99eae22c2230c761d7a14045256db Reviewed-by: Edward Welbourne Reviewed-by: Topi Reiniö --- src/widgets/widgets/qsplitter.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index 55f2dd2421..6ee49aa9f0 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -1234,9 +1234,9 @@ QSplitterHandle *QSplitter::createHandle() } /*! - Returns the handle to the left (or above) for the item in the - splitter's layout at the given \a index. The handle at index 0 is - always hidden. + Returns the handle to the left of (or above) the item in the + splitter's layout at the given \a index, or \c nullptr if there is no such item. + The handle at index 0 is always hidden. For right-to-left languages such as Arabic and Hebrew, the layout of horizontal splitters is reversed. The handle will be to the @@ -1253,7 +1253,8 @@ QSplitterHandle *QSplitter::handle(int index) const } /*! - Returns the widget at the given \a index in the splitter's layout. + Returns the widget at the given \a index in the splitter's layout, + or \c nullptr if there is no such widget. \sa count(), handle(), indexOf(), insertWidget() */ -- cgit v1.2.3 From a75f25a43fd4bc5dab659dfc8d79a120258cec5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 16 Apr 2018 13:37:37 +0200 Subject: Fix runtime platform detection on Apple platforms The watchOS and tvOS platforms also define __IPHONE_OS_VERSION_MIN_REQUIRED for compatibility, so we need account for that in the ordering of the ifdefs. Task-number: QTBUG-67534 Change-Id: Id86e684137550533470370ef29c3563d677d5865 Reviewed-by: Gabriel de Dietrich --- src/corelib/kernel/qcore_mac_objc.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 24d73fa8be..5ecd86a30e 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -346,15 +346,15 @@ Qt::Key qt_mac_cocoaKey2QtKey(QChar keyCode) void qt_apple_check_os_version() { -#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) - const char *os = "iOS"; - const int version = __IPHONE_OS_VERSION_MIN_REQUIRED; +#if defined(__WATCH_OS_VERSION_MIN_REQUIRED) + const char *os = "watchOS"; + const int version = __WATCH_OS_VERSION_MIN_REQUIRED; #elif defined(__TV_OS_VERSION_MIN_REQUIRED) const char *os = "tvOS"; const int version = __TV_OS_VERSION_MIN_REQUIRED; -#elif defined(__WATCH_OS_VERSION_MIN_REQUIRED) - const char *os = "watchOS"; - const int version = __WATCH_OS_VERSION_MIN_REQUIRED; +#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) + const char *os = "iOS"; + const int version = __IPHONE_OS_VERSION_MIN_REQUIRED; #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) const char *os = "macOS"; const int version = __MAC_OS_X_VERSION_MIN_REQUIRED; -- cgit v1.2.3 From e0e1c7ec2da121fa2b3acc8e76eb96e959954608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 16 Apr 2018 15:32:30 +0200 Subject: iOS: Trigger manual layout of root view controller when coming out of background When rotating the device when the application is in the background iOS will ask the root view controller to layout its views when then foregrounding the application, but at that point the application state is still in the suspended state, meaning we block any view resizing or rendering. To ensure the views are resized correctly, we trigger a manual layout after the application comes out of the suspended state. Task-number: QTBUG-67719 Change-Id: I1ef0a4133d4b94edaac7b0f3cb4e49e367eb76d4 Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qiosapplicationstate.h | 4 +- src/plugins/platforms/ios/qiosapplicationstate.mm | 16 ++++---- src/plugins/platforms/ios/qioscontext.mm | 47 +++++++++++++---------- src/plugins/platforms/ios/qiosintegration.h | 2 + src/plugins/platforms/ios/qiosintegration.mm | 3 ++ src/plugins/platforms/ios/qiosviewcontroller.mm | 14 +++++++ 6 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/plugins/platforms/ios/qiosapplicationstate.h b/src/plugins/platforms/ios/qiosapplicationstate.h index a68147a72a..8a15a4a51b 100644 --- a/src/plugins/platforms/ios/qiosapplicationstate.h +++ b/src/plugins/platforms/ios/qiosapplicationstate.h @@ -56,8 +56,8 @@ public: static Qt::ApplicationState toQtApplicationState(UIApplicationState state); Q_SIGNALS: - void applicationStateWillChange(Qt::ApplicationState); - void applicationStateDidChange(Qt::ApplicationState); + void applicationStateWillChange(Qt::ApplicationState oldState, Qt::ApplicationState newState); + void applicationStateDidChange(Qt::ApplicationState oldState, Qt::ApplicationState newState); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiosapplicationstate.mm b/src/plugins/platforms/ios/qiosapplicationstate.mm index 3407aebf8f..6d9bcdacbf 100644 --- a/src/plugins/platforms/ios/qiosapplicationstate.mm +++ b/src/plugins/platforms/ios/qiosapplicationstate.mm @@ -87,18 +87,18 @@ QIOSApplicationState::QIOSApplicationState() void QIOSApplicationState::handleApplicationStateChanged(UIApplicationState uiState, const QString &reason) { - Qt::ApplicationState state = toQtApplicationState(uiState); - qCDebug(lcQpaApplication) << qPrintable(reason) - << "- moving from" << QGuiApplication::applicationState() << "to" << state; + Qt::ApplicationState oldState = QGuiApplication::applicationState(); + Qt::ApplicationState newState = toQtApplicationState(uiState); + qCDebug(lcQpaApplication) << qPrintable(reason) << "- moving from" << oldState << "to" << newState; if (QIOSIntegration *integration = QIOSIntegration::instance()) { - emit integration->applicationState.applicationStateWillChange(state); - QWindowSystemInterface::handleApplicationStateChanged(state); - emit integration->applicationState.applicationStateDidChange(state); - qCDebug(lcQpaApplication) << "done moving to" << state; + emit integration->applicationState.applicationStateWillChange(oldState, newState); + QWindowSystemInterface::handleApplicationStateChanged(newState); + emit integration->applicationState.applicationStateDidChange(oldState, newState); + qCDebug(lcQpaApplication) << "done moving to" << newState; } else { qCDebug(lcQpaApplication) << "no platform integration yet, setting state directly"; - QGuiApplicationPrivate::applicationState = state; + QGuiApplicationPrivate::applicationState = newState; } } diff --git a/src/plugins/platforms/ios/qioscontext.mm b/src/plugins/platforms/ios/qioscontext.mm index 03643c19a9..fff66049ff 100644 --- a/src/plugins/platforms/ios/qioscontext.mm +++ b/src/plugins/platforms/ios/qioscontext.mm @@ -301,29 +301,34 @@ bool QIOSContext::verifyGraphicsHardwareAvailability() static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ QIOSApplicationState *applicationState = &QIOSIntegration::instance()->applicationState; - connect(applicationState, &QIOSApplicationState::applicationStateWillChange, [](Qt::ApplicationState state) { - if (applicationBackgrounded && state != Qt::ApplicationSuspended) { - qCDebug(lcQpaGLContext) << "app no longer backgrounded, rendering enabled"; - applicationBackgrounded = false; + connect(applicationState, &QIOSApplicationState::applicationStateWillChange, + [](Qt::ApplicationState oldState, Qt::ApplicationState newState) { + Q_UNUSED(oldState); + if (applicationBackgrounded && newState != Qt::ApplicationSuspended) { + qCDebug(lcQpaGLContext) << "app no longer backgrounded, rendering enabled"; + applicationBackgrounded = true; + } } - }); - connect(applicationState, &QIOSApplicationState::applicationStateDidChange, [](Qt::ApplicationState state) { - if (state != Qt::ApplicationSuspended) - return; - - qCDebug(lcQpaGLContext) << "app backgrounded, rendering disabled"; - applicationBackgrounded = true; - - // By the time we receive this signal the application has moved into - // Qt::ApplactionStateSuspended, and all windows have been obscured, - // which should stop all rendering. If there's still an active GL context, - // we follow Apple's advice and call glFinish before making it inactive. - if (QOpenGLContext *currentContext = QOpenGLContext::currentContext()) { - qCWarning(lcQpaGLContext) << "explicitly glFinishing and deactivating" << currentContext; - glFinish(); - currentContext->doneCurrent(); + ); + connect(applicationState, &QIOSApplicationState::applicationStateDidChange, + [](Qt::ApplicationState oldState, Qt::ApplicationState newState) { + Q_UNUSED(oldState); + if (newState != Qt::ApplicationSuspended) + return; + + qCDebug(lcQpaGLContext) << "app backgrounded, rendering disabled"; + + // By the time we receive this signal the application has moved into + // Qt::ApplactionStateSuspended, and all windows have been obscured, + // which should stop all rendering. If there's still an active GL context, + // we follow Apple's advice and call glFinish before making it inactive. + if (QOpenGLContext *currentContext = QOpenGLContext::currentContext()) { + qCWarning(lcQpaGLContext) << "explicitly glFinishing and deactivating" << currentContext; + glFinish(); + currentContext->doneCurrent(); + } } - }); + ); }); if (applicationBackgrounded) { diff --git a/src/plugins/platforms/ios/qiosintegration.h b/src/plugins/platforms/ios/qiosintegration.h index 6be8855020..818250fcee 100644 --- a/src/plugins/platforms/ios/qiosintegration.h +++ b/src/plugins/platforms/ios/qiosintegration.h @@ -62,6 +62,8 @@ public: QIOSIntegration(); ~QIOSIntegration(); + void initialize() override; + bool hasCapability(Capability cap) const override; QPlatformWindow *createPlatformWindow(QWindow *window) const override; diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 92c1e39d72..2e657b3798 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -95,7 +95,10 @@ QIOSIntegration::QIOSIntegration() // Set current directory to app bundle folder QDir::setCurrent(QString::fromUtf8([[[NSBundle mainBundle] bundlePath] UTF8String])); +} +void QIOSIntegration::initialize() +{ UIScreen *mainScreen = [UIScreen mainScreen]; NSMutableArray *screens = [[[UIScreen screens] mutableCopy] autorelease]; if (![screens containsObject:mainScreen]) { diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index a7663b9e94..d7db6ba856 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -273,6 +273,20 @@ m_focusWindowChangeConnection = QObject::connect(qApp, &QGuiApplication::focusWindowChanged, [self]() { [self updateProperties]; }); + + QIOSApplicationState *applicationState = &QIOSIntegration::instance()->applicationState; + QObject::connect(applicationState, &QIOSApplicationState::applicationStateDidChange, + [self](Qt::ApplicationState oldState, Qt::ApplicationState newState) { + if (oldState == Qt::ApplicationSuspended && newState != Qt::ApplicationSuspended) { + // We may have ignored an earlier layout because the application was suspended, + // and we didn't want to render anything at that moment in fear of being killed + // due to rendering in the background, so we trigger an explicit layout when + // coming out of the suspended state. + qCDebug(lcQpaWindow) << "triggering root VC layout when coming out of suspended state"; + [self.view setNeedsLayout]; + } + } + ); } return self; -- cgit v1.2.3 From 3520329937ca860a14bc57e3a12b580aa5e03482 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 17 Apr 2018 11:42:31 +0200 Subject: Doc: link to QEnableSharedFromThis from QSharedPointer docs Change-Id: I1c4a168c0581b6273b99a7ea8faa29114bda39e2 Reviewed-by: Giuseppe D'Angelo --- src/corelib/tools/qsharedpointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index f88153db5d..22cf516b68 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -309,7 +309,7 @@ \endomit - \sa QSharedDataPointer, QWeakPointer, QScopedPointer + \sa QSharedDataPointer, QWeakPointer, QScopedPointer, QEnableSharedFromThis */ /*! -- cgit v1.2.3 From 8caf9e6b180eeb7e6668a64694339dac2265b4d0 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 22 Mar 2018 00:58:10 +0100 Subject: iOS: Allow building QML based test cases In order to be able to build and test a testcase on an iOS device it needs to be a bundle. So the app_bundle config should only be removed if the testcase_no_bundle is set. This is already done by testcase.prf. Task-number: QTBUG-45211 Change-Id: I4f16ea832ccff2a5db5fed0050fa0344b4ac9ad6 Reviewed-by: Oswald Buddenhagen --- mkspecs/features/qmltestcase.prf | 1 - 1 file changed, 1 deletion(-) diff --git a/mkspecs/features/qmltestcase.prf b/mkspecs/features/qmltestcase.prf index 4dfec50be8..216f37d61a 100644 --- a/mkspecs/features/qmltestcase.prf +++ b/mkspecs/features/qmltestcase.prf @@ -1,7 +1,6 @@ !isEmpty(SOURCES) { QT += qml qmltest load(testcase) - CONFIG -= app_bundle DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$_PRO_FILE_PWD_\\\"\" } else { # Allow a project to run tests without a CPP stub -- cgit v1.2.3 From c6ee1899eaa50dae56c07b6c4b3490cc5aeb60e6 Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Tue, 17 Apr 2018 16:09:18 +0300 Subject: Blacklist tst_QWindow::isActive on Ubuntu Task-number: QTBUG-67768 Change-Id: Ie1e0b406c152c854ef3629fa4d469dd73452f128 Reviewed-by: Gatis Paeglis --- tests/auto/gui/kernel/qwindow/BLACKLIST | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST index e55bf77403..cd1cb99c3c 100644 --- a/tests/auto/gui/kernel/qwindow/BLACKLIST +++ b/tests/auto/gui/kernel/qwindow/BLACKLIST @@ -23,3 +23,6 @@ osx-10.12 ci [testInputEvents] rhel-7.4 +[isActive] +# QTBUG-67768 +ubuntu -- cgit v1.2.3 From be4eaca053eba747c0458e37ce68ae3db1e6a288 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Mon, 16 Apr 2018 15:20:40 +0200 Subject: Do not ignore MenuItem on macOS The idea was probably to ignore it since macOS already provides accessibility for a menu item in its native system menu. However, a Qt Quick Controls2 Menu will instead show a non-native menu, which should not be ignored. Task-number: QTBUG-63522 Change-Id: Ib5ae16ad991ebd7a18fa73b8f576f20b1c14d4c8 Reviewed-by: Frederik Gladhorn --- src/plugins/platforms/cocoa/qcocoaaccessibility.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm index 8b6dcb35a6..654e6210c8 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm @@ -226,7 +226,6 @@ bool shouldBeIgnored(QAccessibleInterface *interface) const QAccessible::Role role = interface->role(); if (role == QAccessible::Border || // QFrame role == QAccessible::Application || // We use the system-provided application element. - role == QAccessible::MenuItem || // The system also provides the menu items. role == QAccessible::ToolBar || // Access the tool buttons directly. role == QAccessible::Pane || // Scroll areas. role == QAccessible::Client) // The default for QWidget. -- cgit v1.2.3 From 48900145a4e62db95dee812a1d9ac6331e19bc4b Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 4 Apr 2018 10:15:24 -0700 Subject: QMacStyle: Clean up code, remove dead bits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change QMacStylePrivate::drawNSViewInRect() signature to remove all the unused parameters. Reuse recent tab direction functions where appropriate. Includes the infamous outter -> outer fix. Change-Id: I8f92d79d8a6c3b5903bfbb13293afb6f72a5340b Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 233 +++++++++-------------------- src/plugins/styles/mac/qmacstyle_mac_p_p.h | 9 +- 2 files changed, 72 insertions(+), 170 deletions(-) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 225bd77239..81abbc6caf 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -43,7 +43,6 @@ */ #include -#include #include "qmacstyle_mac_p.h" #include "qmacstyle_mac_p_p.h" @@ -273,13 +272,7 @@ QT_BEGIN_NAMESPACE // The following constants are used for adjusting the size // of push buttons so that they are drawn inside their bounds. const int QMacStylePrivate::PushButtonLeftOffset = 6; -const int QMacStylePrivate::PushButtonTopOffset = 4; const int QMacStylePrivate::PushButtonRightOffset = 12; -const int QMacStylePrivate::PushButtonBottomOffset = 12; -const int QMacStylePrivate::MiniButtonH = 26; -const int QMacStylePrivate::SmallButtonH = 30; -const int QMacStylePrivate::BevelButtonW = 50; -const int QMacStylePrivate::BevelButtonH = 22; const int QMacStylePrivate::PushButtonContentPadding = 6; QVector > QMacStylePrivate::scrollBars; @@ -389,15 +382,6 @@ static const int toolButtonArrowMargin = 2; static const qreal focusRingWidth = 3.5; -#if QT_CONFIG(tabbar) -static bool isVerticalTabs(const QTabBar::Shape shape) { - return (shape == QTabBar::RoundedEast - || shape == QTabBar::TriangularEast - || shape == QTabBar::RoundedWest - || shape == QTabBar::TriangularWest); -} -#endif - static bool setupScroller(NSScroller *scroller, const QStyleOptionSlider *sb) { const qreal length = sb->maximum - sb->minimum + sb->pageStep; @@ -502,10 +486,10 @@ static void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pres #if QT_CONFIG(tabbar) QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) { - if (isVerticalTabs(shape)) { + const auto tabDirection = QMacStylePrivate::tabDirection(shape); + if (QMacStylePrivate::verticalTabs(tabDirection)) { int newX, newY, newRot; - if (shape == QTabBar::RoundedEast - || shape == QTabBar::TriangularEast) { + if (tabDirection == QMacStylePrivate::East) { newX = tabRect.width(); newY = tabRect.y(); newRot = 90; @@ -526,23 +510,10 @@ QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) void drawTabShape(QPainter *p, const QStyleOptionTab *tabOpt, bool isUnified, int tabOverlap) { QRect rect = tabOpt->rect; - - switch (tabOpt->shape) { - case QTabBar::RoundedNorth: - case QTabBar::TriangularNorth: - case QTabBar::RoundedSouth: - case QTabBar::TriangularSouth: - rect.adjust(-tabOverlap, 0, 0, 0); - break; - case QTabBar::RoundedEast: - case QTabBar::TriangularEast: - case QTabBar::RoundedWest: - case QTabBar::TriangularWest: - rect.adjust(0, -tabOverlap, 0, 0); - break; - default: - break; - } + if (QMacStylePrivate::verticalTabs(QMacStylePrivate::tabDirection(tabOpt->shape))) + rect = rect.adjusted(-tabOverlap, 0, 0, 0); + else + rect = rect.adjusted(0, -tabOverlap, 0, 0); p->translate(rect.x(), rect.y()); rect.moveLeft(0); @@ -593,11 +564,11 @@ void drawTabShape(QPainter *p, const QStyleOptionTab *tabOpt, bool isUnified, in void drawTabBase(QPainter *p, const QStyleOptionTabBarBase *tbb, const QWidget *w) { QRect r = tbb->rect; - if (isVerticalTabs(tbb->shape)) { + if (QMacStylePrivate::verticalTabs(QMacStylePrivate::tabDirection(tbb->shape))) r.setWidth(w->width()); - } else { + else r.setHeight(w->height()); - } + const QRect tabRect = rotateTabPainter(p, tbb->shape, r); const int width = tabRect.width(); const int height = tabRect.height(); @@ -633,8 +604,7 @@ static QStyleHelper::WidgetSizePolicy getControlSize(const QStyleOption *option, static inline bool isTreeView(const QWidget *widget) { return (widget && widget->parentWidget() && - (qobject_cast(widget->parentWidget()) - )); + qobject_cast(widget->parentWidget())); } #endif @@ -672,15 +642,6 @@ static QString qt_mac_removeMnemonics(const QString &original) return returnText; } -bool qt_macWindowIsTextured(const QWidget *window) -{ - if (QWindow *w = window->windowHandle()) - if (w->handle()) - if (NSWindow *nswindow = static_cast(QGuiApplication::platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("NSWindow"), w))) - return ([nswindow styleMask] & NSTexturedBackgroundWindowMask) ? true : false; - return false; -} - static bool qt_macWindowMainWindow(const QWidget *window) { if (QWindow *w = window->windowHandle()) { @@ -1118,51 +1079,11 @@ static QStyleHelper::WidgetSizePolicy qt_aqua_guess_size(const QWidget *widg, QS return QStyleHelper::SizeLarge; } -#if QT_CONFIG(mainwindow) - if (qEnvironmentVariableIsSet("QWIDGET_ALL_SMALL")) { - //if (small.width() != -1 || small.height() != -1) + if (qEnvironmentVariableIsSet("QWIDGET_ALL_SMALL")) return QStyleHelper::SizeSmall; - } else if (qEnvironmentVariableIsSet("QWIDGET_ALL_MINI")) { + else if (qEnvironmentVariableIsSet("QWIDGET_ALL_MINI")) return QStyleHelper::SizeMini; - } -#endif -#if 0 - /* Figure out which size we're closer to, I just hacked this in, I haven't - tested it as it would probably look pretty strange to have some widgets - big and some widgets small in the same window?? -Sam */ - int large_delta=0; - if (large.width() != -1) { - int delta = large.width() - widg->width(); - large_delta += delta * delta; - } - if (large.height() != -1) { - int delta = large.height() - widg->height(); - large_delta += delta * delta; - } - int small_delta=0; - if (small.width() != -1) { - int delta = small.width() - widg->width(); - small_delta += delta * delta; - } - if (small.height() != -1) { - int delta = small.height() - widg->height(); - small_delta += delta * delta; - } - int mini_delta=0; - if (mini.width() != -1) { - int delta = mini.width() - widg->width(); - mini_delta += delta * delta; - } - if (mini.height() != -1) { - int delta = mini.height() - widg->height(); - mini_delta += delta * delta; - } - if (mini_delta < small_delta && mini_delta < large_delta) - return QStyleHelper::SizeMini; - else if (small_delta < large_delta) - return QStyleHelper::SizeSmall; -#endif return QStyleHelper::SizeLarge; } #endif @@ -1182,10 +1103,10 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRectF &targetRect, int auto innerRect = targetRect; if (cw.type == TextField) innerRect = innerRect.adjusted(hMargin, vMargin, -hMargin, -vMargin).adjusted(0.5, 0.5, -0.5, -0.5); - const auto outterRect = innerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth); - const auto outterRadius = focusRingWidth; + const auto outerRect = innerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth); + const auto outerRadius = focusRingWidth; focusRingPath.addRect(innerRect); - focusRingPath.addRoundedRect(outterRect, outterRadius, outterRadius); + focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius); break; } case Button_CheckBox: { @@ -1196,9 +1117,9 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRectF &targetRect, int cw.size == QStyleHelper::SizeSmall ? 2.0 : 1.0); // As measured vOffset = 0.5 * qreal(targetRect.height() - cbSize); const auto cbInnerRect = QRectF(0, 0, cbSize, cbSize); - const auto cbOutterRadius = cbInnerRadius + focusRingWidth; - const auto cbOutterRect = cbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth); - focusRingPath.addRoundedRect(cbOutterRect, cbOutterRadius, cbOutterRadius); + const auto cbOuterRadius = cbInnerRadius + focusRingWidth; + const auto cbOuterRect = cbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth); + focusRingPath.addRoundedRect(cbOuterRect, cbOuterRadius, cbOuterRadius); focusRingPath.addRoundedRect(cbInnerRect, cbInnerRadius, cbInnerRadius); break; } @@ -1209,9 +1130,9 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRectF &targetRect, int cw.size == QStyleHelper::SizeSmall ? 1.0 : 1.0); // As measured vOffset = 0.5 * qreal(targetRect.height() - rbSize); const auto rbInnerRect = QRectF(0, 0, rbSize, rbSize); - const auto rbOutterRect = rbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth); + const auto rbOuterRect = rbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth); focusRingPath.addEllipse(rbInnerRect); - focusRingPath.addEllipse(rbOutterRect); + focusRingPath.addEllipse(rbOuterRect); break; } case Button_PopupButton: @@ -1219,13 +1140,13 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRectF &targetRect, int case Button_PushButton: case SegmentedControl_Single: { const qreal innerRadius = cw.type == Button_PushButton ? 3 : 4; - const qreal outterRadius = innerRadius + focusRingWidth; + const qreal outerRadius = innerRadius + focusRingWidth; hOffset = targetRect.left(); vOffset = targetRect.top(); const auto innerRect = targetRect.translated(-targetRect.topLeft()); - const auto outterRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin); + const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin); focusRingPath.addRoundedRect(innerRect, innerRadius, innerRadius); - focusRingPath.addRoundedRect(outterRect, outterRadius, outterRadius); + focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius); break; } case ComboBox: @@ -1234,9 +1155,9 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRectF &targetRect, int hOffset = targetRect.left(); vOffset = targetRect.top(); const qreal innerRadius = 8; - const qreal outterRadius = innerRadius + focusRingWidth; + const qreal outerRadius = innerRadius + focusRingWidth; const auto innerRect = targetRect.translated(-targetRect.topLeft()); - const auto outterRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin); + const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin); const auto cbFocusFramePath = [](const QRectF &rect, qreal tRadius, qreal bRadius) { QPainterPath path; @@ -1262,8 +1183,8 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRectF &targetRect, int const auto innerPath = cbFocusFramePath(innerRect, 0, innerRadius); focusRingPath.addPath(innerPath); - const auto outterPath = cbFocusFramePath(outterRect, 2 * focusRingWidth, outterRadius); - focusRingPath.addPath(outterPath); + const auto outerPath = cbFocusFramePath(outerRect, 2 * focusRingWidth, outerRadius); + focusRingPath.addPath(outerPath); break; } default: @@ -1422,6 +1343,12 @@ QMacStylePrivate::Direction QMacStylePrivate::tabDirection(QTabBar::Shape shape) } } +bool QMacStylePrivate::verticalTabs(QMacStylePrivate::Direction direction) +{ + return (direction == QMacStylePrivate::East + || direction == QMacStylePrivate::West); +} + #endif // QT_CONFIG(tabbar) QStyleHelper::WidgetSizePolicy QMacStylePrivate::effectiveAquaSizeConstrain(const QStyleOption *option, @@ -1609,7 +1536,6 @@ QMarginsF QMacStylePrivate::CocoaControl::titleMargins() const return QMarginsF(); } - bool QMacStylePrivate::CocoaControl::getCocoaButtonTypeAndBezelStyle(NSButtonType *buttonType, NSBezelStyle *bezelStyle) const { switch (type) { @@ -1670,9 +1596,9 @@ QMacStylePrivate::CocoaControlType cocoaControlType(const QStyleOption *opt, con Carbon draws comboboxes (and other views) outside the rect given as argument. Use this function to obtain the corresponding inner rect for drawing the same combobox so that it stays inside the given outerBounds. */ -CGRect QMacStylePrivate::comboboxInnerBounds(const CGRect &outterBounds, const CocoaControl &cocoaWidget) +CGRect QMacStylePrivate::comboboxInnerBounds(const CGRect &outerBounds, const CocoaControl &cocoaWidget) { - CGRect innerBounds = outterBounds; + CGRect innerBounds = outerBounds; // Carbon draw parts of the view outside the rect. // So make the rect a bit smaller to compensate // (I wish HIThemeGetButtonBackgroundBounds worked) @@ -1727,9 +1653,9 @@ CGRect QMacStylePrivate::comboboxInnerBounds(const CGRect &outterBounds, const C Inside a combobox Qt places a line edit widget. The size of this widget should depend on the kind of combobox we choose to draw. This function calculates and returns this size. */ -QRectF QMacStylePrivate::comboboxEditBounds(const QRectF &outterBounds, const CocoaControl &cw) +QRectF QMacStylePrivate::comboboxEditBounds(const QRectF &outerBounds, const CocoaControl &cw) { - QRectF ret = outterBounds; + QRectF ret = outerBounds; if (cw.type == ComboBox) { switch (cw.size) { case QStyleHelper::SizeLarge: @@ -1785,27 +1711,12 @@ QMacStylePrivate::~QMacStylePrivate() [cell release]; } -#if 0 -ThemeDrawState QMacStylePrivate::getDrawState(QStyle::State flags) -{ - ThemeDrawState tds = kThemeStateActive; - if (flags & QStyle::State_Sunken) { - tds = kThemeStatePressed; - } else if (flags & QStyle::State_Active) { - if (!(flags & QStyle::State_Enabled)) - tds = kThemeStateUnavailable; - } else { - if (flags & QStyle::State_Enabled) - tds = kThemeStateInactive; - else - tds = kThemeStateUnavailableInactive; - } - return tds; -} -#endif - NSView *QMacStylePrivate::cocoaControl(CocoaControl widget) const { + if (widget.type == QMacStylePrivate::NoControl + || widget.size == QStyleHelper::SizeDefault) + return nil; + NSView *bv = cocoaControls.value(widget, nil); if (!bv) { switch (widget.type) { @@ -1987,15 +1898,13 @@ NSCell *QMacStylePrivate::cocoaCell(CocoaControl widget) const return cell; } -void QMacStylePrivate::drawNSViewInRect(CocoaControl widget, NSView *view, const QRectF &qtRect, QPainter *p, bool isQWidget, __attribute__((noescape)) DrawRectBlock drawRectBlock) const +void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRectF &qtRect, QPainter *p, + __attribute__((noescape)) DrawRectBlock drawRectBlock) const { - Q_UNUSED(isQWidget); - Q_UNUSED(widget); - QMacCGContext ctx(p); setupNSGraphicsContext(ctx, YES); - const CGRect rect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height()); + const CGRect rect = qtRect.toCGRect(); [backingStoreNSView addSubview:view]; view.frame = rect; @@ -3003,9 +2912,9 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai case PE_FrameTabWidget: #endif { - const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeDefault); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeLarge); auto *box = static_cast(d->cocoaControl(cw)); - d->drawNSViewInRect(cw, box, opt->rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) { + d->drawNSViewInRect(box, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height); CGContextScaleCTM(ctx, 1, -1); [box drawRect:rect]; @@ -3165,7 +3074,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai return cs == QStyleHelper::SizeSmall ? 0.5 : 0.0; } (); - d->drawNSViewInRect(cw, tb, opt->rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) { + d->drawNSViewInRect(tb, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { CGContextTranslateCTM(ctx, 0, vOffset); [tb.cell drawInteriorWithFrame:rect inView:tb]; }); @@ -3176,7 +3085,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai case PE_IndicatorBranch: { if (!(opt->state & State_Children)) break; - const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge); NSButtonCell *triangleCell = static_cast(d->cocoaCell(cw)); [triangleCell setState:(opt->state & State_Open) ? NSOnState : NSOffState]; bool viewHasFocus = (w && w->hasFocus()) || (opt->state & State_HasFocus); @@ -3218,7 +3127,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai tf.bezeled = YES; static_cast(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel; tf.frame = opt->rect.toCGRect(); - d->drawNSViewInRect(cw, tf, opt->rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) { + d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { Q_UNUSED(ctx); [tf.cell drawWithFrame:rect inView:tf]; }); @@ -3308,7 +3217,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } } -static inline QPixmap darkenPixmap(const QPixmap &pixmap) +static QPixmap darkenPixmap(const QPixmap &pixmap) { QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); int imgh = img.height(); @@ -3331,8 +3240,6 @@ static inline QPixmap darkenPixmap(const QPixmap &pixmap) return QPixmap::fromImage(img); } - - void QMacStylePrivate::setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const { if (vertical) { @@ -3552,7 +3459,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter pb.enabled = isEnabled; [pb highlight:isPressed]; pb.state = isHighlighted && !isPressed ? NSOnState : NSOffState; - d->drawNSViewInRect(cw, pb, frameRect, p, true, ^(CGContextRef __unused ctx, const CGRect &r) { + d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef __unused ctx, const CGRect &r) { [pb.cell drawBezelWithFrame:r inView:pb.superview]; }); [pb highlight:NO]; @@ -3732,7 +3639,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter auto vOffset = isSelected ? 2 : 1; if (tabDirection == QMacStylePrivate::East) vOffset -= 1; - const auto outterAdjust = isSelected ? 4 : 1; + const auto outerAdjust = isSelected ? 4 : 1; const auto innerAdjust = isSelected ? 10 : 20; QRectF frameRect = tabOpt->rect; if (verticalTabs) @@ -3743,9 +3650,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter case QStyleOptionTab::Beginning: // Pressed state hack: tweak adjustments in preparation for flip below if (!isSelected && tabDirection == QMacStylePrivate::West) - frameRect = frameRect.adjusted(-innerAdjust, 0, outterAdjust, 0); + frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0); else - frameRect = frameRect.adjusted(-outterAdjust, 0, innerAdjust, 0); + frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0); break; case QStyleOptionTab::Middle: frameRect = frameRect.adjusted(-innerAdjust, 0, innerAdjust, 0); @@ -3753,12 +3660,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter case QStyleOptionTab::End: // Pressed state hack: tweak adjustments in preparation for flip below if (isSelected || tabDirection == QMacStylePrivate::West) - frameRect = frameRect.adjusted(-innerAdjust, 0, outterAdjust, 0); + frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0); else - frameRect = frameRect.adjusted(-outterAdjust, 0, innerAdjust, 0); + frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0); break; case QStyleOptionTab::OnlyOneTab: - frameRect = frameRect.adjusted(-outterAdjust, 0, outterAdjust, 0); + frameRect = frameRect.adjusted(-outerAdjust, 0, outerAdjust, 0); break; } pb.frame = frameRect.toCGRect(); @@ -3766,7 +3673,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter pb.enabled = isEnabled; [pb highlight:isPressed]; pb.state = isSelected && !isPressed ? NSOnState : NSOffState; - d->drawNSViewInRect(cw, pb, frameRect, p, true, ^(CGContextRef ctx, const CGRect &r) { + d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef ctx, const CGRect &r) { CGContextClipToRect(ctx, opt->rect.toCGRect()); if (!isSelected) { // Final stage of the pressed state hack: flip NSPopupButton rendering @@ -4203,7 +4110,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize); auto *pi = static_cast(d->cocoaControl(cw)); - d->drawNSViewInRect(cw, pi, rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) { + d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx, const CGRect &rect) { d->setupVerticalInvertedXform(ctx, reverse, vertical, rect); pi.minValue = pb->minimum; pi.maxValue = pb->maximum; @@ -4253,7 +4160,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge); auto *sv = static_cast(d->cocoaControl(cw)); sv.frame = opt->rect.toCGRect(); - d->drawNSViewInRect(cw, sv, opt->rect, p, w != nullptr, ^(CGContextRef __unused ctx, const CGRect &rect) { + d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef __unused ctx, const CGRect &rect) { [sv drawDividerInRect:rect]; }); } else { @@ -5098,7 +5005,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex [slider.cell startTrackingAt:pressPoint inView:slider]; } - d->drawNSViewInRect(cw, slider, opt->rect, p, widget != 0, ^(CGContextRef ctx, const CGRect &rect) { + d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { if (isHorizontal && sl->upsideDown) { CGContextTranslateCTM(ctx, rect.size.width, 0); CGContextScaleCTM(ctx, -1, 1); @@ -5260,7 +5167,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } pb.frame = frameRect.toCGRect(); [pb highlight:isPressed]; - d->drawNSViewInRect(cw, pb, frameRect, p, widget != 0, ^(CGContextRef __unused ctx, const CGRect &r) { + d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef __unused ctx, const CGRect &r) { [pb.cell drawBezelWithFrame:r inView:pb.superview]; }); } else if (cw.type == QMacStylePrivate::ComboBox) { @@ -5273,7 +5180,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex #else // TODO Render to pixmap and darken the button manually #endif - d->drawNSViewInRect(cw, cb, frameRect, p, widget != 0, ^(CGContextRef __unused ctx, const CGRect &r) { + d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef __unused ctx, const CGRect &r) { // FIXME This is usually drawn in the control's superview, but we wouldn't get inactive look in this case [cb.cell drawWithFrame:r inView:cb]; }); @@ -5310,12 +5217,12 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex // FIXME A single drawPath() with 0-sized pen // doesn't look as good as this double fillPath(). - const auto outterFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height())); - QPainterPath outterFramePath = d->windowPanelPath(outterFrameRect); - p->fillPath(outterFramePath, opt->palette.dark()); + const auto outerFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height())); + QPainterPath outerFramePath = d->windowPanelPath(outerFrameRect); + p->fillPath(outerFramePath, opt->palette.dark()); const auto frameAdjust = 1.0 / p->device()->devicePixelRatioF(); - const auto innerFrameRect = outterFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0); + const auto innerFrameRect = outerFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0); QPainterPath innerFramePath = d->windowPanelPath(innerFrameRect); if (isActive) { QLinearGradient g; @@ -5351,7 +5258,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex auto *wbCell = static_cast(wb.cell); [wbCell drawWithFrame:rect inView:wb]; }; - d->drawNSViewInRect(cw, wb, buttonRect, p, widget != nullptr, drawBlock); + d->drawNSViewInRect(wb, buttonRect, p, drawBlock); } } @@ -5461,7 +5368,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex [pb highlight:isPressed]; pb.state = isHighlighted && !isPressed ? NSOnState : NSOffState; const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget); - d->drawNSViewInRect(cw, pb, buttonRect, p, ^(CGContextRef __unused ctx, const CGRect &rect) { + d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef __unused ctx, const CGRect &rect) { [pb.cell drawBezelWithFrame:rect inView:pb]; }); } diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index 2a81274765..4eac0a59d6 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -236,13 +236,7 @@ public: // Ideally these wouldn't exist, but since they already exist we need some accessors. static const int PushButtonLeftOffset; - static const int PushButtonTopOffset; static const int PushButtonRightOffset; - static const int PushButtonBottomOffset; - static const int MiniButtonH; - static const int SmallButtonH; - static const int BevelButtonW; - static const int BevelButtonH; static const int PushButtonContentPadding; enum Animates { AquaPushButton, AquaProgressBar, AquaListViewItemOpen, AquaScrollBar }; @@ -269,7 +263,7 @@ public: void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const; - void drawNSViewInRect(CocoaControl widget, NSView *view, const QRectF &rect, QPainter *p, bool isQWidget = true, __attribute__((noescape)) DrawRectBlock drawRectBlock = nil) const; + void drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, __attribute__((noescape)) DrawRectBlock drawRectBlock = nil) const; void resolveCurrentNSView(QWindow *window) const; void drawFocusRing(QPainter *p, const QRectF &targetRect, int hMargin, int vMargin, const CocoaControl &cw) const; @@ -283,6 +277,7 @@ public: #if QT_CONFIG(tabbar) void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const; static Direction tabDirection(QTabBar::Shape shape); + static bool verticalTabs(QMacStylePrivate::Direction tabDirection); #endif public: -- cgit v1.2.3 From 85cb183488a821a23a15710dc610dd0e506f72f5 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 11 Apr 2018 11:40:49 -0700 Subject: QMacStyle: Fix appearance of selected inactive tab bar button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because we use toggle NSButton for selected tabs, the inactive appearance doesn't follow what NSSegmentedControl would have shown. Therefore, we fall back to our good old habits, i.e., render on a pixmap and do some pixel transformations. Change-Id: I838a2f23abee5846219ba67328c79fa8cc359a9b Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 59 ++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 81abbc6caf..4dc3cfd634 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -3602,6 +3602,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter return; } + const bool isActive = tabOpt->state & State_Active; const bool isEnabled = tabOpt->state & State_Enabled; const bool isPressed = tabOpt->state & State_Sunken; const bool isSelected = tabOpt->state & State_Selected; @@ -3630,17 +3631,20 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter // a push NSButton instead and clip the CGContext. const auto cs = d->effectiveAquaSizeConstrain(opt, w); - // Extra hack to get the proper pressed appreance when not selected - const auto ct = isSelected || tp == QStyleOptionTab::OnlyOneTab ? + // Extra hacks to get the proper pressed appreance when not selected or selected and inactive + const bool needsInactiveHack = (!isActive && isSelected); + const auto ct = !needsInactiveHack && (isSelected || tp == QStyleOptionTab::OnlyOneTab) ? QMacStylePrivate::Button_PushButton : QMacStylePrivate::Button_PopupButton; + const bool isPopupButton = ct == QMacStylePrivate::Button_PopupButton; const auto cw = QMacStylePrivate::CocoaControl(ct, cs); auto *pb = static_cast(d->cocoaControl(cw)); - auto vOffset = isSelected ? 2 : 1; + + auto vOffset = isPopupButton ? 1 : 2; if (tabDirection == QMacStylePrivate::East) vOffset -= 1; - const auto outerAdjust = isSelected ? 4 : 1; - const auto innerAdjust = isSelected ? 10 : 20; + const auto outerAdjust = isPopupButton ? 1 : 4; + const auto innerAdjust = isPopupButton ? 20 : 10; QRectF frameRect = tabOpt->rect; if (verticalTabs) frameRect = QRectF(frameRect.y(), frameRect.x(), frameRect.height(), frameRect.width()); @@ -3672,10 +3676,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter pb.enabled = isEnabled; [pb highlight:isPressed]; - pb.state = isSelected && !isPressed ? NSOnState : NSOffState; - d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef ctx, const CGRect &r) { + // Set off state when inactive. See needsInactiveHack for when it's selected + pb.state = (isActive && isSelected && !isPressed) ? NSOnState : NSOffState; + + const auto drawBezelBlock = ^(CGContextRef ctx, const CGRect &r) { CGContextClipToRect(ctx, opt->rect.toCGRect()); - if (!isSelected) { + if (!isSelected || needsInactiveHack) { // Final stage of the pressed state hack: flip NSPopupButton rendering if (!verticalTabs && tp == QStyleOptionTab::End) { CGContextTranslateCTM(ctx, opt->rect.right(), 0); @@ -3703,7 +3709,42 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } [pb.cell drawBezelWithFrame:r inView:pb.superview]; - }); + }; + + if (needsInactiveHack) { + // First, render tab as non-selected tab on a pixamp + const qreal pixelRatio = p->device()->devicePixelRatioF(); + QImage tabPixmap(opt->rect.size() * pixelRatio, QImage::Format_ARGB32_Premultiplied); + tabPixmap.setDevicePixelRatio(pixelRatio); + tabPixmap.fill(Qt::transparent); + QPainter tabPainter(&tabPixmap); + d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx, const CGRect &r) { + CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top()); + drawBezelBlock(ctx, r); + }); + tabPainter.end(); + + // Then, darken it with the proper shade of gray + const qreal inactiveGray = 0.898; // As measured + const int inactiveGray8 = qRound(inactiveGray * 255.0); + const QRgb inactiveGrayRGB = qRgb(inactiveGray8, inactiveGray8, inactiveGray8); + for (int l = 0; l < tabPixmap.height(); ++l) { + auto *line = reinterpret_cast(tabPixmap.scanLine(l)); + for (int i = 0; i < tabPixmap.width(); ++i) { + if (qAlpha(line[i]) == 255) { + line[i] = inactiveGrayRGB; + } else if (qAlpha(line[i]) > 128) { + const int g = qRound(inactiveGray * qRed(line[i])); + line[i] = qRgba(g, g, g, qAlpha(line[i])); + } + } + } + + // Finally, draw the tab pixmap on the current painter + p->drawImage(opt->rect, tabPixmap); + } else { + d->drawNSViewInRect(pb, frameRect, p, drawBezelBlock); + } if (!isSelected && sp != QStyleOptionTab::NextIsSelected && tp != QStyleOptionTab::End -- cgit v1.2.3 From e991fd480242a1148a9988e7830a8e77afc90e33 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 12 Apr 2018 16:37:36 -0700 Subject: QMacStyle: Fix SC_ComboBoxEditField rect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I851e4bb1e0177ef5c594328c717e58ec7c9494e3 Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 4dc3cfd634..569eeef0ff 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -1682,8 +1682,7 @@ QRectF QMacStylePrivate::comboboxEditBounds(const QRectF &outerBounds, const Coc ret.adjust(13, 4, -20, -3); break; case QStyleHelper::SizeMini: - // FIXME Wrong - ret.adjust(16, 5, -19, 0); + ret.adjust(12, 0, -19, 0); ret.setHeight(13); break; default: -- cgit v1.2.3 From 0c936d74118a31dcee777a3a4a8938590e79c334 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 16 Apr 2018 11:16:42 -0700 Subject: QCocoaPlatformTheme: Fix tooltip background color MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It use to be yellowish in the past, but modern versions of macOS show it light gray. Change-Id: I8cca5cbb37c73a6dfc79e633a746b9a7d7bced05 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoasystemsettings.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm index 7c6f879b18..bad91a2d5d 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm @@ -90,7 +90,9 @@ QPalette * qt_mac_createSystemPalette() palette->setColor(QPalette::Disabled, QPalette::Text, qc); palette->setColor(QPalette::Disabled, QPalette::WindowText, qc); palette->setColor(QPalette::Disabled, QPalette::HighlightedText, qc); - palette->setBrush(QPalette::ToolTipBase, QColor(255, 255, 199)); + + palette->setBrush(QPalette::ToolTipBase, qt_mac_toQBrush([NSColor controlColor])); + return palette; } -- cgit v1.2.3 From 84988886a5503e236ac2eb839cf62a01d8a4789b Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 16 Apr 2018 13:40:53 -0700 Subject: QToolTip: Hide tooltip on key event on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This brings back Qt 4 behavior. The difference is that we only ignore modifier-only key events, as it's done natively. Task-number: QTBUG-49462 Change-Id: I02f2313e1164ba185336d80ac5cc16ce6d883b79 Reviewed-by: Morten Johan Sørvig --- src/widgets/kernel/qtooltip.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index baf717d715..ed7184302a 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -317,15 +317,13 @@ void QTipLabel::timerEvent(QTimerEvent *e) bool QTipLabel::eventFilter(QObject *o, QEvent *e) { switch (e->type()) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC +#ifdef Q_OS_MACOS case QEvent::KeyPress: case QEvent::KeyRelease: { - int key = static_cast(e)->key(); - Qt::KeyboardModifiers mody = static_cast(e)->modifiers(); - if (!(mody & Qt::KeyboardModifierMask) - && key != Qt::Key_Shift && key != Qt::Key_Control - && key != Qt::Key_Alt && key != Qt::Key_Meta) - hideTip(); + const int key = static_cast(e)->key(); + // Anything except key modifiers or caps-lock, etc. + if (key < Qt::Key_Shift || key > Qt::Key_ScrollLock) + hideTipImmediately(); break; } #endif -- cgit v1.2.3 From 34e34f22097c87e8e937d72117d83d8c572bbea4 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 18 Apr 2018 15:37:58 +0200 Subject: iOS: Use the non deprecated application:openURL function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In iOS 9.0, the original application:openURL function was deprecated and replaced with a newer one. As iOS 9.0 is no longer supported we can safely switch to the new one. This is also required to prevent a crash when the LSSupportsOpeningDocumentsInPlace and UIFileSharingEnabled keys are set to true in the Info.plist file. Change-Id: I59a7ee82e3ddb2777ef78e28b964ef8666c629af Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosapplicationdelegate.mm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/ios/qiosapplicationdelegate.mm b/src/plugins/platforms/ios/qiosapplicationdelegate.mm index 9cdbed303c..a56c1e4568 100644 --- a/src/plugins/platforms/ios/qiosapplicationdelegate.mm +++ b/src/plugins/platforms/ios/qiosapplicationdelegate.mm @@ -50,11 +50,10 @@ @implementation QIOSApplicationDelegate -- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation +- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { Q_UNUSED(application); - Q_UNUSED(sourceApplication); - Q_UNUSED(annotation); + Q_UNUSED(options); if (!QGuiApplication::instance()) return NO; -- cgit v1.2.3 From 30874fb2df83b21138860d7470a343221f7de6cb Mon Sep 17 00:00:00 2001 From: Tim Uy Date: Wed, 28 Mar 2018 08:25:32 -0700 Subject: qmake: fix sdk resolution on macos the 'info' variable was re-used too early. make a new one 'infoargs' instead. Task-number: QTBUG-67286 Change-Id: I77881ecbfce338d653358c5e5edac84e1c0c7de3 Reviewed-by: Oswald Buddenhagen --- mkspecs/features/mac/sdk.prf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mkspecs/features/mac/sdk.prf b/mkspecs/features/mac/sdk.prf index bbcad8125c..8360dd8b38 100644 --- a/mkspecs/features/mac/sdk.prf +++ b/mkspecs/features/mac/sdk.prf @@ -8,21 +8,21 @@ contains(QMAKE_MAC_SDK, .*/.*): \ defineReplace(xcodeSDKInfo) { info = $$1 equals(info, "Path"): \ - info = --show-sdk-path + infoarg = --show-sdk-path equals(info, "PlatformPath"): \ - info = --show-sdk-platform-path + infoarg = --show-sdk-platform-path equals(info, "SDKVersion"): \ - info = --show-sdk-version + infoarg = --show-sdk-version sdk = $$2 isEmpty(sdk): \ sdk = $$QMAKE_MAC_SDK isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}) { - QMAKE_MAC_SDK.$${sdk}.$${info} = $$system("/usr/bin/xcrun --sdk $$sdk $$info 2>/dev/null") + QMAKE_MAC_SDK.$${sdk}.$${info} = $$system("/usr/bin/xcrun --sdk $$sdk $$infoarg 2>/dev/null") # --show-sdk-platform-path won't work for Command Line Tools; this is fine # only used by the XCTest backend to testlib - isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}):if(!isEmpty(QMAKE_XCODEBUILD_PATH)|!equals(info, "--show-sdk-platform-path")): \ - error("Could not resolve SDK $$info for \'$$sdk\'") + isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}):if(!isEmpty(QMAKE_XCODEBUILD_PATH)|!equals(infoarg, "--show-sdk-platform-path")): \ + error("Could not resolve SDK $$info for \'$$sdk\' using $$infoarg") cache(QMAKE_MAC_SDK.$${sdk}.$${info}, set stash, QMAKE_MAC_SDK.$${sdk}.$${info}) } -- cgit v1.2.3 From 370cd37ceabc6a27f4140a35180502eed745b5f2 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 13 Apr 2018 16:10:32 +0200 Subject: Manual shortcut test: Arrange in QGridLayout Change-Id: I93264bec8810f4dd1e2c010cc4dd35df93f31102 Reviewed-by: Gatis Paeglis --- tests/manual/shortcuts/main.cpp | 304 +++++++++++++++------------------------- 1 file changed, 114 insertions(+), 190 deletions(-) diff --git a/tests/manual/shortcuts/main.cpp b/tests/manual/shortcuts/main.cpp index 849f8728b3..acc2a2525c 100644 --- a/tests/manual/shortcuts/main.cpp +++ b/tests/manual/shortcuts/main.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -36,200 +37,123 @@ class ShortcutTester : public QWidget { public: - ShortcutTester() { - setupLayout(); - } -protected: - void setupLayout() + ShortcutTester() { - QVBoxLayout *layout = new QVBoxLayout(this); - setLayout(layout); - - QLabel *testPurpose = new QLabel(); - testPurpose->setWordWrap(true); - testPurpose->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding); - testPurpose->setText("This test come in handy to verify shortcuts under different " - "keyboard layouts - qwerty, dvorak, non-latin (russian, arabic), etc."); - layout->addWidget(testPurpose); - - QKeySequence altShiftG(Qt::AltModifier + Qt::ShiftModifier + Qt::Key_G); - QPushButton *_altShiftG = new QPushButton(altShiftG.toString()); - _altShiftG->setShortcut(altShiftG); - layout->addWidget(_altShiftG); - - QKeySequence altG(Qt::AltModifier + Qt::Key_G); - QPushButton *_altG = new QPushButton(altG.toString()); - _altG->setShortcut(altG); - layout->addWidget(_altG); - - QKeySequence ctrlShiftR(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_R); - QPushButton *_ctrlShiftR = new QPushButton(ctrlShiftR.toString()); - _ctrlShiftR->setShortcut(ctrlShiftR); - layout->addWidget(_ctrlShiftR); - - QKeySequence ctrlR(Qt::ControlModifier + Qt::Key_R); - QPushButton *_ctrlR = new QPushButton(ctrlR.toString()); - _ctrlR->setShortcut(ctrlR); - layout->addWidget(_ctrlR); - - QKeySequence ctrlReturn(Qt::ControlModifier + Qt::Key_Return); - QPushButton *_ctrlReturn = new QPushButton(ctrlReturn.toString()); - _ctrlReturn->setShortcut(ctrlReturn); - layout->addWidget(_ctrlReturn); - - QKeySequence ctrlEnter(Qt::ControlModifier + Qt::Key_Enter); - QPushButton *_ctrlEnter = new QPushButton(ctrlEnter.toString()); - _ctrlEnter->setShortcut(ctrlEnter); - layout->addWidget(_ctrlEnter); - - QKeySequence ctrlShiftAltR(Qt::ControlModifier + Qt::ShiftModifier + Qt::AltModifier + Qt::Key_R); - QPushButton *_ctrlShiftAltR = new QPushButton(ctrlShiftAltR.toString()); - _ctrlShiftAltR->setShortcut(ctrlShiftAltR); - layout->addWidget(_ctrlShiftAltR); - - QKeySequence shift5(Qt::ShiftModifier + Qt::Key_5); - QPushButton *_shift5 = new QPushButton(shift5.toString()); - _shift5->setShortcut(shift5); - layout->addWidget(_shift5); - - QKeySequence shiftPercent(Qt::ShiftModifier + Qt::Key_Percent); - QPushButton *_shiftPercent = new QPushButton(shiftPercent.toString()); - _shiftPercent->setShortcut(shiftPercent); - layout->addWidget(_shiftPercent); - - QKeySequence percent(Qt::Key_Percent); - QPushButton *_percent = new QPushButton(percent.toString()); - _percent->setShortcut(percent); - layout->addWidget(_percent); - - QKeySequence key5(Qt::Key_5); - QPushButton *_key5 = new QPushButton(key5.toString()); - _key5->setShortcut(key5); - layout->addWidget(_key5); - - QKeySequence keyQ(Qt::Key_Q); - QPushButton *_keyQ = new QPushButton(keyQ.toString()); - _keyQ->setShortcut(keyQ); - layout->addWidget(_keyQ); - - QKeySequence ctrlPercent(Qt::ControlModifier + Qt::Key_Percent); - QPushButton *_ctrlPercent = new QPushButton(ctrlPercent.toString()); - _ctrlPercent->setShortcut(ctrlPercent); - layout->addWidget(_ctrlPercent); - - QKeySequence ctrlShift5(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_5); - QPushButton *_ctrlShift5 = new QPushButton(ctrlShift5.toString()); - _ctrlShift5->setShortcut(ctrlShift5); - layout->addWidget(_ctrlShift5); - - QKeySequence ctrl5(Qt::ControlModifier + Qt::Key_5); - QPushButton *_ctrl5 = new QPushButton(ctrl5.toString()); - _ctrl5->setShortcut(ctrl5); - layout->addWidget(_ctrl5); - - QKeySequence alt5(Qt::AltModifier + Qt::Key_5); - QPushButton *_alt5 = new QPushButton(alt5.toString()); - _alt5->setShortcut(alt5); - layout->addWidget(_alt5); - - QKeySequence ctrlPlus(Qt::ControlModifier + Qt::Key_Plus); - QPushButton *_ctrlPlus = new QPushButton(ctrlPlus.toString()); - _ctrlPlus->setShortcut(ctrlPlus); - layout->addWidget(_ctrlPlus); - - QKeySequence ctrlShiftPlus(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Plus); - QPushButton *_ctrlShiftPlus = new QPushButton(ctrlShiftPlus.toString()); - _ctrlShiftPlus->setShortcut(ctrlShiftPlus); - layout->addWidget(_ctrlShiftPlus); - - QKeySequence ctrlY(Qt::ControlModifier + Qt::Key_Y); - QPushButton *_ctrlY = new QPushButton(ctrlY.toString()); - _ctrlY->setShortcut(ctrlY); - layout->addWidget(_ctrlY); - - QKeySequence shiftComma(Qt::ShiftModifier + Qt::Key_Comma); - QPushButton *_shiftComma = new QPushButton(shiftComma.toString()); - _shiftComma->setShortcut(shiftComma); - layout->addWidget(_shiftComma); - - QKeySequence ctrlComma(Qt::ControlModifier + Qt::Key_Comma); - QPushButton *_ctrlComma = new QPushButton(ctrlComma.toString()); - _ctrlComma->setShortcut(ctrlComma); - layout->addWidget(_ctrlComma); - - QKeySequence ctrlSlash(Qt::ControlModifier + Qt::Key_Slash); - QPushButton *_ctrlSlash = new QPushButton(ctrlSlash.toString()); - _ctrlSlash->setShortcut(ctrlSlash); - layout->addWidget(_ctrlSlash); - - QKeySequence ctrlBackslash(Qt::ControlModifier + Qt::Key_Backslash); - QPushButton *_ctrlBackslash = new QPushButton(ctrlBackslash.toString()); - _ctrlBackslash->setShortcut(ctrlBackslash); - layout->addWidget(_ctrlBackslash); - - QKeySequence metaShiftA(Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_A); - QPushButton *_metaShiftA = new QPushButton(metaShiftA.toString()); - _metaShiftA->setShortcut(metaShiftA); - layout->addWidget(_metaShiftA); - - QKeySequence metaShift5(Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_5); - QPushButton *_metaShift5 = new QPushButton(metaShift5.toString()); - _metaShift5->setShortcut(metaShift5); - layout->addWidget(_metaShift5); - - QKeySequence ctrlBracketRigth(Qt::ControlModifier + Qt::Key_BracketRight); - QPushButton *_ctrlBracketRigth = new QPushButton(ctrlBracketRigth.toString()); - _ctrlBracketRigth->setShortcut(ctrlBracketRigth); - layout->addWidget(_ctrlBracketRigth); - - QKeySequence shiftF3(Qt::ShiftModifier + Qt::Key_F3); - QPushButton *_shiftF3 = new QPushButton(shiftF3.toString()); - _shiftF3->setShortcut(shiftF3); - layout->addWidget(_shiftF3); - - QKeySequence ctrlF3(Qt::ControlModifier + Qt::Key_F3); - QPushButton *_ctrlF3 = new QPushButton(ctrlF3.toString()); - _ctrlF3->setShortcut(ctrlF3); - layout->addWidget(_ctrlF3); - - QKeySequence euro(0x20AC); // EURO SIGN e.g. US (with euro on 5) on 3rd keyboard level - QPushButton *_euro = new QPushButton(euro.toString()); - _euro->setShortcut(euro); - layout->addWidget(_euro); - - QKeySequence ctrlEuro(Qt::ControlModifier + 0x20AC); - QPushButton *_ctrlEuro = new QPushButton(ctrlEuro.toString()); - _ctrlEuro->setShortcut(ctrlEuro); - layout->addWidget(_ctrlEuro); - - // with german (neo 2) layout on linux under ISO_Level3_Shift + ISO_Level5_Shift + I - QKeySequence greekPsi(QString(QStringLiteral("\u03A8"))); - QPushButton *_greekPsi = new QPushButton(greekPsi.toString()); - _greekPsi->setShortcut(greekPsi); - layout->addWidget(_greekPsi); - - layout->addWidget(new QLabel("Norwegian layout")); - // LATIN SMALL LETTER O WITH STROKE - QKeySequence norwegianO(QString(QStringLiteral("\u00F8"))); - QPushButton *_norwegianO = new QPushButton(norwegianO.toString()); - _norwegianO->setShortcut(norwegianO); - layout->addWidget(_norwegianO); - - layout->addWidget(new QLabel("Russian layout")); - // CYRILLIC SMALL LETTER ZHE - QKeySequence zhe(QString(QStringLiteral("\u0436"))); - QPushButton *_zhe = new QPushButton(zhe.toString()); - _zhe->setShortcut(zhe); - layout->addWidget(_zhe); - - // for sequence definitons see qplatformtheme.cpp - layout->addWidget(new QLabel("QKeySequence::StandardKey(s)")); - QPushButton *_open = new QPushButton("Open"); - _open->setShortcut(QKeySequence::Open); // Qt::CTRL | Qt::Key_O - layout->addWidget(_open); + const QString title = QLatin1String(QT_VERSION_STR) + QLatin1Char(' ') + + qApp->platformName(); + setWindowTitle(title); + setupLayout(); } + +private: + void setupLayout(); + void addToGrid(QWidget *w, int &row, int col); + void addShortcutToGrid(const QKeySequence &k, int &row, int col); + void addShortcutToGrid(int key, int &row, int col) + { addShortcutToGrid(QKeySequence(key), row, col); } + + QGridLayout *m_gridLayout = new QGridLayout; }; +inline void ShortcutTester::addToGrid(QWidget *w, int &row, int col) +{ + m_gridLayout->addWidget(w, row++, col); +} + +void ShortcutTester::addShortcutToGrid(const QKeySequence &k, int &row, int col) +{ + QPushButton *button = new QPushButton(k.toString()); + button->setShortcut(k); + addToGrid(button, row, col); +} + +void addShortcutToGrid(int key, int &row, int col); + +void ShortcutTester::setupLayout() +{ + QVBoxLayout *layout = new QVBoxLayout(this); + + QLabel *testPurpose = new QLabel(); + testPurpose->setWordWrap(true); + testPurpose->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding); + testPurpose->setText("This test come in handy to verify shortcuts under different " + "keyboard layouts - qwerty, dvorak, non-latin (russian, arabic), etc."); + layout->addWidget(testPurpose); + + layout->addLayout(m_gridLayout); + + int row = 0; + int col = 0; + + const int keys1[] = { + Qt::AltModifier + Qt::ShiftModifier + Qt::Key_G, + Qt::AltModifier + Qt::Key_G, + Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_R, + Qt::ControlModifier + Qt::Key_R, + Qt::ControlModifier + Qt::Key_Return, Qt::ControlModifier + Qt::Key_Enter, + Qt::ControlModifier + Qt::ShiftModifier + Qt::AltModifier + Qt::Key_R, + Qt::ShiftModifier + Qt::Key_5, Qt::ShiftModifier + Qt::Key_Percent, + Qt::Key_Percent, Qt::Key_5, Qt::Key_Q + }; + + for (int k : keys1) + addShortcutToGrid(k, row, col); + + row = 0; + col++; + + const int keys2[] = { + Qt::ControlModifier + Qt::Key_Percent, + Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_5, + Qt::ControlModifier + Qt::Key_5, Qt::AltModifier + Qt::Key_5, + Qt::ControlModifier + Qt::Key_Plus, + Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Plus, + Qt::ControlModifier + Qt::Key_Y, Qt::ShiftModifier + Qt::Key_Comma, + Qt::ControlModifier + Qt::Key_Comma, Qt::ControlModifier + Qt::Key_Slash, + Qt::ControlModifier + Qt::Key_Backslash + }; + + for (int k : keys2) + addShortcutToGrid(k, row, col); + + row = 0; + col++; + + const int keys3[] = { + Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_A, + Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_5, + Qt::ControlModifier + Qt::Key_BracketRight, + Qt::ShiftModifier + Qt::Key_F3, + Qt::ControlModifier + Qt::Key_F3, + 0x20AC, // EURO SIGN e.g. US (with euro on 5) on 3rd keyboard level + Qt::ControlModifier + 0x20AC + }; + + for (int k : keys3) + addShortcutToGrid(k, row, col); + + // with german (neo 2) layout on linux under ISO_Level3_Shift + ISO_Level5_Shift + I + const QKeySequence greekPsi(QString(QStringLiteral("\u03A8"))); + addShortcutToGrid(greekPsi, row, col); + + row = 0; + col++; + + addToGrid(new QLabel("Norwegian layout"), row, col); + // LATIN SMALL LETTER O WITH STROKE + QKeySequence norwegianO(QString(QStringLiteral("\u00F8"))); + addShortcutToGrid(norwegianO, row, col); + + addToGrid(new QLabel("Russian layout"), row, col); + // CYRILLIC SMALL LETTER ZHE + QKeySequence zhe(QString(QStringLiteral("\u0436"))); + addShortcutToGrid(zhe, row, col); + + // for sequence definitons see qplatformtheme.cpp + addToGrid(new QLabel("QKeySequence::StandardKey(s)"), row, col); + addShortcutToGrid(QKeySequence(QKeySequence::Open), row, col); // Qt::CTRL | Qt::Key_O +} + int main(int argc, char *argv[]) { QApplication a(argc, argv); -- cgit v1.2.3 From 941db4e0bb3170b6bc3cf775f150a226754e6285 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Tue, 10 Apr 2018 15:11:22 +0200 Subject: Doc: Update QtConcurrent::mapped example snippet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wrap current example code snippet in std::function as a work-around, as suggested in comment to QTBUG-61145 (see history tab) with the same issue. Task-number: QTBUG-67603 Change-Id: I6875b31d8e983e234b88384c7d76917ac144f953 Reviewed-by: Topi Reiniö --- src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp index 9cf82c786a..8424dbe97d 100644 --- a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp @@ -172,9 +172,10 @@ QFuture thumbNails = //! [13] QList images = ...; -QFuture thumbnails = QtConcurrent::mapped(images, [](const QImage &img) { +std::function scale = [](const QImage &img) { return img.scaledToWidth(100, Qt::SmoothTransformation); -}); +}; +QFuture thumbnails = QtConcurrent::mapped(images, scale); //! [13] //! [14] -- cgit v1.2.3