From 8dc2f81c9f0e6eb8cab09e5d682358fd140b49b8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 4 Aug 2011 10:36:48 +0200 Subject: Add WindowStateChanged event. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not currently considering activation state. Change-Id: Iea9265d35536947b6cc85639bd9839e9fda69bdf Reviewed-on: http://codereview.qt.nokia.com/2609 Reviewed-by: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 12 ++++++++++++ src/gui/kernel/qguiapplication_p.h | 1 + src/gui/kernel/qwindowsysteminterface_qpa.cpp | 7 +++++++ src/gui/kernel/qwindowsysteminterface_qpa.h | 1 + src/gui/kernel/qwindowsysteminterface_qpa_p.h | 21 ++++++++++++++++----- src/widgets/kernel/qwidgetwindow_qpa.cpp | 14 ++++++++++++++ src/widgets/kernel/qwidgetwindow_qpa_p.h | 1 + 7 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index f739037cc6..f1edf52b0a 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -510,6 +510,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv case QWindowSystemInterfacePrivate::ActivatedWindow: QGuiApplicationPrivate::processActivatedEvent(static_cast(e)); break; + case QWindowSystemInterfacePrivate::WindowStateChanged: + QGuiApplicationPrivate::processWindowStateChangedEvent(static_cast(e)); + break; case QWindowSystemInterfacePrivate::Close: QGuiApplicationPrivate::processCloseEvent( static_cast(e)); @@ -690,6 +693,15 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate self->notifyActiveWindowChange(previous); } +void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse) +{ + if (QWindow *window = wse->window.data()) { + QWindowStateChangeEvent e(window->windowState()); + window->d_func()->windowState = wse->newState; + QGuiApplication::sendSpontaneousEvent(window, &e); + } +} + void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e) { if (e->tlw.isNull()) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 325c89e363..fc6da6fd31 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -114,6 +114,7 @@ public: static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e); static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e); + static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e); static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index e6fbd5b875..047c134b69 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -80,6 +80,13 @@ void QWindowSystemInterface::handleWindowActivated(QWindow *tlw) QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } +void QWindowSystemInterface::handleWindowStateChanged(QWindow *tlw, Qt::WindowState newState) +{ + QWindowSystemInterfacePrivate::WindowStateChangedEvent *e = + new QWindowSystemInterfacePrivate::WindowStateChangedEvent(tlw, newState); + QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); +} + void QWindowSystemInterface::handleGeometryChange(QWindow *tlw, const QRect &newRect) { QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(tlw,newRect); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 7df7c2deb4..52838e03c5 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -99,6 +99,7 @@ public: static void handleEnterEvent(QWindow *w); static void handleLeaveEvent(QWindow *w); static void handleWindowActivated(QWindow *w); + static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState); static void handleMapEvent(QWindow *w); static void handleUnmapEvent(QWindow *w); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h index 912ac877fb..1e772eb2b8 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h @@ -55,6 +55,7 @@ public: Enter, Leave, ActivatedWindow, + WindowStateChanged, Mouse, Wheel, Key, @@ -69,14 +70,14 @@ public: class WindowSystemEvent { public: - WindowSystemEvent(EventType t) + explicit WindowSystemEvent(EventType t) : type(t) { } EventType type; }; class CloseEvent : public WindowSystemEvent { public: - CloseEvent(QWindow *w) + explicit CloseEvent(QWindow *w) : WindowSystemEvent(Close), window(w) { } QWeakPointer window; }; @@ -92,7 +93,7 @@ public: class EnterEvent : public WindowSystemEvent { public: - EnterEvent(QWindow *enter) + explicit EnterEvent(QWindow *enter) : WindowSystemEvent(Enter), enter(enter) { } QWeakPointer enter; @@ -100,7 +101,7 @@ public: class LeaveEvent : public WindowSystemEvent { public: - LeaveEvent(QWindow *leave) + explicit LeaveEvent(QWindow *leave) : WindowSystemEvent(Leave), leave(leave) { } QWeakPointer leave; @@ -108,12 +109,22 @@ public: class ActivatedWindowEvent : public WindowSystemEvent { public: - ActivatedWindowEvent(QWindow *activatedWindow) + explicit ActivatedWindowEvent(QWindow *activatedWindow) : WindowSystemEvent(ActivatedWindow), activated(activatedWindow) { } QWeakPointer activated; }; + class WindowStateChangedEvent : public WindowSystemEvent { + public: + WindowStateChangedEvent(QWindow *_window, Qt::WindowState _newState) + : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState) + { } + + QWeakPointer window; + Qt::WindowState newState; + }; + class UserEvent : public WindowSystemEvent { public: UserEvent(QWindow * w, ulong time, EventType t) diff --git a/src/widgets/kernel/qwidgetwindow_qpa.cpp b/src/widgets/kernel/qwidgetwindow_qpa.cpp index 24e76f05d6..ab8bacc1c7 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa.cpp +++ b/src/widgets/kernel/qwidgetwindow_qpa.cpp @@ -114,6 +114,10 @@ bool QWidgetWindow::event(QEvent *event) handleExposeEvent(static_cast(event)); return true; + case QEvent::WindowStateChange: + handleWindowStateChangedEvent(static_cast(event)); + return true; + default: break; } @@ -385,4 +389,14 @@ void QWidgetWindow::handleExposeEvent(QExposeEvent *event) m_widget->d_func()->syncBackingStore(event->region()); } +void QWidgetWindow::handleWindowStateChangedEvent(QWindowStateChangeEvent *event) +{ + // QWindow does currently not know 'active'. + Qt::WindowStates eventState = event->oldState(); + if (m_widget->windowState() & Qt::WindowActive) + eventState |= Qt::WindowActive; + QWindowStateChangeEvent widgetEvent(eventState); + QGuiApplication::sendSpontaneousEvent(m_widget, &widgetEvent); +} + QT_END_NAMESPACE diff --git a/src/widgets/kernel/qwidgetwindow_qpa_p.h b/src/widgets/kernel/qwidgetwindow_qpa_p.h index f200839b0b..4253072933 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa_p.h +++ b/src/widgets/kernel/qwidgetwindow_qpa_p.h @@ -76,6 +76,7 @@ protected: void handleWheelEvent(QWheelEvent *); void handleDragEvent(QEvent *); void handleExposeEvent(QExposeEvent *); + void handleWindowStateChangedEvent(QWindowStateChangeEvent *event); private: void updateGeometry(); -- cgit v1.2.3