From 5b0de255d1facfe89efed393447a1c914ffdf414 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Tue, 29 Jun 2010 00:31:37 +0200 Subject: Adapt all qmlviewer testcases to the code changes in the actual viewer. (currently tested on Linux only) --- .../qdeclarativeviewer/tst_qdeclarativeviewer.cpp | 28 ++++++++++++++-------- tools/qml/main.cpp | 2 +- tools/qml/qmlruntime.cpp | 12 +--------- tools/qml/qmlruntime.h | 5 ++-- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp index 1ea2a95..576f721 100644 --- a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp +++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include "../../../shared/util.h" #include "qmlruntime.h" #include "../../../shared/util.h" @@ -52,6 +53,12 @@ #define SRCDIR "." #endif +#if defined(Q_OS_MAC) || defined(Q_WS_MAEMO_5) || defined(Q_WS_S60) +# define MENUBAR_HEIGHT(mw) 0 +#else +# define MENUBAR_HEIGHT(mw) (mw->menuBar()->height()) +#endif + class tst_QDeclarativeViewer : public QObject { @@ -77,45 +84,46 @@ tst_QDeclarativeViewer::tst_QDeclarativeViewer() void tst_QDeclarativeViewer::orientation() { - QWidget window; - QDeclarativeViewer *viewer = new QDeclarativeViewer(&window); + QDeclarativeViewer *viewer = new QDeclarativeViewer(); QVERIFY(viewer); viewer->open(SRCDIR "/data/orientation.qml"); QVERIFY(viewer->view()); QVERIFY(viewer->menuBar()); QDeclarativeItem* rootItem = qobject_cast(viewer->view()->rootObject()); QVERIFY(rootItem); - window.show(); + viewer->show(); - QApplication::setActiveWindow(&window); - QTest::qWaitForWindowShown(&window); - QTRY_COMPARE(QApplication::activeWindow(), static_cast(&window)); + QApplication::setActiveWindow(viewer); + QTest::qWaitForWindowShown(viewer); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(viewer)); QCOMPARE(rootItem->width(), 200.0); QCOMPARE(rootItem->height(), 300.0); QTRY_COMPARE(viewer->view()->size(), 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->rotateOrientation(); qApp->processEvents(); + qApp->processEvents(); // one extra round for the delayed updateSizeHints() call QCOMPARE(rootItem->width(), 300.0); QCOMPARE(rootItem->height(), 200.0); QTRY_COMPARE(viewer->view()->size(), QSize(300, 200)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(300, 200)); - QCOMPARE(viewer->size(), QSize(300, 200+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(300, 200 + MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), viewer->sizeHint()); viewer->rotateOrientation(); qApp->processEvents(); + qApp->processEvents(); // one extra round for the delayed updateSizeHints() call QCOMPARE(rootItem->width(), 200.0); QCOMPARE(rootItem->height(), 300.0); QTRY_COMPARE(viewer->view()->size(), 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()); } @@ -249,7 +257,7 @@ void tst_QDeclarativeViewer::resizing() 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->setSizeToView(false); diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index de5bca2..a75023b 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -346,7 +346,7 @@ int main(int argc, char ** argv) if (stayOnTop) wflags |= Qt::WindowStaysOnTopHint; - QDeclarativeViewer *viewer = QDeclarativeViewer::instance(0, wflags); + QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags); viewer->setAttribute(Qt::WA_DeleteOnClose, true); if (!scriptopts.isEmpty()) { QStringList options = diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index e0482cf..2cca262 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -534,17 +534,6 @@ QString QDeclarativeViewer::getVideoFileName() return QFileDialog::getSaveFileName(this, title, "", types.join(";; ")); } -QDeclarativeViewer *QDeclarativeViewer::inst = 0; - -QDeclarativeViewer *QDeclarativeViewer::instance(QWidget *parent, Qt::WindowFlags flags) -{ - if (!inst) { - inst = new QDeclarativeViewer(parent, flags); - inst->setAttribute(Qt::WA_DeleteOnClose); - } - return inst; -} - QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) , loggerWindow(new LoggerWidget(this)) @@ -1400,6 +1389,7 @@ void QDeclarativeViewer::updateSizeHints() 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)); } } else { // QDeclarativeView::SizeRootObjectToView canvas->setMinimumSize(QSize(0,0)); diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 92c2969..a3a9fb3 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -62,16 +62,15 @@ class QNetworkCookieJar; class NetworkAccessManagerFactory; class QTranslator; class QActionGroup; +class QMenuBar; class QDeclarativeViewer : public QMainWindow { Q_OBJECT - QDeclarativeViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0); - static QDeclarativeViewer *inst; public: - static QDeclarativeViewer *instance(QWidget *parent = 0, Qt::WindowFlags flags = 0); + QDeclarativeViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0); ~QDeclarativeViewer(); static void registerTypes(); -- cgit v0.12