diff --git a/launchers/qt/CMakeLists.txt b/launchers/qt/CMakeLists.txt index e70b001cbe..bd19e10341 100644 --- a/launchers/qt/CMakeLists.txt +++ b/launchers/qt/CMakeLists.txt @@ -33,6 +33,8 @@ set(src_files src/main.cpp src/Launcher.h src/Launcher.cpp + src/LauncherState.h + src/LauncherState.cpp src/LauncherWindow.h src/LauncherWindow.cpp) diff --git a/launchers/qt/resources/qml/SplashScreen.qml b/launchers/qt/resources/qml/SplashScreen.qml new file mode 100644 index 0000000000..793536205a --- /dev/null +++ b/launchers/qt/resources/qml/SplashScreen.qml @@ -0,0 +1,13 @@ +import QtQuick 2.3 +import QtQuick.Controls 2.1 + +Item { + anchors.fill: parent + + Image { + anchors.centerIn: parent + width: 225 + height: 205 + source: "../images/hifi_logo_large@2x.png" + } +} diff --git a/launchers/qt/resources/qml/root.qml b/launchers/qt/resources/qml/root.qml index 13e2770636..5a0e9fc5a4 100644 --- a/launchers/qt/resources/qml/root.qml +++ b/launchers/qt/resources/qml/root.qml @@ -2,6 +2,7 @@ import QtQuick 2.3 import QtQuick.Controls 2.1 +import HQLauncher 1.0 import "HFControls" Image { id: root @@ -9,59 +10,16 @@ Image { height: 450 source: "../images/hifi_window@2x.png" - Text { - id: text - width: 325 - height: 26 - anchors { - left: root.left - leftMargin: 95 - top: root.top - topMargin: 29 - } - text: "Please log in" - font.pointSize: 24 - color: "#FFFFFF" + Loader { + anchors.centerIn: parent + anchors.fill: parent + id: loader } - HFTextField { - id: textField - width: 150 - height: 50 - anchors { - left: root.left - leftMargin: 40 - top: text.bottom - topMargin: 20 - } - echoMode: TextInput.Password - placeholderText: "Organization" - } - - - HFButton { - anchors { - left: root.left - leftMargin: 40 - top: textField.bottom - topMargin: 20 - } - id: button - text: "NEXT" - } - - - Image { - id: spinner - source: "../images/HiFi_Voxel.png" - anchors.bottom: root.bottom - RotationAnimator { - target: spinner; - loops: Animation.Infinite - from: 0; - to: 360; - duration: 5000 - running: true - } + Component.onCompleted: { + loader.source = LauncherState.getCurrentUISource(); + LauncherState.updateSourceUrl.connect(function(url) { + loader.source = url; + }); } } diff --git a/launchers/qt/src/Launcher.cpp b/launchers/qt/src/Launcher.cpp index 24a020dc92..64a3005b28 100644 --- a/launchers/qt/src/Launcher.cpp +++ b/launchers/qt/src/Launcher.cpp @@ -1,6 +1,23 @@ #include "Launcher.h" +#include +#include +#include + +#include "LauncherWindow.h" +#include "LauncherState.h" + Launcher::Launcher(int& argc, char**argv) : QGuiApplication(argc, argv) { + QString resourceBinaryLocation = QGuiApplication::applicationDirPath() + "/resources.rcc"; + QResource::registerResource(resourceBinaryLocation); + _launcherState = std::make_shared(); + _launcherWindow = std::make_unique(); + _launcherWindow->rootContext()->setContextProperty("LauncherState", _launcherState.get()); + _launcherWindow->setFlags(Qt::FramelessWindowHint); + LauncherState::declareQML(); + _launcherWindow->setSource(QUrl("qrc:/qml/root.qml")); + _launcherWindow->setResizeMode(QQuickView::SizeRootObjectToView); + _launcherWindow->show(); } Launcher::~Launcher() { diff --git a/launchers/qt/src/Launcher.h b/launchers/qt/src/Launcher.h index 7a049b0a1d..2310c6ba08 100644 --- a/launchers/qt/src/Launcher.h +++ b/launchers/qt/src/Launcher.h @@ -1,7 +1,15 @@ +#include + #include +class LauncherWindow; +class LauncherState; class Launcher : public QGuiApplication { public: Launcher(int& argc, char** argv); ~Launcher(); + +private: + std::unique_ptr _launcherWindow; + std::shared_ptr _launcherState; }; diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp new file mode 100644 index 0000000000..73197de9c1 --- /dev/null +++ b/launchers/qt/src/LauncherState.cpp @@ -0,0 +1,33 @@ +#include "LauncherState.h" + +#include + +#include + +static const std::array QML_FILE_FOR_UI_STATE = + { { "qrc:/qml/SplashScreen.qml", "qrc:/qml/Login.qml", "qrc:/qml/DisplayName.qml", + "qrc:/qml/Download.qml", "qrc:/qml/DownloadFinshed.qml", "qrc:/qml/Error.qml" } }; + +QString LauncherState::getCurrentUISource() const { + return QML_FILE_FOR_UI_STATE[getUIState()]; +} + +void LauncherState::declareQML() { + qmlRegisterType("HQLauncher", 1, 0, "LauncherStateEnums"); +} + +void LauncherState::setUIState(UIState state) { + _uiState = state; +} + +LauncherState::UIState LauncherState::getUIState() const { + return _uiState; +} + +void LauncherState::setLastLoginError(LastLoginError lastLoginError) { + _lastLoginError = lastLoginError; +} + +LauncherState::LastLoginError LauncherState::getLastLoginError() const { + return _lastLoginError; +} diff --git a/launchers/qt/src/LauncherState.h b/launchers/qt/src/LauncherState.h new file mode 100644 index 0000000000..081d6acfca --- /dev/null +++ b/launchers/qt/src/LauncherState.h @@ -0,0 +1,45 @@ +#include +#include + +class LauncherState : public QObject { + Q_OBJECT + +public: + LauncherState() = default; + ~LauncherState() = default; + + enum UIState { + SPLASH_SCREEN = 0, + LOGIN_SCREEN, + DISPLAY_NAME_SCREEN, + DOWNLOAD_SCREEN, + DOWNLOAD_FINSISHED, + ERROR_SCREEN, + UI_STATE_NUM + }; + Q_ENUMS(UIState); + + enum LastLoginError { + NONE = 0, + ORGINIZATION, + CREDENTIALS, + LAST_ERROR_NUM + }; + Q_ENUMS(LastLoginError); + Q_INVOKABLE QString getCurrentUISource() const; + + static void declareQML(); + + void setUIState(UIState state); + UIState getUIState() const; + + void setLastLoginError(LastLoginError lastLoginError); + LastLoginError getLastLoginError() const; + +signals: + void updateSourceUrl(QString sourceUrl); + +private: + UIState _uiState { SPLASH_SCREEN }; + LastLoginError _lastLoginError { NONE }; +}; diff --git a/launchers/qt/src/LauncherWindow.cpp b/launchers/qt/src/LauncherWindow.cpp index 433d67a5fe..c647ac6e4e 100644 --- a/launchers/qt/src/LauncherWindow.cpp +++ b/launchers/qt/src/LauncherWindow.cpp @@ -5,27 +5,27 @@ void LauncherWindow::keyPressEvent(QKeyEvent* event) { QQuickView::keyPressEvent(event); if (!event->isAccepted()) { - std::cout << "Key press event\n"; + // std::cout << "Key press event\n"; } } void LauncherWindow::mousePressEvent(QMouseEvent* event) { QQuickView::mousePressEvent(event); if (!event->isAccepted()) { - std::cout << "mouse press event\n"; + //std::cout << "mouse press event\n"; } } void LauncherWindow::mouseReleaseEvent(QMouseEvent* event) { QQuickView::mouseReleaseEvent(event); if (!event->isAccepted()) { - std::cout << "mouse release event\n"; + //std::cout << "mouse release event\n"; } } void LauncherWindow::mouseMoveEvent(QMouseEvent* event) { QQuickView::mouseMoveEvent(event); if (!event->isAccepted()) { - std::cout << "mouse move event\n"; + // std::cout << "mouse move event\n"; } } diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index ac83951056..bf4e303e94 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -1,9 +1,4 @@ -#include - -#include #include -#include -#include #include "LauncherWindow.h" #include "Launcher.h" @@ -19,17 +14,5 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName(name); Launcher launcher(argc, argv); - - QString resourceBinaryLocation = QGuiApplication::applicationDirPath() + "/resources.rcc"; - QResource::registerResource(resourceBinaryLocation); - - LauncherWindow launcherWindow; - launcherWindow.setFlags(Qt::FramelessWindowHint); - launcherWindow.setSource(QUrl("qrc:/qml/root.qml")); - if (launcherWindow.status() == QQuickView::Error) { - return -1; - } - launcherWindow.setResizeMode(QQuickView::SizeRootObjectToView); - launcherWindow.show(); return launcher.exec(); }