diff options
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.cpp | 17 | ||||
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qplatformtheme.cpp | 5 | ||||
-rw-r--r-- | src/gui/kernel/qplatformtheme.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsdialoghelpers.cpp | 18 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsdialoghelpers.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.cpp | 2 | ||||
-rw-r--r-- | src/widgets/dialogs/qdialog.cpp | 4 | ||||
-rw-r--r-- | tests/auto/widgets/dialogs/qdialog/qdialog.pro | 2 | ||||
-rw-r--r-- | tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp | 33 |
10 files changed, 45 insertions, 41 deletions
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index 74442736c3..d9e9c4b17c 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -60,18 +60,6 @@ QT_BEGIN_NAMESPACE */ -/*! - \enum QPlatformDialogHelper::StyleHint - - This enum type specifies platform-specific style hints. - - \value SnapToDefaultButton Snap the mouse to the center of the default - button. There is corresponding system - setting on Windows. - - \sa styleHint() -*/ - QPlatformDialogHelper::QPlatformDialogHelper() { } @@ -87,10 +75,7 @@ QVariant QPlatformDialogHelper::styleHint(StyleHint hint) const QVariant QPlatformDialogHelper::defaultStyleHint(QPlatformDialogHelper::StyleHint hint) { - switch (hint) { - case QPlatformDialogHelper::SnapToDefaultButton: - return QVariant(false); - } + Q_UNUSED(hint); return QVariant(); } diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index 092839aaed..6d7d52ccb1 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -78,7 +78,6 @@ class Q_GUI_EXPORT QPlatformDialogHelper : public QObject Q_OBJECT public: enum StyleHint { - SnapToDefaultButton }; enum DialogCode { Rejected, Accepted }; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 5c3673890a..18ac9dc088 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -138,6 +138,9 @@ QT_BEGIN_NAMESPACE \value TabAllWidgets (bool) Whether tab navigation should go through all the widgets or components, or just through text boxes and list views. This is mostly a Mac feature. + \value DialogSnapToDefaultButton (bool) Whether the mouse should snap to the default button when a dialog + becomes visible. + \sa themeHint(), QStyle::pixelMetric() */ @@ -455,6 +458,8 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) return QVariant(true); case IconPixmapSizes: return QVariant::fromValue(QList<int>()); + case DialogSnapToDefaultButton: + return QVariant(false); } return QVariant(); } diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index fd2bb19f2a..3eb103b7e0 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -105,7 +105,8 @@ public: SpellCheckUnderlineStyle, TabAllWidgets, IconPixmapSizes, - PasswordMaskCharacter + PasswordMaskCharacter, + DialogSnapToDefaultButton }; enum DialogType { diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index 354f6700b3..328842677f 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -615,24 +615,6 @@ void QWindowsDialogHelperBase<BaseClass>::exec() } } -static inline bool snapToDefaultButtonHint() -{ - BOOL snapToDefault = false; - if (SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0, &snapToDefault, 0)) - return snapToDefault; - return false; -} - -template <class BaseClass> -QVariant QWindowsDialogHelperBase<BaseClass>::styleHint(QPlatformDialogHelper::StyleHint hint) const -{ - switch (hint) { - case QPlatformDialogHelper::SnapToDefaultButton: - return QVariant(snapToDefaultButtonHint()); - } - return BaseClass::styleHint(hint); -} - /*! \class QWindowsFileDialogSharedData \brief Explicitly shared file dialog parameters that are not in QFileDialogOptions. diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.h b/src/plugins/platforms/windows/qwindowsdialoghelpers.h index 7884f398f3..c0ee60cc1e 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.h +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.h @@ -72,7 +72,6 @@ public: Qt::WindowModality windowModality, QWindow *parent); virtual void hide(); - virtual QVariant styleHint(QPlatformDialogHelper::StyleHint) const; virtual bool supportsNonModalDialog(const QWindow * /* parent */ = 0) const { return true; } diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 882967d22c..724ea00340 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -357,6 +357,8 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const sizes << 16 << 32; return QVariant::fromValue(sizes); } + case DialogSnapToDefaultButton: + return QVariant(booleanSystemParametersInfo(SPI_GETSNAPTODEFBUTTON, false)); default: break; } diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index 2cda99a269..e1097dd1bb 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -767,8 +767,10 @@ void QDialog::setVisible(bool visible) if (d->eventLoop) d->eventLoop->exit(); } + + const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); if (d->mainDef && isActiveWindow() - && d->styleHint(QPlatformDialogHelper::SnapToDefaultButton).toBool()) + && theme->themeHint(QPlatformTheme::DialogSnapToDefaultButton).toBool()) QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center())); } diff --git a/tests/auto/widgets/dialogs/qdialog/qdialog.pro b/tests/auto/widgets/dialogs/qdialog/qdialog.pro index 72a2dc52b3..c7917e8ff6 100644 --- a/tests/auto/widgets/dialogs/qdialog/qdialog.pro +++ b/tests/auto/widgets/dialogs/qdialog/qdialog.pro @@ -1,5 +1,5 @@ CONFIG += testcase CONFIG += parallel_test TARGET = tst_qdialog -QT += widgets testlib +QT += widgets testlib gui-private core-private SOURCES += tst_qdialog.cpp diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index 6d847086d9..1aab794e1b 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -49,8 +49,10 @@ #include <qstyle.h> #include <QVBoxLayout> #include <QSizeGrip> - - +#include <QDesktopWidget> +#include <private/qguiapplication_p.h> +#include <qpa/qplatformtheme.h> +#include <qpa/qplatformtheme_p.h> QT_FORWARD_DECLARE_CLASS(QDialog) @@ -82,6 +84,7 @@ private slots: #endif void setVisible(); void reject(); + void snapToDefaultButton(); private: QDialog *testWidget; @@ -554,6 +557,32 @@ void tst_QDialog::reject() QCOMPARE(dialog.called, 4); } +void tst_QDialog::snapToDefaultButton() +{ +#ifdef QT_NO_CURSOR + QSKIP("Test relies on there being a cursor"); +#else + QPoint topLeftPos = QApplication::desktop()->availableGeometry().topLeft(); + topLeftPos = QPoint(topLeftPos.x() + 100, topLeftPos.y() + 100); + QPoint startingPos(topLeftPos.x() + 250, topLeftPos.y() + 250); + QCursor::setPos(startingPos); + QVERIFY(QCursor::pos() == startingPos); + QDialog dialog; + QPushButton *button = new QPushButton(&dialog); + button->setDefault(true); + dialog.setGeometry(QRect(topLeftPos, QSize(200, 200))); + dialog.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dialog)); + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { + if (theme->themeHint(QPlatformTheme::DialogSnapToDefaultButton).toBool()) { + QPoint localPos = button->mapFromGlobal(QCursor::pos()); + QVERIFY(button->rect().contains(localPos)); + } else { + QVERIFY(startingPos == QCursor::pos()); + } + } +#endif // !QT_NO_CURSOR +} QTEST_MAIN(tst_QDialog) #include "tst_qdialog.moc" |