From 57fa34d2c09529b71e2fdfec077c0f35e9cd7624 Mon Sep 17 00:00:00 2001 From: Samuli Piippo Date: Fri, 29 May 2015 13:21:19 +0300 Subject: Make standalone demos work with 2d renderer Standalone application did not work in non-gpu devices (colibri vf), when the root item did not have size set. Fix this by using the same code as qtlancher has: - QQmlApplicationEngine instead of QQuickView - only one main qml file - Window as root item Change-Id: I482dd86e44faac5dac1839dfb88c5647a0425de6 Reviewed-by: Eirik Aavitsland Reviewed-by: Gatis Paeglis --- basicsuite/shared/SharedMain.qml | 80 +++++++++++++++++++++--------------- basicsuite/shared/main.cpp | 26 +++--------- basicsuite/shared/main_landscape.qml | 29 ------------- basicsuite/shared/shared.pri | 3 +- 4 files changed, 54 insertions(+), 84 deletions(-) delete mode 100644 basicsuite/shared/main_landscape.qml diff --git a/basicsuite/shared/SharedMain.qml b/basicsuite/shared/SharedMain.qml index 301ccb8..fabd9f5 100644 --- a/basicsuite/shared/SharedMain.qml +++ b/basicsuite/shared/SharedMain.qml @@ -15,44 +15,60 @@ ** contact form at http://www.qt.io ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick 2.4 +import QtQuick.Window 2.2 import QtQuick.Enterprise.VirtualKeyboard 1.2 -Item { - id: root +Window { + id: window - Loader { - anchors.left: parent.left - anchors.top: parent.top - anchors.right: parent.right - anchors.bottom: inputPanel.top - source: "main.qml" - } + visible: true + width: Screen.desktopAvailableWidth + height: Screen.desktopAvailableHeight - InputPanel { - id: inputPanel - z: 99 - y: root.height - anchors.left: root.left - anchors.right: root.right + color: "black" - states: State { - name: "visible" - when: Qt.inputMethod.visible - PropertyChanges { - target: inputPanel - y: root.height - inputPanel.height - } + Item { + id: root + anchors.centerIn: window.contentItem + property bool portraitMode: Screen.desktopAvailableHeight > Screen.desktopAvailableWidth ? true : false + rotation: portraitMode ? 90 : 0 + width: portraitMode ? window.height : window.width + height: portraitMode ? window.width : window.height + + Loader { + anchors.left: parent.left + anchors.top: parent.top + anchors.right: parent.right + anchors.bottom: inputPanel.top + source: "main.qml" } - transitions: Transition { - from: "" - to: "visible" - reversible: true - ParallelAnimation { - NumberAnimation { - properties: "y" - duration: 250 - easing.type: Easing.InOutQuad + + InputPanel { + id: inputPanel + z: 99 + y: root.height + anchors.left: root.left + anchors.right: root.right + + states: State { + name: "visible" + when: Qt.inputMethod.visible + PropertyChanges { + target: inputPanel + y: root.height - inputPanel.height + } + } + transitions: Transition { + from: "" + to: "visible" + reversible: true + ParallelAnimation { + NumberAnimation { + properties: "y" + duration: 250 + easing.type: Easing.InOutQuad + } } } } diff --git a/basicsuite/shared/main.cpp b/basicsuite/shared/main.cpp index 9ddb61b..1429260 100644 --- a/basicsuite/shared/main.cpp +++ b/basicsuite/shared/main.cpp @@ -24,11 +24,9 @@ #include #include #include +#include -#if (QT_VERSION < QT_VERSION_CHECK(5, 3, 0)) -#include -#endif -#include +#include #include #include @@ -84,25 +82,11 @@ int main(int argc, char **argv) QGuiApplication::setFont(font); } - QQuickView view; -#if (QT_VERSION < QT_VERSION_CHECK(5, 3, 0)) - // Ensure the width and height are valid because of QTBUG-36938. - QObject::connect(&view, SIGNAL(widthChanged(int)), view.contentItem(), SLOT(setWidth(int))); - QObject::connect(&view, SIGNAL(heightChanged(int)), view.contentItem(), SLOT(setHeight(int))); -#endif - DummyEngine engine; - view.rootContext()->setContextProperty("engine", &engine); - view.setColor(Qt::black); - view.setResizeMode(QQuickView::SizeRootObjectToView); - - QSize screenSize = QGuiApplication::primaryScreen()->size(); - QString mainFile = screenSize.width() < screenSize.height() - ? QStringLiteral("/main_landscape.qml") - : QStringLiteral("/SharedMain.qml"); - view.setSource(QUrl::fromLocalFile(path + mainFile)); - view.show(); + QQmlApplicationEngine applicationengine; + applicationengine.rootContext()->setContextProperty("engine", &engine); + applicationengine.load(QUrl::fromLocalFile(path + "/SharedMain.qml")); app.exec(); } diff --git a/basicsuite/shared/main_landscape.qml b/basicsuite/shared/main_landscape.qml deleted file mode 100644 index e5bf510..0000000 --- a/basicsuite/shared/main_landscape.qml +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://www.qt.io -** -****************************************************************************/ -import QtQuick 2.0 - -Item { - width: engine.screenWidth() - height: engine.screenHeight() - SharedMain { - anchors.centerIn: parent - width: parent.height - height: parent.width - rotation: 90 - } -} diff --git a/basicsuite/shared/shared.pri b/basicsuite/shared/shared.pri index 0d7392d..6b5c535 100644 --- a/basicsuite/shared/shared.pri +++ b/basicsuite/shared/shared.pri @@ -17,8 +17,7 @@ HEADERS += $$PWD/engine.h defineTest(b2qtdemo_deploy_defaults) { commonFiles.files = \ exclude.txt \ - ../shared/SharedMain.qml \ - ../shared/main_landscape.qml + ../shared/SharedMain.qml commonFiles.path = $$DESTPATH OTHER_FILES += $${commonFiles.files} INSTALLS += commonFiles -- cgit v1.2.3