diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2012-10-22 14:43:38 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-25 10:08:04 +0200 |
commit | 9fc7fcb4c90f9fdc5bb3581609a1d5b01cfb7076 (patch) | |
tree | 205dd5103662563949f9bea6ca7c85aea905a33c /src/widgets | |
parent | 8e002f1c0e0e0605d6cdfb90cdf909035eb643c8 (diff) |
Add ContextMenu event to QWindowSystemInterface
Context menu key wasn't working, as QPA had no handling for it.
Added ContextMenu event to QWindowSystemInterface and proper handling
to QGuiApplication and QWidgetWindow.
Also provide Windows implementation.
Task-number: QTBUG-27648
Change-Id: I7ce71ec4b5cdcc7be758e67f9faf6d863f7b19be
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 35 | ||||
-rw-r--r-- | src/widgets/kernel/qwidgetwindow_qpa_p.h | 3 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 5f25e1274e..900818d5c6 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -200,7 +200,11 @@ bool QWidgetWindow::event(QEvent *event) handleTabletEvent(static_cast<QTabletEvent *>(event)); return true; #endif - +#ifndef QT_NO_CONTEXTMENU + case QEvent::ContextMenu: + handleContextMenuEvent(static_cast<QContextMenuEvent *>(event)); + return true; +#endif default: break; } @@ -618,6 +622,35 @@ void QWidgetWindow::handleTabletEvent(QTabletEvent *event) } #endif // QT_NO_TABLETEVENT +#ifndef QT_NO_CONTEXTMENU +void QWidgetWindow::handleContextMenuEvent(QContextMenuEvent *e) +{ + // We are only interested in keyboard originating context menu events here, + // mouse originated context menu events for widgets are generated in mouse handling methods. + if (e->reason() != QContextMenuEvent::Keyboard) + return; + + QWidget *fw = QWidget::keyboardGrabber(); + if (!fw) { + if (QApplication::activePopupWidget()) { + fw = (QApplication::activePopupWidget()->focusWidget() + ? QApplication::activePopupWidget()->focusWidget() + : QApplication::activePopupWidget()); + } else if (QApplication::focusWidget()) { + fw = QApplication::focusWidget(); + } else { + fw = m_widget; + } + } + if (fw && fw->isEnabled()) { + QPoint pos = fw->inputMethodQuery(Qt::ImMicroFocus).toRect().center(); + QContextMenuEvent widgetEvent(QContextMenuEvent::Keyboard, pos, fw->mapToGlobal(pos), + e->modifiers()); + QGuiApplication::sendSpontaneousEvent(fw, &widgetEvent); + } +} +#endif // QT_NO_CONTEXTMENU + void QWidgetWindow::updateObjectName() { QString name = m_widget->objectName(); diff --git a/src/widgets/kernel/qwidgetwindow_qpa_p.h b/src/widgets/kernel/qwidgetwindow_qpa_p.h index 80aa022ce2..e832249107 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa_p.h +++ b/src/widgets/kernel/qwidgetwindow_qpa_p.h @@ -92,6 +92,9 @@ protected: #ifndef QT_NO_TABLETEVENT void handleTabletEvent(QTabletEvent *); #endif +#ifndef QT_NO_CONTEXTMENU + void handleContextMenuEvent(QContextMenuEvent *); +#endif private slots: void updateObjectName(); |