From 7538e100f8e393a4ced1a2710277abf50cebfa10 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Fri, 13 Sep 2019 15:04:28 -0700 Subject: [PATCH] do not recompile qml --- launchers/qt/CMakeLists.txt | 12 ++++++++++-- launchers/qt/resources/qml/DownloadFinished.qml | 4 ++-- launchers/qt/resources/qml/SplashScreen.qml | 13 ++++++++++++- launchers/qt/src/Launcher.cpp | 6 ++++-- launchers/qt/src/LauncherState.cpp | 7 ++++--- launchers/qt/src/LauncherState.h | 1 + launchers/qt/src/LauncherWindow.h | 5 ++++- launchers/qt/src/PathUtils.cpp | 7 +++++++ launchers/qt/src/PathUtils.h | 9 +++++++-- 9 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 launchers/qt/src/PathUtils.cpp diff --git a/launchers/qt/CMakeLists.txt b/launchers/qt/CMakeLists.txt index eefbbe969d..8a4f6ea623 100644 --- a/launchers/qt/CMakeLists.txt +++ b/launchers/qt/CMakeLists.txt @@ -62,7 +62,6 @@ if (WIN32) endif () - if (APPLE) ExternalProject_Add( qtlite @@ -126,7 +125,9 @@ set(src_files src/LauncherState.h src/LauncherState.cpp src/LauncherWindow.h - src/LauncherWindow.cpp) + src/LauncherWindow.cpp + src/PathUtils.cpp + src/PathUtils.h) set(TARGET_NAME ${PROJECT_NAME}) @@ -195,6 +196,13 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD "${INTERFACE_EXEC_DIR}") +if (LAUNCHER_SOURCE_TREE_RESOURCES) + target_compile_definitions(${PROJECT_NAME} PRIVATE RESOURCE_PREFIX_URL="${CMAKE_CURRENT_SOURCE_DIR}/resources/") + message("Use source tree resources path: file://${CMAKE_CURRENT_SOURCE_DIR}/resources/") +else() + target_compile_definitions(${PROJECT_NAME} PRIVATE RESOURCE_PREFIX_URL="qrc:/") + message("Use resource.rcc path: qrc:/") +endif() if (APPLE) install( diff --git a/launchers/qt/resources/qml/DownloadFinished.qml b/launchers/qt/resources/qml/DownloadFinished.qml index f817137a8c..a16800fa49 100644 --- a/launchers/qt/resources/qml/DownloadFinished.qml +++ b/launchers/qt/resources/qml/DownloadFinished.qml @@ -11,7 +11,7 @@ Item { width: parent.width height: parent.height mirror: true - source: "qrc:/images/hifi_window@2x.png" + source: PathUtils.resourcePath("images/hifi_window@2x.png"); transformOrigin: Item.Center rotation: 0 } @@ -21,7 +21,7 @@ Item { id: logo width: 132 height: 134 - source: "qrc:/images/HiFi_Voxel.png" + source: PathUtils.resourcePath("images/HiFi_Voxel.png"); anchors { top: root.top diff --git a/launchers/qt/resources/qml/SplashScreen.qml b/launchers/qt/resources/qml/SplashScreen.qml index 793536205a..a710a7245c 100644 --- a/launchers/qt/resources/qml/SplashScreen.qml +++ b/launchers/qt/resources/qml/SplashScreen.qml @@ -4,10 +4,21 @@ import QtQuick.Controls 2.1 Item { anchors.fill: parent + + Image { + anchors.centerIn: parent + width: parent.width + height: parent.height + mirror: true + source: PathUtils.resourcePath("images/hifi_window@2x.png"); + transformOrigin: Item.Center + rotation: 0 + } + Image { anchors.centerIn: parent width: 225 height: 205 - source: "../images/hifi_logo_large@2x.png" + source: PathUtils.resourcePath("images/hifi_logo_large@2x.png"); } } diff --git a/launchers/qt/src/Launcher.cpp b/launchers/qt/src/Launcher.cpp index 50c4a665e5..a2a993c7dd 100644 --- a/launchers/qt/src/Launcher.cpp +++ b/launchers/qt/src/Launcher.cpp @@ -6,17 +6,19 @@ #include "LauncherWindow.h" #include "LauncherState.h" +#include "PathUtils.h" Launcher::Launcher(int& argc, char**argv) : QGuiApplication(argc, argv) { QString resourceBinaryLocation = QGuiApplication::applicationDirPath() + "/resources.rcc"; QResource::registerResource(resourceBinaryLocation); _launcherState = std::make_shared(); - _launcherState->setUIState(LauncherState::DOWNLOAD_FINSISHED); + _launcherState->setUIState(LauncherState::SPLASH_SCREEN); _launcherWindow = std::make_unique(); _launcherWindow->rootContext()->setContextProperty("LauncherState", _launcherState.get()); + _launcherWindow->rootContext()->setContextProperty("PathUtils", new PathUtils()); _launcherWindow->setFlags(Qt::FramelessWindowHint); LauncherState::declareQML(); - _launcherWindow->setSource(QUrl("qrc:/qml/root.qml")); + _launcherWindow->setSource(QUrl(PathUtils::resourcePath("qml/root.qml"))); _launcherWindow->setResizeMode(QQuickView::SizeRootObjectToView); _launcherWindow->show(); } diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index 090bf5e9c5..2312478cc1 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -1,5 +1,6 @@ #include "LauncherState.h" +#include "PathUtils.h" #include #include @@ -14,8 +15,8 @@ #include static const std::array QML_FILE_FOR_UI_STATE = - { { "qrc:/qml/SplashScreen.qml", "qrc:/qml/HFBase/CreateAccountBase.qml", "qrc:/qml/DisplayName.qml", - "qrc:/qml/Download.qml", "qrc:/qml/DownloadFinished.qml", "qrc:/qml/HFBase/Error.qml" } }; + { { "SplashScreen.qml", "HFBase/CreateAccountBase.qml", "DisplayName.qml", + "Download.qml", "DownloadFinished.qml", "HFBase/Error.qml" } }; LauncherState::LauncherState() { // TODO Show splash screen until this request is complete @@ -75,7 +76,7 @@ void LauncherState::declareQML() { void LauncherState::setUIState(UIState state) { _uiState = state; - emit updateSourceUrl(getCurrentUISource()); + emit updateSourceUrl(PathUtils::resourcePath(getCurrentUISource())); } LauncherState::UIState LauncherState::getUIState() const { diff --git a/launchers/qt/src/LauncherState.h b/launchers/qt/src/LauncherState.h index e7d2055995..fab7697d90 100644 --- a/launchers/qt/src/LauncherState.h +++ b/launchers/qt/src/LauncherState.h @@ -1,5 +1,6 @@ #include #include +#include #include struct Build { diff --git a/launchers/qt/src/LauncherWindow.h b/launchers/qt/src/LauncherWindow.h index 394d9aed41..376ab9ae7b 100644 --- a/launchers/qt/src/LauncherWindow.h +++ b/launchers/qt/src/LauncherWindow.h @@ -1,5 +1,6 @@ #include #include +#include class LauncherWindow : public QQuickView { public: @@ -7,8 +8,10 @@ public: void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; - + //void setLauncherState(std::shared_ptr launcherState) { _launcherState = launcherState; } private: bool _drag { false }; QPoint _previousMousePos; + + ///std::shared_ptr _launcherState { nullptr }; }; diff --git a/launchers/qt/src/PathUtils.cpp b/launchers/qt/src/PathUtils.cpp new file mode 100644 index 0000000000..ae02585788 --- /dev/null +++ b/launchers/qt/src/PathUtils.cpp @@ -0,0 +1,7 @@ +#include "PathUtils.h" + +#include + +QString PathUtils::resourcePath(const QString& source) { + return QString(RESOURCE_PREFIX_URL + source); +} diff --git a/launchers/qt/src/PathUtils.h b/launchers/qt/src/PathUtils.h index 4c6c6e9515..29d9b609d6 100644 --- a/launchers/qt/src/PathUtils.h +++ b/launchers/qt/src/PathUtils.h @@ -1,6 +1,11 @@ #pragma once -class PathUtils { +#include +#include +class PathUtils : public QObject { + Q_OBJECT public: - static resourcePath(); + PathUtils() = default; + ~PathUtils() = default; + Q_INVOKABLE static QString resourcePath(const QString& source); };