From 9fc7fcb4c90f9fdc5bb3581609a1d5b01cfb7076 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 22 Oct 2012 14:43:38 +0300 Subject: Add ContextMenu event to QWindowSystemInterface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 19 +++++++++++++++++++ src/gui/kernel/qguiapplication_p.h | 3 +++ src/gui/kernel/qwindowsysteminterface.cpp | 12 ++++++++++++ src/gui/kernel/qwindowsysteminterface.h | 5 +++++ src/gui/kernel/qwindowsysteminterface_p.h | 18 +++++++++++++++++- 5 files changed, 56 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index a67917ca3b..64d2f8001f 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1211,6 +1211,12 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv QGuiApplicationPrivate::processFileOpenEvent( static_cast(e)); break; +#ifndef QT_NO_CONTEXTMENU + case QWindowSystemInterfacePrivate::ContextMenu: + QGuiApplicationPrivate::processContextMenuEvent( + static_cast(e)); + break; +#endif default: qWarning() << "Unknown user input event type:" << e->type; break; @@ -1639,6 +1645,19 @@ void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePri QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev); } +#ifndef QT_NO_CONTEXTMENU +void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e) +{ + // Widgets do not care about mouse triggered context menu events. Also, do not forward event + // to a window blocked by a modal window. + if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow) + return; + + QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers); + QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev); +} +#endif + Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k) { return qHash(k.device) + k.touchPointId; diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 0c81d78f86..44a9275688 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -138,6 +138,9 @@ public: static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e); static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e); +#ifndef QT_NO_CONTEXTMENU + static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e); +#endif #ifndef QT_NO_DRAGANDDROP static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions); diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 82e0e44ac7..6fb10b6c75 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -630,6 +630,18 @@ void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w) QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } +#ifndef QT_NO_CONTEXTMENU +void QWindowSystemInterface::handleContextMenuEvent(QWindow *w, bool mouseTriggered, + const QPoint &pos, const QPoint &globalPos, + Qt::KeyboardModifiers modifiers) +{ + QWindowSystemInterfacePrivate::ContextMenuEvent *e = + new QWindowSystemInterfacePrivate::ContextMenuEvent(w, mouseTriggered, pos, + globalPos, modifiers); + QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); +} +#endif + Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier) { QWindowSystemInterface::handleMouseEvent(w, local, global, b, mods); } diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 74b5a136f4..b4b2e845fc 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -175,6 +175,11 @@ public: static void handleTabletLeaveProximityEvent(int device, int pointerType, qint64 uid); static void handlePlatformPanelEvent(QWindow *w); +#ifndef QT_NO_CONTEXTMENU + static void handleContextMenuEvent(QWindow *w, bool mouseTriggered, + const QPoint &pos, const QPoint &globalPos, + Qt::KeyboardModifiers modifiers); +#endif // For event dispatcher implementations static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 4e907f3f51..1b5351db71 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -77,7 +77,8 @@ public: Tablet, TabletEnterProximity, TabletLeaveProximity, - PlatformPanel + PlatformPanel, + ContextMenu }; class WindowSystemEvent { @@ -333,6 +334,21 @@ public: QPointer window; }; +#ifndef QT_NO_CONTEXTMENU + class ContextMenuEvent : public WindowSystemEvent { + public: + explicit ContextMenuEvent(QWindow *w, bool mouseTriggered, const QPoint &pos, + const QPoint &globalPos, Qt::KeyboardModifiers modifiers) + : WindowSystemEvent(ContextMenu), window(w), mouseTriggered(mouseTriggered), pos(pos), + globalPos(globalPos), modifiers(modifiers) { } + QPointer window; + bool mouseTriggered; + QPoint pos; // Only valid if triggered by mouse + QPoint globalPos; // Only valid if triggered by mouse + Qt::KeyboardModifiers modifiers; + }; +#endif + class WindowSystemEventList { QList impl; mutable QMutex mutex; -- cgit v1.2.3