Add some properties to QWindow
authorAlan Alpert <alan.alpert@nokia.com>
Fri, 18 Nov 2011 10:47:05 +0000 (20:47 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 22 Nov 2011 09:54:57 +0000 (10:54 +0100)
x,y,width,height,visible and orientation
Includes slot setters and notify signals for maximal QML compatibility.

Change-Id: I124399093c00f8ad1485d4fbae816dfbe3027eff
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/gui/kernel/qguiapplication.cpp
src/gui/kernel/qwindow.cpp
src/gui/kernel/qwindow.h

index 1101764..7e60689 100644 (file)
@@ -790,12 +790,22 @@ void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePr
         QGuiApplication::sendSpontaneousEvent(window, &e);
 
         window->d_func()->resizeEventPending = false;
+
+        if (cr.width() != newRect.width())
+            window->widthChanged(cr.width());
+        if (cr.height() != newRect.height())
+            window->heightChanged(cr.height());
     }
 
     if (isMove) {
         //### frame geometry
         QMoveEvent e(newRect.topLeft(), cr.topLeft());
         QGuiApplication::sendSpontaneousEvent(window, &e);
+
+        if (cr.x() != newRect.x())
+            window->xChanged(cr.x());
+        if (cr.y() != newRect.y())
+            window->yChanged(cr.y());
     }
 }
 
index 2878551..4156fd8 100644 (file)
@@ -129,6 +129,7 @@ void QWindow::setVisible(bool visible)
     if (d->visible == visible)
         return;
     d->visible = visible;
+    emit visibleChanged(visible);
 
     if (!d->platformWindow)
         create();
@@ -383,10 +384,14 @@ Qt::ScreenOrientation QWindow::orientation() const
 void QWindow::setOrientation(Qt::ScreenOrientation orientation)
 {
     Q_D(QWindow);
+    if (orientation == d->orientation)
+        return;
+
     d->orientation = orientation;
     if (d->platformWindow) {
         d->platformWindow->setOrientation(orientation);
     }
+    emit orientationChanged(orientation);
 }
 
 Qt::WindowState QWindow::windowState() const
@@ -519,12 +524,25 @@ void QWindow::setSizeIncrement(const QSize &size)
 void QWindow::setGeometry(const QRect &rect)
 {
     Q_D(QWindow);
+    if (rect == geometry())
+        return;
+    QRect oldRect = geometry();
+
     d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
     if (d->platformWindow) {
         d->platformWindow->setGeometry(rect);
     } else {
         d->geometry = rect;
     }
+
+    if (rect.x() != oldRect.x())
+        emit xChanged(rect.x());
+    if (rect.y() != oldRect.y())
+        emit yChanged(rect.y());
+    if (rect.width() != oldRect.width())
+        emit widthChanged(rect.width());
+    if (rect.height() != oldRect.height())
+        emit heightChanged(rect.height());
 }
 
 /*!
index 1c3dd3a..c1dcee4 100644 (file)
@@ -85,6 +85,12 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
     Q_DECLARE_PRIVATE(QWindow)
 
     Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
+    Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
+    Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
+    Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
+    Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
+    Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
+    Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
 
 public:
     enum SurfaceType { RasterSurface, OpenGLSurface };
@@ -96,7 +102,6 @@ public:
     void setSurfaceType(SurfaceType surfaceType);
     SurfaceType surfaceType() const;
 
-    void setVisible(bool visible);
     bool visible() const;
 
     void create();
@@ -201,6 +206,8 @@ public:
     QPoint mapFromGlobal(const QPoint &pos) const;
 
 public Q_SLOTS:
+    void setVisible(bool visible);
+
     inline void show() { setVisible(true); }
     inline void hide() { setVisible(false); }
 
@@ -215,9 +222,45 @@ public Q_SLOTS:
 
     void setWindowTitle(const QString &);
 
+    void setX(int arg)
+    {
+        if (x() != arg)
+            setGeometry(QRect(arg, y(), width(), height()));
+    }
+
+    void setY(int arg)
+    {
+        if (y() != arg)
+            setGeometry(QRect(x(), arg, width(), height()));
+    }
+
+    void setWidth(int arg)
+    {
+        if (width() != arg)
+            setGeometry(QRect(x(), y(), arg, height()));
+    }
+
+    void setHeight(int arg)
+    {
+        if (height() != arg)
+            setGeometry(QRect(x(), y(), width(), arg));
+    }
+
 Q_SIGNALS:
     void backBufferReady();
 
+    void xChanged(int arg);
+
+    void yChanged(int arg);
+
+    void widthChanged(int arg);
+
+    void heightChanged(int arg);
+
+    void visibleChanged(bool arg);
+
+    void orientationChanged(Qt::ScreenOrientation arg);
+
 protected:
     virtual void exposeEvent(QExposeEvent *);
     virtual void resizeEvent(QResizeEvent *);