From ffdaadf13c946eb8082d9ea39849ff2c71d7d6b4 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 Jul 2016 15:48:14 -0700 Subject: [PATCH 1/7] Make toolbars work even when debugging a script --- .../src/scripting/ToolbarScriptingInterface.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/interface/src/scripting/ToolbarScriptingInterface.cpp b/interface/src/scripting/ToolbarScriptingInterface.cpp index 175a7fd539..0cb314615a 100644 --- a/interface/src/scripting/ToolbarScriptingInterface.cpp +++ b/interface/src/scripting/ToolbarScriptingInterface.cpp @@ -8,6 +8,8 @@ #include "ToolbarScriptingInterface.h" +#include + #include class QmlWrapper : public QObject { @@ -79,7 +81,11 @@ public: Q_INVOKABLE QObject* addButton(const QVariant& properties) { QVariant resultVar; - bool invokeResult = QMetaObject::invokeMethod(_qmlObject, "addButton", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, properties)); + Qt::ConnectionType connectionType = Qt::AutoConnection; + if (QThread::currentThread() != _qmlObject->thread()) { + connectionType = Qt::BlockingQueuedConnection; + } + bool invokeResult = QMetaObject::invokeMethod(_qmlObject, "addButton", connectionType, Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, properties)); if (!invokeResult) { return nullptr; } @@ -101,8 +107,12 @@ public: QObject* ToolbarScriptingInterface::getToolbar(const QString& toolbarId) { auto offscreenUi = DependencyManager::get(); auto desktop = offscreenUi->getDesktop(); + Qt::ConnectionType connectionType = Qt::AutoConnection; + if (QThread::currentThread() != desktop->thread()) { + connectionType = Qt::BlockingQueuedConnection; + } QVariant resultVar; - bool invokeResult = QMetaObject::invokeMethod(desktop, "getToolbar", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, toolbarId)); + bool invokeResult = QMetaObject::invokeMethod(desktop, "getToolbar", connectionType, Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, toolbarId)); if (!invokeResult) { return nullptr; } From fdcbf7162395546c9507bc59cd7c6569e7936b1e Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 Jul 2016 15:49:32 -0700 Subject: [PATCH 2/7] Remove fade effect from toolbar buttons --- .../qml/hifi/toolbars/ToolbarButton.qml | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml index 4356b18253..47a52c4c36 100644 --- a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml +++ b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml @@ -4,7 +4,7 @@ import QtQuick.Controls 1.4 Item { id: button property alias imageURL: image.source - property alias alpha: button.opacity + property alias alpha: image.opacity property var subImage; property int yOffset: 0 property int buttonState: 0 @@ -14,32 +14,11 @@ Item { width: size; height: size property bool pinned: false clip: true - - Behavior on opacity { - NumberAnimation { - duration: 150 - easing.type: Easing.InOutCubic - } - } - - property alias fadeTargetProperty: button.opacity - - onFadeTargetPropertyChanged: { - visible = (fadeTargetProperty !== 0.0); - } - - onVisibleChanged: { - if ((!visible && fadeTargetProperty != 0.0) || (visible && fadeTargetProperty == 0.0)) { - var target = visible; - visible = !visible; - fadeTargetProperty = target ? 1.0 : 0.0; - return; - } - } - + function updateOffset() { yOffset = size * (buttonState + hoverOffset); } + onButtonStateChanged: { hoverOffset = 0; // subtle: show the new state without hover. don't wait for mouse to be moved away // The above is per UX design, but ALSO avoid a subtle issue that would be a problem because @@ -64,11 +43,19 @@ Item { width: parent.width } + Timer { + id: asyncClickSender + interval: 10 + repeat: false + running: false + onTriggered: button.clicked(); + } + MouseArea { id: mouseArea hoverEnabled: true anchors.fill: parent - onClicked: button.clicked(); + onClicked: asyncClickSender.start(); onEntered: { hoverOffset = 2; updateOffset(); From 1adf96c8df1d9ffde4d1708d45b22a46f965eff9 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 Jul 2016 15:50:40 -0700 Subject: [PATCH 3/7] Move edit.js to new toolbar API --- scripts/system/edit.js | 439 +++++++++++++---------------------------- 1 file changed, 132 insertions(+), 307 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 4e87fcbf71..47d6fd4367 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -16,7 +16,6 @@ HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; Script.include([ "libraries/stringHelpers.js", "libraries/dataViewHelpers.js", - "libraries/toolBars.js", "libraries/progressDialog.js", "libraries/entitySelectionTool.js", @@ -50,11 +49,6 @@ selectionManager.addEventListener(function() { lightOverlayManager.updatePositions(); }); -var toolIconUrl = Script.resolvePath("assets/images/tools/"); -var toolHeight = 50; -var toolWidth = 50; -var TOOLBAR_MARGIN_Y = 0; - var DEGREES_TO_RADIANS = Math.PI / 180.0; var RADIANS_TO_DEGREES = 180.0 / Math.PI; var epsilon = 0.001; @@ -104,6 +98,7 @@ IMPORTING_SVO_OVERLAY_WIDTH = 144; IMPORTING_SVO_OVERLAY_HEIGHT = 30; IMPORTING_SVO_OVERLAY_MARGIN = 5; IMPORTING_SVO_OVERLAY_LEFT_MARGIN = 34; + var importingSVOImageOverlay = Overlays.addOverlay("image", { imageURL: Script.resolvePath("assets") + "/images/hourglass.svg", width: 20, @@ -168,241 +163,19 @@ function toggleMarketplace() { } var toolBar = (function() { + var EDIT_SETTING = "io.highfidelity.isEditting"; // for communication with other scripts + var TOOL_ICON_URL = Script.resolvePath("assets/images/tools/"); var that = {}, toolBar, - activeButton, - newModelButton, - newCubeButton, - newSphereButton, - newLightButton, - newTextButton, - newWebButton, - newZoneButton, - newParticleButton - - function initialize() { - toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL, "highfidelity.edit.toolbar", function(windowDimensions, toolbar) { - return { - x: (windowDimensions.x / 2) + (Tool.IMAGE_WIDTH * 2), - y: windowDimensions.y - }; - }, { - x: toolWidth, - y: -TOOLBAR_MARGIN_Y - toolHeight - }); - - activeButton = toolBar.addTool({ - imageURL: toolIconUrl + "edit.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - visible: true - }, true, false); - - newModelButton = toolBar.addTool({ - imageURL: toolIconUrl + "model-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - newCubeButton = toolBar.addTool({ - imageURL: toolIconUrl + "cube-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - newSphereButton = toolBar.addTool({ - imageURL: toolIconUrl + "sphere-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - newLightButton = toolBar.addTool({ - imageURL: toolIconUrl + "light-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - newTextButton = toolBar.addTool({ - imageURL: toolIconUrl + "text-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - newWebButton = toolBar.addTool({ - imageURL: toolIconUrl + "web-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - newZoneButton = toolBar.addTool({ - imageURL: toolIconUrl + "zone-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - newParticleButton = toolBar.addTool({ - imageURL: toolIconUrl + "particle-01.svg", - subImage: { - x: 0, - y: Tool.IMAGE_WIDTH, - width: Tool.IMAGE_WIDTH, - height: Tool.IMAGE_HEIGHT - }, - width: toolWidth, - height: toolHeight, - alpha: 0.9, - showButtonDown: true, - visible: false - }); - - that.setActive(false); - } - - that.clearEntityList = function() { - entityListTool.clearEntityList(); - }; - - var EDIT_SETTING = "io.highfidelity.isEditting"; // for communication with other scripts - Settings.setValue(EDIT_SETTING, false); - that.setActive = function(active) { - if (active != isActive) { - if (active && !Entities.canRez() && !Entities.canRezTmp()) { - Window.alert(INSUFFICIENT_PERMISSIONS_ERROR_MSG); - } else { - Messages.sendLocalMessage("edit-events", JSON.stringify({ - enabled: active - })); - isActive = active; - Settings.setValue(EDIT_SETTING, active); - if (!isActive) { - entityListTool.setVisible(false); - gridTool.setVisible(false); - grid.setEnabled(false); - propertiesTool.setVisible(false); - selectionManager.clearSelections(); - cameraManager.disable(); - selectionDisplay.triggerMapping.disable(); - } else { - UserActivityLogger.enabledEdit(); - hasShownPropertiesTool = false; - entityListTool.setVisible(true); - gridTool.setVisible(true); - grid.setEnabled(true); - propertiesTool.setVisible(true); - // Not sure what the following was meant to accomplish, but it currently causes - selectionDisplay.triggerMapping.enable(); - // everybody else to think that Interface has lost focus overall. fogbugzid:558 - // Window.setFocus(); - } - that.showTools(isActive); - } - } - toolBar.selectTool(activeButton, isActive); - lightOverlayManager.setVisible(isActive && Menu.isOptionChecked(MENU_SHOW_LIGHTS_IN_EDIT_MODE)); - Entities.setDrawZoneBoundaries(isActive && Menu.isOptionChecked(MENU_SHOW_ZONES_IN_EDIT_MODE)); - }; - - // Sets visibility of tool buttons, excluding the power button - that.showTools = function(doShow) { - toolBar.showTool(newModelButton, doShow); - toolBar.showTool(newCubeButton, doShow); - toolBar.showTool(newSphereButton, doShow); - toolBar.showTool(newLightButton, doShow); - toolBar.showTool(newTextButton, doShow); - toolBar.showTool(newWebButton, doShow); - toolBar.showTool(newZoneButton, doShow); - toolBar.showTool(newParticleButton, doShow); - }; - - var RESIZE_INTERVAL = 50; - var RESIZE_TIMEOUT = 120000; // 2 minutes - var RESIZE_MAX_CHECKS = RESIZE_TIMEOUT / RESIZE_INTERVAL; - - function addModel(url) { - var entityID = createNewEntity({ - type: "Model", - modelURL: url - }, false); - - if (entityID) { - print("Model added: " + url); - selectionManager.setSelections([entityID]); - } - } - + systemToolbar, + activeButton; + function createNewEntity(properties, dragOnCreate) { + Settings.setValue(EDIT_SETTING, false); + // Default to true if not passed in - dragOnCreate = dragOnCreate == undefined ? true : dragOnCreate; + // dragOnCreate = dragOnCreate == undefined ? true : dragOnCreate; + dragOnCreate = false; var dimensions = properties.dimensions ? properties.dimensions : DEFAULT_DIMENSIONS; var position = getPositionToCreateEntity(); @@ -426,35 +199,69 @@ var toolBar = (function() { return entityID; } - that.mousePressEvent = function(event) { - var clickedOverlay, - url, - file; - - if (!event.isLeftButton) { - // if another mouse button than left is pressed ignore it - return false; + function cleanup() { + that.setActive(false); + } + + function addButton(name, image, handler) { + var imageUrl = TOOL_ICON_URL + image; + var button = toolBar.addButton({ + objectName: name, + imageURL: imageUrl, + buttonState: 1, + alpha: 0.9, + visible: true, + }); + if (handler) { + button.clicked.connect(function(){ + Script.setTimeout(handler, 100); + }); } + return button; + } - clickedOverlay = Overlays.getOverlayAtPoint({ - x: event.x, - y: event.y + function initialize() { + print("QQQ creating edit toolbar"); + Script.scriptEnding.connect(cleanup); + + Window.domainChanged.connect(function() { + that.setActive(false); + that.clearEntityList(); }); - if (activeButton === toolBar.clicked(clickedOverlay)) { - that.setActive(!isActive); - return true; - } - - if (newModelButton === toolBar.clicked(clickedOverlay)) { - url = Window.prompt("Model URL"); - if (url !== null && url !== "") { - addModel(url); + Entities.canAdjustLocksChanged.connect(function(canAdjustLocks) { + if (isActive && !canAdjustLocks) { + that.setActive(false); } - return true; - } + }); - if (newCubeButton === toolBar.clicked(clickedOverlay)) { + systemToolbar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); + activeButton = systemToolbar.addButton({ + objectName: "activeButton", + imageURL: TOOL_ICON_URL + "edit.svg", + visible: true, + buttonState: 1, + alpha: 0.9, + }); + activeButton.clicked.connect(function(){ + that.setActive(!isActive); + activeButton.writeProperty("buttonState", isActive ? 0 : 1); + }); + + toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.edit"); + toolBar.writeProperty("shown", false); + + addButton("newModelButton", "model-01.svg", function(){ + var url = Window.prompt("Model URL"); + if (url !== null && url !== "") { + createNewEntity({ + type: "Model", + modelURL: url + }, false); + } + }); + + addButton("newCubeButton", "cube-01.svg", function(){ createNewEntity({ type: "Box", dimensions: DEFAULT_DIMENSIONS, @@ -464,11 +271,9 @@ var toolBar = (function() { blue: 0 } }); + }); - return true; - } - - if (newSphereButton === toolBar.clicked(clickedOverlay)) { + addButton("newSphereButton", "sphere-01.svg", function(){ createNewEntity({ type: "Sphere", dimensions: DEFAULT_DIMENSIONS, @@ -478,11 +283,9 @@ var toolBar = (function() { blue: 0 } }); + }); - return true; - } - - if (newLightButton === toolBar.clicked(clickedOverlay)) { + addButton("newLightButton", "light-01.svg", function(){ createNewEntity({ type: "Light", dimensions: DEFAULT_LIGHT_DIMENSIONS, @@ -499,11 +302,9 @@ var toolBar = (function() { exponent: 0, cutoff: 180, // in degrees }); + }); - return true; - } - - if (newTextButton === toolBar.clicked(clickedOverlay)) { + addButton("newTextButton", "text-01.svg", function(){ createNewEntity({ type: "Text", dimensions: { @@ -524,11 +325,9 @@ var toolBar = (function() { text: "some text", lineHeight: 0.06 }); + }); - return true; - } - - if (newWebButton === toolBar.clicked(clickedOverlay)) { + addButton("newWebButton", "web-01.svg", function(){ createNewEntity({ type: "Web", dimensions: { @@ -538,11 +337,9 @@ var toolBar = (function() { }, sourceUrl: "https://highfidelity.com/", }); + }); - return true; - } - - if (newZoneButton === toolBar.clicked(clickedOverlay)) { + addButton("newZoneButton", "zone-01.svg", function(){ createNewEntity({ type: "Zone", dimensions: { @@ -551,11 +348,9 @@ var toolBar = (function() { z: 10 }, }); + }); - return true; - } - - if (newParticleButton === toolBar.clicked(clickedOverlay)) { + addButton("newParticleButton", "particle-01.svg", function(){ createNewEntity({ type: "ParticleEffect", isEmitting: true, @@ -577,33 +372,65 @@ var toolBar = (function() { emitRate: 100, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", }); - } + }); - return false; + that.setActive(false); + } + + that.clearEntityList = function() { + entityListTool.clearEntityList(); }; - that.mouseReleaseEvent = function(event) { - return false; - } - - Window.domainChanged.connect(function() { - that.setActive(false); - that.clearEntityList(); - }); - - Entities.canAdjustLocksChanged.connect(function(canAdjustLocks) { - if (isActive && !canAdjustLocks) { - that.setActive(false); + that.setActive = function(active) { + if (active == isActive) { + return; } - }); - - that.cleanup = function() { - toolBar.cleanup(); + if (active && !Entities.canRez() && !Entities.canRezTmp()) { + Window.alert(INSUFFICIENT_PERMISSIONS_ERROR_MSG); + return; + } + Messages.sendLocalMessage("edit-events", JSON.stringify({ + enabled: active + })); + isActive = active; + Settings.setValue(EDIT_SETTING, active); + if (!isActive) { + entityListTool.setVisible(false); + gridTool.setVisible(false); + grid.setEnabled(false); + propertiesTool.setVisible(false); + selectionManager.clearSelections(); + cameraManager.disable(); + selectionDisplay.triggerMapping.disable(); + } else { + UserActivityLogger.enabledEdit(); + hasShownPropertiesTool = false; + entityListTool.setVisible(true); + gridTool.setVisible(true); + grid.setEnabled(true); + propertiesTool.setVisible(true); + // Not sure what the following was meant to accomplish, but it currently causes + selectionDisplay.triggerMapping.enable(); + // everybody else to think that Interface has lost focus overall. fogbugzid:558 + // Window.setFocus(); + } + // Sets visibility of tool buttons, excluding the power button + toolBar.writeProperty("shown", active); + var visible = toolBar.readProperty("visible"); + if (active && !visible) { + toolBar.writeProperty("visible", false); + toolBar.writeProperty("shown", false); + toolBar.writeProperty("visible", true); + toolBar.writeProperty("shown", true); + } + //toolBar.selectTool(activeButton, isActive); + lightOverlayManager.setVisible(isActive && Menu.isOptionChecked(MENU_SHOW_LIGHTS_IN_EDIT_MODE)); + Entities.setDrawZoneBoundaries(isActive && Menu.isOptionChecked(MENU_SHOW_ZONES_IN_EDIT_MODE)); }; initialize(); return that; -}()); +})(); function isLocked(properties) { @@ -712,7 +539,7 @@ function mousePressEvent(event) { mouseHasMovedSincePress = false; mouseCapturedByTool = false; - if (propertyMenu.mousePressEvent(event) || toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) { + if (propertyMenu.mousePressEvent(event) || progressDialog.mousePressEvent(event)) { mouseCapturedByTool = true; return; } @@ -796,8 +623,7 @@ function mouseReleaseEvent(event) { mouseMove(lastMouseMoveEvent); lastMouseMoveEvent = null; } - if (propertyMenu.mouseReleaseEvent(event) || toolBar.mouseReleaseEvent(event)) { - + if (propertyMenu.mouseReleaseEvent(event)) { return true; } if (placingEntityID) { @@ -1094,7 +920,6 @@ Script.scriptEnding.connect(function() { Settings.setValue(SETTING_SHOW_ZONES_IN_EDIT_MODE, Menu.isOptionChecked(MENU_SHOW_ZONES_IN_EDIT_MODE)); progressDialog.cleanup(); - toolBar.cleanup(); cleanupModelMenus(); tooltip.cleanup(); selectionDisplay.cleanup(); From a6d71f508ea6ad11d21e84b72d2b2fb5842d24c0 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 Jul 2016 17:20:08 -0700 Subject: [PATCH 4/7] Fix edit toolbar button vanishing, persistent edit button --- .../resources/qml/hifi/toolbars/Toolbar.qml | 3 +-- .../qml/hifi/toolbars/ToolbarButton.qml | 25 ++++++++----------- scripts/system/edit.js | 6 ++--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/interface/resources/qml/hifi/toolbars/Toolbar.qml b/interface/resources/qml/hifi/toolbars/Toolbar.qml index c5c15a6406..4e7eef62d5 100644 --- a/interface/resources/qml/hifi/toolbars/Toolbar.qml +++ b/interface/resources/qml/hifi/toolbars/Toolbar.qml @@ -19,7 +19,6 @@ Window { shown: true width: content.width height: content.height - visible: true // Disable this window from being able to call 'desktop.raise() and desktop.showDesktop' activator: MouseArea { width: frame.decoration ? frame.decoration.width : window.width @@ -38,7 +37,7 @@ Window { property real buttonSize: 50; property var buttons: [] property var container: horizontal ? row : column - + Settings { category: "toolbar/" + window.objectName property alias x: window.x diff --git a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml index 47a52c4c36..f4693adec5 100644 --- a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml +++ b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml @@ -8,23 +8,16 @@ Item { property var subImage; property int yOffset: 0 property int buttonState: 0 - property int hoverOffset: 0 + property int hoverState: -1 + property int defaultState: -1 property var toolbar; property real size: 50 // toolbar ? toolbar.buttonSize : 50 width: size; height: size property bool pinned: false clip: true - - function updateOffset() { - yOffset = size * (buttonState + hoverOffset); - } - + onButtonStateChanged: { - hoverOffset = 0; // subtle: show the new state without hover. don't wait for mouse to be moved away - // The above is per UX design, but ALSO avoid a subtle issue that would be a problem because - // the hand controllers don't move the mouse when not triggered, so releasing the trigger would - // never show unhovered. - updateOffset(); + yOffset = size * buttonState; } Component.onCompleted: { @@ -57,12 +50,14 @@ Item { anchors.fill: parent onClicked: asyncClickSender.start(); onEntered: { - hoverOffset = 2; - updateOffset(); + if (hoverState > 0) { + buttonState = hoverState; + } } onExited: { - hoverOffset = 0; - updateOffset(); + if (defaultState > 0) { + buttonState = defaultState; + } } } } diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 47d6fd4367..883a804e4b 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -201,6 +201,7 @@ var toolBar = (function() { function cleanup() { that.setActive(false); + systemToolbar.removeButton("com.highfidelity.interface.system.editButton"); } function addButton(name, image, handler) { @@ -237,11 +238,10 @@ var toolBar = (function() { systemToolbar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); activeButton = systemToolbar.addButton({ - objectName: "activeButton", + objectName: "com.highfidelity.interface.system.editButton", imageURL: TOOL_ICON_URL + "edit.svg", visible: true, buttonState: 1, - alpha: 0.9, }); activeButton.clicked.connect(function(){ that.setActive(!isActive); @@ -418,9 +418,7 @@ var toolBar = (function() { toolBar.writeProperty("shown", active); var visible = toolBar.readProperty("visible"); if (active && !visible) { - toolBar.writeProperty("visible", false); toolBar.writeProperty("shown", false); - toolBar.writeProperty("visible", true); toolBar.writeProperty("shown", true); } //toolBar.selectTool(activeButton, isActive); From 43e045c22acae96d64f453dd74cd0d1a3f932a6b Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 Jul 2016 17:45:49 -0700 Subject: [PATCH 5/7] Restore mouseover events for items in windows --- interface/resources/qml/hifi/toolbars/Toolbar.qml | 14 +------------- interface/resources/qml/windows/Decoration.qml | 8 ++++++-- interface/resources/qml/windows/Window.qml | 4 ---- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/interface/resources/qml/hifi/toolbars/Toolbar.qml b/interface/resources/qml/hifi/toolbars/Toolbar.qml index 4e7eef62d5..30989be688 100644 --- a/interface/resources/qml/hifi/toolbars/Toolbar.qml +++ b/interface/resources/qml/hifi/toolbars/Toolbar.qml @@ -20,19 +20,7 @@ Window { width: content.width height: content.height // Disable this window from being able to call 'desktop.raise() and desktop.showDesktop' - activator: MouseArea { - width: frame.decoration ? frame.decoration.width : window.width - height: frame.decoration ? frame.decoration.height : window.height - x: frame.decoration ? frame.decoration.anchors.leftMargin : 0 - y: frame.decoration ? frame.decoration.anchors.topMargin : 0 - propagateComposedEvents: true - acceptedButtons: Qt.AllButtons - enabled: window.visible - hoverEnabled: true - onPressed: mouse.accepted = false; - onEntered: window.mouseEntered(); - onExited: window.mouseExited(); - } + activator: Item {} property bool horizontal: true property real buttonSize: 50; property var buttons: [] diff --git a/interface/resources/qml/windows/Decoration.qml b/interface/resources/qml/windows/Decoration.qml index edfb369c0f..0048c556eb 100644 --- a/interface/resources/qml/windows/Decoration.qml +++ b/interface/resources/qml/windows/Decoration.qml @@ -43,15 +43,19 @@ Rectangle { // Enable dragging of the window, // detect mouseover of the window (including decoration) MouseArea { + id: decorationMouseArea anchors.fill: parent drag.target: window + hoverEnabled: true + onEntered: window.mouseEntered(); + onExited: window.mouseExited(); } Connections { target: window onMouseEntered: { if (desktop.hmdHandMouseActive) { root.inflateDecorations() - } + } } onMouseExited: root.deflateDecorations(); } @@ -59,7 +63,7 @@ Rectangle { target: desktop onHmdHandMouseActiveChanged: { if (desktop.hmdHandMouseActive) { - if (window.activator.containsMouse) { + if (decorationMouseArea.containsMouse) { root.inflateDecorations(); } } else { diff --git a/interface/resources/qml/windows/Window.qml b/interface/resources/qml/windows/Window.qml index ca37c55f4d..c873872692 100644 --- a/interface/resources/qml/windows/Window.qml +++ b/interface/resources/qml/windows/Window.qml @@ -115,14 +115,10 @@ Fadable { propagateComposedEvents: true acceptedButtons: Qt.AllButtons enabled: window.visible - hoverEnabled: true onPressed: { - //console.log("Pressed on activator area"); window.raise(); mouse.accepted = false; } - onEntered: window.mouseEntered(); - onExited: window.mouseExited(); } // This mouse area serves to swallow mouse events while the mouse is over the window From cd6abadc41fb9531477724e22e79b55ff20e4be7 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 Jul 2016 17:37:14 -0700 Subject: [PATCH 6/7] Make sure buttons get removed when shutting down scripts --- scripts/system/examples.js | 1 + scripts/system/goto.js | 1 + scripts/system/hmd.js | 1 + scripts/system/mute.js | 1 + 4 files changed, 4 insertions(+) diff --git a/scripts/system/examples.js b/scripts/system/examples.js index 0ec2644f9c..cea176f6b1 100644 --- a/scripts/system/examples.js +++ b/scripts/system/examples.js @@ -69,6 +69,7 @@ browseExamplesButton.clicked.connect(onClick); examplesWindow.visibleChanged.connect(onExamplesWindowVisibilityChanged); Script.scriptEnding.connect(function () { + toolBar.removeButton("examples"); browseExamplesButton.clicked.disconnect(onClick); examplesWindow.visibleChanged.disconnect(onExamplesWindowVisibilityChanged); }); diff --git a/scripts/system/goto.js b/scripts/system/goto.js index 24c402ab85..9cdf579d72 100644 --- a/scripts/system/goto.js +++ b/scripts/system/goto.js @@ -30,6 +30,7 @@ button.clicked.connect(onClicked); DialogsManager.addressBarShown.connect(onAddressBarShown); Script.scriptEnding.connect(function () { + toolBar.removeButton("goto"); button.clicked.disconnect(onClicked); DialogsManager.addressBarShown.disconnect(onAddressBarShown); }); diff --git a/scripts/system/hmd.js b/scripts/system/hmd.js index 305557b60c..9b749c306f 100644 --- a/scripts/system/hmd.js +++ b/scripts/system/hmd.js @@ -40,6 +40,7 @@ if (headset) { HMD.displayModeChanged.connect(onHmdChanged); Script.scriptEnding.connect(function () { + toolBar.removeButton("hmdToggle"); button.clicked.disconnect(onClicked); HMD.displayModeChanged.disconnect(onHmdChanged); }); diff --git a/scripts/system/mute.js b/scripts/system/mute.js index 1a575efa01..511c013d5e 100644 --- a/scripts/system/mute.js +++ b/scripts/system/mute.js @@ -34,6 +34,7 @@ button.clicked.connect(onClicked); AudioDevice.muteToggled.connect(onMuteToggled); Script.scriptEnding.connect(function () { + toolBar.removeButton("mute"); button.clicked.disconnect(onClicked); AudioDevice.muteToggled.disconnect(onMuteToggled); }); From d0846236622f32a76e4c15bed35f0f124cec0aab Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 15 Jul 2016 12:15:23 -0700 Subject: [PATCH 7/7] PR feedback --- scripts/system/edit.js | 68 +++++++++++++----------------------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 883a804e4b..05d554393f 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -12,7 +12,10 @@ // HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; - +var EDIT_TOGGLE_BUTTON = "com.highfidelity.interface.system.editButton"; +var SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system"; +var EDIT_TOOLBAR = "com.highfidelity.interface.toolbar.edit"; + Script.include([ "libraries/stringHelpers.js", "libraries/dataViewHelpers.js", @@ -92,8 +95,6 @@ var INSUFFICIENT_PERMISSIONS_IMPORT_ERROR_MSG = "You do not have the necessary p var mode = 0; var isActive = false; -var placingEntityID = null; - IMPORTING_SVO_OVERLAY_WIDTH = 144; IMPORTING_SVO_OVERLAY_HEIGHT = 30; IMPORTING_SVO_OVERLAY_MARGIN = 5; @@ -170,24 +171,16 @@ var toolBar = (function() { systemToolbar, activeButton; - function createNewEntity(properties, dragOnCreate) { + function createNewEntity(properties) { Settings.setValue(EDIT_SETTING, false); - // Default to true if not passed in - // dragOnCreate = dragOnCreate == undefined ? true : dragOnCreate; - dragOnCreate = false; - var dimensions = properties.dimensions ? properties.dimensions : DEFAULT_DIMENSIONS; var position = getPositionToCreateEntity(); var entityID = null; if (position != null) { position = grid.snapToSurface(grid.snapToGrid(position, false, dimensions), dimensions), properties.position = position; - entityID = Entities.addEntity(properties); - if (dragOnCreate) { - placingEntityID = entityID; - } } else { Window.alert("Can't create " + properties.type + ": " + properties.type + " would be out of bounds."); } @@ -201,7 +194,7 @@ var toolBar = (function() { function cleanup() { that.setActive(false); - systemToolbar.removeButton("com.highfidelity.interface.system.editButton"); + systemToolbar.removeButton(EDIT_TOGGLE_BUTTON); } function addButton(name, image, handler) { @@ -214,7 +207,7 @@ var toolBar = (function() { visible: true, }); if (handler) { - button.clicked.connect(function(){ + button.clicked.connect(function() { Script.setTimeout(handler, 100); }); } @@ -236,32 +229,32 @@ var toolBar = (function() { } }); - systemToolbar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); + systemToolbar = Toolbars.getToolbar(SYSTEM_TOOLBAR); activeButton = systemToolbar.addButton({ - objectName: "com.highfidelity.interface.system.editButton", + objectName: EDIT_TOGGLE_BUTTON, imageURL: TOOL_ICON_URL + "edit.svg", visible: true, buttonState: 1, }); - activeButton.clicked.connect(function(){ + activeButton.clicked.connect(function() { that.setActive(!isActive); activeButton.writeProperty("buttonState", isActive ? 0 : 1); }); - toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.edit"); + toolBar = Toolbars.getToolbar(EDIT_TOOLBAR); toolBar.writeProperty("shown", false); - addButton("newModelButton", "model-01.svg", function(){ + addButton("newModelButton", "model-01.svg", function() { var url = Window.prompt("Model URL"); if (url !== null && url !== "") { createNewEntity({ type: "Model", modelURL: url - }, false); + }); } }); - addButton("newCubeButton", "cube-01.svg", function(){ + addButton("newCubeButton", "cube-01.svg", function() { createNewEntity({ type: "Box", dimensions: DEFAULT_DIMENSIONS, @@ -273,7 +266,7 @@ var toolBar = (function() { }); }); - addButton("newSphereButton", "sphere-01.svg", function(){ + addButton("newSphereButton", "sphere-01.svg", function() { createNewEntity({ type: "Sphere", dimensions: DEFAULT_DIMENSIONS, @@ -285,7 +278,7 @@ var toolBar = (function() { }); }); - addButton("newLightButton", "light-01.svg", function(){ + addButton("newLightButton", "light-01.svg", function() { createNewEntity({ type: "Light", dimensions: DEFAULT_LIGHT_DIMENSIONS, @@ -304,7 +297,7 @@ var toolBar = (function() { }); }); - addButton("newTextButton", "text-01.svg", function(){ + addButton("newTextButton", "text-01.svg", function() { createNewEntity({ type: "Text", dimensions: { @@ -327,7 +320,7 @@ var toolBar = (function() { }); }); - addButton("newWebButton", "web-01.svg", function(){ + addButton("newWebButton", "web-01.svg", function() { createNewEntity({ type: "Web", dimensions: { @@ -339,7 +332,7 @@ var toolBar = (function() { }); }); - addButton("newZoneButton", "zone-01.svg", function(){ + addButton("newZoneButton", "zone-01.svg", function() { createNewEntity({ type: "Zone", dimensions: { @@ -350,7 +343,7 @@ var toolBar = (function() { }); }); - addButton("newParticleButton", "particle-01.svg", function(){ + addButton("newParticleButton", "particle-01.svg", function() { createNewEntity({ type: "ParticleEffect", isEmitting: true, @@ -409,8 +402,8 @@ var toolBar = (function() { gridTool.setVisible(true); grid.setEnabled(true); propertiesTool.setVisible(true); - // Not sure what the following was meant to accomplish, but it currently causes selectionDisplay.triggerMapping.enable(); + // Not sure what the following was meant to accomplish, but it currently causes // everybody else to think that Interface has lost focus overall. fogbugzid:558 // Window.setFocus(); } @@ -580,16 +573,6 @@ function mouseMove(event) { mouseHasMovedSincePress = true; } - if (placingEntityID) { - var pickRay = Camera.computePickRay(event.x, event.y); - var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; - var offset = Vec3.multiply(distance, pickRay.direction); - var position = Vec3.sum(Camera.position, offset); - Entities.editEntity(placingEntityID, { - position: position, - }); - return; - } if (!isActive) { return; } @@ -624,16 +607,7 @@ function mouseReleaseEvent(event) { if (propertyMenu.mouseReleaseEvent(event)) { return true; } - if (placingEntityID) { - - if (isActive) { - - selectionManager.setSelections([placingEntityID]); - } - placingEntityID = null; - } if (isActive && selectionManager.hasSelection()) { - tooltip.show(false); } if (mouseCapturedByTool) {