diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-09-04 17:56:30 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-09-27 20:44:17 +0000 |
commit | 126c2cb8fbb50848a5006fd25e83b8afc7b3e781 (patch) | |
tree | 237625fd169b89935233f8125931d9c3c0c24b49 /src/widgets/dialogs | |
parent | b2e664df614dea23bf77c0fa293682b47a8b5557 (diff) |
Clean up cancel operation handling on OS X
The logic for handling cancel operations was spread out through
the code base and sometimes hard-coded to only include the Escape
key shortcut, missing the Command+. shortcut.
We now intercept both attempts at cancel operations from the system
through cancelOperation, which we forward as normal key events.
A new QKeySequence::StandardKey has been added for the Cancel sequence,
which maps to Escape on all platforms, and Command+. in addition for
OS X. The hard-coded logic in QWidget and subclasses for dealing
with closing the dialogs has been replaced with this key sequence,
which allows clients to override the behavior. Note that the widget
code is not wrapped in checks for QT_NO_SHORTCUT, as we don't care
about keeping widgets building and working under that define.
The logic in QCocoaWindow to bypass windowShouldClose when delivering
IM events has been removed as we now handle that specific case by
also forwarding Escape as a cancel operation.
Task-number: QTBUG-47557
Task-number: QTBUG-45771
Task-number: QTBUG-44076
Change-Id: Ibe0b3a4819f8659d246a2142dd7d9cd3a826ef78
Reviewed-by: Tim Blechmann <tim@klingt.org>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r-- | src/widgets/dialogs/qcolordialog.cpp | 8 | ||||
-rw-r--r-- | src/widgets/dialogs/qdialog.cpp | 7 | ||||
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 11 | ||||
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 7 | ||||
-rw-r--r-- | src/widgets/dialogs/qprogressdialog.cpp | 3 |
5 files changed, 14 insertions, 22 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 2ebbaaee10..468bffe49e 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -2286,16 +2286,12 @@ bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e) bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e) { Q_Q(QColorDialog); - switch (e->key()) { - case Qt::Key_Escape: + if (e->matches(QKeySequence::Cancel)) { releaseColorPicking(); q->setCurrentColor(beforeScreenColorPicking); - break; - case Qt::Key_Return: - case Qt::Key_Enter: + } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { q->setCurrentColor(grabScreenColor(QCursor::pos())); releaseColorPicking(); - break; } e->accept(); return true; diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index d04241fee0..5124960ab4 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -651,11 +651,9 @@ void QDialog::keyPressEvent(QKeyEvent *e) // Calls reject() if Escape is pressed. Simulates a button // click for the default button if Enter is pressed. Move focus // for the arrow keys. Ignore the rest. -#ifdef Q_OS_MAC - if(e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) { + if (e->matches(QKeySequence::Cancel)) { reject(); } else -#endif if (!e->modifiers() || (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter)) { switch (e->key()) { case Qt::Key_Enter: @@ -671,9 +669,6 @@ void QDialog::keyPressEvent(QKeyEvent *e) } } break; - case Qt::Key_Escape: - reject(); - break; default: e->ignore(); return; diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 81beccd5c8..ee2b1e6dae 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -3778,6 +3778,12 @@ void QFileDialogPrivate::_q_nativeEnterDirectory(const QUrl &directory) bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) { Q_Q(QFileDialog); + + if (event->matches(QKeySequence::Cancel)) { + q->hide(); + return true; + } + switch (event->key()) { case Qt::Key_Backspace: _q_navigateToParent(); @@ -3793,9 +3799,6 @@ bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) { return true; } break; - case Qt::Key_Escape: - q->hide(); - return true; default: break; } @@ -3982,7 +3985,7 @@ void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) int key = e->key(); QLineEdit::keyPressEvent(e); - if (key != Qt::Key_Escape && key != Qt::Key_Back) + if (!e->matches(QKeySequence::Cancel) && key != Qt::Key_Back) e->accept(); } diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index ef9b55acd6..8a48100ea7 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1450,11 +1450,8 @@ void QMessageBox::changeEvent(QEvent *ev) void QMessageBox::keyPressEvent(QKeyEvent *e) { Q_D(QMessageBox); - if (e->key() == Qt::Key_Escape -#ifdef Q_OS_MAC - || (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) -#endif - ) { + + if (e->matches(QKeySequence::Cancel)) { if (d->detectedEscapeButton) { #ifdef Q_OS_MAC d->detectedEscapeButton->animateClick(); diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index 97e9267a9d..bbb251c8b2 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -411,7 +411,8 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton) if (cancelButton) { connect(d->cancel, SIGNAL(clicked()), this, SIGNAL(canceled())); #ifndef QT_NO_SHORTCUT - d->escapeShortcut = new QShortcut(Qt::Key_Escape, this, SIGNAL(canceled())); + // FIXME: This only registers the primary key sequence of the cancel action + d->escapeShortcut = new QShortcut(QKeySequence::Cancel, this, SIGNAL(canceled())); #endif } else { #ifndef QT_NO_SHORTCUT |