diff --git a/utils/fgqcanvas/applicationcontroller.cpp b/utils/fgqcanvas/applicationcontroller.cpp index 37f84a9b4..4c6b1d8a0 100644 --- a/utils/fgqcanvas/applicationcontroller.cpp +++ b/utils/fgqcanvas/applicationcontroller.cpp @@ -64,6 +64,13 @@ void ApplicationController::setWindow(QWindow *window) m_window = window; } +void ApplicationController::restoreWindowState() +{ + if (!m_window) + return; + m_window->setWindowState(m_windowState); +} + void ApplicationController::loadFromFile(QString path) { if (!QFile::exists(path)) { @@ -79,6 +86,11 @@ void ApplicationController::loadFromFile(QString path) restoreState(f.readAll()); } +void ApplicationController::setDaemonMode() +{ + m_daemonMode = true; +} + void ApplicationController::save(QString configName) { QDir d(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); @@ -440,12 +452,18 @@ void ApplicationController::restoreState(QByteArray bytes) m_window->setGeometry(r); } - m_window->setWindowState(static_cast(json.value("window-state").toInt())); + // we have to cache the state becuase it seems to be ignored + // before show is called(); + m_windowState = static_cast(json.value("window-state").toInt()); + m_window->setWindowState(m_windowState); } // background color for (auto c : json.value("canvases").toArray()) { auto cc = new CanvasConnection(this); + if (m_daemonMode) + cc->setAutoReconnect(); + cc->setNetworkAccess(m_netAccess); m_activeCanvases.append(cc); cc->restoreState(c.toObject()); diff --git a/utils/fgqcanvas/applicationcontroller.h b/utils/fgqcanvas/applicationcontroller.h index 26e2494f2..fcb2a70c4 100644 --- a/utils/fgqcanvas/applicationcontroller.h +++ b/utils/fgqcanvas/applicationcontroller.h @@ -52,8 +52,12 @@ public: void setWindow(QWindow* window); + void restoreWindowState(); + void loadFromFile(QString path); + void setDaemonMode(); + Q_INVOKABLE void query(); Q_INVOKABLE void cancelQuery(); Q_INVOKABLE void clearQuery(); @@ -146,7 +150,11 @@ private: QVariantList m_configs; QNetworkReply* m_query = nullptr; QVariantList m_snapshots; + QWindow* m_window = nullptr; + Qt::WindowState m_windowState = Qt::WindowNoState; + + bool m_daemonMode = false; }; #endif // APPLICATIONCONTROLLER_H diff --git a/utils/fgqcanvas/canvasconnection.cpp b/utils/fgqcanvas/canvasconnection.cpp index 8f34a398c..9f3ba6bda 100644 --- a/utils/fgqcanvas/canvasconnection.cpp +++ b/utils/fgqcanvas/canvasconnection.cpp @@ -41,6 +41,11 @@ CanvasConnection::CanvasConnection(QObject *parent) : QObject(parent) this, &CanvasConnection::onTextMessageReceived); m_destRect = QRectF(50, 50, 400, 400); + m_reconnectTimer = new QTimer(this); + m_reconnectTimer->setInterval(1000 * 10); + m_reconnectTimer->setSingleShot(true); + connect(m_reconnectTimer, &QTimer::timeout, + this, &CanvasConnection::reconnect); } CanvasConnection::~CanvasConnection() @@ -61,6 +66,11 @@ void CanvasConnection::setRootPropertyPath(QByteArray path) emit rootPathChanged(); } +void CanvasConnection::setAutoReconnect() +{ + m_autoReconnect = true; +} + QJsonObject CanvasConnection::saveState() const { QJsonObject json; @@ -104,6 +114,7 @@ void CanvasConnection::restoreSnapshot(QDataStream &ds) void CanvasConnection::reconnect() { + qDebug() << "starting connection attempt to:" << m_webSocketUrl; m_webSocket.open(m_webSocketUrl); setStatus(Connecting); } @@ -185,6 +196,7 @@ FGQCanvasFontCache *CanvasConnection::fontCache() const void CanvasConnection::onWebSocketConnected() { + qDebug() << Q_FUNC_INFO << m_webSocketUrl; m_localPropertyRoot.reset(new LocalProp{nullptr, NameIndexTuple("")}); setStatus(Connected); } @@ -272,10 +284,9 @@ void CanvasConnection::onWebSocketClosed() setStatus(Closed); - // if we're in automatic mode, start reconnection timer -// update state - - // ui->stack->setCurrentIndex(0); + if (m_autoReconnect) { + m_reconnectTimer->start(); + } } void CanvasConnection::setStatus(CanvasConnection::Status newStatus) diff --git a/utils/fgqcanvas/canvasconnection.h b/utils/fgqcanvas/canvasconnection.h index 79de7e394..3bc9a5b22 100644 --- a/utils/fgqcanvas/canvasconnection.h +++ b/utils/fgqcanvas/canvasconnection.h @@ -26,6 +26,7 @@ #include #include #include +#include class LocalProp; class QNetworkAccessManager; @@ -54,6 +55,8 @@ public: void setNetworkAccess(QNetworkAccessManager *dl); void setRootPropertyPath(QByteArray path); + void setAutoReconnect(); + enum Status { NotConnected, @@ -132,6 +135,9 @@ private: QWebSocket m_webSocket; QNetworkAccessManager* m_netAccess = nullptr; + QTimer* m_reconnectTimer = nullptr; + bool m_autoReconnect = false; + std::unique_ptr m_localPropertyRoot; QHash> idPropertyDict; Status m_status = NotConnected; diff --git a/utils/fgqcanvas/canvaspainteddisplay.cpp b/utils/fgqcanvas/canvaspainteddisplay.cpp index 0c01e657d..cc8d6a798 100644 --- a/utils/fgqcanvas/canvaspainteddisplay.cpp +++ b/utils/fgqcanvas/canvaspainteddisplay.cpp @@ -33,7 +33,6 @@ CanvasPaintedDisplay::CanvasPaintedDisplay(QQuickItem* parent) : CanvasPaintedDisplay::~CanvasPaintedDisplay() { - qDebug() << "did destory canvas painted"; } void CanvasPaintedDisplay::paint(QPainter *painter) @@ -64,7 +63,7 @@ void CanvasPaintedDisplay::setCanvas(CanvasConnection *canvas) if (m_connection) { disconnect(m_connection, nullptr, this, nullptr); - m_rootElement.reset(); + delete m_rootElement; } m_connection = canvas; @@ -84,29 +83,35 @@ void CanvasPaintedDisplay::setCanvas(CanvasConnection *canvas) void CanvasPaintedDisplay::onConnectionDestroyed() { + qDebug() << "saw connection destroyed"; m_connection = nullptr; - emit canvasChanged(m_connection); + delete m_rootElement; - m_rootElement.reset(); + emit canvasChanged(m_connection); } void CanvasPaintedDisplay::onConnectionStatusChanged() { if ((m_connection->status() == CanvasConnection::Connected) || - (m_connection->status() == CanvasConnection::Snapshot)) + (m_connection->status() == CanvasConnection::Snapshot)) { buildElements(); + } else { + qDebug() << Q_FUNC_INFO << "clearing root element"; + delete m_rootElement; + update(); } } void CanvasPaintedDisplay::buildElements() { - m_rootElement.reset(new FGCanvasGroup(nullptr, m_connection->propertyRoot())); + qDebug() << Q_FUNC_INFO; + m_rootElement = new FGCanvasGroup(nullptr, m_connection->propertyRoot()); // this is important to elements can discover their connection // by walking their parent chain m_rootElement->setParent(m_connection); - connect(m_rootElement.get(), &FGCanvasGroup::canvasSizeChanged, + connect(m_rootElement, &FGCanvasGroup::canvasSizeChanged, this, &CanvasPaintedDisplay::onCanvasSizeChanged); onCanvasSizeChanged(); diff --git a/utils/fgqcanvas/canvaspainteddisplay.h b/utils/fgqcanvas/canvaspainteddisplay.h index 31bdff856..6f5f3cc72 100644 --- a/utils/fgqcanvas/canvaspainteddisplay.h +++ b/utils/fgqcanvas/canvaspainteddisplay.h @@ -21,6 +21,7 @@ #include #include +#include class CanvasConnection; class FGCanvasGroup; @@ -67,7 +68,7 @@ private: void buildElements(); CanvasConnection* m_connection = nullptr; - std::unique_ptr m_rootElement; + QPointer m_rootElement; // QQuickItem* m_rootItem = nullptr; QSizeF m_sourceSize; }; diff --git a/utils/fgqcanvas/fgcanvaselement.cpp b/utils/fgqcanvas/fgcanvaselement.cpp index 0a23521c3..e842a5603 100644 --- a/utils/fgqcanvas/fgcanvaselement.cpp +++ b/utils/fgqcanvas/fgcanvaselement.cpp @@ -102,7 +102,9 @@ FGCanvasElement::FGCanvasElement(FGCanvasGroup* pr, LocalProp* prop) : void FGCanvasElement::onPropDestroyed() { doDestroy(); - const_cast(_parent)->removeChild(this); + if (_parent) { + const_cast(_parent)->removeChild(this); + } deleteLater(); } diff --git a/utils/fgqcanvas/fgcanvastext.cpp b/utils/fgqcanvas/fgcanvastext.cpp index 5fa1bd5d5..1f60c3e63 100644 --- a/utils/fgqcanvas/fgcanvastext.cpp +++ b/utils/fgqcanvas/fgcanvastext.cpp @@ -253,7 +253,6 @@ void FGCanvasText::markStyleDirty() void FGCanvasText::doDestroy() { - qDebug() << Q_FUNC_INFO; delete _quickItem; } diff --git a/utils/fgqcanvas/main.cpp b/utils/fgqcanvas/main.cpp index a33e6fd38..a3ccf20d7 100644 --- a/utils/fgqcanvas/main.cpp +++ b/utils/fgqcanvas/main.cpp @@ -49,6 +49,7 @@ int main(int argc, char *argv[]) quickView.rootContext()->setContextProperty("_application", &appController); if (argc > 1) { + appController.setDaemonMode(); appController.loadFromFile(QString::fromLocal8Bit(argv[1])); } else { quickView.setWidth(1024); @@ -59,6 +60,8 @@ int main(int argc, char *argv[]) quickView.setResizeMode(QQuickView::SizeRootObjectToView); quickView.show(); + appController.restoreWindowState(); + int result = a.exec(); return result; diff --git a/utils/fgqcanvas/qml/mainMenu.qml b/utils/fgqcanvas/qml/mainMenu.qml index 5dd5d3a2a..7b12e0b87 100644 --- a/utils/fgqcanvas/qml/mainMenu.qml +++ b/utils/fgqcanvas/qml/mainMenu.qml @@ -31,6 +31,16 @@ Rectangle { onClicked: { uiVisible = !uiVisible; } + + hoverEnabled: uiVisible + onMouseXChanged: idleTimer.restart() + onMouseYChanged: idleTimer.restart() + } + + Timer { + id: idleTimer + interval: 1000 * 10 + onTriggered: { uiVisible = false; } } Repeater { @@ -65,4 +75,6 @@ Rectangle { SnapshotsPanel { } } + + }