diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-03-29 06:57:56 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-04-16 05:26:40 (GMT) |
commit | 8620548e1024c44fbff1cb1becaab8d2d9e53cd5 (patch) | |
tree | b33e880d091aed966e54762ed971a15fd8be360a /tools | |
parent | ba3f33401c97c5517abe19f4ea6f6307e4374c6c (diff) | |
download | Qt-8620548e1024c44fbff1cb1becaab8d2d9e53cd5.zip Qt-8620548e1024c44fbff1cb1becaab8d2d9e53cd5.tar.gz Qt-8620548e1024c44fbff1cb1becaab8d2d9e53cd5.tar.bz2 |
ResizeMode support for QGraphicsWidgets created with QDeclarativeView
Task-number: QTBUG-8814
Reviewed-by: alexis
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qml/main.cpp | 9 | ||||
-rw-r--r-- | tools/qml/qmlruntime.cpp | 112 | ||||
-rw-r--r-- | tools/qml/qmlruntime.h | 4 |
3 files changed, 81 insertions, 44 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 341908e..5e829a4 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -88,6 +88,8 @@ void usage() qWarning(" -skin <qvfbskindir> ...................... run with a skin window frame"); qWarning(" \"list\" for a list of built-ins"); qWarning(" -resizeview .............................. resize the view, not the skin"); + qWarning(" -sizeviewtorootobject .................... the view resizes to the changes in the content"); + qWarning(" -sizerootobjecttoview .................... the content resizes to the changes in the view"); qWarning(" -qmlbrowser .............................. use a QML-based file browser"); qWarning(" -recordfile <output> ..................... set video recording file"); qWarning(" - ImageMagick 'convert' for GIF)"); @@ -184,6 +186,7 @@ int main(int argc, char ** argv) bool stayOnTop = false; bool maximized = false; bool useNativeFileBrowser = true; + bool sizeToView = true; #if defined(Q_OS_SYMBIAN) maximized = true; @@ -270,6 +273,10 @@ int main(int argc, char ** argv) if (lastArg) usage(); script = QString(argv[++i]); runScript = true; + } else if (arg == "-sizeviewtorootobject") { + sizeToView = false; + } else if (arg == "-sizerootobjecttoview") { + sizeToView = true; } else if (arg[0] != '-') { fileName = arg; } else if (1 || arg == "-help") { @@ -339,6 +346,7 @@ int main(int argc, char ** argv) viewer.setNetworkCacheSize(cache); viewer.setRecordFile(recordfile); + viewer.setSizeToView(sizeToView); if (resizeview) viewer.setScaleView(); if (fps>0) @@ -390,6 +398,5 @@ int main(int argc, char ** argv) } viewer.setUseGL(useGL); viewer.raise(); - return app.exec(); } diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 53409c1..7b4706b 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -496,7 +496,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) canvas = new QDeclarativeView(this); canvas->setAttribute(Qt::WA_OpaquePaintEvent); canvas->setAttribute(Qt::WA_NoSystemBackground); - canvas->setResizeMode((!skin || !scaleSkin) ? QDeclarativeView::SizeRootObjectToView : QDeclarativeView::SizeViewToRootObject); + canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); @@ -519,7 +519,6 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) #else setCentralWidget(canvas); #endif - namFactory = new NetworkAccessManagerFactory; canvas->engine()->setNetworkAccessManagerFactory(namFactory); @@ -753,10 +752,11 @@ void QDeclarativeViewer::setScaleSkin() if (scaleSkin) return; scaleSkin = true; - canvas->setResizeMode((!skin || !scaleSkin) ? QDeclarativeView::SizeRootObjectToView : QDeclarativeView::SizeViewToRootObject); if (skin) { - canvas->setFixedSize(canvas->sizeHint()); - skin->setScreenSize(canvas->sizeHint()); + canvas->resize(initialSize); + canvas->setFixedSize(initialSize); + canvas->setResizeMode(QDeclarativeView::SizeViewToRootObject); + updateSizeHints(); } } @@ -766,11 +766,8 @@ void QDeclarativeViewer::setScaleView() return; scaleSkin = false; if (skin) { - canvas->setResizeMode((!skin || !scaleSkin) ? QDeclarativeView::SizeRootObjectToView : QDeclarativeView::SizeViewToRootObject); - canvas->setMinimumSize(QSize(0,0)); - canvas->setMaximumSize(QSize(16777215,16777215)); - canvas->resize(skin->standardScreenSize()); - skin->setScreenSize(skin->standardScreenSize()); + canvas->setResizeMode(QDeclarativeView::SizeRootObjectToView); + updateSizeHints(); } } @@ -916,19 +913,12 @@ void QDeclarativeViewer::statusChanged() tester->executefailure(); if (canvas->status() == QDeclarativeView::Ready) { - if (!skin) { - canvas->updateGeometry(); - if (mb) - mb->updateGeometry(); - if (!isFullScreen() && !isMaximized()) - resize(sizeHint()); - } else { - if (scaleSkin) - canvas->resize(canvas->sizeHint()); - else { - canvas->setFixedSize(skin->standardScreenSize()); - canvas->resize(skin->standardScreenSize()); - } + initialSize = canvas->sizeHint(); + if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { + QSize newWindowSize = initialSize; + newWindowSize.setHeight(newWindowSize.height()+menuBar()->height()); + updateSizeHints(); + resize(newWindowSize); } } } @@ -1010,7 +1000,6 @@ bool QDeclarativeViewer::open(const QString& file_or_url) t.start(); canvas->setSource(url); - qWarning() << "Wall startup time:" << t.elapsed(); return true; @@ -1056,41 +1045,43 @@ void QDeclarativeViewer::setSkin(const QString& skinDirOrName) skin->deleteLater(); } - canvas->setResizeMode((!skin || !scaleSkin) ? QDeclarativeView::SizeRootObjectToView : QDeclarativeView::SizeViewToRootObject); - DeviceSkinParameters parameters; if (!skinDirectory.isEmpty() && parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) { layout()->setEnabled(false); - //setMenuBar(0); if (mb) mb->hide(); if (!err.isEmpty()) qWarning() << err; skin = new PreviewDeviceSkin(parameters,this); - canvas->resize(canvas->sizeHint()); if (scaleSkin) skin->setPreviewAndScale(canvas); else skin->setPreview(canvas); createMenu(0,skin->menu); + if (scaleSkin) { + canvas->setResizeMode(QDeclarativeView::SizeViewToRootObject); + } + updateSizeHints(); skin->show(); - } else { + } else if (skin) { skin = 0; clearMask(); menuBar()->clear(); - canvas->setParent(this, Qt::SubWindow); createMenu(menuBar(),0); - mb->show(); - setMinimumSize(QSize(0,0)); - setMaximumSize(QSize(16777215,16777215)); - canvas->setMinimumSize(QSize(0,0)); - canvas->setMaximumSize(QSize(16777215,16777215)); - QRect g = geometry(); - g.setSize(sizeHint()); + canvas->setParent(this, Qt::SubWindow); setParent(0,windowFlags()); // recreate - canvas->move(0,menuBar()->sizeHint().height()); - setGeometry(g); + mb->show(); + canvas->setResizeMode(QDeclarativeView::SizeRootObjectToView); + updateSizeHints(); + layout()->setEnabled(true); + if (!scaleSkin) { + canvas->resize(initialSize); + canvas->setFixedSize(initialSize); + } + QSize newWindowSize = canvas->size(); + newWindowSize.setHeight(newWindowSize.height()+menuBar()->height()); + resize(newWindowSize); show(); } canvas->show(); @@ -1122,9 +1113,10 @@ void QDeclarativeViewer::setRecordRate(int fps) void QDeclarativeViewer::sceneResized(QSize size) { if (size.width() > 0 && size.height() > 0) { - if (skin && scaleSkin) - skin->setScreenSize(size); - } + if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { + updateSizeHints(); + } + } } void QDeclarativeViewer::keyPressEvent(QKeyEvent *event) @@ -1397,6 +1389,42 @@ void QDeclarativeViewer::setUseNativeFileBrowser(bool use) useQmlFileBrowser = !use; } +void QDeclarativeViewer::setSizeToView(bool sizeToView) +{ + QDeclarativeView::ResizeMode resizeMode = sizeToView ? QDeclarativeView::SizeRootObjectToView : QDeclarativeView::SizeViewToRootObject; + if (resizeMode != canvas->resizeMode()) { + canvas->setResizeMode(resizeMode); + updateSizeHints(); + } +} + +void QDeclarativeViewer::updateSizeHints() +{ + if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { + QSize newWindowSize = canvas->sizeHint(); + if (!skin) { + newWindowSize.setHeight(newWindowSize.height()+menuBar()->height()); + } + if (!isFullScreen() && !isMaximized()) { + resize(newWindowSize); + setFixedSize(newWindowSize); + if (skin && scaleSkin) { + skin->setScreenSize(newWindowSize); + } + } + } else { // QDeclarativeView::SizeRootObjectToView + canvas->setMinimumSize(QSize(0,0)); + canvas->setMaximumSize(QSize(16777215,16777215)); + setMinimumSize(QSize(0,0)); + setMaximumSize(QSize(16777215,16777215)); + if (skin && !scaleSkin) { + canvas->setFixedSize(skin->standardScreenSize()); + skin->setScreenSize(skin->standardScreenSize()); + } + } + updateGeometry(); +} + void QDeclarativeViewer::registerTypes() { static bool registered = false; diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 2089dda..a00a703 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -100,7 +100,8 @@ public: void addPluginPath(const QString& plugin); void setUseGL(bool use); void setUseNativeFileBrowser(bool); - + void updateSizeHints(); + void setSizeToView(bool sizeToView); QStringList builtinSkins() const; QMenuBar *menuBar() const; @@ -149,6 +150,7 @@ private: PreviewDeviceSkin *skin; QSize skinscreensize; QDeclarativeView *canvas; + QSize initialSize; QString currentFileOrUrl; QDeclarativeTimer recordTimer; QString frame_fmt; |