Move SnapToDefaultButton from QPlatformDialogHelper to QPlatformTheme
Since QPlatformTheme covers all dialogs whereas QPlatformDialogHelper is really only for the native dialogs then the SnapToDefaultButton hint is moved as it has relevance for all dialogs Task-number: QTBUG-32631 Change-Id: I1dce0bb4abcd4cfd39c4a199a33fc7078176ab4b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
3abecf2ee9
commit
1baf293548
@ -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();
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,6 @@ class Q_GUI_EXPORT QPlatformDialogHelper : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum StyleHint {
|
||||
SnapToDefaultButton
|
||||
};
|
||||
enum DialogCode { Rejected, Accepted };
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -105,7 +105,8 @@ public:
|
||||
SpellCheckUnderlineStyle,
|
||||
TabAllWidgets,
|
||||
IconPixmapSizes,
|
||||
PasswordMaskCharacter
|
||||
PasswordMaskCharacter,
|
||||
DialogSnapToDefaultButton
|
||||
};
|
||||
|
||||
enum DialogType {
|
||||
|
@ -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.
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user