From 130cf33cdc1a1f7c2a0b33fcef0ac63b8163306d Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Sun, 30 May 2010 10:52:42 +1000 Subject: Some tweaks on the QML-enhanced QtDemo -don't crash if we aren't showing the FPS -different method of unloading the QML example when hidden -fix screwed up background when scaled. --- demos/qtdemo/menumanager.cpp | 25 ++++++++++++++++--------- demos/qtdemo/menumanager.h | 1 - demos/qtdemo/qmlShell.qml | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/demos/qtdemo/menumanager.cpp b/demos/qtdemo/menumanager.cpp index 9e2ba6b..a2ceb0e 100644 --- a/demos/qtdemo/menumanager.cpp +++ b/demos/qtdemo/menumanager.cpp @@ -378,13 +378,19 @@ void MenuManager::launchQmlExample(const QString &name) return; } } + if(!Colors::noBlur){ + QImage qmlBgImage(this->window->rect().size(), QImage::Format_ARGB32_Premultiplied); + QPainter painter(&qmlBgImage); + if(Colors::showFps) + this->window->fpsLabel->setOpacity(0); + this->window->render(&painter); + if(Colors::showFps) + this->window->fpsLabel->setOpacity(1.0); + Qt::ImageConversionFlags convFlags = Qt::AvoidDither | Qt::NoOpaqueDetection; + this->declarativeEngine->rootContext()->setContextProperty("bgAppPixmap", QVariant(QPixmap::fromImage(qmlBgImage, convFlags))); + } - QPainter painter(qmlBgImage); - this->window->fpsLabel->setOpacity(0); - this->window->render(&painter); - this->window->fpsLabel->setOpacity(1.0); - Qt::ImageConversionFlags convFlags = Qt::AvoidDither | Qt::NoOpaqueDetection; - this->declarativeEngine->rootContext()->setContextProperty("bgAppPixmap", QVariant(QPixmap::fromImage(*qmlBgImage, convFlags))); + qmlRoot->setProperty("qmlFile", QVariant(""));//unload component qmlRoot->setProperty("show", QVariant(true)); qmlRoot->setProperty("qmlFile", QUrl::fromLocalFile(file.fileName())); } @@ -439,10 +445,11 @@ void MenuManager::init(MainWindow *window) // Note that we paint the background into a static image for a theorized performance improvement when blurring // It has not yet been determined what, if any, speed up this gives (but is left in 'cause the QML expects it now) - this->qmlBgImage = new QImage(window->sceneRect().size().toSize(), QImage::Format_ARGB32); - this->qmlBgImage->fill(0); declarativeEngine->rootContext()->setContextProperty("useBlur", !Colors::noBlur); - declarativeEngine->rootContext()->setContextProperty("bgAppPixmap", QVariant(QPixmap::fromImage(*qmlBgImage))); + QImage qmlBgImage(this->window->rect().size(), QImage::Format_ARGB32_Premultiplied); + qmlBgImage.fill(0); + this->declarativeEngine->rootContext()->setContextProperty("bgAppPixmap", QVariant(QPixmap::fromImage(qmlBgImage))); + QDeclarativeComponent component(declarativeEngine, QUrl("qrc:qml/qmlShell.qml"), this); qmlRoot = 0; if(component.isReady()) diff --git a/demos/qtdemo/menumanager.h b/demos/qtdemo/menumanager.h index e90e02c..5e14204 100644 --- a/demos/qtdemo/menumanager.h +++ b/demos/qtdemo/menumanager.h @@ -85,7 +85,6 @@ public: QDeclarativeEngine* declarativeEngine; QDeclarativeItem *qmlRoot; - QImage *qmlBgImage; private slots: void exampleFinished(); diff --git a/demos/qtdemo/qmlShell.qml b/demos/qtdemo/qmlShell.qml index b9021e8..b1ee79a 100644 --- a/demos/qtdemo/qmlShell.qml +++ b/demos/qtdemo/qmlShell.qml @@ -167,6 +167,7 @@ Item { SequentialAnimation{ PropertyAction { target: bg; property: useBlur?"y":"opacity";}//fade in blurred background only if blurred NumberAnimation{ properties: "opacity"; easing.type: Easing.InQuad; duration: 500} + PropertyAction { target: loader; property: "focus"; value: true}//Might be needed to ensure the focus stays with us } } ] -- cgit v0.12