From d052dc25767483c5c1aaca84a8c0736bcd48f66a Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 6 Nov 2018 18:58:44 +0100 Subject: [PATCH] Remote canvas: UI fixes --- utils/fgqcanvas/applicationcontroller.cpp | 57 +++++++++++++++++++++++ utils/fgqcanvas/applicationcontroller.h | 30 ++++++++++++ utils/fgqcanvas/fgqcanvas_resources.qrc | 1 + utils/fgqcanvas/qml/CanvasFrame.qml | 16 +++++++ utils/fgqcanvas/qml/CanvasMenu.qml | 41 ++++++++++++++++ utils/fgqcanvas/qml/InputLine.qml | 5 ++ utils/fgqcanvas/qml/LoadSavePanel.qml | 3 ++ utils/fgqcanvas/qml/SnapshotsPanel.qml | 3 ++ utils/fgqcanvas/qml/VerticalTabPanel.qml | 8 +++- utils/fgqcanvas/qml/mainMenu.qml | 28 ++--------- 10 files changed, 167 insertions(+), 25 deletions(-) create mode 100644 utils/fgqcanvas/qml/CanvasMenu.qml diff --git a/utils/fgqcanvas/applicationcontroller.cpp b/utils/fgqcanvas/applicationcontroller.cpp index 4c6b1d8a0..48d1ed07a 100644 --- a/utils/fgqcanvas/applicationcontroller.cpp +++ b/utils/fgqcanvas/applicationcontroller.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "jsonutils.h" #include "canvasconnection.h" @@ -52,6 +54,14 @@ ApplicationController::ApplicationController(QObject *parent) setStatus(Idle); rebuildConfigData(); rebuildSnapshotData(); + + m_uiIdleTimer = new QTimer(this); + m_uiIdleTimer->setInterval(10 * 1000); + connect(m_uiIdleTimer, &QTimer::timeout, this, + &ApplicationController::onUIIdleTimeout); + m_uiIdleTimer->start(); + + qApp->installEventFilter(this); } ApplicationController::~ApplicationController() @@ -319,6 +329,14 @@ void ApplicationController::openCanvas(QString path) emit activeCanvasesChanged(); } +void ApplicationController::closeCanvas(CanvasConnection *canvas) +{ + Q_ASSERT(m_activeCanvases.indexOf(canvas) >= 0); + m_activeCanvases.removeOne(canvas); + canvas->deleteLater(); + emit activeCanvasesChanged(); +} + QString ApplicationController::host() const { return m_host; @@ -344,6 +362,14 @@ QNetworkAccessManager *ApplicationController::netAccess() const return m_netAccess; } +bool ApplicationController::showUI() const +{ + if (m_blockUIIdle) + return true; + + return m_showUI; +} + void ApplicationController::setHost(QString host) { if (m_host == host) @@ -407,6 +433,12 @@ void ApplicationController::onFinishedGetCanvasList() setStatus(SuccessfulQuery); } +void ApplicationController::onUIIdleTimeout() +{ + m_showUI = false; + emit showUIChanged(); +} + void ApplicationController::setStatus(ApplicationController::Status newStatus) { if (newStatus == m_status) @@ -498,3 +530,28 @@ QByteArray ApplicationController::createSnapshot(QString name) const return bytes; } + +bool ApplicationController::eventFilter(QObject* obj, QEvent* event) +{ + Q_UNUSED(obj); + switch (event->type()) { + case QEvent::MouseButtonPress: + case QEvent::TouchUpdate: + case QEvent::MouseMove: + case QEvent::TouchBegin: + case QEvent::KeyPress: + case QEvent::KeyRelease: + if (!m_showUI) { + m_showUI = true; + emit showUIChanged(); + } else { + m_uiIdleTimer->start(); + } + + break; + default: + break; + } + + return false; //process as normal +} diff --git a/utils/fgqcanvas/applicationcontroller.h b/utils/fgqcanvas/applicationcontroller.h index fcb2a70c4..e38201529 100644 --- a/utils/fgqcanvas/applicationcontroller.h +++ b/utils/fgqcanvas/applicationcontroller.h @@ -26,6 +26,7 @@ class CanvasConnection; class QWindow; +class QTimer; class ApplicationController : public QObject { @@ -46,6 +47,8 @@ class ApplicationController : public QObject Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(bool showUI READ showUI NOTIFY showUIChanged) + Q_PROPERTY(bool blockUIIdle READ blockUIIdle WRITE setBlockUIIdle NOTIFY blockUIIdleChanged) public: explicit ApplicationController(QObject *parent = nullptr); ~ApplicationController(); @@ -68,6 +71,7 @@ public: Q_INVOKABLE void saveConfigChanges(int index); Q_INVOKABLE void openCanvas(QString path); + Q_INVOKABLE void closeCanvas(CanvasConnection* canvas); Q_INVOKABLE void saveSnapshot(QString snapshotName); Q_INVOKABLE void restoreSnapshot(int index); @@ -104,6 +108,13 @@ public: return m_snapshots; } + bool showUI() const; + + bool blockUIIdle() const + { + return m_blockUIIdle; + } + signals: void hostChanged(QString host); @@ -119,13 +130,29 @@ signals: void snapshotListChanged(); + void showUIChanged(); + void blockUIIdleChanged(bool blockUIIdle); + public slots: void setHost(QString host); void setPort(unsigned int port); + void setBlockUIIdle(bool blockUIIdle) + { + if (m_blockUIIdle == blockUIIdle) + return; + + m_blockUIIdle = blockUIIdle; + emit blockUIIdleChanged(m_blockUIIdle); + } + +protected: + bool eventFilter(QObject* obj, QEvent* event) override; + private slots: void onFinishedGetCanvasList(); + void onUIIdleTimeout(); private: void setStatus(Status newStatus); @@ -155,6 +182,9 @@ private: Qt::WindowState m_windowState = Qt::WindowNoState; bool m_daemonMode = false; + bool m_showUI = true; + bool m_blockUIIdle = false; + QTimer* m_uiIdleTimer; }; #endif // APPLICATIONCONTROLLER_H diff --git a/utils/fgqcanvas/fgqcanvas_resources.qrc b/utils/fgqcanvas/fgqcanvas_resources.qrc index 7d5749f82..88e8e104e 100644 --- a/utils/fgqcanvas/fgqcanvas_resources.qrc +++ b/utils/fgqcanvas/fgqcanvas_resources.qrc @@ -9,5 +9,6 @@ qml/LoadSavePanel.qml qml/VerticalTabPanel.qml qml/SnapshotsPanel.qml + qml/CanvasMenu.qml diff --git a/utils/fgqcanvas/qml/CanvasFrame.qml b/utils/fgqcanvas/qml/CanvasFrame.qml index 67004593e..d834f9413 100644 --- a/utils/fgqcanvas/qml/CanvasFrame.qml +++ b/utils/fgqcanvas/qml/CanvasFrame.qml @@ -6,6 +6,8 @@ Item { property bool showDecorations: true property alias canvas: paintedDisplay.canvas property bool showUi: true + property bool showMenu: false + Component.onCompleted: { if (canvas) { @@ -74,6 +76,10 @@ Item { onReleased: { root.saveGeometry(); } + + onPressAndHold: { + root.showMenu = true; + } } Rectangle { @@ -108,6 +114,7 @@ Item { color: "orange" anchors.centerIn: parent text: "Canvas" + visible: !root.showMenu } Text { @@ -133,5 +140,14 @@ Item { color: "white" } + + CanvasMenu { + anchors.fill:parent + visible: root.showMenu + onMenuBack: root.showMenu = false + onCloseCanvas: _application.closeCanvas(canvas); + onReconnectCanvas: canvas.reconnect(); + } + } } diff --git a/utils/fgqcanvas/qml/CanvasMenu.qml b/utils/fgqcanvas/qml/CanvasMenu.qml new file mode 100644 index 000000000..bf009898d --- /dev/null +++ b/utils/fgqcanvas/qml/CanvasMenu.qml @@ -0,0 +1,41 @@ +import QtQuick 2.0 + +Item { + id: root + + signal menuBack(); + signal closeCanvas(); + signal reconnectCanvas(); + + Rectangle { + anchors.centerIn: parent + width: buttons.childrenRect.width + 20 + height: buttons.childrenRect.height + 20 + border.width: 1 + border.color: "orange" + color: "#5f5f5f" + + Column { + id: buttons + spacing: 30 + + Button { + label: qsTr("Back") + onClicked: root.menuBack(); + anchors.horizontalCenter: parent.horizontalCenter + } + + Button { + label: qsTr("Close") + onClicked: root.closeCanvas(); + anchors.horizontalCenter: parent.horizontalCenter + } + + Button { + label: qsTr("Reconnect") + onClicked: root.reconnectCanvas(); + anchors.horizontalCenter: parent.horizontalCenter + } + } // of buttons column + } +} diff --git a/utils/fgqcanvas/qml/InputLine.qml b/utils/fgqcanvas/qml/InputLine.qml index b2a90b7b8..0d8b3179e 100644 --- a/utils/fgqcanvas/qml/InputLine.qml +++ b/utils/fgqcanvas/qml/InputLine.qml @@ -39,6 +39,11 @@ Item { verticalCenter: parent.verticalCenter } + onActiveFocusChanged: { + if (activeFocus) { + selectAll(); + } + } verticalAlignment: Text.AlignVCenter diff --git a/utils/fgqcanvas/qml/LoadSavePanel.qml b/utils/fgqcanvas/qml/LoadSavePanel.qml index 402f0e2ef..31b464aa1 100644 --- a/utils/fgqcanvas/qml/LoadSavePanel.qml +++ b/utils/fgqcanvas/qml/LoadSavePanel.qml @@ -2,6 +2,8 @@ import QtQuick 2.0 import FlightGear 1.0 as FG Item { + id: root + signal requestPanelClose(); Rectangle { id: savePanel @@ -116,6 +118,7 @@ Item { anchors.fill: parent onClicked: { _application.restoreConfig(model.index) + root.requestPanelClose(); } drag.target: delegateFrame diff --git a/utils/fgqcanvas/qml/SnapshotsPanel.qml b/utils/fgqcanvas/qml/SnapshotsPanel.qml index ac92002a0..75b42fbb6 100644 --- a/utils/fgqcanvas/qml/SnapshotsPanel.qml +++ b/utils/fgqcanvas/qml/SnapshotsPanel.qml @@ -2,6 +2,8 @@ import QtQuick 2.0 import FlightGear 1.0 as FG Item { + id: root + signal requestPanelClose(); Rectangle { id: savePanel @@ -106,6 +108,7 @@ Item { anchors.fill: parent onClicked: { _application.restoreSnapshot(model.index); + root.requestPanelClose(); } drag.target: delegateFrame diff --git a/utils/fgqcanvas/qml/VerticalTabPanel.qml b/utils/fgqcanvas/qml/VerticalTabPanel.qml index 8d37a5f2e..c112f3fc5 100644 --- a/utils/fgqcanvas/qml/VerticalTabPanel.qml +++ b/utils/fgqcanvas/qml/VerticalTabPanel.qml @@ -26,9 +26,15 @@ Item { clip: true Loader { + id: loader anchors.fill: parent sourceComponent: (activeTab >= 0) ? tabs[activeTab] : null } + + Connections { + target: loader.item + onRequestPanelClose: root.activeTab = -1; + } } Rectangle { @@ -42,7 +48,7 @@ Item { MouseArea { id: splitterDrag height: parent.height - width: parent.width* 3 + width: parent.width * 25 drag.target: contentBox drag.axis: Drag.XAxis diff --git a/utils/fgqcanvas/qml/mainMenu.qml b/utils/fgqcanvas/qml/mainMenu.qml index 5002e9533..71d47b5fe 100644 --- a/utils/fgqcanvas/qml/mainMenu.qml +++ b/utils/fgqcanvas/qml/mainMenu.qml @@ -2,24 +2,21 @@ import QtQuick 2.0 import FlightGear 1.0 as FG Rectangle { - property bool uiVisible: true width: 1024 height: 768 color: "black" - property double __uiOpacity: uiVisible ? 1.0 : 0.0 + property double __uiOpacity: _application.showUI ? 1.0 : 0.0 property bool __uiVisible: true Behavior on __uiOpacity { SequentialAnimation { - ScriptAction { script: if (uiVisible) __uiVisible = true; } - NumberAnimation { duration: 250 } - ScriptAction { script: if (!uiVisible) __uiVisible = false; } + ScriptAction { script: if (_application.showUI) __uiVisible = true; } + NumberAnimation { duration: 400 } + ScriptAction { script: if (!_application.showUI) __uiVisible = false; } } } - Component.onCompleted: idleTimer.start(); - Image { opacity: __uiOpacity * 0.5 source: "qrc:///images/checkerboard" @@ -28,23 +25,6 @@ Rectangle { visible: __uiVisible } - MouseArea { - anchors.fill: parent - onClicked: { - uiVisible = !uiVisible; - } - - hoverEnabled: uiVisible - onMouseXChanged: idleTimer.restart() - onMouseYChanged: idleTimer.restart() - } - - Timer { - id: idleTimer - interval: 1000 * 10 - onTriggered: { uiVisible = false; } - } - Repeater { model: _application.activeCanvases delegate: CanvasFrame {