Quick GUI: Move filter to its own dialog

Because under Android the usability of the text box
inside the drawer is not very good.
This commit is contained in:
Martchus 2018-11-20 00:45:05 +01:00
parent 863970fdb3
commit 9c370b375d
4 changed files with 87 additions and 2 deletions

View File

@ -13,7 +13,7 @@ set(META_GUI_OPTIONAL YES)
set(META_USE_QQC2 ON) set(META_USE_QQC2 ON)
set(META_VERSION_MAJOR 3) set(META_VERSION_MAJOR 3)
set(META_VERSION_MINOR 2) 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}) set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
# add project files # add project files

View File

@ -36,6 +36,7 @@ Kirigami.ApplicationWindow {
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: filterTextField.implicitHeight Layout.preferredHeight: filterTextField.implicitHeight
enabled: nativeInterface.fileOpen enabled: nativeInterface.fileOpen
visible: !nativeInterface.filterAsDialog
Controls.TextField { Controls.TextField {
id: filterTextField id: filterTextField
@ -150,7 +151,31 @@ Kirigami.ApplicationWindow {
shortcut: "Ctrl+P" shortcut: "Ctrl+P"
}, },
Kirigami.Action { 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 enabled: nativeInterface.fileOpen
iconName: "document-close" iconName: "document-close"
onTriggered: nativeInterface.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 { Connections {
target: nativeInterface target: nativeInterface
onEntryFilterChanged: {
if (filterTextField.text !== newFilter) {
filterTextField.text = newFilter
}
}
onFileError: { onFileError: {
showPassiveNotification(errorMessage) showPassiveNotification(errorMessage)
} }

View File

@ -39,6 +39,13 @@ Controller::Controller(QSettings &settings, const QString &filePath, QObject *pa
, m_fileOpen(false) , m_fileOpen(false)
, m_fileModified(false) , m_fileModified(false)
, m_useNativeFileDialog(false) , m_useNativeFileDialog(false)
, m_filterAsDialog(
#ifdef Q_OS_ANDROID
true
#else
false
#endif
)
{ {
m_entryFilterModel.setSourceModel(&m_entryModel); m_entryFilterModel.setSourceModel(&m_entryModel);
connect(&m_entryModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &Controller::handleEntriesRemoved); connect(&m_entryModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &Controller::handleEntriesRemoved);

View File

@ -36,6 +36,7 @@ class Controller : public QObject {
Q_PROPERTY(bool supportsNativeFileDialog READ supportsNativeFileDialog NOTIFY supportsNativeFileDialogChanged) Q_PROPERTY(bool supportsNativeFileDialog READ supportsNativeFileDialog NOTIFY supportsNativeFileDialogChanged)
Q_PROPERTY(QString entryFilter READ entryFilter WRITE setEntryFilter NOTIFY entryFilterChanged) Q_PROPERTY(QString entryFilter READ entryFilter WRITE setEntryFilter NOTIFY entryFilterChanged)
Q_PROPERTY(bool hasEntryFilter READ hasEntryFilter NOTIFY hasEntryFilterChanged) Q_PROPERTY(bool hasEntryFilter READ hasEntryFilter NOTIFY hasEntryFilterChanged)
Q_PROPERTY(bool filterAsDialog READ filterAsDialog NOTIFY filterAsDialogChanged)
public: public:
explicit Controller(QSettings &settings, const QString &filePath = QString(), QObject *parent = nullptr); explicit Controller(QSettings &settings, const QString &filePath = QString(), QObject *parent = nullptr);
@ -73,6 +74,7 @@ public:
QString entryFilter() const; QString entryFilter() const;
void setEntryFilter(const QString &filter); void setEntryFilter(const QString &filter);
bool hasEntryFilter() const; bool hasEntryFilter() const;
bool filterAsDialog() const;
public slots: public slots:
void init(); void init();
@ -107,6 +109,7 @@ signals:
void entryAboutToBeRemoved(const QModelIndex &removedIndex); void entryAboutToBeRemoved(const QModelIndex &removedIndex);
void entryFilterChanged(const QString &newFilter); void entryFilterChanged(const QString &newFilter);
void hasEntryFilterChanged(bool hasEntryFilter); void hasEntryFilterChanged(bool hasEntryFilter);
void filterAsDialogChanged(bool filterAsDialog);
private slots: private slots:
void handleEntriesRemoved(const QModelIndex &parentIndex, int first, int last); void handleEntriesRemoved(const QModelIndex &parentIndex, int first, int last);
@ -134,6 +137,7 @@ private:
bool m_fileOpen; bool m_fileOpen;
bool m_fileModified; bool m_fileModified;
bool m_useNativeFileDialog; bool m_useNativeFileDialog;
bool m_filterAsDialog;
}; };
inline QModelIndex Controller::ensureSourceEntryIndex(const QModelIndex &entryIndexMaybeFromFilterModel) const inline QModelIndex Controller::ensureSourceEntryIndex(const QModelIndex &entryIndexMaybeFromFilterModel) const
@ -279,6 +283,11 @@ inline bool Controller::hasEntryFilter() const
return !m_entryFilterModel.filterRegExp().isEmpty(); return !m_entryFilterModel.filterRegExp().isEmpty();
} }
inline bool Controller::filterAsDialog() const
{
return m_filterAsDialog;
}
} // namespace QtGui } // namespace QtGui
#endif // QT_QUICK_GUI_CONTROLLER_H #endif // QT_QUICK_GUI_CONTROLLER_H