From 8ccca86deef782e1759d75c4c3756f17763d179e Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 16 Feb 2017 15:57:36 -0800 Subject: [PATCH] Settings for Tablet Becomes Toolbar --- interface/resources/qml/hifi/Desktop.qml | 16 +++++++++--- interface/src/Application.cpp | 25 +++++++++++++++++++ interface/src/Application.h | 8 ++++++ interface/src/ui/PreferencesDialog.cpp | 10 ++++++++ .../src/TabletScriptingInterface.cpp | 11 ++++++++ .../src/TabletScriptingInterface.h | 3 +++ 6 files changed, 70 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index 4c81027211..3e6e5b6764 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -48,7 +48,16 @@ OriginalDesktop.Desktop { // This used to create sysToolbar dynamically with a call to getToolbar() within onCompleted. // Beginning with QT 5.6, this stopped working, as anything added to toolbars too early got // wiped during startup. - + Toolbar { + id: sysToolbar; + objectName: "com.highfidelity.interface.toolbar.system"; + anchors.horizontalCenter: settings.constrainToolbarToCenterX ? desktop.horizontalCenter : undefined; + // Literal 50 is overwritten by settings from previous session, and sysToolbar.x comes from settings when not constrained. + x: sysToolbar.x + y: 50 + shown: false + } + Settings { id: settings; category: "toolbar"; @@ -58,8 +67,9 @@ OriginalDesktop.Desktop { settings.constrainToolbarToCenterX = constrain; } property var toolbars: (function (map) { // answer dictionary preloaded with sysToolbar - return map; })({}); - + map[sysToolbar.objectName] = sysToolbar; + return map; + })({}); Component.onCompleted: { WebEngine.settings.javascriptCanOpenWindows = true; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 745cadbbdd..3a246fa166 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -545,6 +545,8 @@ Setting::Handle sessionRunTime{ "sessionRunTime", 0 }; const float DEFAULT_HMD_TABLET_SCALE_PERCENT = 100.0f; const float DEFAULT_DESKTOP_TABLET_SCALE_PERCENT = 75.0f; +const bool DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR = true; +const bool DEFAULT_HMD_TABLET_BECOMES_TOOLBAR = false; Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runServer, QString runServerPathOption) : QApplication(argc, argv), @@ -565,6 +567,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES), _hmdTabletScale("hmdTabletScale", DEFAULT_HMD_TABLET_SCALE_PERCENT), _desktopTabletScale("desktopTabletScale", DEFAULT_DESKTOP_TABLET_SCALE_PERCENT), + _desktopTabletBecomesToolbarSetting("desktopTabletBecomesToolbar", DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR), + _hmdTabletBecomesToolbarSetting("hmdTabletBecomesToolbar", DEFAULT_HMD_TABLET_BECOMES_TOOLBAR), _constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true), _scaleMirror(1.0f), _rotateMirror(0.0f), @@ -831,6 +835,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(this, &QCoreApplication::aboutToQuit, addressManager.data(), &AddressManager::storeCurrentAddress); connect(this, &Application::activeDisplayPluginChanged, this, &Application::updateThreadPoolCount); + connect(this, &Application::activeDisplayPluginChanged, this, &Application::updateSystemTabletMode); // Save avatar location immediately after a teleport. connect(myAvatar.get(), &MyAvatar::positionGoneTo, @@ -1537,6 +1542,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(this, &QCoreApplication::aboutToQuit, this, &Application::addAssetToWorldMessageClose); connect(&domainHandler, &DomainHandler::hostnameChanged, this, &Application::addAssetToWorldMessageClose); + + updateSystemTabletMode(); } void Application::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) { @@ -2330,6 +2337,16 @@ void Application::setDesktopTabletScale(float desktopTabletScale) { _desktopTabletScale.set(desktopTabletScale); } +void Application::setDesktopTabletBecomesToolbarSetting(bool value) { + _desktopTabletBecomesToolbarSetting.set(value); + updateSystemTabletMode(); +} + +void Application::setHmdTabletBecomesToolbarSetting(bool value) { + _hmdTabletBecomesToolbarSetting.set(value); + updateSystemTabletMode(); +} + void Application::setSettingConstrainToolbarPosition(bool setting) { _constrainToolbarPosition.set(setting); DependencyManager::get()->setConstrainToolbarToCenterX(setting); @@ -6856,6 +6873,14 @@ void Application::updateThreadPoolCount() const { QThreadPool::globalInstance()->setMaxThreadCount(threadPoolSize); } +void Application::updateSystemTabletMode() { + if (isHMDMode()) { + DependencyManager::get()->setToolbarMode(getHmdTabletBecomesToolbarSetting()); + } else { + DependencyManager::get()->setToolbarMode(getDesktopTabletBecomesToolbarSetting()); + } +} + void Application::toggleMuteAudio() { auto menu = Menu::getInstance(); menu->setIsOptionChecked(MenuOption::MuteAudio, !menu->isOptionChecked(MenuOption::MuteAudio)); diff --git a/interface/src/Application.h b/interface/src/Application.h index cab830ec88..5fc79bedb5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -214,6 +214,11 @@ public: float getDesktopTabletScale() { return _desktopTabletScale.get(); } void setDesktopTabletScale(float desktopTabletScale); + bool getDesktopTabletBecomesToolbarSetting() { return _desktopTabletBecomesToolbarSetting.get(); } + void setDesktopTabletBecomesToolbarSetting(bool value); + bool getHmdTabletBecomesToolbarSetting() { return _hmdTabletBecomesToolbarSetting.get(); } + void setHmdTabletBecomesToolbarSetting(bool value); + float getSettingConstrainToolbarPosition() { return _constrainToolbarPosition.get(); } void setSettingConstrainToolbarPosition(bool setting); @@ -310,6 +315,7 @@ public slots: bool exportEntities(const QString& filename, float x, float y, float z, float scale); bool importEntities(const QString& url); void updateThreadPoolCount() const; + void updateSystemTabletMode(); static void setLowVelocityFilter(bool lowVelocityFilter); Q_INVOKABLE void loadDialog(); @@ -550,6 +556,8 @@ private: Setting::Handle _fieldOfView; Setting::Handle _hmdTabletScale; Setting::Handle _desktopTabletScale; + Setting::Handle _desktopTabletBecomesToolbarSetting; + Setting::Handle _hmdTabletBecomesToolbarSetting; Setting::Handle _constrainToolbarPosition; float _scaleMirror; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 6377cda281..dd05d5c0e1 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -92,6 +92,16 @@ void setupPreferences() { preference->setMax(500); preferences->addPreference(preference); } + { + auto getter = []()->bool { return qApp->getDesktopTabletBecomesToolbarSetting(); }; + auto setter = [](bool value) { qApp->setDesktopTabletBecomesToolbarSetting(value); }; + preferences->addPreference(new CheckPreference(UI_CATEGORY, "Desktop Tablet Becomes Toolbar", getter, setter)); + } + { + auto getter = []()->bool { return qApp->getHmdTabletBecomesToolbarSetting(); }; + auto setter = [](bool value) { qApp->setHmdTabletBecomesToolbarSetting(value); }; + preferences->addPreference(new CheckPreference(UI_CATEGORY, "HMD Tablet Becomes Toolbar", getter, setter)); + } // Snapshots static const QString SNAPSHOTS { "Snapshots" }; diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index a28bfc2f4b..4f269ef041 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -54,10 +54,21 @@ QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { // allocate a new tablet, add it to the map then return it. auto tabletProxy = QSharedPointer(new TabletProxy(tabletId)); _tabletProxies[tabletId] = tabletProxy; + tabletProxy->setToolbarMode(_toolbarMode); return tabletProxy.data(); } } +void TabletScriptingInterface::setToolbarMode(bool toolbarMode) { + std::lock_guard guard(_mutex); + + _toolbarMode = toolbarMode; + + for (auto& iter : _tabletProxies) { + iter.second->setToolbarMode(toolbarMode); + } +} + void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) { TabletProxy* tablet = qobject_cast(getTablet(tabletId)); if (tablet) { diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index 6c4633a161..e450923758 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -47,6 +47,8 @@ public: */ Q_INVOKABLE QObject* getTablet(const QString& tabletId); + void setToolbarMode(bool toolbarMode); + void setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface); void processEvent(const QKeyEvent* event); @@ -63,6 +65,7 @@ protected: std::mutex _mutex; std::map> _tabletProxies; QObject* _toolbarScriptingInterface { nullptr }; + bool _toolbarMode { false }; }; /**jsdoc