aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-07-26 13:48:45 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-26 08:00:31 +0200
commite06211e4c67c0c7470fdac86c3fa6d50792516c5 (patch)
treefc672331a442d93f714c962efc47cbeb6b23dd3c
parente5be1482c81fb3a502e2e5f8e56f11f182c2adab (diff)
qmlviewer resizes the root object multiple times.
In SizeRootObjectToView mode on initial load the view was set to root object size, then the sceneResized() slot would resize back, then we would finally reset back to the correct value in statusChanged(true). Now react directly to the initial size being set. Change-Id: Ib6977cf7bad3fe79b9ac80bb6d916fb0f57c5f5e Fixes: QTBUG-16499 Reviewed-on: http://codereview.qt.nokia.com/2148 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r--src/qtquick1/util/qdeclarativeview.cpp5
-rw-r--r--src/qtquick1/util/qdeclarativeview.h1
-rw-r--r--tests/auto/qtquick1/qdeclarativeviewer/tst_qdeclarativeviewer.cpp24
-rw-r--r--tools/qmlviewer/qmlruntime.cpp13
-rw-r--r--tools/qmlviewer/qmlruntime.h1
5 files changed, 42 insertions, 2 deletions
diff --git a/src/qtquick1/util/qdeclarativeview.cpp b/src/qtquick1/util/qdeclarativeview.cpp
index ae7e07d0ce..cc19828c40 100644
--- a/src/qtquick1/util/qdeclarativeview.cpp
+++ b/src/qtquick1/util/qdeclarativeview.cpp
@@ -248,6 +248,10 @@ void QDeclarativeViewPrivate::itemGeometryChanged(QDeclarativeItem *resizeItem,
This signal is emitted when the component's current \a status changes.
*/
+/*! \fn void QDeclarativeView::initialSizeChanged(QSize size)
+ \internal
+*/
+
/*!
\fn QDeclarativeView::QDeclarativeView(QWidget *parent)
@@ -609,6 +613,7 @@ void QDeclarativeView::setRootObject(QObject *obj)
resize(d->initialSize);
}
}
+ emit initialSizeChanged(d->initialSize);
d->initResize();
}
}
diff --git a/src/qtquick1/util/qdeclarativeview.h b/src/qtquick1/util/qdeclarativeview.h
index cfe1d458dc..39a2322f99 100644
--- a/src/qtquick1/util/qdeclarativeview.h
+++ b/src/qtquick1/util/qdeclarativeview.h
@@ -97,6 +97,7 @@ public Q_SLOTS:
Q_SIGNALS:
void sceneResized(QSize size); // ???
void statusChanged(QDeclarativeView::Status);
+ void initialSizeChanged(QSize size);
private Q_SLOTS:
void continueExecute();
diff --git a/tests/auto/qtquick1/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/qtquick1/qdeclarativeviewer/tst_qdeclarativeviewer.cpp
index 6ef2a114d7..f4fc4f0d46 100644
--- a/tests/auto/qtquick1/qdeclarativeviewer/tst_qdeclarativeviewer.cpp
+++ b/tests/auto/qtquick1/qdeclarativeviewer/tst_qdeclarativeviewer.cpp
@@ -62,6 +62,20 @@
# define MENUBAR_HEIGHT(mw) (mw->menuBar()->height())
#endif
+
+class QDeclarativeViewerTest : public QDeclarativeViewer
+{
+public:
+ QDeclarativeViewerTest() : QDeclarativeViewer(), resizeCount(0) {}
+
+ void resizeEvent (QResizeEvent *event) {
+ QDeclarativeViewer::resizeEvent(event);
+ ++resizeCount;
+ }
+
+ int resizeCount;
+};
+
class tst_QDeclarativeViewer : public QObject
{
@@ -288,7 +302,7 @@ void tst_QDeclarativeViewer::fileBrowser()
void tst_QDeclarativeViewer::resizing()
{
- QDeclarativeViewer *viewer = new QDeclarativeViewer();
+ QDeclarativeViewerTest *viewer = new QDeclarativeViewerTest();
QVERIFY(viewer);
viewer->open(SRCDIR "/data/orientation.qml");
QVERIFY(viewer->view());
@@ -303,6 +317,8 @@ void tst_QDeclarativeViewer::resizing()
TEST_INITIAL_SIZES(viewer);
+ QCOMPARE(viewer->resizeCount, 1);
+
viewer->setSizeToView(false);
// size view to root object
@@ -317,6 +333,8 @@ void tst_QDeclarativeViewer::resizing()
QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(150, 200));
QCOMPARE(viewer->size(), QSize(150, 200 + MENUBAR_HEIGHT(viewer)));
+ QCOMPARE(viewer->resizeCount, 2);
+
// do not size root object to view
viewer->resize(QSize(180,250));
QCOMPARE(rootItem->width(), 150.0);
@@ -336,10 +354,14 @@ void tst_QDeclarativeViewer::resizing()
QCOMPARE(viewer->size(), QSize(250, 350));
// do not size view to root object
+ viewer->resizeCount = 0;
+
rootItem->setWidth(150);
rootItem->setHeight(200);
QTRY_COMPARE(viewer->size(), QSize(250, 350));
+ QCOMPARE(viewer->resizeCount, 0);
+
delete viewer;
}
diff --git a/tools/qmlviewer/qmlruntime.cpp b/tools/qmlviewer/qmlruntime.cpp
index 55f0f4f2bc..bb2191b2a4 100644
--- a/tools/qmlviewer/qmlruntime.cpp
+++ b/tools/qmlviewer/qmlruntime.cpp
@@ -651,7 +651,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
canvas->setFocus();
- QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize)));
+ QObject::connect(canvas, SIGNAL(initialSizeChanged(QSize)), this, SLOT(initialSizeChanged(QSize)));
QObject::connect(canvas, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(statusChanged()));
QObject::connect(canvas->engine(), SIGNAL(quit()), this, SLOT(close()));
@@ -1052,6 +1052,7 @@ void QDeclarativeViewer::statusChanged()
if (canvas->status() == QDeclarativeView::Ready) {
initialSize = canvas->initialSize();
updateSizeHints(true);
+ QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize)));
}
}
@@ -1144,6 +1145,7 @@ bool QDeclarativeViewer::open(const QString& file_or_url)
QTime t;
t.start();
+ QObject::disconnect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize)));
canvas->setSource(url);
return true;
@@ -1177,6 +1179,15 @@ void QDeclarativeViewer::sceneResized(QSize)
updateSizeHints();
}
+void QDeclarativeViewer::initialSizeChanged(QSize size)
+{
+ if (!isFullScreen() && !isMaximized()) {
+ canvas->setFixedSize(size);
+ layout()->setSizeConstraint(QLayout::SetFixedSize);
+ layout()->activate();
+ }
+}
+
void QDeclarativeViewer::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_0 && devicemode)
diff --git a/tools/qmlviewer/qmlruntime.h b/tools/qmlviewer/qmlruntime.h
index d56cee8d2f..20e0303b14 100644
--- a/tools/qmlviewer/qmlruntime.h
+++ b/tools/qmlviewer/qmlruntime.h
@@ -112,6 +112,7 @@ public:
public slots:
void sceneResized(QSize size);
+ void initialSizeChanged(QSize size);
bool open(const QString&);
void openFile();
void openUrl();