From 1fa31d3c10545609f5816c726ba07ba1f47fa70a Mon Sep 17 00:00:00 2001
From: David Rowe <david@ctrlaltstudio.com>
Date: Sat, 13 Jan 2018 10:27:43 +1300
Subject: [PATCH] Remove old ToolWindow code

---
 interface/resources/qml/ToolWindow.qml        | 256 ------------------
 interface/resources/qml/hifi/Desktop.qml      |   4 -
 libraries/ui/src/OffscreenUi.cpp              |   5 -
 libraries/ui/src/OffscreenUi.h                |   2 -
 libraries/ui/src/QmlWindowClass.cpp           | 105 ++-----
 libraries/ui/src/QmlWindowClass.h             |   8 -
 .../developer/tests/playaPerformanceTest.js   |   1 -
 scripts/developer/tests/qmlTest.js            |   1 -
 scripts/developer/tests/textureStress.js      |   1 -
 .../developer/tests/toolWindowStressTest.js   |  31 ---
 10 files changed, 28 insertions(+), 386 deletions(-)
 delete mode 100644 interface/resources/qml/ToolWindow.qml
 delete mode 100644 scripts/developer/tests/toolWindowStressTest.js

diff --git a/interface/resources/qml/ToolWindow.qml b/interface/resources/qml/ToolWindow.qml
deleted file mode 100644
index b1120058f9..0000000000
--- a/interface/resources/qml/ToolWindow.qml
+++ /dev/null
@@ -1,256 +0,0 @@
-//
-//  ToolWindow.qml
-//
-//  Created by Bradley Austin Davis on 12 Jan 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
-//
-
-import QtQuick 2.5
-import QtQuick.Controls 1.4
-import QtQuick.Controls.Styles 1.4
-import QtWebEngine 1.1
-import QtWebChannel 1.0
-import Qt.labs.settings 1.0
-
-import "windows"
-import "controls-uit"
-import "styles-uit"
-
-
-ScrollingWindow {
-    id: toolWindow
-    resizable: true
-    objectName: "ToolWindow"
-    destroyOnCloseButton: false
-    destroyOnHidden: false
-    closable: true
-    shown: false
-    title: "Edit"
-    property alias tabView: tabView
-    implicitWidth: 520; implicitHeight: 695
-    minSize: Qt.vector2d(456, 500)
-
-    HifiConstants { id: hifi }
-
-    onParentChanged: {
-        if (parent) {
-            x = 120;
-            y = 120;
-        }
-    }
-
-    onShownChanged: {
-        keyboardEnabled = HMD.active;
-    }
-
-    Settings {
-        category: "ToolWindow.Position"
-        property alias x: toolWindow.x
-        property alias y: toolWindow.y
-    }
-
-    Item {
-        id: toolWindowTabViewItem
-        height: pane.scrollHeight
-        width: pane.contentWidth
-        anchors.left: parent.left
-        anchors.top: parent.top
-
-        TabView {
-            id: tabView
-            width: pane.contentWidth
-            // Pane height so that don't use Window's scrollbars otherwise tabs may be scrolled out of view.
-            height: pane.scrollHeight
-            property int tabCount: 0
-
-            Repeater {
-                model: 4
-                Tab {
-                    // Force loading of the content even if the tab is not visible
-                    // (required for letting the C++ code access the webview)
-                    active: true
-                    enabled: false
-                    property string originalUrl: ""
-
-                    WebView {
-                        id: webView
-                        anchors.fill: parent
-                        enabled: false
-                        Component.onCompleted: {
-                            webChannel.registerObject("eventBridge", eventBridge);
-                            webChannel.registerObject("eventBridgeWrapper", eventBridgeWrapper);
-                        }
-
-                        onEnabledChanged: toolWindow.updateVisiblity()
-                    }
-                }
-            }
-
-            style: TabViewStyle {
-
-                frame: Rectangle {  // Background shown before content loads.
-                    anchors.fill: parent
-                    color: hifi.colors.baseGray
-                }
-
-                frameOverlap: 0
-
-                tab: Rectangle {
-                    implicitWidth: text.width
-                    implicitHeight: 3 * text.height
-                    color: styleData.selected ? hifi.colors.black : hifi.colors.tabBackgroundDark
-
-                    RalewayRegular {
-                        id: text
-                        text: styleData.title
-                        font.capitalization: Font.AllUppercase
-                        size: hifi.fontSizes.tabName
-                        width: tabView.tabCount > 1 ? styleData.availableWidth / tabView.tabCount : implicitWidth + 2 * hifi.dimensions.contentSpacing.x
-                        elide: Text.ElideRight
-                        color: styleData.selected ? hifi.colors.primaryHighlight : hifi.colors.lightGrayText
-                        horizontalAlignment: Text.AlignHCenter
-                        anchors.centerIn: parent
-                    }
-
-                    Rectangle {  // Separator.
-                        width: 1
-                        height: parent.height
-                        color: hifi.colors.black
-                        anchors.left: parent.left
-                        anchors.top: parent.top
-                        visible: styleData.index > 0
-
-                        Rectangle {
-                            width: 1
-                            height: 1
-                            color: hifi.colors.baseGray
-                            anchors.left: parent.left
-                            anchors.bottom: parent.bottom
-                        }
-                    }
-
-                    Rectangle {  // Active underline.
-                        width: parent.width - (styleData.index > 0 ? 1 : 0)
-                        height: 1
-                        anchors.right: parent.right
-                        anchors.bottom: parent.bottom
-                        color: styleData.selected ? hifi.colors.primaryHighlight : hifi.colors.baseGray
-                    }
-                }
-
-                tabOverlap: 0
-            }
-        }
-    }
-
-    function updateVisiblity() {
-        if (visible) {
-            for (var i = 0; i < tabView.count; ++i) {
-                if (tabView.getTab(i).enabled) {
-                    return;
-                }
-            }
-            shown = false;
-        }
-    }
-
-    function findIndexForUrl(source) {
-        for (var i = 0; i < tabView.count; ++i) {
-            var tab = tabView.getTab(i);
-            if (tab.originalUrl === source) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    function findTabForUrl(source) {
-        var index = findIndexForUrl(source);
-        if (index < 0) {
-            return;
-        }
-        return tabView.getTab(index);
-    }
-
-    function showTabForUrl(source, newVisible) {
-        var index = findIndexForUrl(source);
-        if (index < 0) {
-            return;
-        }
-
-        var tab = tabView.getTab(index);
-        if (newVisible) {
-            toolWindow.shown = true
-            tab.enabled = true
-        } else {
-            tab.enabled = false;
-            updateVisiblity();
-        }
-    }
-
-    function findFreeTab() {
-        for (var i = 0; i < tabView.count; ++i) {
-            var tab = tabView.getTab(i);
-            if (tab && (!tab.originalUrl || tab.originalUrl === "")) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    function removeTabForUrl(source) {
-        var index = findIndexForUrl(source);
-        if (index < 0) {
-            return;
-        }
-
-        var tab = tabView.getTab(index);
-        tab.title = "";
-        tab.enabled = false;
-        tab.originalUrl = "";
-        tab.item.url = "about:blank";
-        tab.item.enabled = false;
-        tabView.tabCount--;
-    }
-
-    function addWebTab(properties) {
-        if (!properties.source) {
-            console.warn("Attempted to open Web Tool Pane without URL");
-            return;
-        }
-
-        var existingTabIndex = findIndexForUrl(properties.source);
-        if (existingTabIndex >= 0) {
-            var tab = tabView.getTab(existingTabIndex);
-            return tab.item;
-        }
-
-        var freeTabIndex = findFreeTab();
-        if (freeTabIndex === -1) {
-            console.warn("Unable to add new tab");
-            return;
-        }
-
-        if (properties.width) {
-            tabView.width = Math.min(Math.max(tabView.width, properties.width), toolWindow.maxSize.x);
-        }
-
-        if (properties.height) {
-            tabView.height = Math.min(Math.max(tabView.height, properties.height), toolWindow.maxSize.y);
-        }
-
-        var tab = tabView.getTab(freeTabIndex);
-        tab.title = properties.title || "Unknown";
-        tab.enabled = true;
-        tab.originalUrl = properties.source;
-
-        var result = tab.item;
-        result.enabled = true;
-        tabView.tabCount++;
-        result.url = properties.source;
-        return result;
-    }
-}
diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml
index 896b3cf10e..8c732aac40 100644
--- a/interface/resources/qml/hifi/Desktop.qml
+++ b/interface/resources/qml/hifi/Desktop.qml
@@ -22,10 +22,6 @@ OriginalDesktop.Desktop {
         acceptedButtons: Qt.NoButton
     }
 
-    // The tool window, one instance
-    property alias toolWindow: toolWindow
-    ToolWindow { id: toolWindow }
-
     Action {
         text: "Open Browser"
         shortcut: "Ctrl+B"
diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp
index 905a224ef4..221f5013bf 100644
--- a/libraries/ui/src/OffscreenUi.cpp
+++ b/libraries/ui/src/OffscreenUi.cpp
@@ -666,7 +666,6 @@ void OffscreenUi::createDesktop(const QUrl& url) {
         Q_UNUSED(context)
         _desktop = static_cast<QQuickItem*>(newObject);
         getSurfaceContext()->setContextProperty("desktop", _desktop);
-        _toolWindow = _desktop->findChild<QQuickItem*>("ToolWindow");
 
         _vrMenu = new VrMenu(this);
         for (const auto& menuInitializer : _queuedMenuInitializers) {
@@ -686,10 +685,6 @@ QObject* OffscreenUi::getRootMenu() {
     return getRootItem()->findChild<QObject*>("rootMenu");
 }
 
-QQuickItem* OffscreenUi::getToolWindow() {
-    return _toolWindow;
-}
-
 void OffscreenUi::unfocusWindows() {
     bool invokeResult = QMetaObject::invokeMethod(_desktop, "unfocusWindows");
     Q_ASSERT(invokeResult);
diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h
index 76e4261cd3..ab3a209820 100644
--- a/libraries/ui/src/OffscreenUi.h
+++ b/libraries/ui/src/OffscreenUi.h
@@ -80,7 +80,6 @@ public:
     QObject* getFlags();
     Q_INVOKABLE bool isPointOnDesktopWindow(QVariant point);
     QQuickItem* getDesktop();
-    QQuickItem* getToolWindow();
     QObject* getRootMenu();
     enum Icon {
         ICON_NONE = 0,
@@ -261,7 +260,6 @@ private:
     ModalDialogListener* assetDialogAsync(const QVariantMap& properties);
 
     QQuickItem* _desktop { nullptr };
-    QQuickItem* _toolWindow { nullptr };
     QList<QObject*> _modalDialogListeners;
     std::unordered_map<int, bool> _pressedKeys;
     VrMenu* _vrMenu { nullptr };
diff --git a/libraries/ui/src/QmlWindowClass.cpp b/libraries/ui/src/QmlWindowClass.cpp
index 90b91c5ec2..1209d39dcf 100644
--- a/libraries/ui/src/QmlWindowClass.cpp
+++ b/libraries/ui/src/QmlWindowClass.cpp
@@ -32,7 +32,6 @@ static const char* const EVENT_BRIDGE_PROPERTY = "eventBridge";
 static const char* const WIDTH_PROPERTY = "width";
 static const char* const HEIGHT_PROPERTY = "height";
 static const char* const VISIBILE_PROPERTY = "visible";
-static const char* const TOOLWINDOW_PROPERTY = "toolWindow";
 static const uvec2 MAX_QML_WINDOW_SIZE { 1280, 720 };
 static const uvec2 MIN_QML_WINDOW_SIZE { 120, 80 };
 
@@ -53,9 +52,6 @@ QVariantMap QmlWindowClass::parseArguments(QScriptContext* context) {
         if (context->argument(3).isNumber()) {
             properties[HEIGHT_PROPERTY] = context->argument(3).toInt32();
         }
-        if (context->argument(4).isBool()) {
-            properties[TOOLWINDOW_PROPERTY] = context->argument(4).toBool();
-        }
     } else {
         properties = context->argument(0).toVariant().toMap();
     }
@@ -96,52 +92,37 @@ void QmlWindowClass::initQml(QVariantMap properties) {
     auto offscreenUi = DependencyManager::get<OffscreenUi>();
     _source = properties[SOURCE_PROPERTY].toString();
 
-#if QML_TOOL_WINDOW
-    _toolWindow = properties.contains(TOOLWINDOW_PROPERTY) && properties[TOOLWINDOW_PROPERTY].toBool();
-    if (_toolWindow) {
-        // Build the event bridge and wrapper on the main thread
-        _qmlWindow = offscreenUi->getToolWindow();
-        properties[EVENT_BRIDGE_PROPERTY] = QVariant::fromValue(this);
-        QVariant newTabVar;
-        bool invokeResult = QMetaObject::invokeMethod(_qmlWindow, "addWebTab", Qt::DirectConnection,
-            Q_RETURN_ARG(QVariant, newTabVar),
-            Q_ARG(QVariant, QVariant::fromValue(properties)));
-        Q_ASSERT(invokeResult);
-    } else {
-#endif
-        // Build the event bridge and wrapper on the main thread
-        offscreenUi->loadInNewContext(qmlSource(), [&](QQmlContext* context, QObject* object) {
-            _qmlWindow = object;
-            context->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
-            context->engine()->setObjectOwnership(this, QQmlEngine::CppOwnership);
-            context->engine()->setObjectOwnership(object, QQmlEngine::CppOwnership);
-            if (properties.contains(TITLE_PROPERTY)) {
-                object->setProperty(TITLE_PROPERTY, properties[TITLE_PROPERTY].toString());
-            }
-            if (properties.contains(HEIGHT_PROPERTY) && properties.contains(WIDTH_PROPERTY)) {
-                uvec2 requestedSize { properties[WIDTH_PROPERTY].toUInt(), properties[HEIGHT_PROPERTY].toUInt() };
-                requestedSize = glm::clamp(requestedSize, MIN_QML_WINDOW_SIZE, MAX_QML_WINDOW_SIZE);
-                asQuickItem()->setSize(QSize(requestedSize.x, requestedSize.y));
-            }
+    // Build the event bridge and wrapper on the main thread
+    offscreenUi->loadInNewContext(qmlSource(), [&](QQmlContext* context, QObject* object) {
+        _qmlWindow = object;
+        context->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
+        context->engine()->setObjectOwnership(this, QQmlEngine::CppOwnership);
+        context->engine()->setObjectOwnership(object, QQmlEngine::CppOwnership);
+        if (properties.contains(TITLE_PROPERTY)) {
+            object->setProperty(TITLE_PROPERTY, properties[TITLE_PROPERTY].toString());
+        }
+        if (properties.contains(HEIGHT_PROPERTY) && properties.contains(WIDTH_PROPERTY)) {
+            uvec2 requestedSize { properties[WIDTH_PROPERTY].toUInt(), properties[HEIGHT_PROPERTY].toUInt() };
+            requestedSize = glm::clamp(requestedSize, MIN_QML_WINDOW_SIZE, MAX_QML_WINDOW_SIZE);
+            asQuickItem()->setSize(QSize(requestedSize.x, requestedSize.y));
+        }
 
-            bool visible = !properties.contains(VISIBILE_PROPERTY) || properties[VISIBILE_PROPERTY].toBool();
-            object->setProperty(OFFSCREEN_VISIBILITY_PROPERTY, visible);
-            object->setProperty(SOURCE_PROPERTY, _source);
+        bool visible = !properties.contains(VISIBILE_PROPERTY) || properties[VISIBILE_PROPERTY].toBool();
+        object->setProperty(OFFSCREEN_VISIBILITY_PROPERTY, visible);
+        object->setProperty(SOURCE_PROPERTY, _source);
 
-            const QMetaObject *metaObject = _qmlWindow->metaObject();
-            // Forward messages received from QML on to the script
-            connect(_qmlWindow, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::QueuedConnection);
-            connect(_qmlWindow, SIGNAL(visibleChanged()), this, SIGNAL(visibleChanged()), Qt::QueuedConnection);
+        const QMetaObject *metaObject = _qmlWindow->metaObject();
+        // Forward messages received from QML on to the script
+        connect(_qmlWindow, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::QueuedConnection);
+        connect(_qmlWindow, SIGNAL(visibleChanged()), this, SIGNAL(visibleChanged()), Qt::QueuedConnection);
+
+        if (metaObject->indexOfSignal("resized") >= 0)
+            connect(_qmlWindow, SIGNAL(resized(QSizeF)), this, SIGNAL(resized(QSizeF)), Qt::QueuedConnection);
+        if (metaObject->indexOfSignal("moved") >= 0)
+            connect(_qmlWindow, SIGNAL(moved(QVector2D)), this, SLOT(hasMoved(QVector2D)), Qt::QueuedConnection);
+        connect(_qmlWindow, SIGNAL(windowClosed()), this, SLOT(hasClosed()), Qt::QueuedConnection);
+    });
 
-            if (metaObject->indexOfSignal("resized") >= 0)
-                connect(_qmlWindow, SIGNAL(resized(QSizeF)), this, SIGNAL(resized(QSizeF)), Qt::QueuedConnection);
-            if (metaObject->indexOfSignal("moved") >= 0)
-                connect(_qmlWindow, SIGNAL(moved(QVector2D)), this, SLOT(hasMoved(QVector2D)), Qt::QueuedConnection);
-            connect(_qmlWindow, SIGNAL(windowClosed()), this, SLOT(hasClosed()), Qt::QueuedConnection);
-        });
-#if QML_TOOL_WINDOW
-    }
-#endif
     Q_ASSERT(_qmlWindow);
     Q_ASSERT(dynamic_cast<const QQuickItem*>(_qmlWindow.data()));
 }
@@ -215,11 +196,6 @@ QmlWindowClass::~QmlWindowClass() {
 }
 
 QQuickItem* QmlWindowClass::asQuickItem() const {
-#if QML_TOOL_WINDOW
-    if (_toolWindow) {
-        return DependencyManager::get<OffscreenUi>()->getToolWindow();
-    }
-#endif
     return _qmlWindow.isNull() ? nullptr : dynamic_cast<QQuickItem*>(_qmlWindow.data());
 }
 
@@ -230,14 +206,6 @@ void QmlWindowClass::setVisible(bool visible) {
     }
 
     QQuickItem* targetWindow = asQuickItem();
-#if QML_TOOL_WINDOW
-    if (_toolWindow) {
-        // For tool window tabs we special case visibility as a function call on the tab parent
-        // The tool window itself has special logic based on whether any tabs are visible
-        QMetaObject::invokeMethod(targetWindow, "showTabForUrl", Qt::QueuedConnection, Q_ARG(QVariant, _source), Q_ARG(QVariant, visible));
-        return;
-    } 
-#endif
     targetWindow->setProperty(OFFSCREEN_VISIBILITY_PROPERTY, visible);
 }
 
@@ -253,12 +221,6 @@ bool QmlWindowClass::isVisible() {
         return false;
     }
 
-#if QML_TOOL_WINDOW
-    if (_toolWindow) {
-        return dynamic_cast<QQuickItem*>(_qmlWindow.data())->isEnabled();
-    } 
-#endif
-
     return asQuickItem()->isVisible();
 }
 
@@ -343,17 +305,6 @@ void QmlWindowClass::close() {
         return;
     }
 
-#if QML_TOOL_WINDOW
-    if (_toolWindow) {
-        auto offscreenUi = DependencyManager::get<OffscreenUi>();
-        auto toolWindow = offscreenUi->getToolWindow();
-        auto invokeResult = QMetaObject::invokeMethod(toolWindow, "removeTabForUrl", Qt::DirectConnection,
-            Q_ARG(QVariant, _source));
-        Q_ASSERT(invokeResult);
-        return;
-    } 
-#endif
-
     if (_qmlWindow) {
         _qmlWindow->deleteLater();
     }
diff --git a/libraries/ui/src/QmlWindowClass.h b/libraries/ui/src/QmlWindowClass.h
index e01bc8f14b..f274501d35 100644
--- a/libraries/ui/src/QmlWindowClass.h
+++ b/libraries/ui/src/QmlWindowClass.h
@@ -19,8 +19,6 @@
 class QScriptEngine;
 class QScriptContext;
 
-#define QML_TOOL_WINDOW 0
-
 // FIXME refactor this class to be a QQuickItem derived type and eliminate the needless wrapping 
 class QmlWindowClass : public QObject {
     Q_OBJECT
@@ -87,12 +85,6 @@ protected:
 
     virtual QString qmlSource() const { return "QmlWindow.qml"; }
 
-#if QML_TOOL_WINDOW
-    // FIXME needs to be initialized in the ctor once we have support
-    // for tool window panes in QML
-    bool _toolWindow { false };
-#endif
-
     QPointer<QObject> _qmlWindow;
     QString _source;
 
diff --git a/scripts/developer/tests/playaPerformanceTest.js b/scripts/developer/tests/playaPerformanceTest.js
index 4c8a728a15..6250fe1175 100644
--- a/scripts/developer/tests/playaPerformanceTest.js
+++ b/scripts/developer/tests/playaPerformanceTest.js
@@ -4,7 +4,6 @@ qmlWindow = new OverlayWindow({
     source: qml, 
     height: 320, 
     width: 640, 
-    toolWindow: false,
     visible: true
 });
 
diff --git a/scripts/developer/tests/qmlTest.js b/scripts/developer/tests/qmlTest.js
index 0eaabac6d1..7d248a9cc7 100644
--- a/scripts/developer/tests/qmlTest.js
+++ b/scripts/developer/tests/qmlTest.js
@@ -4,7 +4,6 @@ qmlWindow = new OverlayWindow({
     source: "qrc:///qml/OverlayWindowTest.qml", 
     height: 240, 
     width: 320, 
-    toolWindow: false,
     visible: true
 });
 
diff --git a/scripts/developer/tests/textureStress.js b/scripts/developer/tests/textureStress.js
index 1e3cf9a367..98af4b19b7 100644
--- a/scripts/developer/tests/textureStress.js
+++ b/scripts/developer/tests/textureStress.js
@@ -15,7 +15,6 @@ qmlWindow = new OverlayWindow({
     source: qml, 
     height: 240, 
     width: 320, 
-    toolWindow: false,
     visible: true
 });
 
diff --git a/scripts/developer/tests/toolWindowStressTest.js b/scripts/developer/tests/toolWindowStressTest.js
deleted file mode 100644
index 44b059ebda..0000000000
--- a/scripts/developer/tests/toolWindowStressTest.js
+++ /dev/null
@@ -1,31 +0,0 @@
-var TOGGLE_RATE = 1000;
-var RUNTIME = 60 * 1000;
-
-var webView;
-var running = true;
-
-function toggleWindow() {
-    if (!running) {
-        return;
-    }
-    
-    if (webView) {
-        webView.close();
-        webView = null;
-    } else {
-        webView = new OverlayWebWindow({
-            title: 'Entity Properties', 
-            source: "http://www.google.com", 
-            toolWindow: true
-        });
-        webView.setVisible(true);
-    }
-    Script.setTimeout(toggleWindow, TOGGLE_RATE)
-}
-
-toggleWindow();
-print("Creating window?")
-
-Script.setTimeout(function(){
-    print("Shutting down")
-}, RUNTIME)