diff options
author | Robert Griebl <robert.griebl@nokia.com> | 2010-07-12 12:35:33 (GMT) |
---|---|---|
committer | Robert Griebl <robert.griebl@nokia.com> | 2010-07-12 12:35:33 (GMT) |
commit | 07321dfceed41c1851781841e03c4148da47e41e (patch) | |
tree | 582964432da373f5e8979de156c30773ca8c9737 | |
parent | cbc7a0251a727827418707c7a05ea44241a06efb (diff) | |
download | Qt-07321dfceed41c1851781841e03c4148da47e41e.zip Qt-07321dfceed41c1851781841e03c4148da47e41e.tar.gz Qt-07321dfceed41c1851781841e03c4148da47e41e.tar.bz2 |
Calling setMinimumSize(0, 0) on a top-level window sometimes triggers a bug
in the Compiz window manager which leads to the QML viewer mainwindow not
being composited anymore (at least until the next resize).
Since we need to somehow switch between fixed size and freely resizable
views, we have to work around that bug using the layout constraint hints.
Task-number: QTBUG-11771
Reviewed-by: kkoehne
-rw-r--r-- | tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp | 26 | ||||
-rw-r--r-- | tools/qml/qmlruntime.cpp | 60 | ||||
-rw-r--r-- | tools/qml/qmlruntime.h | 4 |
3 files changed, 40 insertions, 50 deletions
diff --git a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp index 695c038..b08da0f 100644 --- a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp +++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp @@ -113,7 +113,6 @@ void tst_QDeclarativeViewer::orientation() viewer->rotateOrientation(); qApp->processEvents(); - qApp->processEvents(); // one extra round for the delayed updateSizeHints() call QCOMPARE(rootItem->width(), 300.0); QCOMPARE(rootItem->height(), 200.0); @@ -124,7 +123,6 @@ void tst_QDeclarativeViewer::orientation() viewer->rotateOrientation(); qApp->processEvents(); - qApp->processEvents(); // one extra round for the delayed updateSizeHints() call QCOMPARE(rootItem->width(), 200.0); QCOMPARE(rootItem->height(), 300.0); @@ -159,10 +157,10 @@ void tst_QDeclarativeViewer::loading() // window resized QTRY_COMPARE(rootItem->width(), 400.0); - QTRY_COMPARE(rootItem->height(), 500.0-viewer->menuBar()->height()); - QCOMPARE(viewer->view()->size(), QSize(400, 500-viewer->menuBar()->height())); + QTRY_COMPARE(rootItem->height(), 500.0 - MENUBAR_HEIGHT(viewer)); + QCOMPARE(viewer->view()->size(), QSize(400, 500 - MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); - QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(400, 500-viewer->menuBar()->height())); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(400, 500 - MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), QSize(400, 500)); QCOMPARE(viewer->size(), viewer->sizeHint()); @@ -176,7 +174,7 @@ void tst_QDeclarativeViewer::loading() QCOMPARE(viewer->view()->size(), QSize(200, 300)); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); - QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), viewer->sizeHint()); viewer->resize(QSize(400, 500)); @@ -184,10 +182,10 @@ void tst_QDeclarativeViewer::loading() // window resized again QTRY_COMPARE(rootItem->width(), 400.0); - QTRY_COMPARE(rootItem->height(), 500.0-viewer->menuBar()->height()); - QCOMPARE(viewer->view()->size(), QSize(400, 500-viewer->menuBar()->height())); + QTRY_COMPARE(rootItem->height(), 500.0 - MENUBAR_HEIGHT(viewer)); + QCOMPARE(viewer->view()->size(), QSize(400, 500 - MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); - QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(400, 500-viewer->menuBar()->height())); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(400, 500 - MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), QSize(400, 500)); QCOMPARE(viewer->size(), viewer->sizeHint()); @@ -201,7 +199,7 @@ void tst_QDeclarativeViewer::loading() QCOMPARE(viewer->view()->size(), QSize(200, 300)); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); - QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), viewer->sizeHint()); delete viewer; @@ -272,7 +270,7 @@ void tst_QDeclarativeViewer::resizing() QTRY_COMPARE(viewer->view()->size(), QSize(150, 200)); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(150, 200)); - QCOMPARE(viewer->size(), QSize(150, 200+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(150, 200 + MENUBAR_HEIGHT(viewer))); // do not size root object to view viewer->resize(QSize(180,250)); @@ -286,10 +284,10 @@ void tst_QDeclarativeViewer::resizing() qApp->processEvents(); QTRY_COMPARE(rootItem->width(), 250.0); - QTRY_COMPARE(rootItem->height(), 350.0-viewer->menuBar()->height()); - QTRY_COMPARE(viewer->view()->size(), QSize(250, 350-viewer->menuBar()->height())); + QTRY_COMPARE(rootItem->height(), 350.0 - MENUBAR_HEIGHT(viewer)); + QTRY_COMPARE(viewer->view()->size(), QSize(250, 350 - MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); - QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(250, 350-viewer->menuBar()->height())); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(250, 350 - MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), QSize(250, 350)); // do not size view to root object diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 03ca798..951b187 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -944,13 +944,7 @@ void QDeclarativeViewer::statusChanged() if (canvas->status() == QDeclarativeView::Ready) { initialSize = canvas->initialSize(); - if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { - if (!isFullScreen() && !isMaximized()) { - canvas->setFixedSize(initialSize); - resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrink - QTimer::singleShot(0, this, SLOT(updateSizeHints())); - } - } + updateSizeHints(true); } } @@ -1075,13 +1069,9 @@ void QDeclarativeViewer::setRecordRate(int fps) record_rate = fps; } -void QDeclarativeViewer::sceneResized(QSize size) +void QDeclarativeViewer::sceneResized(QSize) { - if (size.width() > 0 && size.height() > 0) { - if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { - updateSizeHints(); - } - } + updateSizeHints(); } void QDeclarativeViewer::keyPressEvent(QKeyEvent *event) @@ -1344,17 +1334,7 @@ void QDeclarativeViewer::changeOrientation(QAction *action) void QDeclarativeViewer::orientationChanged() { - if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { - if (canvas->rootObject()) { - QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size(); - if (size() != rootObjectSize.toSize()) { - canvas->setMinimumSize(rootObjectSize.toSize()); - canvas->resize(rootObjectSize.toSize()); - resize(rootObjectSize.toSize()); - resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks - } - } - } + updateSizeHints(); } void QDeclarativeViewer::setDeviceKeys(bool on) @@ -1403,20 +1383,32 @@ void QDeclarativeViewer::setSizeToView(bool sizeToView) } } -void QDeclarativeViewer::updateSizeHints() +void QDeclarativeViewer::updateSizeHints(bool initial) { - if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { - QSize newWindowSize = canvas->sizeHint(); + static bool isRecursive = false; + + if (isRecursive) + return; + isRecursive = true; + + if (initial || (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject)) { + QSize newWindowSize = initial ? initialSize : canvas->sizeHint(); + //qWarning() << "USH:" << (initial ? "INIT:" : "V2R:") << "setting fixed size " << newWindowSize; if (!isFullScreen() && !isMaximized()) { - canvas->setMinimumSize(newWindowSize); - canvas->resize(newWindowSize); - resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks - canvas->setMinimumSize(QSize(0, 0)); + canvas->setFixedSize(newWindowSize); + resize(1, 1); + layout()->setSizeConstraint(QLayout::SetFixedSize); + layout()->activate(); } - } else { // QDeclarativeView::SizeRootObjectToView - canvas->setMinimumSize(QSize(0,0)); - canvas->setMaximumSize(QSize(16777215,16777215)); } + //qWarning() << "USH: R2V: setting free size "; + layout()->setSizeConstraint(QLayout::SetNoConstraint); + layout()->activate(); + setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); + canvas->setMinimumSize(QSize(0,0)); + canvas->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); + + isRecursive = false; } void QDeclarativeViewer::registerTypes() diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index e70e69f..68d3452 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -145,9 +145,9 @@ private slots: void warningsWidgetOpened(); void warningsWidgetClosed(); - void updateSizeHints(); - private: + void updateSizeHints(bool initial = false); + QString getVideoFileName(); LoggerWidget *loggerWindow; |