diff --git a/interface/resources/qml/hifi/dialogs/TabletDebugWindow.qml b/interface/resources/qml/hifi/dialogs/TabletDebugWindow.qml new file mode 100644 index 0000000000..d4bbe0af04 --- /dev/null +++ b/interface/resources/qml/hifi/dialogs/TabletDebugWindow.qml @@ -0,0 +1,78 @@ +// +// TabletDebugWindow.qml +// +// Vlad Stelmahovsky, created on 20/03/2017. +// Copyright 2017 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 Hifi 1.0 as Hifi + +import "../../styles-uit" +import "../../controls-uit" as HifiControls + +Rectangle { + id: root + + objectName: "DebugWindow" + property var eventBridge; + + property var title: "Debug Window" + property bool isHMD: false + + color: hifi.colors.baseGray + + HifiConstants { id: hifi } + + signal sendToScript(var message); + property int colorScheme: hifi.colorSchemes.dark + + property var channel; + property var scripts: ScriptDiscoveryService; + + function fromScript(message) { + var MAX_LINE_COUNT = 2000; + var TRIM_LINES = 500; + if (textArea.lineCount > MAX_LINE_COUNT) { + var lines = textArea.text.split('\n'); + lines.splice(0, TRIM_LINES); + textArea.text = lines.join('\n'); + } + textArea.append(message); + } + + function getFormattedDate() { + var date = new Date(); + return date.getMonth() + "/" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); + } + + function sendToLogWindow(type, message, scriptFileName) { + var typeFormatted = ""; + if (type) { + typeFormatted = type + " - "; + } + fromScript("[" + getFormattedDate() + "] " + "[" + scriptFileName + "] " + typeFormatted + message); + } + + Connections { + target: ScriptDiscoveryService + onPrintedMessage: sendToLogWindow("", message, engineName); + onWarningMessage: sendToLogWindow("WARNING", message, engineName); + onErrorMessage: sendToLogWindow("ERROR", message, engineName); + onInfoMessage: sendToLogWindow("INFO", message, engineName); + } + + TextArea { + id: textArea + width: parent.width + height: parent.height + backgroundVisible: false + textColor: hifi.colors.white + text:"" + } + +} diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0738b463a4..be1db95c0a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5855,6 +5855,24 @@ void Application::toggleRunningScriptsWidget() const { //} } +void Application::showScriptLogs() { + auto tabletScriptingInterface = DependencyManager::get(); + auto tablet = dynamic_cast(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system")); + auto scriptEngines = DependencyManager::get(); + QUrl defaultScriptsLoc = defaultScriptsLocation(); + defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/debugging/debugWindow.js"); + + if (tablet->getToolbarMode()) { + scriptEngines->loadScript(defaultScriptsLoc.toString()); + } else { + QQuickItem* tabletRoot = tablet->getTabletRoot(); + if (!tabletRoot && !isHMDMode()) { + scriptEngines->loadScript(defaultScriptsLoc.toString()); + } else { + tablet->pushOntoStack("../../hifi/dialogs/TabletDebugWindow.qml"); + } + } +} void Application::showAssetServerWidget(QString filePath) { if (!DependencyManager::get()->getThisNodeCanWriteAssets()) { diff --git a/interface/src/Application.h b/interface/src/Application.h index f7af922148..8b59374aad 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -408,6 +408,7 @@ public slots: void loadLODToolsDialog(); void loadEntityStatisticsDialog(); void loadDomainConnectionDialog(); + void showScriptLogs(); private slots: void showDesktop(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 977c5817e9..de29020ab7 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -719,14 +719,8 @@ Menu::Menu() { }); essLogAction->setEnabled(nodeList->getThisNodeCanRez()); - action = addActionToQMenuAndActionHash(developerMenu, "Script Log (HMD friendly)..."); - connect(action, &QAction::triggered, [] { - auto scriptEngines = DependencyManager::get(); - QUrl defaultScriptsLoc = defaultScriptsLocation(); - defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/debugging/debugWindow.js"); - scriptEngines->loadScript(defaultScriptsLoc.toString()); - }); - + action = addActionToQMenuAndActionHash(developerMenu, "Script Log (HMD friendly)...", Qt::NoButton, + qApp, SLOT(showScriptLogs())); // Developer > Stats addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::Stats);