From 9c370b375d09dd9d53b3fb2ac83c4e74a84505c4 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 20 Nov 2018 00:45:05 +0100 Subject: [PATCH] Quick GUI: Move filter to its own dialog Because under Android the usability of the text box inside the drawer is not very good. --- CMakeLists.txt | 2 +- qml/main.qml | 71 ++++++++++++++++++++++++++++++++++++++++- quickgui/controller.cpp | 7 ++++ quickgui/controller.h | 9 ++++++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40ca97f..d960b73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(META_GUI_OPTIONAL YES) set(META_USE_QQC2 ON) set(META_VERSION_MAJOR 3) set(META_VERSION_MINOR 2) -set(META_VERSION_PATCH 0) +set(META_VERSION_PATCH 1) set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) # add project files diff --git a/qml/main.qml b/qml/main.qml index b572ed9..62f0fd6 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -36,6 +36,7 @@ Kirigami.ApplicationWindow { Layout.fillWidth: true Layout.preferredHeight: filterTextField.implicitHeight enabled: nativeInterface.fileOpen + visible: !nativeInterface.filterAsDialog Controls.TextField { id: filterTextField @@ -150,7 +151,31 @@ Kirigami.ApplicationWindow { shortcut: "Ctrl+P" }, Kirigami.Action { - text: "Close file" + text: nativeInterface.entryFilter.length === 0 ? qsTr("Search") : qsTr( + "Adjust search") + enabled: nativeInterface.fileOpen + visible: nativeInterface.filterAsDialog + iconName: "search" + onTriggered: { + leftMenu.resetMenu() + filterDialog.open() + } + shortcut: "Ctrl+F" + }, + Kirigami.Action { + text: qsTr("Clear search") + enabled: nativeInterface.fileOpen + visible: nativeInterface.filterAsDialog + && nativeInterface.entryFilter.length > 0 + iconName: "edit-clear" + onTriggered: { + leftMenu.resetMenu() + nativeInterface.entryFilter = "" + } + shortcut: "Ctrl+Shift+F" + }, + Kirigami.Action { + text: qsTr("Close file") enabled: nativeInterface.fileOpen iconName: "document-close" onTriggered: nativeInterface.close() @@ -214,8 +239,52 @@ Kirigami.ApplicationWindow { } } + BasicDialog { + id: filterDialog + title: qsTr("Search for categories and accounts") + onAccepted: nativeInterface.entryFilter = filterDialogTextField.text + onReset: { + nativeInterface.entryFilter = "" + filterDialog.close() + } + onVisibleChanged: { + if (visible) { + filterDialogTextField.forceActiveFocus() + } + } + footer: Controls.DialogButtonBox { + Controls.Button { + text: qsTr("Apply search term") + Controls.DialogButtonBox.buttonRole: Controls.DialogButtonBox.AcceptRole + enabled: filterDialogTextField.text.length > 0 + } + Controls.Button { + text: qsTr("Clear search") + Controls.DialogButtonBox.buttonRole: Controls.DialogButtonBox.ResetRole + enabled: nativeInterface.entryFilter + } + Controls.Button { + text: qsTr("Quit dialog") + Controls.DialogButtonBox.buttonRole: Controls.DialogButtonBox.RejectRole + } + } + + ColumnLayout { + Controls.TextField { + id: filterDialogTextField + Layout.preferredWidth: filterDialog.availableWidth + Keys.onPressed: filterDialog.acceptOnReturn(event) + } + } + } + Connections { target: nativeInterface + onEntryFilterChanged: { + if (filterTextField.text !== newFilter) { + filterTextField.text = newFilter + } + } onFileError: { showPassiveNotification(errorMessage) } diff --git a/quickgui/controller.cpp b/quickgui/controller.cpp index 881ec63..a8d364a 100644 --- a/quickgui/controller.cpp +++ b/quickgui/controller.cpp @@ -39,6 +39,13 @@ Controller::Controller(QSettings &settings, const QString &filePath, QObject *pa , m_fileOpen(false) , m_fileModified(false) , m_useNativeFileDialog(false) + , m_filterAsDialog( +#ifdef Q_OS_ANDROID + true +#else + false +#endif + ) { m_entryFilterModel.setSourceModel(&m_entryModel); connect(&m_entryModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &Controller::handleEntriesRemoved); diff --git a/quickgui/controller.h b/quickgui/controller.h index 446908d..b27553c 100644 --- a/quickgui/controller.h +++ b/quickgui/controller.h @@ -36,6 +36,7 @@ class Controller : public QObject { Q_PROPERTY(bool supportsNativeFileDialog READ supportsNativeFileDialog NOTIFY supportsNativeFileDialogChanged) Q_PROPERTY(QString entryFilter READ entryFilter WRITE setEntryFilter NOTIFY entryFilterChanged) Q_PROPERTY(bool hasEntryFilter READ hasEntryFilter NOTIFY hasEntryFilterChanged) + Q_PROPERTY(bool filterAsDialog READ filterAsDialog NOTIFY filterAsDialogChanged) public: explicit Controller(QSettings &settings, const QString &filePath = QString(), QObject *parent = nullptr); @@ -73,6 +74,7 @@ public: QString entryFilter() const; void setEntryFilter(const QString &filter); bool hasEntryFilter() const; + bool filterAsDialog() const; public slots: void init(); @@ -107,6 +109,7 @@ signals: void entryAboutToBeRemoved(const QModelIndex &removedIndex); void entryFilterChanged(const QString &newFilter); void hasEntryFilterChanged(bool hasEntryFilter); + void filterAsDialogChanged(bool filterAsDialog); private slots: void handleEntriesRemoved(const QModelIndex &parentIndex, int first, int last); @@ -134,6 +137,7 @@ private: bool m_fileOpen; bool m_fileModified; bool m_useNativeFileDialog; + bool m_filterAsDialog; }; inline QModelIndex Controller::ensureSourceEntryIndex(const QModelIndex &entryIndexMaybeFromFilterModel) const @@ -279,6 +283,11 @@ inline bool Controller::hasEntryFilter() const return !m_entryFilterModel.filterRegExp().isEmpty(); } +inline bool Controller::filterAsDialog() const +{ + return m_filterAsDialog; +} + } // namespace QtGui #endif // QT_QUICK_GUI_CONTROLLER_H