From 6670cd14b6e5a3f192045bd2826333047eaed0a9 Mon Sep 17 00:00:00 2001 From: Emeric Date: Tue, 1 Aug 2023 15:43:28 +0200 Subject: [PATCH] Various bugfixes --- qml/components/ActionMenuFixed.qml | 367 +++++++++--------- qml/components_generic/ButtonCompactable.qml | 17 +- qml/components_generic/ButtonWireframe.qml | 11 +- .../ButtonWireframeIcon.qml | 9 +- .../ButtonWireframeIconCentered.qml | 9 +- src/DeviceManager.cpp | 4 +- src/DeviceManager_nearby.cpp | 19 +- 7 files changed, 215 insertions(+), 221 deletions(-) diff --git a/qml/components/ActionMenuFixed.qml b/qml/components/ActionMenuFixed.qml index 6a5af1a6..13569fe2 100644 --- a/qml/components/ActionMenuFixed.qml +++ b/qml/components/ActionMenuFixed.qml @@ -1,29 +1,32 @@ -import QtQuick -import QtQuick.Controls +import QtQuick 2.15 +import QtQuick.Controls.impl 2.15 +import QtQuick.Templates 2.15 as T import ThemeEngine 1.0 -Popup { +T.Popup { id: actionMenu - width: 200 + implicitWidth: 200 + implicitHeight: contentColumn.height + padding: 0 margins: 0 - parent: Overlay.overlay modal: true dim: false focus: isMobile - closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside - - property int layoutDirection: Qt.RightToLeft - - signal menuSelected(var index) + closePolicy: T.Popup.CloseOnEscape | T.Popup.CloseOnPressOutside + parent: Overlay.overlay property bool partonevisible: (actionUpdate.visible || actionRealtime.visible) property bool parttwovisible: (actionHistoryRefresh.visible || actionHistoryClear.visible) property bool partthreevisible: (actionLed.visible || actionWatering.visible || actionGraphMode.visible || actionShowSettings.visible) + property int layoutDirection: Qt.RightToLeft + + signal menuSelected(var index) + //////////////////////////////////////////////////////////////////////////// enter: Transition { NumberAnimation { property: "opacity"; from: 0.0; to: 1.0; duration: 133; } } @@ -40,204 +43,206 @@ Popup { //////////////////////////////////////////////////////////////////////////// - Column { - anchors.left: parent.left - anchors.right: parent.right - - topPadding: 8 - bottomPadding: 8 - spacing: 4 - - //////// - - ActionMenuItem { - id: actionUpdate + contentItem: Item { + Column { + id: contentColumn width: parent.width - index: 0 - text: qsTr("Update data") - source: "qrc:/assets/icons_material/baseline-refresh-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasBluetoothConnection)) + topPadding: 8 + bottomPadding: 8 + spacing: 4 - onClicked: { - deviceRefreshButtonClicked() - menuSelected(index) - close() - } - } + //////// - ActionMenuItem { - id: actionRealtime - width: parent.width + ActionMenuItem { + id: actionUpdate + width: parent.width - index: 1 - text: qsTr("Real time data") - source: "qrc:/assets/icons_material/duotone-update-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasRealTime)) + index: 0 + text: qsTr("Update data") + source: "qrc:/assets/icons_material/baseline-refresh-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasBluetoothConnection)) - onClicked: { - deviceRefreshRealtimeButtonClicked() - menuSelected(index) - close() + onClicked: { + deviceRefreshButtonClicked() + menuSelected(index) + close() + } } - } - - //////// - ListSeparatorPadded { - anchors.leftMargin: Theme.componentMargin - anchors.rightMargin: Theme.componentMargin - height: 9 - visible: (partonevisible && parttwovisible) - } - - ActionMenuItem { - id: actionHistoryRefresh - width: parent.width - - index: 2 - text: qsTr("Update history") - source: "qrc:/assets/icons_material/duotone-date_range-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasHistory)) - - onClicked: { - deviceRefreshHistoryButtonClicked() - menuSelected(index) - close() + ActionMenuItem { + id: actionRealtime + width: parent.width + + index: 1 + text: qsTr("Real time data") + source: "qrc:/assets/icons_material/duotone-update-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasRealTime)) + + onClicked: { + deviceRefreshRealtimeButtonClicked() + menuSelected(index) + close() + } } - } - - ActionMenuItem { - id: actionHistoryClear - width: parent.width - index: 3 - text: qsTr("Clear history") - source: "qrc:/assets/icons_material/duotone-date_clear-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasHistory)) + //////// - onClicked: { - deviceClearButtonClicked() - menuSelected(index) - close() + ListSeparatorPadded { + anchors.leftMargin: Theme.componentMargin + anchors.rightMargin: Theme.componentMargin + height: 9 + visible: (partonevisible && parttwovisible) } - } - - //////// - - ListSeparatorPadded { - anchors.leftMargin: Theme.componentMargin - anchors.rightMargin: Theme.componentMargin - height: 9 - visible: ((partonevisible || parttwovisible) && partthreevisible) - } - - ActionMenuItem { - id: actionLed - width: parent.width - index: 8 - text: qsTr("Blink LED") - source: "qrc:/assets/icons_material/duotone-emoji_objects-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasLED)) - - onClicked: { - deviceLedButtonClicked() - menuSelected(index) - close() + ActionMenuItem { + id: actionHistoryRefresh + width: parent.width + + index: 2 + text: qsTr("Update history") + source: "qrc:/assets/icons_material/duotone-date_range-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasHistory)) + + onClicked: { + deviceRefreshHistoryButtonClicked() + menuSelected(index) + close() + } } - } - - ActionMenuItem { - id: actionWatering - width: parent.width - - index: 9 - text: qsTr("Watering") - source: "qrc:/assets/icons_material/duotone-local_drink-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasWaterTank)) - onClicked: { - deviceWateringButtonClicked() - menuSelected(index) - close() + ActionMenuItem { + id: actionHistoryClear + width: parent.width + + index: 3 + text: qsTr("Clear history") + source: "qrc:/assets/icons_material/duotone-date_clear-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasHistory)) + + onClicked: { + deviceClearButtonClicked() + menuSelected(index) + close() + } } - } - ActionMenuItem { - id: actionCalibrate - width: parent.width - - index: 10 - text: qsTr("Calibrate sensor") - source: "qrc:/assets/icons_material/duotone-model_training-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasCalibration)) + //////// - onClicked: { - deviceCalibrateButtonClicked() - menuSelected(index) - close() + ListSeparatorPadded { + anchors.leftMargin: Theme.componentMargin + anchors.rightMargin: Theme.componentMargin + height: 9 + visible: ((partonevisible || parttwovisible) && partthreevisible) } - } - ActionMenuItem { - id: actionGraphMode - width: parent.width - - index: 16 - text: qsTr("Switch graph") - layoutDirection: actionMenu.layoutDirection - visible: (appContent.state === "DeviceThermometer") - source: (settingsManager.graphThermometer === "minmax") ? - "qrc:/assets/icons_material/duotone-insert_chart-24px.svg" : - "qrc:/assets/icons_material/baseline-timeline-24px.svg" - - onClicked: { - if (settingsManager.graphThermometer === "minmax") settingsManager.graphThermometer = "lines" - else settingsManager.graphThermometer = "minmax" - menuSelected(index) - close() + ActionMenuItem { + id: actionLed + width: parent.width + + index: 8 + text: qsTr("Blink LED") + source: "qrc:/assets/icons_material/duotone-emoji_objects-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasLED)) + + onClicked: { + deviceLedButtonClicked() + menuSelected(index) + close() + } } - } - ActionMenuItem { - id: actionShowSettings - width: parent.width - - index: 17 - text: qsTr("Sensor infos") - source: "qrc:/assets/icons_material/duotone-memory-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (appContent.state === "DeviceThermometer" || appContent.state === "DeviceEnvironmental") + ActionMenuItem { + id: actionWatering + width: parent.width + + index: 9 + text: qsTr("Watering") + source: "qrc:/assets/icons_material/duotone-local_drink-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasWaterTank)) + + onClicked: { + deviceWateringButtonClicked() + menuSelected(index) + close() + } + } - onClicked: { - deviceSettingsButtonClicked() - menuSelected(index) - close() + ActionMenuItem { + id: actionCalibrate + width: parent.width + + index: 10 + text: qsTr("Calibrate sensor") + source: "qrc:/assets/icons_material/duotone-model_training-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasCalibration)) + + onClicked: { + deviceCalibrateButtonClicked() + menuSelected(index) + close() + } } - } - ActionMenuItem { - id: actionReboot - width: parent.width + ActionMenuItem { + id: actionGraphMode + width: parent.width + + index: 16 + text: qsTr("Switch graph") + layoutDirection: actionMenu.layoutDirection + visible: (appContent.state === "DeviceThermometer") + source: (settingsManager.graphThermometer === "minmax") ? + "qrc:/assets/icons_material/duotone-insert_chart-24px.svg" : + "qrc:/assets/icons_material/baseline-timeline-24px.svg" + + onClicked: { + if (settingsManager.graphThermometer === "minmax") settingsManager.graphThermometer = "lines" + else settingsManager.graphThermometer = "minmax" + menuSelected(index) + close() + } + } - index: 32 - text: qsTr("Reboot sensor") - source: "qrc:/assets/icons_material/baseline-refresh-24px.svg" - layoutDirection: actionMenu.layoutDirection - visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasReboot)) + ActionMenuItem { + id: actionShowSettings + width: parent.width + + index: 17 + text: qsTr("Sensor infos") + source: "qrc:/assets/icons_material/duotone-memory-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (appContent.state === "DeviceThermometer" || appContent.state === "DeviceEnvironmental") + + onClicked: { + deviceSettingsButtonClicked() + menuSelected(index) + close() + } + } - onClicked: { - deviceRebootButtonClicked() - menuSelected(index) - close() + ActionMenuItem { + id: actionReboot + width: parent.width + + index: 32 + text: qsTr("Reboot sensor") + source: "qrc:/assets/icons_material/baseline-refresh-24px.svg" + layoutDirection: actionMenu.layoutDirection + visible: (deviceManager.bluetooth && (selectedDevice && selectedDevice.hasReboot)) + + onClicked: { + deviceRebootButtonClicked() + menuSelected(index) + close() + } } } } diff --git a/qml/components_generic/ButtonCompactable.qml b/qml/components_generic/ButtonCompactable.qml index e272457c..98ef2db5 100644 --- a/qml/components_generic/ButtonCompactable.qml +++ b/qml/components_generic/ButtonCompactable.qml @@ -1,4 +1,6 @@ import QtQuick 2.15 +import QtQuick.Controls.impl 2.15 +import QtQuick.Templates 2.15 as T //import QtGraphicalEffects 1.15 // Qt5 import Qt5Compat.GraphicalEffects // Qt6 @@ -8,6 +10,7 @@ import "qrc:/js/UtilsNumber.js" as UtilsNumber Item { id: control + implicitWidth: Theme.componentHeight implicitHeight: Theme.componentHeight @@ -42,13 +45,13 @@ Item { property string tooltipText property string tooltipPosition: "bottom" - //////////////////////////////////////////////////////////////////////////// + //////////////// MouseArea { id: mouseArea anchors.fill: parent - hoverEnabled: (isDesktop && control.enabled) + hoverEnabled: (hoverAnimation && control.enabled) onClicked: control.clicked() onPressed: { @@ -63,7 +66,7 @@ Item { onCanceled: mouseBackground.width = 0 } - //////////////////////////////////////////////////////////////////////////// + //////////////// Rectangle { id: background @@ -87,7 +90,7 @@ Item { Behavior on width { NumberAnimation { duration: 200 } } } - layer.enabled: control.hoverAnimation + layer.enabled: true layer.effect: OpacityMask { maskSource: Rectangle { x: background.x @@ -99,7 +102,7 @@ Item { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// Row { id: contentRow @@ -158,7 +161,7 @@ Item { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// Loader { anchors.fill: control @@ -173,5 +176,5 @@ Item { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// } diff --git a/qml/components_generic/ButtonWireframe.qml b/qml/components_generic/ButtonWireframe.qml index d8c51607..da39004d 100644 --- a/qml/components_generic/ButtonWireframe.qml +++ b/qml/components_generic/ButtonWireframe.qml @@ -32,11 +32,11 @@ T.Button { // animation property bool hoverAnimation: isDesktop - //////////////////////////////////////////////////////////////////////////// + //////////////// MouseArea { id: mousearea - anchors.fill: parent + anchors.fill: control enabled: control.hoverAnimation hoverEnabled: control.hoverAnimation @@ -65,7 +65,7 @@ T.Button { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// background: Rectangle { implicitWidth: 80 @@ -106,7 +106,7 @@ T.Button { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// contentItem: Text { text: control.text @@ -114,11 +114,12 @@ T.Button { font: control.font elide: Text.ElideMiddle - //wrapMode: Text.WordWrap horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter opacity: enabled ? (control.down && !control.hoverAnimation ? 0.8 : 1.0) : 0.66 color: control.fullColor ? control.fulltextColor : control.primaryColor } + + //////////////// } diff --git a/qml/components_generic/ButtonWireframeIcon.qml b/qml/components_generic/ButtonWireframeIcon.qml index 01024e51..8cf98ca9 100644 --- a/qml/components_generic/ButtonWireframeIcon.qml +++ b/qml/components_generic/ButtonWireframeIcon.qml @@ -39,7 +39,7 @@ T.Button { // animation property bool hoverAnimation: isDesktop - //////////////////////////////////////////////////////////////////////////// + //////////////// MouseArea { id: mousearea @@ -73,7 +73,7 @@ T.Button { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// background: Rectangle { implicitWidth: 80 @@ -115,7 +115,7 @@ T.Button { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// contentItem: RowLayout { spacing: control.spacing @@ -144,7 +144,6 @@ T.Button { font: control.font elide: Text.ElideMiddle - //wrapMode: Text.WordWrap horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter @@ -153,5 +152,5 @@ T.Button { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// } diff --git a/qml/components_generic/ButtonWireframeIconCentered.qml b/qml/components_generic/ButtonWireframeIconCentered.qml index 07ee802b..5f22cd34 100644 --- a/qml/components_generic/ButtonWireframeIconCentered.qml +++ b/qml/components_generic/ButtonWireframeIconCentered.qml @@ -39,7 +39,7 @@ T.Button { // animation property bool hoverAnimation: isDesktop - //////////////////////////////////////////////////////////////////////////// + //////////////// MouseArea { id: mousearea @@ -73,7 +73,7 @@ T.Button { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// background: Rectangle { implicitWidth: 80 @@ -115,7 +115,7 @@ T.Button { } } - //////////////////////////////////////////////////////////////////////////// + //////////////// contentItem: Item { Row { @@ -142,11 +142,12 @@ T.Button { text: control.text textFormat: Text.PlainText font: control.font + opacity: enabled ? (control.down && !control.hoverAnimation ? 0.8 : 1.0) : 0.66 color: control.fullColor ? control.fulltextColor : control.primaryColor } } } - //////////////////////////////////////////////////////////////////////////// + //////////////// } diff --git a/src/DeviceManager.cpp b/src/DeviceManager.cpp index 6d29155b..19274644 100644 --- a/src/DeviceManager.cpp +++ b/src/DeviceManager.cpp @@ -571,7 +571,7 @@ void DeviceManager::deviceDiscoveryErrorIOS() { //qDebug() << "DeviceManager::deviceDiscoveryErrorIOS()"; - m_discoveryAgent->stop(); + if (m_discoveryAgent) m_discoveryAgent->stop(); m_checking_ios_ble = false; if (m_bleEnabled) @@ -1167,7 +1167,7 @@ void DeviceManager::refreshDevices_stop() { //qDebug() << "DeviceManager::refreshDevices_stop()"; - if (m_discoveryAgent->isActive()) + if (m_discoveryAgent && m_discoveryAgent->isActive()) { m_discoveryAgent->stop(); diff --git a/src/DeviceManager_nearby.cpp b/src/DeviceManager_nearby.cpp index d8cb080e..0afd84d2 100644 --- a/src/DeviceManager_nearby.cpp +++ b/src/DeviceManager_nearby.cpp @@ -142,6 +142,8 @@ void DeviceManager::addNearbyBleDevice(const QBluetoothDeviceInfo &info) if (edd && edd->getAddress() == info.address().toString()) #endif { + edd->setName(info.name()); + edd->setRssi(info.rssi()); return; } } @@ -167,23 +169,6 @@ void DeviceManager::updateNearbyBleDevice(const QBluetoothDeviceInfo &info, QBlu //qDebug() << "DeviceManager::updateNearbyBleDevice()" << " > NAME" << info.name() << " > RSSI" << info.rssi(); Q_UNUSED(updatedFields) - // Check if it's not already in the UI - for (auto d: qAsConst(m_devices_nearby_model->m_devices)) - { - Device *dd = qobject_cast(d); - -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) - if (dd && dd->getAddress() == info.deviceUuid().toString()) -#else - if (dd && dd->getAddress() == info.address().toString()) -#endif - { - dd->setName(info.name()); - dd->setRssi(info.rssi()); - return; - } - } - addNearbyBleDevice(info); }