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>
This commit is contained in:
parent
8e002f1c0e
commit
9fc7fcb4c9
@ -1211,6 +1211,12 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
|
|||||||
QGuiApplicationPrivate::processFileOpenEvent(
|
QGuiApplicationPrivate::processFileOpenEvent(
|
||||||
static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
|
static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
|
||||||
break;
|
break;
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
case QWindowSystemInterfacePrivate::ContextMenu:
|
||||||
|
QGuiApplicationPrivate::processContextMenuEvent(
|
||||||
|
static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
qWarning() << "Unknown user input event type:" << e->type;
|
qWarning() << "Unknown user input event type:" << e->type;
|
||||||
break;
|
break;
|
||||||
@ -1639,6 +1645,19 @@ void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePri
|
|||||||
QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
|
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)
|
Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k)
|
||||||
{
|
{
|
||||||
return qHash(k.device) + k.touchPointId;
|
return qHash(k.device) + k.touchPointId;
|
||||||
|
@ -138,6 +138,9 @@ public:
|
|||||||
static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
|
static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
|
||||||
|
|
||||||
static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
|
static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef QT_NO_DRAGANDDROP
|
#ifndef QT_NO_DRAGANDDROP
|
||||||
static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
|
static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
|
||||||
|
@ -630,6 +630,18 @@ void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
|
|||||||
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
|
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) {
|
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);
|
QWindowSystemInterface::handleMouseEvent(w, local, global, b, mods);
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,11 @@ public:
|
|||||||
static void handleTabletLeaveProximityEvent(int device, int pointerType, qint64 uid);
|
static void handleTabletLeaveProximityEvent(int device, int pointerType, qint64 uid);
|
||||||
|
|
||||||
static void handlePlatformPanelEvent(QWindow *w);
|
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
|
// For event dispatcher implementations
|
||||||
static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
|
static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
|
||||||
|
@ -77,7 +77,8 @@ public:
|
|||||||
Tablet,
|
Tablet,
|
||||||
TabletEnterProximity,
|
TabletEnterProximity,
|
||||||
TabletLeaveProximity,
|
TabletLeaveProximity,
|
||||||
PlatformPanel
|
PlatformPanel,
|
||||||
|
ContextMenu
|
||||||
};
|
};
|
||||||
|
|
||||||
class WindowSystemEvent {
|
class WindowSystemEvent {
|
||||||
@ -333,6 +334,21 @@ public:
|
|||||||
QPointer<QWindow> window;
|
QPointer<QWindow> 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<QWindow> 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 {
|
class WindowSystemEventList {
|
||||||
QList<WindowSystemEvent *> impl;
|
QList<WindowSystemEvent *> impl;
|
||||||
mutable QMutex mutex;
|
mutable QMutex mutex;
|
||||||
|
@ -105,6 +105,7 @@ enum WindowsEventType // Simplify event types
|
|||||||
ThemeChanged = ThemingEventFlag + 1,
|
ThemeChanged = ThemingEventFlag + 1,
|
||||||
DisplayChangedEvent = 437,
|
DisplayChangedEvent = 437,
|
||||||
SettingChangedEvent = DisplayChangedEvent + 1,
|
SettingChangedEvent = DisplayChangedEvent + 1,
|
||||||
|
ContextMenu = 123,
|
||||||
UnknownEvent = 542
|
UnknownEvent = 542
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,6 +195,10 @@ inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamI
|
|||||||
return QtWindows::DisplayChangedEvent;
|
return QtWindows::DisplayChangedEvent;
|
||||||
case WM_THEMECHANGED:
|
case WM_THEMECHANGED:
|
||||||
return QtWindows::ThemeChanged;
|
return QtWindows::ThemeChanged;
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
case WM_CONTEXTMENU:
|
||||||
|
return QtWindows::ContextMenu;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -868,6 +868,11 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
|
|||||||
if (const QWindow *modalWindow = QGuiApplication::modalWindow())
|
if (const QWindow *modalWindow = QGuiApplication::modalWindow())
|
||||||
QWindowsWindow::baseWindowOf(modalWindow)->alertWindow();
|
QWindowsWindow::baseWindowOf(modalWindow)->alertWindow();
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
case QtWindows::ContextMenu:
|
||||||
|
handleContextMenuEvent(platformWindow->window(), msg);
|
||||||
|
return true;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -900,6 +905,24 @@ void QWindowsContext::handleFocusEvent(QtWindows::WindowsEventType et,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
void QWindowsContext::handleContextMenuEvent(QWindow *window, const MSG &msg)
|
||||||
|
{
|
||||||
|
bool mouseTriggered = false;
|
||||||
|
QPoint globalPos;
|
||||||
|
QPoint pos;
|
||||||
|
if (msg.lParam != (int)0xffffffff) {
|
||||||
|
mouseTriggered = true;
|
||||||
|
globalPos.setX(msg.pt.x);
|
||||||
|
globalPos.setY(msg.pt.y);
|
||||||
|
pos = QWindowsGeometryHint::mapFromGlobal(msg.hwnd, globalPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWindowSystemInterface::handleContextMenuEvent(window, mouseTriggered, pos, globalPos,
|
||||||
|
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Windows functions for actual windows.
|
\brief Windows functions for actual windows.
|
||||||
|
|
||||||
|
@ -187,6 +187,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void handleFocusEvent(QtWindows::WindowsEventType et, QWindowsWindow *w);
|
void handleFocusEvent(QtWindows::WindowsEventType et, QWindowsWindow *w);
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
void handleContextMenuEvent(QWindow *window, const MSG &msg);
|
||||||
|
#endif
|
||||||
void unregisterWindowClasses();
|
void unregisterWindowClasses();
|
||||||
|
|
||||||
QScopedPointer<QWindowsContextPrivate> d;
|
QScopedPointer<QWindowsContextPrivate> d;
|
||||||
|
@ -200,7 +200,11 @@ bool QWidgetWindow::event(QEvent *event)
|
|||||||
handleTabletEvent(static_cast<QTabletEvent *>(event));
|
handleTabletEvent(static_cast<QTabletEvent *>(event));
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
case QEvent::ContextMenu:
|
||||||
|
handleContextMenuEvent(static_cast<QContextMenuEvent *>(event));
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -618,6 +622,35 @@ void QWidgetWindow::handleTabletEvent(QTabletEvent *event)
|
|||||||
}
|
}
|
||||||
#endif // QT_NO_TABLETEVENT
|
#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()
|
void QWidgetWindow::updateObjectName()
|
||||||
{
|
{
|
||||||
QString name = m_widget->objectName();
|
QString name = m_widget->objectName();
|
||||||
|
@ -92,6 +92,9 @@ protected:
|
|||||||
#ifndef QT_NO_TABLETEVENT
|
#ifndef QT_NO_TABLETEVENT
|
||||||
void handleTabletEvent(QTabletEvent *);
|
void handleTabletEvent(QTabletEvent *);
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
|
void handleContextMenuEvent(QContextMenuEvent *);
|
||||||
|
#endif
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateObjectName();
|
void updateObjectName();
|
||||||
|
Loading…
Reference in New Issue
Block a user