Remote canvas: UI fixes
This commit is contained in:
parent
3b3c99777d
commit
d052dc2576
10 changed files with 167 additions and 25 deletions
|
@ -33,6 +33,8 @@
|
|||
#include <QRegularExpression>
|
||||
#include <QDataStream>
|
||||
#include <QWindow>
|
||||
#include <QTimer>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -9,5 +9,6 @@
|
|||
<file>qml/LoadSavePanel.qml</file>
|
||||
<file>qml/VerticalTabPanel.qml</file>
|
||||
<file>qml/SnapshotsPanel.qml</file>
|
||||
<file>qml/CanvasMenu.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
41
utils/fgqcanvas/qml/CanvasMenu.qml
Normal file
41
utils/fgqcanvas/qml/CanvasMenu.qml
Normal file
|
@ -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
|
||||
}
|
||||
}
|
|
@ -39,6 +39,11 @@ Item {
|
|||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
onActiveFocusChanged: {
|
||||
if (activeFocus) {
|
||||
selectAll();
|
||||
}
|
||||
}
|
||||
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue