From e791fbcff8409e829a2494613dc1ebffb3567795 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 27 Oct 2024 22:10:01 +0100 Subject: [PATCH] Prefer native menus and dialogs in Qt Quick GUI --- tray/gui/app.h | 9 +++++++++ tray/gui/qml/AboutDialog.qml | 1 + tray/gui/qml/AdvancedConfigPage.qml | 23 +++++++++++++++++++---- tray/gui/qml/ArrayElementButtons.qml | 1 + tray/gui/qml/ExpandableItemDelegate.qml | 1 + tray/gui/qml/FilesPage.qml | 2 ++ tray/gui/qml/HelpButton.qml | 1 + tray/gui/qml/Main.qml | 15 ++++++++++++--- tray/gui/qml/ObjectConfigDelegate.qml | 10 +++++++++- tray/gui/qml/ObjectConfigPage.qml | 1 + 10 files changed, 56 insertions(+), 8 deletions(-) diff --git a/tray/gui/app.h b/tray/gui/app.h index e4aa8ac4..6741edc6 100644 --- a/tray/gui/app.h +++ b/tray/gui/app.h @@ -45,6 +45,7 @@ class App : public QObject { Q_PROPERTY(QString faUrlBase READ faUrlBase CONSTANT) Q_PROPERTY(bool darkmodeEnabled READ isDarkmodeEnabled NOTIFY darkmodeEnabledChanged) Q_PROPERTY(int iconSize READ iconSize CONSTANT) + Q_PROPERTY(bool nativePopups READ nativePopups CONSTANT) Q_PROPERTY(QString status READ status NOTIFY statusChanged) Q_PROPERTY(QString syncthingVersion READ syncthingVersion CONSTANT) Q_PROPERTY(QString readmeUrl READ readmeUrl CONSTANT) @@ -93,6 +94,14 @@ class App : public QObject { storeSettings(); emit settingsChanged(m_settings); } + bool nativePopups() const + { +#ifdef Q_OS_ANDROID + return false; +#else + return true; +#endif + } QString syncthingVersion() const { #ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING diff --git a/tray/gui/qml/AboutDialog.qml b/tray/gui/qml/AboutDialog.qml index afcd7649..668f33e9 100644 --- a/tray/gui/qml/AboutDialog.qml +++ b/tray/gui/qml/AboutDialog.qml @@ -4,6 +4,7 @@ import QtQuick.Controls Dialog { id: aboutDialog + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay parent: Overlay.overlay modal: true diff --git a/tray/gui/qml/AdvancedConfigPage.qml b/tray/gui/qml/AdvancedConfigPage.qml index fe023779..1357d852 100644 --- a/tray/gui/qml/AdvancedConfigPage.qml +++ b/tray/gui/qml/AdvancedConfigPage.qml @@ -1,4 +1,5 @@ import QtQuick +import QtQuick.Layouts import QtQuick.Controls import QtQuick.Dialogs @@ -22,11 +23,25 @@ ObjectConfigPage { } ] - MessageDialog { + Dialog { id: removeDialog - text: qsTr("Do you really want to remove the %1?").arg(advancedConfigPage.entryName) - informativeText: qsTr("This will only remove the %1 from Syncthing. No files will be deleted on disk.").arg(advancedConfigPage.entryName) - buttons: MessageDialog.Ok | MessageDialog.Cancel + popupType: app.nativePopups ? Popup.Native : Popup.Item + anchors.centerIn: Overlay.overlay + parent: Overlay.overlay + modal: true + standardButtons: Dialog.Yes | Dialog.No + contentItem: ColumnLayout { + Label { + Layout.fillWidth: true + text: qsTr("Do you really want to remove the %1?").arg(advancedConfigPage.entryName) + wrapMode: Text.WordWrap + } + Label { + Layout.fillWidth: true + text: qsTr("This will only remove the %1 from Syncthing. No files will be deleted on disk.").arg(advancedConfigPage.entryName) + wrapMode: Text.WordWrap + } + } onAccepted: advancedConfigPage.removeConfigObject() } diff --git a/tray/gui/qml/ArrayElementButtons.qml b/tray/gui/qml/ArrayElementButtons.qml index 515287d1..8f969e44 100644 --- a/tray/gui/qml/ArrayElementButtons.qml +++ b/tray/gui/qml/ArrayElementButtons.qml @@ -20,6 +20,7 @@ RowLayout { onClicked: menu.popup() Menu { id: menu + popupType: app.nativePopups ? Popup.Native : Popup.Item MenuItem { text: qsTr("Remove") Layout.preferredWidth: 36 diff --git a/tray/gui/qml/ExpandableItemDelegate.qml b/tray/gui/qml/ExpandableItemDelegate.qml index 6a0ce67c..37bd5a34 100644 --- a/tray/gui/qml/ExpandableItemDelegate.qml +++ b/tray/gui/qml/ExpandableItemDelegate.qml @@ -60,6 +60,7 @@ ItemDelegate { onClicked: menu.popup() Menu { id: menu + popupType: app.nativePopups ? Popup.Native : Popup.Item Instantiator { model: mainDelegate.actions delegate: MenuItem { diff --git a/tray/gui/qml/FilesPage.qml b/tray/gui/qml/FilesPage.qml index cac0d919..dd1c1bb2 100644 --- a/tray/gui/qml/FilesPage.qml +++ b/tray/gui/qml/FilesPage.qml @@ -75,6 +75,7 @@ Page { } Menu { id: contextMenu + popupType: app.nativePopups ? Popup.Native : Popup.Item Instantiator { model: actions delegate: MenuItem { @@ -109,6 +110,7 @@ Page { } Dialog { id: confirmActionDialog + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay standardButtons: Dialog.Ok | Dialog.Cancel width: parent.width - 20 diff --git a/tray/gui/qml/HelpButton.qml b/tray/gui/qml/HelpButton.qml index 3f3f7356..6ae69499 100644 --- a/tray/gui/qml/HelpButton.qml +++ b/tray/gui/qml/HelpButton.qml @@ -11,6 +11,7 @@ IconOnlyButton { Dialog { id: helpDlg + popupType: app.nativePopups ? Popup.Native : Popup.Item parent: Overlay.overlay anchors.centerIn: Overlay.overlay title: modelData.label ?? helpButton.key diff --git a/tray/gui/qml/Main.qml b/tray/gui/qml/Main.qml index 5b161be8..9e807487 100644 --- a/tray/gui/qml/Main.qml +++ b/tray/gui/qml/Main.qml @@ -131,6 +131,7 @@ ApplicationWindow { onPressAndHold: app.performHapticFeedback() Menu { id: extraActionsMenu + popupType: app.nativePopups ? Popup.Native : Popup.Item Instantiator { model: pageStack.currentExtraActions delegate: MenuItem { @@ -393,11 +394,19 @@ ApplicationWindow { } // avoid closing app (TODO: allow to keep Syncthing running in the background) - MessageDialog { + Dialog { id: closeDialog - buttons: MessageDialog.Yes | MessageDialog.No + popupType: app.nativePopups ? Popup.Native : Popup.Item + anchors.centerIn: Overlay.overlay + parent: Overlay.overlay + modal: true + standardButtons: Dialog.Yes | Dialog.No title: window.title - text: qsTr("Do you really want to close Syncthing?") + contentItem: Label { + Layout.fillWidth: true + text: qsTr("Do you really want to close Syncthing?") + wrapMode: Text.WordWrap + } onAccepted: { window.forceClose = true; window.close(); diff --git a/tray/gui/qml/ObjectConfigDelegate.qml b/tray/gui/qml/ObjectConfigDelegate.qml index 842e4064..1746a3b7 100644 --- a/tray/gui/qml/ObjectConfigDelegate.qml +++ b/tray/gui/qml/ObjectConfigDelegate.qml @@ -38,6 +38,7 @@ DelegateChooser { onClicked: stringDlg.visible = true Dialog { id: stringDlg + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay title: modelData.label standardButtons: objectConfigPage.standardButtons @@ -94,6 +95,7 @@ DelegateChooser { onClicked: optionsDlg.visible = true Dialog { id: optionsDlg + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay title: modelData.label standardButtons: objectConfigPage.standardButtons @@ -111,7 +113,10 @@ DelegateChooser { textRole: "label" enabled: modelData?.enabled ?? true onAccepted: optionsDlg.accept() - Component.onCompleted: editText = textForValue(modelData.value) + Component.onCompleted: { + //popup.popupType = Popup.Native; + editText = textForValue(modelData.value); + } readonly property var currentOption: modelData.options.get(optionsValue.currentIndex) readonly property string currentValueOrEditText: { const currentOption = optionsValue.currentOption; @@ -210,6 +215,7 @@ DelegateChooser { } Dialog { id: encryptionPasswordDlg + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay parent: Overlay.overlay title: qsTr("Set encryption password for sharing with \"%1\"").arg(deviceNameOrIdLabel.text) @@ -316,6 +322,7 @@ DelegateChooser { onClicked: numberDlg.visible = true Dialog { id: numberDlg + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay title: modelData.label standardButtons: objectConfigPage.standardButtons @@ -554,6 +561,7 @@ DelegateChooser { } Dialog { id: manualFolderDlg + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay title: modelData.label standardButtons: objectConfigPage.standardButtons diff --git a/tray/gui/qml/ObjectConfigPage.qml b/tray/gui/qml/ObjectConfigPage.qml index 2febfa95..63a312e4 100644 --- a/tray/gui/qml/ObjectConfigPage.qml +++ b/tray/gui/qml/ObjectConfigPage.qml @@ -44,6 +44,7 @@ Page { } Dialog { id: newValueDialog + popupType: app.nativePopups ? Popup.Native : Popup.Item anchors.centerIn: Overlay.overlay title: qsTr("Add new value") standardButtons: Dialog.Ok | Dialog.Cancel