Merge pull request #8990 from howard-stearns/centered-toolbar

centered toolbar
This commit is contained in:
Brad Hefta-Gaub 2016-11-03 14:18:32 -07:00 committed by GitHub
commit 206f1ead1a
11 changed files with 204 additions and 10 deletions

View file

@ -51,27 +51,41 @@ OriginalDesktop.Desktop {
Toolbar {
id: sysToolbar;
objectName: "com.highfidelity.interface.toolbar.system";
// These values will be overridden by sysToolbar.x/y if there is a saved position in Settings
// On exit, the sysToolbar position is saved to settings
x: 30
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
}
Settings {
id: settings;
category: "toolbar";
property bool constrainToolbarToCenterX: true;
}
function setConstrainToolbarToCenterX(constrain) { // Learn about c++ preference change.
settings.constrainToolbarToCenterX = constrain;
}
property var toolbars: (function (map) { // answer dictionary preloaded with sysToolbar
map[sysToolbar.objectName] = sysToolbar;
return map; })({});
Component.onCompleted: {
WebEngine.settings.javascriptCanOpenWindows = true;
WebEngine.settings.javascriptCanAccessClipboard = false;
WebEngine.settings.spatialNavigationEnabled = false;
WebEngine.settings.localContentCanAccessRemoteUrls = true;
var toggleHudButton = sysToolbar.addButton({
objectName: "hudToggle",
imageURL: "../../../icons/hud.svg",
visible: true,
pinned: true,
[ // Allocate the standard buttons in the correct order. They will get images, etc., via scripts.
"hmdToggle", "mute", "mod", "help",
"hudToggle",
"com.highfidelity.interface.system.editButton", "marketplace", "snapshot", "goto"
].forEach(function (name) {
sysToolbar.addButton({objectName: name});
});
var toggleHudButton = sysToolbar.findButton("hudToggle");
toggleHudButton.imageURL = "../../../icons/hud.svg";
toggleHudButton.pinned = true;
sysToolbar.updatePinned(); // automatic when adding buttons only IFF button is pinned at creation.
toggleHudButton.buttonState = Qt.binding(function(){
return desktop.pinned ? 1 : 0

View file

@ -17,7 +17,7 @@ PreferencesDialog {
id: root
objectName: "GeneralPreferencesDialog"
title: "General Settings"
showCategories: ["Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers"]
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers"]
property var settings: Settings {
category: root.objectName
property alias x: root.x

View file

@ -114,6 +114,9 @@ Window {
// and allow scripts to be idempotent so they don't duplicate buttons if they're reloaded
var result = findButton(properties.objectName);
if (result) {
for (var property in properties) {
result[property] = properties[property];
}
return result;
}
properties.toolbar = this;

View file

@ -523,6 +523,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
_previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION),
_fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),
_constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true),
_scaleMirror(1.0f),
_rotateMirror(0.0f),
_raiseMirror(0.0f),
@ -2150,6 +2151,11 @@ void Application::setFieldOfView(float fov) {
}
}
void Application::setSettingConstrainToolbarPosition(bool setting) {
_constrainToolbarPosition.set(setting);
DependencyManager::get<OffscreenUi>()->setConstrainToolbarToCenterX(setting);
}
void Application::aboutApp() {
InfoView::show(INFO_WELCOME_PATH);
}

View file

@ -206,6 +206,9 @@ public:
float getFieldOfView() { return _fieldOfView.get(); }
void setFieldOfView(float fov);
float getSettingConstrainToolbarPosition() { return _constrainToolbarPosition.get(); }
void setSettingConstrainToolbarPosition(bool setting);
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
virtual controller::ScriptingInterface* getControllerScriptingInterface() { return _controllerScriptingInterface; }
@ -506,6 +509,7 @@ private:
Setting::Handle<QString> _previousScriptLocation;
Setting::Handle<float> _fieldOfView;
Setting::Handle<bool> _constrainToolbarPosition;
float _scaleMirror;
float _rotateMirror;

View file

@ -68,6 +68,13 @@ void setupPreferences() {
preferences->addPreference(new CheckPreference(AVATAR_BASICS, "Clear overlays when moving", getter, setter));
}
// UI
{
auto getter = []()->bool { return qApp->getSettingConstrainToolbarPosition(); };
auto setter = [](bool value) { qApp->setSettingConstrainToolbarPosition(value); };
preferences->addPreference(new CheckPreference("UI", "Constrain Toolbar Position to Horizontal Center", getter, setter));
}
// Snapshots
static const QString SNAPSHOTS { "Snapshots" };
{

View file

@ -371,6 +371,13 @@ void OffscreenUi::setPinned(bool pinned) {
}
}
void OffscreenUi::setConstrainToolbarToCenterX(bool constrained) {
bool invokeResult = QMetaObject::invokeMethod(_desktop, "setConstrainToolbarToCenterX", Q_ARG(QVariant, constrained));
if (!invokeResult) {
qWarning() << "Failed to set toolbar constraint";
}
}
void OffscreenUi::addMenuInitializer(std::function<void(VrMenu*)> f) {
if (!_vrMenu) {
_queuedMenuInitializers.push_back(f);

View file

@ -52,6 +52,7 @@ public:
void setPinned(bool pinned = true);
void togglePinned();
void setConstrainToolbarToCenterX(bool constrained);
bool eventFilter(QObject* originalDestination, QEvent* event) override;
void addMenuInitializer(std::function<void(VrMenu*)> f);

View file

@ -32,7 +32,8 @@ var DEFAULT_SCRIPTS = [
"system/controllers/toggleAdvancedMovementForHandControllers.js",
"system/dialTone.js",
"system/firstPersonHMD.js",
"system/snapshot.js"
"system/snapshot.js",
"system/help.js"
];
// add a menu item for debugging

View file

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 50 200.1" style="enable-background:new 0 0 50 200.1;" xml:space="preserve">
<style type="text/css">
.st0{fill:#414042;}
.st1{fill:#FFFFFF;}
.st2{fill:#1E1E1E;}
.st3{fill:#333333;}
</style>
<g id="Layer_2">
<g>
<g>
<path class="st0" d="M50.1,146.1c0,2.2-1.8,4-4,4h-42c-2.2,0-4-1.8-4-4v-42c0-2.2,1.8-4,4-4h42c2.2,0,4,1.8,4,4V146.1z"/>
</g>
</g>
<g>
<g>
<path class="st0" d="M50,196.1c0,2.2-1.8,4-4,4H4c-2.2,0-4-1.8-4-4v-42c0-2.2,1.8-4,4-4h42c2.2,0,4,1.8,4,4V196.1z"/>
</g>
</g>
<g>
<g>
<path class="st1" d="M50,46c0,2.2-1.8,4-4,4H4c-2.2,0-4-1.8-4-4V4c0-2.2,1.8-4,4-4h42c2.2,0,4,1.8,4,4V46z"/>
</g>
</g>
<g>
<path class="st2" d="M50,96.1c0,2.2-1.8,4-4,4H4c-2.2,0-4-1.8-4-4v-42c0-2.2,1.8-4,4-4h42c2.2,0,4,1.8,4,4V96.1z"/>
</g>
</g>
<g id="Layer_3">
</g>
<g>
<path class="st1" d="M20.1,86v6.4h-1.2v-2.7H16v2.7h-1.2V86H16v2.6h2.9V86H20.1z"/>
<path class="st1" d="M26.1,91.3v1.1h-4.4V86H26v1.1h-3.1v1.5h2.7v1h-2.7v1.7H26.1z"/>
<path class="st1" d="M27.3,92.4V86h1.2v5.3h3.3v1.1H27.3z"/>
<path class="st1" d="M32.8,92.4V86h2.7c0.3,0,0.6,0.1,0.8,0.2s0.5,0.3,0.6,0.5c0.2,0.2,0.3,0.4,0.4,0.7c0.1,0.3,0.2,0.5,0.2,0.8
c0,0.3,0,0.5-0.1,0.8c-0.1,0.3-0.2,0.5-0.4,0.7c-0.2,0.2-0.4,0.4-0.6,0.5c-0.2,0.1-0.5,0.2-0.8,0.2h-1.5v2.1H32.8z M34.1,89.2h1.4
c0.2,0,0.4-0.1,0.6-0.3c0.2-0.2,0.2-0.4,0.2-0.8c0-0.2,0-0.3-0.1-0.4c0-0.1-0.1-0.2-0.2-0.3c-0.1-0.1-0.2-0.2-0.3-0.2
c-0.1,0-0.2-0.1-0.3-0.1h-1.4V89.2z"/>
</g>
<g>
<path class="st1" d="M35.1,60.2c0.2,0,0.4,0.1,0.4,0.3v18.5c0,0.2-0.2,0.3-0.4,0.3H16.6c-0.2,0-0.3-0.2-0.3-0.3V60.5
c0-0.2,0.2-0.3,0.3-0.3H35.1 M35.1,58.5H16.6c-1.1,0-2.1,0.9-2.1,2v18.5c0,1.1,0.9,2.1,2.1,2.1h18.5c1.1,0,2.1-0.9,2.1-2.1V60.5
C37.2,59.3,36.2,58.5,35.1,58.5L35.1,58.5z"/>
<g>
<path class="st1" d="M21.6,64c2-0.6,2.9-0.8,4.8-0.8c2.8,0,4.1,0.9,4.1,3.5v0.4c0,1.7-0.6,2.4-1.7,2.8c-0.9,0.3-1.6,0.5-2.6,0.8
v1.8h-2l-0.3-3.1c1.2-0.4,2.2-0.7,3-1c0.8-0.3,1.1-0.7,1.1-1.3v-0.4c0-1.3-0.4-1.6-1.8-1.6c-1,0-1.6,0.1-2.4,0.4l-0.2,1.2h-2V64z
M23.8,75.3c0-0.9,0.4-1.3,1.4-1.3c1,0,1.4,0.4,1.4,1.3c0,0.9-0.5,1.3-1.4,1.3C24.2,76.6,23.8,76.2,23.8,75.3z"/>
</g>
</g>
<g>
<path class="st3" d="M20.1,36.3v6.4h-1.2V40H16v2.7h-1.2v-6.4H16v2.6h2.9v-2.6H20.1z"/>
<path class="st3" d="M26.1,41.6v1.1h-4.4v-6.4H26v1.1h-3.1v1.5h2.7v1h-2.7v1.7H26.1z"/>
<path class="st3" d="M27.3,42.7v-6.4h1.2v5.3h3.3v1.1H27.3z"/>
<path class="st3" d="M32.8,42.7v-6.4h2.7c0.3,0,0.6,0.1,0.8,0.2s0.5,0.3,0.6,0.5c0.2,0.2,0.3,0.4,0.4,0.7c0.1,0.3,0.2,0.5,0.2,0.8
c0,0.3,0,0.5-0.1,0.8c-0.1,0.3-0.2,0.5-0.4,0.7c-0.2,0.2-0.4,0.4-0.6,0.5c-0.2,0.1-0.5,0.2-0.8,0.2h-1.5v2.1H32.8z M34.1,39.5h1.4
c0.2,0,0.4-0.1,0.6-0.3c0.2-0.2,0.2-0.4,0.2-0.8c0-0.2,0-0.3-0.1-0.4c0-0.1-0.1-0.2-0.2-0.3c-0.1-0.1-0.2-0.2-0.3-0.2
c-0.1,0-0.2-0.1-0.3-0.1h-1.4V39.5z"/>
</g>
<g>
<path class="st3" d="M35.1,10.5c0.2,0,0.4,0.1,0.4,0.3v18.5c0,0.2-0.2,0.3-0.4,0.3H16.6c-0.2,0-0.3-0.2-0.3-0.3V10.7
c0-0.2,0.2-0.3,0.3-0.3H35.1 M35.1,8.7H16.6c-1.1,0-2.1,0.9-2.1,2v18.5c0,1.1,0.9,2.1,2.1,2.1h18.5c1.1,0,2.1-0.9,2.1-2.1V10.7
C37.2,9.6,36.2,8.7,35.1,8.7L35.1,8.7z"/>
<g>
<path class="st3" d="M21.6,14.3c2-0.6,2.9-0.8,4.8-0.8c2.8,0,4.1,0.9,4.1,3.5v0.4c0,1.7-0.6,2.4-1.7,2.8c-0.9,0.3-1.6,0.5-2.6,0.8
v1.8h-2l-0.3-3.1c1.2-0.4,2.2-0.7,3-1c0.8-0.3,1.1-0.7,1.1-1.3v-0.4c0-1.3-0.4-1.6-1.8-1.6c-1,0-1.6,0.1-2.4,0.4l-0.2,1.2h-2V14.3
z M23.8,25.6c0-0.9,0.4-1.3,1.4-1.3c1,0,1.4,0.4,1.4,1.3c0,0.9-0.5,1.3-1.4,1.3C24.2,26.9,23.8,26.5,23.8,25.6z"/>
</g>
</g>
<g>
<path class="st1" d="M20.1,136v6.4h-1.2v-2.7H16v2.7h-1.2V136H16v2.6h2.9V136H20.1z"/>
<path class="st1" d="M26.1,141.3v1.1h-4.4V136H26v1.1h-3.1v1.5h2.7v1h-2.7v1.7H26.1z"/>
<path class="st1" d="M27.3,142.4V136h1.2v5.3h3.3v1.1H27.3z"/>
<path class="st1" d="M32.8,142.4V136h2.7c0.3,0,0.6,0.1,0.8,0.2s0.5,0.3,0.6,0.5c0.2,0.2,0.3,0.4,0.4,0.7c0.1,0.3,0.2,0.5,0.2,0.8
c0,0.3,0,0.5-0.1,0.8c-0.1,0.3-0.2,0.5-0.4,0.7c-0.2,0.2-0.4,0.4-0.6,0.5c-0.2,0.1-0.5,0.2-0.8,0.2h-1.5v2.1H32.8z M34.1,139.2h1.4
c0.2,0,0.4-0.1,0.6-0.3c0.2-0.2,0.2-0.4,0.2-0.8c0-0.2,0-0.3-0.1-0.4c0-0.1-0.1-0.2-0.2-0.3c-0.1-0.1-0.2-0.2-0.3-0.2
c-0.1,0-0.2-0.1-0.3-0.1h-1.4V139.2z"/>
</g>
<g>
<path class="st1" d="M36.4,108.9c0.2,0,0.4,0.1,0.4,0.3v21c0,0.2-0.2,0.4-0.4,0.4h-21c-0.2,0-0.4-0.2-0.4-0.4v-21
c0-0.2,0.2-0.3,0.4-0.3H36.4 M36.4,106.9h-21c-1.3,0-2.3,1-2.3,2.3v21c0,1.3,1.1,2.3,2.3,2.3h21c1.3,0,2.4-1.1,2.4-2.3v-21
C38.8,107.9,37.7,106.9,36.4,106.9L36.4,106.9z"/>
<g>
<path class="st1" d="M21,113.2c2.3-0.7,3.3-0.9,5.5-0.9c3.2,0,4.6,1.1,4.6,4v0.5c0,2-0.7,2.8-2,3.2c-1,0.4-1.9,0.6-2.9,0.9v2H24
l-0.3-3.5c1.4-0.4,2.5-0.8,3.4-1.1c1-0.4,1.3-0.8,1.3-1.5v-0.5c0-1.5-0.4-1.8-2.1-1.8c-1.1,0-1.9,0.1-2.7,0.5l-0.2,1.4H21V113.2z
M23.5,126.1c0-1,0.5-1.5,1.6-1.5c1.1,0,1.6,0.5,1.6,1.5c0,1-0.6,1.5-1.6,1.5C24,127.6,23.5,127.1,23.5,126.1z"/>
</g>
</g>
<g>
<path class="st1" d="M20.1,186.1v6.4h-1.2v-2.7H16v2.7h-1.2v-6.4H16v2.6h2.9v-2.6H20.1z"/>
<path class="st1" d="M26.1,191.4v1.1h-4.4v-6.4H26v1.1h-3.1v1.5h2.7v1h-2.7v1.7H26.1z"/>
<path class="st1" d="M27.3,192.5v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
</svg>

After

Width:  |  Height:  |  Size: 6.3 KiB

41
scripts/system/help.js Normal file
View file

@ -0,0 +1,41 @@
"use strict";
//
// help.js
// scripts/system/
//
// Created by Howard Stearns on 2 Nov 2016
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() { // BEGIN LOCAL_SCOPE
var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
var buttonName = "help"; // matching location reserved in Desktop.qml
var button = toolBar.addButton({
objectName: buttonName,
imageURL: Script.resolvePath("assets/images/tools/help.svg"),
visible: true,
hoverState: 2,
defaultState: 1,
buttonState: 1,
alpha: 0.9
});
// TODO: make button state reflect whether the window is opened or closed (independently from us).
function onClicked(){
Menu.triggerOption('Help...')
}
button.clicked.connect(onClicked);
Script.scriptEnding.connect(function () {
toolBar.removeButton(buttonName);
button.clicked.disconnect(onClicked);
});
}()); // END LOCAL_SCOPE