Add QPlatformTheme::standardButtonShortcut()

It allows to set shortcuts for the standard buttons in
QDialogButtonBox.

Restore Qt4's behavior for the "Don't Save" button on macOS
by setting a shortcut for it (it was Cmd-D before Lion,
now it's Cmd-Delete).

Change-Id: I6b56f68f37670962178693a8983d9fe550540856
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Alexander Volkov 2016-11-09 17:33:00 +03:00
parent 2f103bde11
commit de63bbd2f8
5 changed files with 22 additions and 6 deletions

View File

@ -671,6 +671,19 @@ QString QPlatformTheme::standardButtonText(int button) const
return QPlatformTheme::defaultStandardButtonText(button);
}
/*!
Returns the mnemonic that should be used for a standard \a button.
\since 5.9
\sa QPlatformDialogHelper::StandardButton
*/
QKeySequence QPlatformTheme::standardButtonShortcut(int button) const
{
Q_UNUSED(button)
return QKeySequence();
}
QString QPlatformTheme::defaultStandardButtonText(int button)
{
switch (button) {

View File

@ -312,6 +312,7 @@ public:
#endif
virtual QString standardButtonText(int button) const;
virtual QKeySequence standardButtonShortcut(int button) const;
static QVariant defaultThemeHint(ThemeHint hint);
static QString defaultStandardButtonText(int button);

View File

@ -74,6 +74,7 @@ public:
QVariant themeHint(ThemeHint hint) const Q_DECL_OVERRIDE;
QString standardButtonText(int button) const Q_DECL_OVERRIDE;
QKeySequence standardButtonShortcut(int button) const Q_DECL_OVERRIDE;
static const char *name;

View File

@ -344,6 +344,12 @@ QString QCocoaTheme::standardButtonText(int button) const
return button == QPlatformDialogHelper::Discard ? msgDialogButtonDiscard() : QPlatformTheme::standardButtonText(button);
}
QKeySequence QCocoaTheme::standardButtonShortcut(int button) const
{
return button == QPlatformDialogHelper::Discard ? QKeySequence(Qt::CTRL | Qt::Key_Delete)
: QPlatformTheme::standardButtonShortcut(button);
}
QPlatformMenuItem *QCocoaTheme::createPlatformMenuItem() const
{
return new QCocoaMenuItem();

View File

@ -411,12 +411,7 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut
else
addButton(button, static_cast<QDialogButtonBox::ButtonRole>(role), doLayout);
#if 0 // Used to be included in Qt4 for Q_WS_MAC
// Since mnemonics is off by default on Mac, we add a Cmd-D
// shortcut here to e.g. make the "Don't Save" button work nativly:
if (sbutton == QDialogButtonBox::Discard)
button->setShortcut(QKeySequence(QLatin1String("Ctrl+D")));
#endif
button->setShortcut(QGuiApplicationPrivate::platformTheme()->standardButtonShortcut(sbutton));
return button;
}