-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add filter options menu to QuickFilterView and ComboQuickFilterView (#2230) #3582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
961764f
873ad17
f01659a
bd1c8a5
5e56cf0
63517fc
dfd5fd2
c4f740c
c290cfd
5209e49
bb23643
fc72708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,57 @@ | ||
| #include "AbstractFilterView.h" | ||
|
|
||
| #include "common/CutterSearchable.h" | ||
| #include "common/Helpers.h" | ||
| #include "common/Configuration.h" | ||
|
|
||
| #include <QAction> | ||
| #include <QIcon> | ||
| #include <QMenu> | ||
|
|
||
| AbstractFilterView::AbstractFilterView(QWidget *parent) : QWidget(parent) {} | ||
|
|
||
| void AbstractFilterView::setupSharedConnections() | ||
| { | ||
| auto *optionsMenu = new QMenu(this); | ||
| caseSensitiveAction = optionsMenu->addAction(tr("&Case Sensitive")); | ||
| caseSensitiveAction->setCheckable(true); | ||
| caseSensitiveAction->setChecked(Config()->getQuickFilterCaseSensitive()); | ||
|
|
||
| wholeWordsAction = optionsMenu->addAction(tr("&Exact Match")); | ||
| wholeWordsAction->setCheckable(true); | ||
| wholeWordsAction->setChecked(Config()->getQuickFilterWholeWords()); | ||
|
|
||
| regexAction = optionsMenu->addAction(tr("&Regular Expression")); | ||
| regexAction->setCheckable(true); | ||
|
Comment on lines
+15
to
+25
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're going to use the "&" shortcut then you should use them for all three actions, currently it's only being used on "Case sensitive" action Also, there should be a shortcut key in my opinion that opens the actions menu. Default shortcuts are defined in "shortcuts/DefaultShortcuts.cpp" |
||
| regexAction->setChecked(Config()->getQuickFilterRegex()); | ||
|
|
||
| auto emitFilterChanged = [this]() { emit filterChanged(lineEdit()->text(), filterOptions()); }; | ||
|
|
||
| connect(caseSensitiveAction, &QAction::toggled, this, emitFilterChanged); | ||
| connect(Config(), &Configuration::quickFilterCaseSensitiveChanged, caseSensitiveAction, &QAction::setChecked); | ||
|
|
||
| connect(wholeWordsAction, &QAction::toggled, this, emitFilterChanged); | ||
| connect(Config(), &Configuration::quickFilterWholeWordsChanged, wholeWordsAction, &QAction::setChecked); | ||
|
|
||
| connect(regexAction, &QAction::toggled, this, emitFilterChanged); | ||
| connect(Config(), &Configuration::quickFilterRegexChanged, regexAction, &QAction::setChecked); | ||
|
|
||
| auto *optionsAction = new QAction(this); | ||
| const int lineEditHeight = lineEdit()->fontMetrics().height(); | ||
| const int targetIconSize = qRound(lineEditHeight * 0.8); | ||
| const QIcon cogIcon(":/img/icons/cog_light.svg"); | ||
| const qreal dpr = qhelpers::devicePixelRatio(this); | ||
| QPixmap pixmap = cogIcon.pixmap(qRound(targetIconSize * dpr), qRound(targetIconSize * dpr)); | ||
| pixmap.setDevicePixelRatio(dpr); | ||
| optionsAction->setIcon(pixmap); | ||
| optionsAction->setMenu(optionsMenu); | ||
| lineEdit()->addAction(optionsAction, QLineEdit::LeadingPosition); | ||
|
|
||
| debounceTimer = new QTimer(this); | ||
| debounceTimer->setSingleShot(true); | ||
|
|
||
| connect(debounceTimer, &QTimer::timeout, this, | ||
| [this]() { emit filterTextChanged(lineEdit()->text()); }); | ||
| [this]() { emit filterChanged(lineEdit()->text(), filterOptions()); }); | ||
|
|
||
| connect(lineEdit(), &QLineEdit::textChanged, this, [this]() { debounceTimer->start(150); }); | ||
| } | ||
|
|
@@ -44,6 +84,21 @@ void AbstractFilterView::closeFilter() | |
| emit filterClosed(); | ||
| } | ||
|
|
||
| int AbstractFilterView::filterOptions() const | ||
| { | ||
| int options = 0; | ||
| if (caseSensitiveAction->isChecked()) { | ||
| options |= SearchOption::CaseSensitive; | ||
| } | ||
| if (wholeWordsAction->isChecked()) { | ||
| options |= SearchOption::WholeWords; | ||
| } | ||
| if (regexAction->isChecked()) { | ||
| options |= SearchOption::RegExp; | ||
| } | ||
| return options; | ||
| } | ||
|
|
||
| void AbstractFilterView::showCustomContextMenu(const QPoint &pos) | ||
| { | ||
| const QWidget *child = this->childAt(pos); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but in my opinion there should be options in "Edit->Preferences->Interface" under the "Quick Filter" tab for these three things:
User preference should be saved, just so that if a user always prefers case sensitive search they don't have to manually change it each time cutter is opened
The actions will be added/handled in "InterfaceOptionsWidget"