summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2012-07-04 13:43:05 +0200
committerJens Bache-Wiig <jens.bache-wiig@nokia.com>2012-07-05 11:13:22 +0200
commit124c54e4e305c6aa9eb81a8f8fa563384779a1c9 (patch)
tree3a2acb2ccda491c10937ce66f0725c223320a25b
parent7dfe54c9808ed3057fa2f42b684a8b28a1bd22ce (diff)
downloadqtquickcontrols-124c54e4e305c6aa9eb81a8f8fa563384779a1c9.tar.gz
Remove overriden final properties in QWindowItem
x, y, width, and height are declared as final in QQuickItem, and should therefore not be redefined in inherited classes. Also changed the event filter accordingly. Change-Id: Ife4f655235916f96b0608c6d20593ef50d3d4313 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@nokia.com>
-rw-r--r--src/qtoplevelwindow.cpp1
-rw-r--r--src/qwindowitem.cpp96
-rw-r--r--src/qwindowitem.h18
3 files changed, 48 insertions, 67 deletions
diff --git a/src/qtoplevelwindow.cpp b/src/qtoplevelwindow.cpp
index b9a9213c..cf1ace23 100644
--- a/src/qtoplevelwindow.cpp
+++ b/src/qtoplevelwindow.cpp
@@ -91,7 +91,6 @@ void QTopLevelWindow::center()
void QTopLevelWindow::move(int x, int y)
{
- qDebug("a %d, %d", x, y);
move(QPoint(x,y));
}
diff --git a/src/qwindowitem.cpp b/src/qwindowitem.cpp
index 67b6a44b..8810b0b7 100644
--- a/src/qwindowitem.cpp
+++ b/src/qwindowitem.cpp
@@ -44,11 +44,21 @@
#include <QTimer>
QWindowItem::QWindowItem()
- : _window(new QTopLevelWindow), _positionIsDefined(false), _delayedVisible(false), _deleteOnClose(true), _x(0), _y(0)
+ : QQuickItem()
+ , _window(new QTopLevelWindow)
+ , _positionIsDefined(false)
+ , _delayedVisible(false)
+ , _deleteOnClose(false)
+ , _x(0), _y(0)
{
connect(_window, SIGNAL(visibilityChanged()), this, SIGNAL(visibleChanged()));
connect(_window, SIGNAL(windowStateChanged()), this, SIGNAL(windowStateChanged()));
- connect(_window, SIGNAL(sizeChanged(QSize)), this, SLOT(updateSize(QSize)));
+ connect(_window, SIGNAL(sizeChanged(QSize)), this, SLOT(setSize(QSize)));
+
+ connect(this, SIGNAL(xChanged()), this, SLOT(updateWindowGeometry()));
+ connect(this, SIGNAL(yChanged()), this, SLOT(updateWindowGeometry()));
+ connect(this, SIGNAL(widthChanged()), this, SLOT(updateWindowGeometry()));
+ connect(this, SIGNAL(heightChanged()), this, SLOT(updateWindowGeometry()));
view()->setResizeMode(QQuickView::SizeRootObjectToView);
_window->installEventFilter(this);
@@ -63,22 +73,20 @@ bool QWindowItem::eventFilter(QObject *, QEvent *ev)
{
switch (ev->type()) {
case QEvent::Close:
- ev->ignore();
- if (_deleteOnClose)
- deleteLater();
- else
- _window->hide();
- return true;
- case QEvent::Resize:
- emit sizeChanged();
- emit widthChanged();
- emit heightChanged();
+ close();
+ return _deleteOnClose;
+
+ case QEvent::Resize: {
+ QResizeEvent *rev = static_cast<QResizeEvent *>(ev);
+ setSize(rev->size());
break;
+ }
- case QEvent::Move:
- emit xChanged();
- emit yChanged();
+ case QEvent::Move: {
+ QMoveEvent *mev = static_cast<QMoveEvent *>(ev);
+ setPos(mev->pos());
break;
+ }
default:
break;
@@ -113,10 +121,15 @@ void QWindowItem::componentComplete()
}
}
-void QWindowItem::updateSize(QSize newSize)
+void QWindowItem::updateWindowGeometry()
{
- QQuickItem::setSize(newSize);
- emit sizeChanged();
+ // Translate the view's root item on the other direction to keep this item in place
+ QQuickItem *viewRootItem = _window->view()->rootItem();
+ viewRootItem->setX(-x());
+ viewRootItem->setY(-y());
+
+ _window->move(x(), y());
+ _window->resize(width(), height());
}
void QWindowItem::center()
@@ -124,17 +137,6 @@ void QWindowItem::center()
_window->center();
}
-void QWindowItem::setX(int x)
-{
- _x = x;
- _window->move(x, _y);
-}
-void QWindowItem::setY(int y)
-{
- _y = y;
- _window->move(_x, y);
-}
-
void QWindowItem::moveWindow(int x,int y, int lx, int ly)
{
QPoint p = _window->mapToGlobal(QPoint(x,y));
@@ -143,36 +145,32 @@ void QWindowItem::moveWindow(int x,int y, int lx, int ly)
_window->move(p);
}
-void QWindowItem::setHeight(int height)
-{
- _window->resize(width(), height);
- QQuickItem::setHeight(_window->height());
-}
-
-void QWindowItem::setMinimumHeight(int height)
-{
- _window->setMinimumSize(QSize(_window->minimumSize().width(), height));
-}
-
-void QWindowItem::setMaximumHeight(int height)
+void QWindowItem::setMinimumHeight(int h)
{
- _window->setMaximumSize(QSize(_window->maximumSize().width(), height));
+ _window->setMinimumSize(QSize(_window->minimumSize().width(), h));
+ if (height() < h)
+ setHeight(h);
}
-void QWindowItem::setWidth(int width)
+void QWindowItem::setMaximumHeight(int h)
{
- _window->resize(width, height());
- QQuickItem::setWidth(_window->width());
+ _window->setMaximumSize(QSize(_window->maximumSize().width(), h));
+ if (height() > h)
+ setHeight(h);
}
-void QWindowItem::setMinimumWidth(int width)
+void QWindowItem::setMinimumWidth(int w)
{
- _window->setMinimumSize(QSize(width, _window->minimumSize().height()));
+ _window->setMinimumSize(QSize(w, _window->minimumSize().height()));
+ if (width() < w)
+ setWidth(w);
}
-void QWindowItem::setMaximumWidth(int width)
+void QWindowItem::setMaximumWidth(int w)
{
- _window->setMinimumSize(QSize(width, _window->maximumSize().height()));
+ _window->setMinimumSize(QSize(w, _window->maximumSize().height()));
+ if (width() > w)
+ setWidth(w);
}
void QWindowItem::setTitle(QString title)
diff --git a/src/qwindowitem.h b/src/qwindowitem.h
index 3cd50a2d..472015c3 100644
--- a/src/qwindowitem.h
+++ b/src/qwindowitem.h
@@ -51,10 +51,6 @@
class QWindowItem : public QQuickItem
{
Q_OBJECT
- Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
- Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
- Q_PROPERTY(int height READ height WRITE setHeight NOTIFY sizeChanged)
- Q_PROPERTY(int width READ width WRITE setWidth NOTIFY sizeChanged)
Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight NOTIFY minimumHeightChanged)
Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged)
Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
@@ -71,12 +67,8 @@ public:
~QWindowItem();
QTopLevelWindow *window() { return _window; }
QQuickView *view() { return _window->view(); }
- int x() const { return _window->x(); }
- int y() const { return _window->y(); }
- int height() const { return _window->size().height(); }
int minimumHeight() const { return _window->minimumSize().height(); }
int maximumHeight() const { return _window->maximumSize().height(); }
- int width() const { return _window->size().width(); }
int minimumWidth() const { return _window->minimumSize().width(); }
int maximumWidth() const { return _window->maximumSize().width(); }
bool isVisible() const { return _window->isVisible(); }
@@ -86,13 +78,8 @@ public:
bool deleteOnClose() const { return _deleteOnClose; }
bool modal() const { return _window->isModal(); }
- void setX(int x);
- void setY(int y);
-
- void setHeight(int height);
void setMinimumHeight(int height);
void setMaximumHeight(int height);
- void setWidth(int width);
void setMinimumWidth(int width);
void setMaximumWidth(int width);
void setVisible(bool visible);
@@ -112,14 +99,11 @@ protected:
void componentComplete();
protected Q_SLOTS:
- void updateSize(QSize newSize);
+ void updateWindowGeometry();
void center();
void moveWindow(int x, int y, int lx, int ly);
Q_SIGNALS:
- void sizeChanged();
- void xChanged();
- void yChanged();
void visibleChanged();
void windowDecorationChanged();
void windowStateChanged();