Skip to content

Commit

Permalink
Prefer native menus and dialogs in Qt Quick GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Oct 27, 2024
1 parent f03fd71 commit e791fbc
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 8 deletions.
9 changes: 9 additions & 0 deletions tray/gui/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tray/gui/qml/AboutDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tray/gui/qml/AdvancedConfigPage.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Dialogs

Expand All @@ -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()
}

Expand Down
1 change: 1 addition & 0 deletions tray/gui/qml/ArrayElementButtons.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tray/gui/qml/ExpandableItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ItemDelegate {
onClicked: menu.popup()
Menu {
id: menu
popupType: app.nativePopups ? Popup.Native : Popup.Item
Instantiator {
model: mainDelegate.actions
delegate: MenuItem {
Expand Down
2 changes: 2 additions & 0 deletions tray/gui/qml/FilesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Page {
}
Menu {
id: contextMenu
popupType: app.nativePopups ? Popup.Native : Popup.Item
Instantiator {
model: actions
delegate: MenuItem {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tray/gui/qml/HelpButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions tray/gui/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ ApplicationWindow {
onPressAndHold: app.performHapticFeedback()
Menu {
id: extraActionsMenu
popupType: app.nativePopups ? Popup.Native : Popup.Item
Instantiator {
model: pageStack.currentExtraActions
delegate: MenuItem {
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion tray/gui/qml/ObjectConfigDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tray/gui/qml/ObjectConfigPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e791fbc

Please sign in to comment.