From 91be655a7e893d34fdbdb71aa5a329b641c80992 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 26 Oct 2009 15:41:51 +1000 Subject: Fix "initial" size for remote content. --- src/declarative/util/qmlview.cpp | 12 +++++++++++- src/declarative/util/qmlview.h | 1 + tools/qmlviewer/qmlviewer.cpp | 8 +++++++- tools/qmlviewer/qmlviewer.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 14f8279..f91d0db 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -360,6 +360,8 @@ void QmlView::continueExecute() emit sceneResized(sz); resize(sz); } + updateGeometry(); + emit initialSize(d->initialSize); } else if (QWidget *wid = qobject_cast(obj)) { window()->setAttribute(Qt::WA_OpaquePaintEvent, false); window()->setAttribute(Qt::WA_NoSystemBackground, false); @@ -374,6 +376,7 @@ void QmlView::continueExecute() } layout()->addWidget(wid); emit sceneResized(wid->size()); + emit initialSize(wid->size()); } } } @@ -382,6 +385,10 @@ void QmlView::continueExecute() This signal is emitted when the view is resized to \a size. */ +/*! \fn void QmlView::initialSize(QSize size) + This signal is emitted when the initial size of the root item is known. + */ + /*! \fn void QmlView::errors(const QList &errors) This signal is emitted when the qml loaded contains \a errors. */ @@ -425,7 +432,10 @@ void QmlView::timerEvent(QTimerEvent* e) automatically resize the root item. Regardless of this property, the sizeHint of the view - is the initial size of the root item. + is the initial size of the root item. Note though that + since QML may load dynamically, that size may change. + + \sa initialSize() */ void QmlView::setContentResizable(bool on) diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index faf2564..822827a 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -88,6 +88,7 @@ public: QSize sizeHint() const; Q_SIGNALS: + void initialSize(QSize size); void sceneResized(QSize size); void errors(const QList &error); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 73aae44..b115abb 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -310,6 +310,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); + QObject::connect(canvas, SIGNAL(initialSize(QSize)), this, SLOT(adjustSizeSlot())); QObject::connect(canvas, SIGNAL(errors(QList)), this, SLOT(executeErrors())); if (!(flags & Qt::FramelessWindowHint)) @@ -335,6 +336,11 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) recordTimer.setRepeating(true); } +void QmlViewer::adjustSizeSlot() +{ + adjustSize(); +} + QMenuBar *QmlViewer::menuBar() const { if (!mb) @@ -680,7 +686,7 @@ void QmlViewer::openQml(const QUrl& url) canvas->updateGeometry(); if (mb) mb->updateGeometry(); - resize(sizeHint()); + adjustSize(); } else { if (scaleSkin) canvas->resize(canvas->sizeHint()); diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index f0578eb..50495db 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -88,6 +88,7 @@ private slots: void chooseRecordingOptions(); void pickRecordingFile(); void setScaleSkin(); + void adjustSizeSlot(); private: void setupProxy(); -- cgit v0.12