From 02ae0e0db18b29b10c1877e4591f42087be39c7a Mon Sep 17 00:00:00 2001 From: Alex Spataru Date: Sun, 14 Nov 2021 19:52:41 -0600 Subject: [PATCH] Windows-specific improvments --- Serial-Studio.pro | 1 + assets/qml/FramelessWindow/CustomWindow.qml | 1 + assets/qml/FramelessWindow/Titlebar.qml | 21 +- assets/qml/Panes/Setup.qml | 74 +----- assets/qml/PlatformDependent/Menubar.qml | 4 +- assets/qml/Widgets/LED.qml | 4 +- assets/qml/Windows/MainWindow.qml | 108 +++++++-- assets/themes/3_MathWorks.json | 4 +- src/MQTT/Client.cpp | 243 ++++++++++---------- 9 files changed, 222 insertions(+), 238 deletions(-) diff --git a/Serial-Studio.pro b/Serial-Studio.pro index 2147327c..15af2009 100644 --- a/Serial-Studio.pro +++ b/Serial-Studio.pro @@ -99,6 +99,7 @@ CONFIG += silent # Unity build #----------------------------------------------------------------------------------------- +CONFIG += unity_build CONFIG(unity_build) { CONFIG += ltcg # Enable linker optimization DEFINES += UNITY_BUILD=1 # Enable unity build diff --git a/assets/qml/FramelessWindow/CustomWindow.qml b/assets/qml/FramelessWindow/CustomWindow.qml index a3ece6fb..83d374a4 100644 --- a/assets/qml/FramelessWindow/CustomWindow.qml +++ b/assets/qml/FramelessWindow/CustomWindow.qml @@ -51,6 +51,7 @@ Window { property bool firstChange: true property bool isMaximized: false property bool isMinimized: false + property alias showIcon: _title.showIcon property alias isFullscreen: _title.isFullscreen readonly property int customFlags: Qt.Window | Qt.CustomizeWindowHint | diff --git a/assets/qml/FramelessWindow/Titlebar.qml b/assets/qml/FramelessWindow/Titlebar.qml index d0f57363..7227f56e 100644 --- a/assets/qml/FramelessWindow/Titlebar.qml +++ b/assets/qml/FramelessWindow/Titlebar.qml @@ -42,6 +42,7 @@ Rectangle { // Window controls // property Window window + property bool showIcon: false property bool closeEnabled: true property bool isFullscreen: false property bool minimizeEnabled: true @@ -81,14 +82,11 @@ Rectangle { // Calculations for Windows/Linux layout else { - // Default spacer margin = 10 - // Add space for fullscreen button - if (fullscreenEnabled) - margin += 18 + if (root.showIcon) + margin += 24 - // Add extra spacer if icon is visible if (margin > 10) margin += 8 } @@ -305,16 +303,12 @@ Rectangle { } WindowButton { - width: 16 - height: 16 - rotation: 90 + visible: root.showIcon + enabled: root.showIcon textColor: root.textColor - visible: root.fullscreenEnabled - enabled: root.fullscreenEnabled + highlightColor: root.textColor Layout.alignment: Qt.AlignVCenter - onClicked: root.toggleFullscreen() - highlightColor: Cpp_ThemeManager.highlight - name: root.isFullscreen ? "restore" : "fullscreen" + source: "qrc:/images/icon-window.svg" } Item { @@ -359,7 +353,6 @@ Rectangle { window.close() root.closed() } - } Item { diff --git a/assets/qml/Panes/Setup.qml b/assets/qml/Panes/Setup.qml index bdcff8af..c0c5d7e7 100644 --- a/assets/qml/Panes/Setup.qml +++ b/assets/qml/Panes/Setup.qml @@ -369,82 +369,10 @@ Item { } // - // RX/TX LEDs + // Vertical spacer // Item { - Layout.fillWidth: true Layout.fillHeight: true - - RowLayout { - spacing: app.spacing - - anchors { - left: parent.left - right: parent.right - verticalCenter: parent.verticalCenter - } - - Item { - Layout.fillWidth: true - } - - Widgets.LED { - id: _rx - enabled: false - Layout.alignment: Qt.AlignVCenter - - Connections { - target: Cpp_IO_Manager - function onRx() { - _rx.flash() - } - } - } - - Label { - text: "RX" - font.bold: true - font.pixelSize: 18 - font.family: app.monoFont - Layout.alignment: Qt.AlignVCenter - color: _rx.enabled ? Cpp_ThemeManager.ledEnabled : Cpp_ThemeManager.ledDisabled - } - - Widgets.Icon { - width: 32 - height: 32 - source: "qrc:/icons/ethernet.svg" - Layout.alignment: Qt.AlignVCenter - color: Cpp_ThemeManager.ledDisabled - } - - Label { - text: "TX" - font.bold: true - font.pixelSize: 18 - font.family: app.monoFont - Layout.alignment: Qt.AlignVCenter - color: _tx.enabled ? Cpp_ThemeManager.ledEnabled : Cpp_ThemeManager.ledDisabled - } - - Widgets.LED { - id: _tx - enabled: false - layoutDirection: Qt.RightToLeft - Layout.alignment: Qt.AlignVCenter - - Connections { - target: Cpp_IO_Manager - function onTx() { - _tx.flash() - } - } - } - - Item { - Layout.fillWidth: true - } - } } } } diff --git a/assets/qml/PlatformDependent/Menubar.qml b/assets/qml/PlatformDependent/Menubar.qml index 55ebfffb..6a7417ed 100644 --- a/assets/qml/PlatformDependent/Menubar.qml +++ b/assets/qml/PlatformDependent/Menubar.qml @@ -196,8 +196,8 @@ MenuBar { DecentMenuItem { sequence: "f11" onTriggered: app.mainWindow.toggleFullscreen() - text: app.mainWindow.fullScreen ? qsTr("Exit full screen") : - qsTr("Enter full screen") + text: app.mainWindow.isFullscreen ? qsTr("Exit full screen") : + qsTr("Enter full screen") } } diff --git a/assets/qml/Widgets/LED.qml b/assets/qml/Widgets/LED.qml index 969d95ca..71046fe3 100644 --- a/assets/qml/Widgets/LED.qml +++ b/assets/qml/Widgets/LED.qml @@ -62,8 +62,8 @@ RowLayout { // Rectangle { id: _dot - width: 18 - height: 18 + width: 14 + height: 14 radius: width / 2 Layout.alignment: Qt.AlignVCenter color: root.enabled ? Cpp_ThemeManager.ledEnabled : Cpp_ThemeManager.ledDisabled diff --git a/assets/qml/Windows/MainWindow.qml b/assets/qml/Windows/MainWindow.qml index 2880e457..86dd2548 100644 --- a/assets/qml/Windows/MainWindow.qml +++ b/assets/qml/Windows/MainWindow.qml @@ -45,6 +45,7 @@ FramelessWindow.CustomWindow { // // Customize window border // + showIcon: true borderWidth: 1 fullscreenEnabled: true borderColor: Qt.darker(Cpp_ThemeManager.toolbarGradient2, 1.5) @@ -167,12 +168,8 @@ FramelessWindow.CustomWindow { // Startup code // Component.onCompleted: { - // Load welcome guide terminal.showWelcomeGuide() - - // Display the window & check for updates in 500 ms (we do this so that - // we wait for the window to read settings before showing it) - timer.start() + root.showMainWindow() } // @@ -223,15 +220,6 @@ FramelessWindow.CustomWindow { property alias autoUpdater: root.automaticUpdates } - // - // Startup timer - // - Timer { - id: timer - interval: 500 - onTriggered: root.showMainWindow() - } - // // macOS menubar loader // @@ -247,11 +235,6 @@ FramelessWindow.CustomWindow { RowLayout { spacing: app.spacing height: titlebar.height - opacity: enabled ? 1 : 0 - enabled: !root.showMacControls || isFullscreen - visible: !root.showMacControls || isFullscreen - - Behavior on opacity {NumberAnimation{}} anchors { top: parent.top @@ -262,17 +245,98 @@ FramelessWindow.CustomWindow { topMargin: root.shadowMargin + (!root.showMacControls ? 1 : 0) } + // + // Menubar + // PlatformDependent.Menubar { id: menubar - opacity: 0.8 + opacity: enabled ? 0.8 : 0 Layout.alignment: Qt.AlignVCenter + enabled: !root.showMacControls || isFullscreen + visible: !root.showMacControls || isFullscreen + + Behavior on opacity {NumberAnimation{}} } - // Leaving this layout for future usage... - + // + // Spacer + // Item { Layout.fillWidth: true } + + // + // RX LED + // + LED { + id: _rx + enabled: false + Layout.alignment: Qt.AlignVCenter + + Connections { + target: Cpp_IO_Manager + function onRx() { + _rx.flash() + } + } + } + + // + // RX label + // + Label { + text: "RX" + font.bold: true + font.family: app.monoFont + Layout.alignment: Qt.AlignVCenter + color: _rx.enabled ? Cpp_ThemeManager.ledEnabled : Cpp_ThemeManager.ledDisabled + } + + // + // RX/TX middleman icon + // + Icon { + width: 24 + height: 24 + source: "qrc:/icons/ethernet.svg" + Layout.alignment: Qt.AlignVCenter + color: Cpp_ThemeManager.ledDisabled + } + + // + // TX Label + // + Label { + text: "TX" + font.bold: true + font.family: app.monoFont + Layout.alignment: Qt.AlignVCenter + color: _tx.enabled ? Cpp_ThemeManager.ledEnabled : Cpp_ThemeManager.ledDisabled + } + + // + // TX LED + // + LED { + id: _tx + enabled: false + layoutDirection: Qt.RightToLeft + Layout.alignment: Qt.AlignVCenter + + Connections { + target: Cpp_IO_Manager + function onTx() { + _tx.flash() + } + } + } + + // + // Spacer + // + Item { + width: app.spacing + } } // diff --git a/assets/themes/3_MathWorks.json b/assets/themes/3_MathWorks.json index 10c529af..2f55bb6d 100644 --- a/assets/themes/3_MathWorks.json +++ b/assets/themes/3_MathWorks.json @@ -34,8 +34,8 @@ "alternativeHighlight":"#53ab27", "setupPanelBackground":"#e8e8e8", "paneWindowBackground":"#f1f1f1", - "ledEnabled":"#0072C3", - "ledDisabled":"#686868", + "ledEnabled":"#fe696e", + "ledDisabled":"#0072C3", "csvCheckbox":"#2e895c", "connectButtonChecked":"#fe696e", "connectButtonUnchecked":"#26cd40", diff --git a/src/MQTT/Client.cpp b/src/MQTT/Client.cpp index e288ab95..2efd1b10 100644 --- a/src/MQTT/Client.cpp +++ b/src/MQTT/Client.cpp @@ -118,15 +118,15 @@ int Client::mqttVersion() const { switch (m_client.version()) { - case QMQTT::V3_1_0: - return 0; - break; - case QMQTT::V3_1_1: - return 1; - break; - default: - return -1; - break; + case QMQTT::V3_1_0: + return 0; + break; + case QMQTT::V3_1_1: + return 1; + break; + default: + return -1; + break; } } @@ -206,8 +206,8 @@ StringList Client::qosLevels() const // clang-format off return StringList { tr("0: At most once"), - tr("1: At least once"), - tr("2: Exactly once") + tr("1: At least once"), + tr("2: Exactly once") }; // clang-format on } @@ -235,12 +235,12 @@ StringList Client::sslProtocols() const { return StringList { tr("System default"), - "TLS v1.0", - "TLS v1.1", - "TLS v1.2", - "DTLS v1.0", - "DTLS v1.2", - "DTLS v1.3" + "TLS v1.0", + "TLS v1.1", + "TLS v1.2", + "DTLS v1.0", + "DTLS v1.2", + "DTLS v1.3" }; } @@ -277,11 +277,8 @@ void Client::disconnectFromHost() */ void Client::setQos(const quint8 qos) { - if (qos >= 0 && qos <= 2) - { - m_client.setWillQos(qos); - emit qosChanged(); - } + m_client.setWillQos(qos); + emit qosChanged(); } /** @@ -378,14 +375,14 @@ void Client::setMqttVersion(const int versionIndex) { switch (versionIndex) { - case 0: - m_client.setVersion(QMQTT::V3_1_0); - break; - case 1: - m_client.setVersion(QMQTT::V3_1_1); - break; - default: - break; + case 0: + m_client.setVersion(QMQTT::V3_1_0); + break; + case 1: + m_client.setVersion(QMQTT::V3_1_1); + break; + default: + break; } emit mqttVersionChanged(); @@ -467,99 +464,99 @@ void Client::onError(const QMQTT::ClientError error) switch (error) { - case QMQTT::UnknownError: - str = tr("Unknown error"); - break; - case QMQTT::SocketConnectionRefusedError: - str = tr("Connection refused"); - break; - case QMQTT::SocketRemoteHostClosedError: - str = tr("Remote host closed the connection"); - break; - case QMQTT::SocketHostNotFoundError: - str = tr("Host not found"); - break; - case QMQTT::SocketAccessError: - str = tr("Socket access error"); - break; - case QMQTT::SocketResourceError: - str = tr("Socket resource error"); - break; - case QMQTT::SocketTimeoutError: - str = tr("Socket timeout"); - break; - case QMQTT::SocketDatagramTooLargeError: - str = tr("Socket datagram too large"); - break; - case QMQTT::SocketNetworkError: - str = tr("Network error"); - break; - case QMQTT::SocketAddressInUseError: - str = tr("Address in use"); - break; - case QMQTT::SocketAddressNotAvailableError: - str = tr("Address not available"); - break; - case QMQTT::SocketUnsupportedSocketOperationError: - str = tr("Unsupported socket operation"); - break; - case QMQTT::SocketUnfinishedSocketOperationError: - str = tr("Unfinished socket operation"); - break; - case QMQTT::SocketProxyAuthenticationRequiredError: - str = tr("Proxy authentication required"); - break; - case QMQTT::SocketSslHandshakeFailedError: - str = tr("SSL handshake failed"); - break; - case QMQTT::SocketProxyConnectionRefusedError: - str = tr("Proxy connection refused"); - break; - case QMQTT::SocketProxyConnectionClosedError: - str = tr("Proxy connection closed"); - break; - case QMQTT::SocketProxyConnectionTimeoutError: - str = tr("Proxy connection timeout"); - break; - case QMQTT::SocketProxyNotFoundError: - str = tr("Proxy not found"); - break; - case QMQTT::SocketProxyProtocolError: - str = tr("Proxy protocol error"); - break; - case QMQTT::SocketOperationError: - str = tr("Operation error"); - break; - case QMQTT::SocketSslInternalError: - str = tr("SSL internal error"); - break; - case QMQTT::SocketSslInvalidUserDataError: - str = tr("Invalid SSL user data"); - break; - case QMQTT::SocketTemporaryError: - str = tr("Socket temprary error"); - break; - case QMQTT::MqttUnacceptableProtocolVersionError: - str = tr("Unacceptable MQTT protocol"); - break; - case QMQTT::MqttIdentifierRejectedError: - str = tr("MQTT identifier rejected"); - break; - case QMQTT::MqttServerUnavailableError: - str = tr("MQTT server unavailable"); - break; - case QMQTT::MqttBadUserNameOrPasswordError: - str = tr("Bad MQTT username or password"); - break; - case QMQTT::MqttNotAuthorizedError: - str = tr("MQTT authorization error"); - break; - case QMQTT::MqttNoPingResponse: - str = tr("MQTT no ping response"); - break; - default: - str = ""; - break; + case QMQTT::UnknownError: + str = tr("Unknown error"); + break; + case QMQTT::SocketConnectionRefusedError: + str = tr("Connection refused"); + break; + case QMQTT::SocketRemoteHostClosedError: + str = tr("Remote host closed the connection"); + break; + case QMQTT::SocketHostNotFoundError: + str = tr("Host not found"); + break; + case QMQTT::SocketAccessError: + str = tr("Socket access error"); + break; + case QMQTT::SocketResourceError: + str = tr("Socket resource error"); + break; + case QMQTT::SocketTimeoutError: + str = tr("Socket timeout"); + break; + case QMQTT::SocketDatagramTooLargeError: + str = tr("Socket datagram too large"); + break; + case QMQTT::SocketNetworkError: + str = tr("Network error"); + break; + case QMQTT::SocketAddressInUseError: + str = tr("Address in use"); + break; + case QMQTT::SocketAddressNotAvailableError: + str = tr("Address not available"); + break; + case QMQTT::SocketUnsupportedSocketOperationError: + str = tr("Unsupported socket operation"); + break; + case QMQTT::SocketUnfinishedSocketOperationError: + str = tr("Unfinished socket operation"); + break; + case QMQTT::SocketProxyAuthenticationRequiredError: + str = tr("Proxy authentication required"); + break; + case QMQTT::SocketSslHandshakeFailedError: + str = tr("SSL handshake failed"); + break; + case QMQTT::SocketProxyConnectionRefusedError: + str = tr("Proxy connection refused"); + break; + case QMQTT::SocketProxyConnectionClosedError: + str = tr("Proxy connection closed"); + break; + case QMQTT::SocketProxyConnectionTimeoutError: + str = tr("Proxy connection timeout"); + break; + case QMQTT::SocketProxyNotFoundError: + str = tr("Proxy not found"); + break; + case QMQTT::SocketProxyProtocolError: + str = tr("Proxy protocol error"); + break; + case QMQTT::SocketOperationError: + str = tr("Operation error"); + break; + case QMQTT::SocketSslInternalError: + str = tr("SSL internal error"); + break; + case QMQTT::SocketSslInvalidUserDataError: + str = tr("Invalid SSL user data"); + break; + case QMQTT::SocketTemporaryError: + str = tr("Socket temprary error"); + break; + case QMQTT::MqttUnacceptableProtocolVersionError: + str = tr("Unacceptable MQTT protocol"); + break; + case QMQTT::MqttIdentifierRejectedError: + str = tr("MQTT identifier rejected"); + break; + case QMQTT::MqttServerUnavailableError: + str = tr("MQTT server unavailable"); + break; + case QMQTT::MqttBadUserNameOrPasswordError: + str = tr("Bad MQTT username or password"); + break; + case QMQTT::MqttNotAuthorizedError: + str = tr("MQTT authorization error"); + break; + case QMQTT::MqttNoPingResponse: + str = tr("MQTT no ping response"); + break; + default: + str = ""; + break; } if (!str.isEmpty())