Add WindowStateChanged event.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Thu, 4 Aug 2011 08:36:48 +0000 (10:36 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Fri, 5 Aug 2011 08:41:43 +0000 (10:41 +0200)
Not currently considering activation state.

Change-Id: Iea9265d35536947b6cc85639bd9839e9fda69bdf
Reviewed-on: http://codereview.qt.nokia.com/2609
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/gui/kernel/qguiapplication.cpp
src/gui/kernel/qguiapplication_p.h
src/gui/kernel/qwindowsysteminterface_qpa.cpp
src/gui/kernel/qwindowsysteminterface_qpa.h
src/gui/kernel/qwindowsysteminterface_qpa_p.h
src/widgets/kernel/qwidgetwindow_qpa.cpp
src/widgets/kernel/qwidgetwindow_qpa_p.h

index f739037..f1edf52 100644 (file)
@@ -510,6 +510,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
     case QWindowSystemInterfacePrivate::ActivatedWindow:
         QGuiApplicationPrivate::processActivatedEvent(static_cast<QWindowSystemInterfacePrivate::ActivatedWindowEvent *>(e));
         break;
+    case QWindowSystemInterfacePrivate::WindowStateChanged:
+        QGuiApplicationPrivate::processWindowStateChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
+        break;
     case QWindowSystemInterfacePrivate::Close:
         QGuiApplicationPrivate::processCloseEvent(
                 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(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())
index 325c89e..fc6da6f 100644 (file)
@@ -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);
 
index e6fbd5b..047c134 100644 (file)
@@ -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);
index 7df7c2d..52838e0 100644 (file)
@@ -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);
index 912ac87..1e772eb 100644 (file)
@@ -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<QWindow> window;
     };
@@ -92,7 +93,7 @@ public:
 
     class EnterEvent : public WindowSystemEvent {
     public:
-        EnterEvent(QWindow *enter)
+        explicit EnterEvent(QWindow *enter)
             : WindowSystemEvent(Enter), enter(enter)
         { }
         QWeakPointer<QWindow> enter;
@@ -100,7 +101,7 @@ public:
 
     class LeaveEvent : public WindowSystemEvent {
     public:
-        LeaveEvent(QWindow *leave)
+        explicit LeaveEvent(QWindow *leave)
             : WindowSystemEvent(Leave), leave(leave)
         { }
         QWeakPointer<QWindow> leave;
@@ -108,12 +109,22 @@ public:
 
     class ActivatedWindowEvent : public WindowSystemEvent {
     public:
-        ActivatedWindowEvent(QWindow *activatedWindow)
+        explicit ActivatedWindowEvent(QWindow *activatedWindow)
             : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
         { }
         QWeakPointer<QWindow> activated;
     };
 
+    class WindowStateChangedEvent : public WindowSystemEvent {
+    public:
+        WindowStateChangedEvent(QWindow *_window, Qt::WindowState _newState)
+            : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState)
+        { }
+
+        QWeakPointer<QWindow> window;
+        Qt::WindowState newState;
+    };
+
     class UserEvent : public WindowSystemEvent {
     public:
         UserEvent(QWindow * w, ulong time, EventType t)
index 24e76f0..ab8bacc 100644 (file)
@@ -114,6 +114,10 @@ bool QWidgetWindow::event(QEvent *event)
         handleExposeEvent(static_cast<QExposeEvent *>(event));
         return true;
 
+    case QEvent::WindowStateChange:
+        handleWindowStateChangedEvent(static_cast<QWindowStateChangeEvent *>(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
index f200839..4253072 100644 (file)
@@ -76,6 +76,7 @@ protected:
     void handleWheelEvent(QWheelEvent *);
     void handleDragEvent(QEvent *);
     void handleExposeEvent(QExposeEvent *);
+    void handleWindowStateChangedEvent(QWindowStateChangeEvent *event);
 
 private:
     void updateGeometry();