summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@theqtcompany.com>2014-11-20 12:03:40 +0100
committerAndy Nichols <andy.nichols@theqtcompany.com>2014-11-21 13:24:29 +0200
commit67f7c8ae093c4d99b21f14f8b61a57f5059780d0 (patch)
treec653cd5d796851af662867b928dd5af03e5fb374
parentfbca4e2effee224e522d2a6be97f5e05cf60ec93 (diff)
Some cleanup and refactoring
Changed to using QQmlApplication Engine Now creating Engine and ApplicationsModel from QML Change-Id: Icea8475f0ca351c7cab467d18a93fb869f2c2865 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@theqtcompany.com>
-rw-r--r--qml/Main.qml531
-rw-r--r--qml/main_landscape.qml29
-rw-r--r--resources.qrc1
-rw-r--r--src/applicationsettings.cpp81
-rw-r--r--src/applicationsettings.h62
-rw-r--r--src/applicationsmodel.h2
-rw-r--r--src/engine.cpp35
-rw-r--r--src/engine.h19
-rw-r--r--src/fpscounter.cpp3
-rw-r--r--src/main.cpp89
-rw-r--r--startup.pro7
11 files changed, 482 insertions, 377 deletions
diff --git a/qml/Main.qml b/qml/Main.qml
index 027f67f..cc369d0 100644
--- a/qml/Main.qml
+++ b/qml/Main.qml
@@ -15,308 +15,339 @@
** contact form at http://www.qt.io
**
****************************************************************************/
-import QtQuick 2.0
-import QtQuick.Enterprise.VirtualKeyboard 1.1
+import QtQuick 2.3
+import QtQuick.Window 2.2
+import QtQuick.Enterprise.VirtualKeyboard 1.2
+import com.qtcompany.B2QtLauncher 1.0
-Item {
- id: root
- width: 1280
- height: 800
+Window {
+ id: window
- property int stateDelay: 400;
- property int bootDelay: 1000;
+ visible: true
+ width: Screen.desktopAvailableWidth
+ height: Screen.desktopAvailableHeight
+ color: "black"
property color qtpurple: '#ae32a0'
- states: [
- State {
- name: "booting"
- PropertyChanges { target: appGrid; opacity: 0 }
- PropertyChanges { target: splashScreen; opacity: 0 }
- PropertyChanges { target: url; opacity: 0 }
- },
- State {
- name: "running"
- PropertyChanges { target: appGrid; opacity: 1 }
- PropertyChanges { target: applicationLoader; opacity: 0 }
- PropertyChanges { target: splashScreen; opacity: 0 }
- },
- State {
- name: "app-launching"
- PropertyChanges { target: appGrid; opacity: 0 }
- PropertyChanges { target: splashScreen; opacity: 1 }
- },
- State {
- name: "app-running"
- PropertyChanges { target: applicationLoader; opacity: 1 }
- PropertyChanges { target: appGrid; opacity: 0 }
- PropertyChanges { target: splashScreen; opacity: 0 }
- PropertyChanges { target: url; opacity: 0 }
- },
- State {
- name: "app-closing"
- PropertyChanges { target: applicationLoader; opacity: 0 }
- PropertyChanges { target: appGrid; opacity: 0 }
- PropertyChanges { target: splashScreen; opacity: 0 }
+ 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
+
+ property int stateDelay: 400;
+ property int bootDelay: 1000;
+
+ LauncherApplicationsModel {
+ id: applicationsModel
+ onReady: {
+ engine.markApplicationsModelReady();
+ }
+ Component.onCompleted: {
+ //Set the directory to parse for apps
+ initialize(applicationSettings.appsRoot);
+ }
}
- ]
- transitions: [
- Transition {
- from: "booting"
- to: "running"
- SequentialAnimation {
- ParallelAnimation {
- NumberAnimation { target: appGrid; property: "opacity"; duration: root.bootDelay; easing.type: Easing.InOutQuad }
- }
+ LauncherEngine {
+ id: engine
+ bootAnimationEnabled: applicationSettings.isBootAnimationEnabled
+ fpsEnabled: applicationSettings.isShowFPSEnabled
+ }
- ScriptAction { script: bootScreenLoader.sourceComponent = undefined }
+ states: [
+ State {
+ name: "booting"
+ PropertyChanges { target: appGrid; opacity: 0 }
+ PropertyChanges { target: splashScreen; opacity: 0 }
+ PropertyChanges { target: url; opacity: 0 }
+ },
+ State {
+ name: "running"
+ PropertyChanges { target: appGrid; opacity: 1 }
+ PropertyChanges { target: applicationLoader; opacity: 0 }
+ PropertyChanges { target: splashScreen; opacity: 0 }
+ },
+ State {
+ name: "app-launching"
+ PropertyChanges { target: appGrid; opacity: 0 }
+ PropertyChanges { target: splashScreen; opacity: 1 }
+ },
+ State {
+ name: "app-running"
+ PropertyChanges { target: applicationLoader; opacity: 1 }
+ PropertyChanges { target: appGrid; opacity: 0 }
+ PropertyChanges { target: splashScreen; opacity: 0 }
+ PropertyChanges { target: url; opacity: 0 }
+ },
+ State {
+ name: "app-closing"
+ PropertyChanges { target: applicationLoader; opacity: 0 }
+ PropertyChanges { target: appGrid; opacity: 0 }
+ PropertyChanges { target: splashScreen; opacity: 0 }
}
- },
- Transition {
- NumberAnimation { property: "opacity"; duration: root.stateDelay }
- },
- Transition {
- from: "running"
- to: "app-launching"
- SequentialAnimation {
- NumberAnimation { property: "opacity"; duration: root.stateDelay }
- PauseAnimation { duration: 500 }
- ScriptAction { script: {
- applicationLoader.source = engine.applicationMain;
+ ]
+
+ transitions: [
+ Transition {
+ from: "booting"
+ to: "running"
+ SequentialAnimation {
+ ParallelAnimation {
+ NumberAnimation { target: appGrid; property: "opacity"; duration: root.bootDelay; easing.type: Easing.InOutQuad }
}
+
+ ScriptAction { script: bootScreenLoader.sourceComponent = undefined }
}
- }
- },
- Transition {
- from: "app-launching"
- to: "running"
- SequentialAnimation {
- NumberAnimation { target: appGrid; property: "opacity"; duration: root.stateDelay }
- ScriptAction { script: {
- engine.closeApplication();
- applicationLoader.source = "";
+ },
+ Transition {
+ NumberAnimation { property: "opacity"; duration: root.stateDelay }
+ },
+ Transition {
+ from: "running"
+ to: "app-launching"
+ SequentialAnimation {
+ NumberAnimation { property: "opacity"; duration: root.stateDelay }
+ PauseAnimation { duration: 500 }
+ ScriptAction { script: {
+ applicationLoader.source = engine.applicationMain;
+ }
}
}
- }
- },
- Transition {
- from: "app-launching"
- to: "app-running"
- NumberAnimation { property: "opacity"; duration: root.stateDelay }
- },
- Transition {
- from: "app-running"
- to: "app-closing"
- SequentialAnimation {
- ParallelAnimation {
+ },
+ Transition {
+ from: "app-launching"
+ to: "running"
+ SequentialAnimation {
NumberAnimation { target: appGrid; property: "opacity"; duration: root.stateDelay }
- NumberAnimation { target: applicationLoader; property: "opacity"; duration: root.stateDelay }
- NumberAnimation { target: applicationCloseButton; property: "opacity"; duration: root.stateDelay}
+ ScriptAction { script: {
+ engine.closeApplication();
+ applicationLoader.source = "";
+ }
+ }
}
- NumberAnimation { target: applicationLoader; property: "opacity"; duration: root.stateDelay }
- ScriptAction { script: {
- engine.closeApplication();
- applicationLoader.source = "";
+ },
+ Transition {
+ from: "app-launching"
+ to: "app-running"
+ NumberAnimation { property: "opacity"; duration: root.stateDelay }
+ },
+ Transition {
+ from: "app-running"
+ to: "app-closing"
+ SequentialAnimation {
+ ParallelAnimation {
+ NumberAnimation { target: appGrid; property: "opacity"; duration: root.stateDelay }
+ NumberAnimation { target: applicationLoader; property: "opacity"; duration: root.stateDelay }
+ NumberAnimation { target: applicationCloseButton; property: "opacity"; duration: root.stateDelay}
+ }
+ NumberAnimation { target: applicationLoader; property: "opacity"; duration: root.stateDelay }
+ ScriptAction { script: {
+ engine.closeApplication();
+ applicationLoader.source = "";
+ }
}
}
}
- }
-
- ]
- state: engine.state
-// onStateChanged: print("---state: " + engine.state);
+ ]
- LaunchScreen {
- id: appGrid
- visible: opacity > 0
- anchors.fill: parent
- }
+ state: engine.state
+ // onStateChanged: print("---state: " + engine.state);
- Loader {
- id: bootScreenLoader
- visible: opacity > 0
- anchors.fill: parent
- sourceComponent: BootScreen {}
- }
+ LaunchScreen {
+ id: appGrid
+ visible: opacity > 0
+ anchors.fill: parent
+ }
- Timer {
- id: failedAppLaunchTrigger;
- interval: 500;
- running: false
- repeat: false
- onTriggered: {
- engine.closeApplication()
+ Loader {
+ id: bootScreenLoader
+ visible: opacity > 0
+ anchors.fill: parent
+ sourceComponent: BootScreen {}
}
- }
- Loader {
- id: applicationLoader
- opacity: 0;
- visible: opacity > 0
-
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.right: parent.right
- anchors.bottom: inputPanel.top
- asynchronous: false;
-
- onStatusChanged: {
-// switch (status) {
-// case Loader.Null: print("applicationLoader status: Null"); break;
-// case Loader.Ready: print("applicationLoader status: Ready"); break;
-// case Loader.Error: print("applicationLoader status: Error"); break;
-// case Loader.Loading: print("applicationLoader status: Loading"); break;
-// default: print("applicationLoader: unknown status: " + status); break;
-// }
- if (status == Loader.Error) {
-// print("applicationLoader: app failed, reverting to 'running' state");
- failedAppLaunchTrigger.running = true;
+ Timer {
+ id: failedAppLaunchTrigger;
+ interval: 500;
+ running: false
+ repeat: false
+ onTriggered: {
+ engine.closeApplication()
}
-
}
- onLoaded: {
- engine.state = "app-running";
- }
+ Loader {
+ id: applicationLoader
+ opacity: 0;
+ visible: opacity > 0
+
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.right: parent.right
+ anchors.bottom: inputPanel.top
+ asynchronous: false;
+
+ onStatusChanged: {
+ // switch (status) {
+ // case Loader.Null: print("applicationLoader status: Null"); break;
+ // case Loader.Ready: print("applicationLoader status: Ready"); break;
+ // case Loader.Error: print("applicationLoader status: Error"); break;
+ // case Loader.Loading: print("applicationLoader status: Loading"); break;
+ // default: print("applicationLoader: unknown status: " + status); break;
+ // }
+ if (status == Loader.Error) {
+ // print("applicationLoader: app failed, reverting to 'running' state");
+ failedAppLaunchTrigger.running = true;
+ }
- Rectangle {
- id: applicationCloseButton;
+ }
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.horizontalCenterOffset: parent.width / 4
- y: -height / 2;
+ onLoaded: {
+ engine.state = "app-running";
+ }
- width: closeLabel.width + engine.centimeter() * 2
- height: engine.fontSize() * 3;
- radius: height / 2;
+ Rectangle {
+ id: applicationCloseButton;
- gradient: Gradient {
- GradientStop { position: 0.5; color: "gray" }
- GradientStop { position: 1; color: "black"; }
- }
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.horizontalCenterOffset: parent.width / 4
+ y: -height / 2;
-// border.color: "gray"
+ width: closeLabel.width + engine.centimeter() * 2
+ height: engine.fontSize() * 3;
+ radius: height / 2;
- Text {
- id: closeLabel
- color: "white"
- text: "Close"
- anchors.centerIn: parent
- anchors.verticalCenterOffset: parent.height / 4;
- font.pixelSize: engine.fontSize();
- }
+ gradient: Gradient {
+ GradientStop { position: 0.5; color: "gray" }
+ GradientStop { position: 1; color: "black"; }
+ }
+
+ // border.color: "gray"
- enabled: engine.state == "app-running"
- MouseArea {
- anchors.fill: parent
- onClicked: {
- engine.state = "app-closing"
+ Text {
+ id: closeLabel
+ color: "white"
+ text: "Close"
+ anchors.centerIn: parent
+ anchors.verticalCenterOffset: parent.height / 4;
+ font.pixelSize: engine.fontSize();
}
+
+ enabled: engine.state == "app-running"
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ engine.state = "app-closing"
+ }
+ }
+ z: 1
}
- z: 1
}
- }
- 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
+ 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
+ transitions: Transition {
+ from: ""
+ to: "visible"
+ reversible: true
+ ParallelAnimation {
+ NumberAnimation {
+ properties: "y"
+ duration: 250
+ easing.type: Easing.InOutQuad
+ }
}
}
}
- }
- Item {
- id: splashScreen
- visible: opacity > 0
-
- anchors.fill: parent
-
- Text {
- id: splashLabel
- color: "white"
- text: "Loading..."
- anchors.centerIn: parent;
- anchors.verticalCenterOffset: -height
- font.pixelSize: engine.titleFontSize()
- }
+ Item {
+ id: splashScreen
+ visible: opacity > 0
- Image {
- source: "images/codeless.png"
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.bottom: parent.bottom;
- anchors.margins: parent.height * 0.1;
- }
+ anchors.fill: parent
- }
+ Text {
+ id: splashLabel
+ color: "white"
+ text: "Loading..."
+ anchors.centerIn: parent;
+ anchors.verticalCenterOffset: -height
+ font.pixelSize: engine.titleFontSize()
+ }
- Item {
- id: fps
- opacity: engine.fpsEnabled ? 1 : 0
- Behavior on opacity { NumberAnimation { duration: 500 } }
-
- anchors.bottom: parent.bottom;
- anchors.left: parent.left;
- width: fpsLabel.width
- height: fpsLabel.height
-
- Rectangle {
- color: "black"
- opacity: 0.5
- anchors.fill: fpsLabel
- }
+ Image {
+ source: "images/codeless.png"
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.bottom: parent.bottom;
+ anchors.margins: parent.height * 0.1;
+ }
- Text {
- id: fpsLabel;
- color: "white"
- text: "FPS: " + engine.fps
- font.pixelSize: engine.sensibleButtonSize() * 0.2
}
- }
- Item {
- id: url
- anchors.bottom: parent.bottom;
- anchors.horizontalCenter: parent.horizontalCenter;
- anchors.margins: height/2
- width: urlLabel.width
- height: urlLabel.height
-
- Rectangle {
- color: "black"
- opacity: 0.7
- anchors.fill: urlLabel
+ Item {
+ id: fps
+ opacity: engine.fpsEnabled ? 1 : 0
+ Behavior on opacity { NumberAnimation { duration: 500 } }
+
+ anchors.bottom: parent.bottom;
+ anchors.left: parent.left;
+ width: fpsLabel.width
+ height: fpsLabel.height
+
+ Rectangle {
+ color: "black"
+ opacity: 0.5
+ anchors.fill: fpsLabel
+ }
+
+ Text {
+ id: fpsLabel;
+ color: "white"
+ text: "FPS: " + engine.fps
+ font.pixelSize: engine.sensibleButtonSize() * 0.2
+ }
}
- Text {
- id: urlLabel;
- text: "http://www.qt.io/qt-for-device-creation"
- color: qtpurple
- font.pixelSize: engine.sensibleButtonSize() * 0.2
- font.bold: true
+ Item {
+ id: url
+ anchors.bottom: parent.bottom;
+ anchors.horizontalCenter: parent.horizontalCenter;
+ anchors.margins: height/2
+ width: urlLabel.width
+ height: urlLabel.height
+
+ Rectangle {
+ color: "black"
+ opacity: 0.7
+ anchors.fill: urlLabel
+ }
+
+ Text {
+ id: urlLabel;
+ text: "http://www.qt.io/qt-for-device-creation"
+ color: qtpurple
+ font.pixelSize: engine.sensibleButtonSize() * 0.2
+ font.bold: true
+ }
}
}
}
diff --git a/qml/main_landscape.qml b/qml/main_landscape.qml
deleted file mode 100644
index 33a9a43..0000000
--- a/qml/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()
- Main {
- anchors.centerIn: parent
- width: parent.height
- height: parent.width
- rotation: 90
- }
-}
diff --git a/resources.qrc b/resources.qrc
index 034cc60..b8b644d 100644
--- a/resources.qrc
+++ b/resources.qrc
@@ -1,7 +1,6 @@
<RCC>
<qresource prefix="/">
<file>qml/Main.qml</file>
- <file>qml/main_landscape.qml</file>
<file>qml/ApplicationIcon.qml</file>
<file>qml/BootScreen.qml</file>
<file>qml/LaunchScreen.qml</file>
diff --git a/src/applicationsettings.cpp b/src/applicationsettings.cpp
new file mode 100644
index 0000000..27dae84
--- /dev/null
+++ b/src/applicationsettings.cpp
@@ -0,0 +1,81 @@
+#include "applicationsettings.h"
+#include <QtCore/QCoreApplication>
+/****************************************************************************
+**
+** 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
+**
+****************************************************************************/
+
+#include <QtCore/QStringList>
+
+ApplicationSettings::ApplicationSettings(QObject *parent)
+ : QObject(parent)
+ , m_mainFile(QUrl(QStringLiteral("qrc:///qml/Main.qml")))
+ , m_appsRoot("/data/user/qt")
+ , m_isLogcatEnabled(false)
+ , m_isBootAnimationEnabled(true)
+ , m_isShowFPSEnabled(false)
+{
+}
+
+QString ApplicationSettings::appsRoot() const
+{
+ return m_appsRoot;
+}
+
+bool ApplicationSettings::isLogcatEnable() const
+{
+ return m_isLogcatEnabled;
+}
+
+bool ApplicationSettings::isBootAnimationEnabled() const
+{
+ return m_isBootAnimationEnabled;
+}
+
+bool ApplicationSettings::isShowFPSEnabled() const
+{
+ return m_isShowFPSEnabled;
+}
+
+bool ApplicationSettings::parseCommandLineArguments()
+{
+ QStringList args = QCoreApplication::instance()->arguments();
+ for (int i=0; i<args.size(); ++i) {
+ if (args.at(i) == QStringLiteral("--main-file")) {
+ ++i;
+ m_mainFile = QUrl::fromUserInput(args.at(i));
+ } else if (args.at(i) == QStringLiteral("--applications-root")) {
+ ++i;
+ m_appsRoot = args.at(i);
+ } else if (args.at(i) == QStringLiteral("--no-boot-animation")) {
+ m_isBootAnimationEnabled = false;
+ } else if (args.at(i) == QStringLiteral("--show-fps")) {
+ m_isShowFPSEnabled = true;
+ } else if (args.at(i) == QStringLiteral("--logcat")) {
+ m_isLogcatEnabled = true;
+ } else if (args.at(i) == QStringLiteral("-h")
+ || args.at(i) == QStringLiteral("--help")
+ || args.at(i) == QStringLiteral("-?")) {
+ return false;
+ }
+ }
+ return true;
+}
+
+QUrl ApplicationSettings::mainFile() const
+{
+ return m_mainFile;
+}
diff --git a/src/applicationsettings.h b/src/applicationsettings.h
new file mode 100644
index 0000000..d439eb0
--- /dev/null
+++ b/src/applicationsettings.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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
+**
+****************************************************************************/
+
+#ifndef APPLICATIONSETTINGS_H
+#define APPLICATIONSETTINGS_H
+
+#include <QObject>
+#include <QUrl>
+
+class ApplicationSettings : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl mainFile READ mainFile NOTIFY mainFileChanged)
+ Q_PROPERTY(QString appsRoot READ appsRoot NOTIFY appsRootChanged)
+ Q_PROPERTY(bool isLogcatEnabled READ isLogcatEnable NOTIFY isLogcatEnabledChanged)
+ Q_PROPERTY(bool isBootAnimationEnabled READ isBootAnimationEnabled NOTIFY isBootAnimationEnabledChanged)
+ Q_PROPERTY(bool isShowFPSEnabled READ isShowFPSEnabled NOTIFY isShowFPSEnabledChanged)
+public:
+ explicit ApplicationSettings(QObject *parent = 0);
+
+ QUrl mainFile() const;
+ QString appsRoot() const;
+ bool isLogcatEnable() const;
+ bool isBootAnimationEnabled() const;
+ bool isShowFPSEnabled() const;
+
+ bool parseCommandLineArguments();
+
+
+
+signals:
+ void mainFileChanged(QUrl newFile);
+ void appsRootChanged(QString appRoot);
+ void isLogcatEnabledChanged(bool isEnabled);
+ void isBootAnimationEnabledChanged(bool isEnabled);
+ void isShowFPSEnabledChanged(bool isEnabled);
+
+private:
+ QUrl m_mainFile;
+ QString m_appsRoot;
+ bool m_isLogcatEnabled;
+ bool m_isBootAnimationEnabled;
+ bool m_isShowFPSEnabled;
+
+};
+
+#endif // APPLICATIONSETTINGS_H
diff --git a/src/applicationsmodel.h b/src/applicationsmodel.h
index 659c6ef..6c791c2 100644
--- a/src/applicationsmodel.h
+++ b/src/applicationsmodel.h
@@ -46,7 +46,7 @@ public:
explicit ApplicationsModel(QObject *parent = 0);
- void initialize(const QString &appsRoot);
+ Q_INVOKABLE void initialize(const QString &appsRoot);
QModelIndex index(int r, int c, const QModelIndex &) const { return createIndex(r, c); }
QModelIndex parent(const QModelIndex&) const { return QModelIndex(); }
diff --git a/src/engine.cpp b/src/engine.cpp
index b15885e..1adfa6d 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -39,9 +39,8 @@
#define ENGINE_STATE_APPRUNNING QStringLiteral("app-running")
#define ENGINE_STATE_APPCLOSING QStringLiteral("app-closing")
-Engine::Engine(QObject *parent)
- : QObject(parent)
- , m_qmlEngine(0)
+Engine::Engine(QQuickItem *parent)
+ : QQuickItem(parent)
, m_fpsCounter(0)
, m_fps(0)
, m_intro_done(false)
@@ -63,6 +62,8 @@ Engine::Engine(QObject *parent)
m_dpcm *= (screenSizeCM - low) / (high - low) * 0.5 + 0.5;
m_screenWidth = m_screenSize.width();
m_screenHeight = m_screenSize.height();
+
+ connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(windowChanged(QQuickWindow*)));
}
@@ -77,6 +78,19 @@ void Engine::updateReadyness()
emit stateChanged(m_state);
}
+void Engine::updateFPSCounter()
+{
+ if (m_fpsCounter) {
+ delete m_fpsCounter;
+ m_fpsCounter = 0;
+ }
+
+ if (m_fps_enabled && window()) {
+ m_fpsCounter = new FpsCounter(window());
+ connect(m_fpsCounter, SIGNAL(fps(qreal)), this, SLOT(setFps(qreal)));
+ }
+}
+
void Engine::setState(const QString &state)
{
if (state == m_state)
@@ -109,19 +123,20 @@ void Engine::setFps(qreal fps)
emit fpsChanged(m_fps);
}
+void Engine::windowChanged(QQuickWindow *window)
+{
+ Q_UNUSED(window)
+ //When window changes we need to recreate the fps counters
+ updateFPSCounter();
+}
+
void Engine::setFpsEnabled(bool enabled)
{
if (m_fps_enabled == enabled)
return;
m_fps_enabled = enabled;
- if (m_fps_enabled) {
- m_fpsCounter = new FpsCounter(m_window);
- connect(m_fpsCounter, SIGNAL(fps(qreal)), this, SLOT(setFps(qreal)));
- } else {
- delete m_fpsCounter;
- m_fpsCounter = 0;
- }
+ updateFPSCounter();
emit fpsEnabledChanged(m_fps_enabled);
}
diff --git a/src/engine.h b/src/engine.h
index ae9f3fb..fe7c058 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -18,18 +18,17 @@
#ifndef ENGINE_H
#define ENGINE_H
-#include <QObject>
+#include <QQuickItem>
#include <QUrl>
#include <QSize>
#include <QColor>
class QQmlEngine;
-class QQuickItem;
class FpsCounter;
class QQuickWindow;
-class Engine : public QObject
+class Engine : public QQuickItem
{
Q_OBJECT
@@ -47,7 +46,7 @@ class Engine : public QObject
Q_PROPERTY(const QString qtVersion READ qtVersion)
public:
- explicit Engine(QObject *parent = 0);
+ explicit Engine(QQuickItem *parent = 0);
QString state() const { return m_state; }
void setState(const QString &state);
@@ -57,9 +56,6 @@ public:
qreal fps() const { return m_fps; }
- QQmlEngine *qmlEngine() const { return m_qmlEngine; }
- void setQmlEngine(QQmlEngine *engine) { m_qmlEngine = engine; }
-
bool isBootAnimationEnabled() const { return m_bootAnimationEnabled; }
void setBootAnimationEnabled(bool enabled);
@@ -69,8 +65,6 @@ public:
QUrl applicationMain() const { return m_applicationMain; }
QString applicationName() const { return m_applicationName; }
- void setWindow(QQuickWindow *window) { m_window = window; }
-
Q_INVOKABLE QUrl fromUserInput(const QString& userInput) { return QUrl::fromUserInput(userInput); }
Q_INVOKABLE int sensibleButtonSize() const;
Q_INVOKABLE int titleBarSize() const;
@@ -103,11 +97,12 @@ public slots:
void setFps(qreal fps);
+private slots:
+ void windowChanged(QQuickWindow *window);
+
private:
void updateReadyness();
-
- QQuickWindow *m_window;
- QQmlEngine *m_qmlEngine;
+ void updateFPSCounter();
QString m_state;
diff --git a/src/fpscounter.cpp b/src/fpscounter.cpp
index dce2378..6bf54b4 100644
--- a/src/fpscounter.cpp
+++ b/src/fpscounter.cpp
@@ -33,6 +33,3 @@ void FpsCounter::timerEvent(QTimerEvent *)
m_frameCounter = 0;
m_timer.start();
}
-
-
-
diff --git a/src/main.cpp b/src/main.cpp
index 5a2fd3b..27eec85 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -20,15 +20,9 @@
#include <QtWidgets/QApplication>
#include <QtGui/QFont>
#include <QtGui/QFontDatabase>
-#include <QtGui/QScreen>
-#include <QtGui/QPalette>
+#include <QtCore/QFile>
-#if (QT_VERSION < QT_VERSION_CHECK(5, 3, 0))
-#include <QtQuick/QQuickItem>
-#endif
-#include <QtQuick/QQuickView>
-
-#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include <QtQml/QQmlComponent>
@@ -39,6 +33,7 @@
#include "engine.h"
#include "applicationsmodel.h"
#include "logmanager.h"
+#include "applicationsettings.h"
void displayHelp(const char *appName)
{
@@ -77,72 +72,30 @@ int main(int argc, char **argv)
QGuiApplication::setFont(font);
}
- QSize screenSize = QGuiApplication::primaryScreen()->size();
-
- QString mainFile = screenSize.width() < screenSize.height()
- ? QStringLiteral("qrc:///qml/main_landscape.qml")
- : QStringLiteral("qrc:///qml/Main.qml");
- QString appsRoot = QStringLiteral("/data/user/qt");
-
- bool logcat = false;
- bool bootAnimation = true;
- bool showFps = false;
-
- QStringList args = app.arguments();
- for (int i=0; i<args.size(); ++i) {
- if (args.at(i) == QStringLiteral("--main-file")) {
- ++i;
- mainFile = args.at(i);
- } else if (args.at(i) == QStringLiteral("--applications-root")) {
- ++i;
- appsRoot = args.at(i);
- } else if (args.at(i) == QStringLiteral("--no-boot-animation")) {
- bootAnimation = false;
- } else if (args.at(i) == QStringLiteral("--show-fps")) {
- showFps = true;
- } else if (args.at(i) == QStringLiteral("--logcat")) {
- logcat = true;
- } else if (args.at(i) == QStringLiteral("-h")
- || args.at(i) == QStringLiteral("--help")
- || args.at(i) == QStringLiteral("-?")) {
- displayHelp(argv[0]);
- return 0;
- }
+ ApplicationSettings applicationSettings;
+
+ if (!applicationSettings.parseCommandLineArguments()) {
+ displayHelp(argv[0]);
+ return 0;
}
- if (logcat) {
+ if (applicationSettings.isLogcatEnable()) {
LogManager::install();
}
- qDebug() << "Main File:" << mainFile;
- qDebug() << "Applications Root:" << appsRoot;
- qDebug() << "Boot Animation:" << (bootAnimation ? "yes" : "no");
- qDebug() << "Show FPS:" << (showFps ? "yes" : "no");
- qDebug() << "Log redirection:" << (logcat ? "yes" : "no");
-
- 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
+ qDebug() << "Main File:" << applicationSettings.mainFile();
+ qDebug() << "Applications Root:" << applicationSettings.appsRoot();
+ qDebug() << "Boot Animation:" << (applicationSettings.isBootAnimationEnabled() ? "yes" : "no");
+ qDebug() << "Show FPS:" << (applicationSettings.isShowFPSEnabled() ? "yes" : "no");
+ qDebug() << "Log redirection:" << (applicationSettings.isLogcatEnable() ? "yes" : "no");
+
+
+ qmlRegisterType<ApplicationsModel>("com.qtcompany.B2QtLauncher", 1, 0, "LauncherApplicationsModel");
+ qmlRegisterType<Engine>("com.qtcompany.B2QtLauncher", 1, 0, "LauncherEngine");
- Engine engine;
- engine.setWindow(&view);
- engine.setFpsEnabled(showFps);
- engine.setQmlEngine(view.engine());
- engine.setBootAnimationEnabled(bootAnimation);
-
- ApplicationsModel appsModel;
- QObject::connect(&appsModel, SIGNAL(ready()), &engine, SLOT(markApplicationsModelReady()));
- appsModel.initialize(appsRoot);
-
- view.rootContext()->setContextProperty("engine", &engine);
- view.rootContext()->setContextProperty("applicationsModel", &appsModel);
- view.setColor(Qt::black);
- view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl(mainFile));
- view.show();
+ QQmlApplicationEngine engine;
+ engine.rootContext()->setContextProperty("applicationSettings", &applicationSettings);
+ engine.load(applicationSettings.mainFile());
app.exec();
}
diff --git a/startup.pro b/startup.pro
index 98da2ae..283db2a 100644
--- a/startup.pro
+++ b/startup.pro
@@ -1,4 +1,3 @@
-# widgets dependency needed for QtChars demo
QT += quick widgets
TARGET = qtlauncher
@@ -11,13 +10,15 @@ HEADERS += \
src/engine.h \
src/applicationsmodel.h \
src/logmanager.h \
- src/fpscounter.h
+ src/fpscounter.h \
+ src/applicationsettings.h
SOURCES += src/main.cpp \
src/engine.cpp \
src/applicationsmodel.cpp \
src/logmanager.cpp \
- src/fpscounter.cpp
+ src/fpscounter.cpp \
+ src/applicationsettings.cpp
OTHER_FILES += \
qml/LaunchScreen.qml \