|
1 | 1 | #include "ComboQuickFilterView.h" |
2 | 2 | #include "ui_ComboQuickFilterView.h" |
| 3 | +#include "common/CutterSearchable.h" |
| 4 | +#include <QMenu> |
3 | 5 |
|
4 | 6 | ComboQuickFilterView::ComboQuickFilterView(QWidget *parent) |
5 | 7 | : QWidget(parent), ui(new Ui::ComboQuickFilterView) |
6 | 8 | { |
7 | 9 | ui->setupUi(this); |
8 | 10 |
|
| 11 | + QMenu *optionsMenu = new QMenu(this); |
| 12 | + m_caseSensitiveAction = optionsMenu->addAction(tr("&Case Sensitive")); |
| 13 | + m_caseSensitiveAction->setCheckable(true); |
| 14 | + |
| 15 | + m_wholeWordsAction = optionsMenu->addAction(tr("Exact Match")); |
| 16 | + m_wholeWordsAction->setCheckable(true); |
| 17 | + |
| 18 | + m_regexAction = optionsMenu->addAction(tr("Regular Expression")); |
| 19 | + m_regexAction->setCheckable(true); |
| 20 | + |
| 21 | + auto emitFilterChanged = [this]() { |
| 22 | + emit filterChanged(ui->lineEdit->text(), filterOptions()); |
| 23 | + }; |
| 24 | + connect(m_caseSensitiveAction, &QAction::triggered, this, emitFilterChanged); |
| 25 | + connect(m_wholeWordsAction, &QAction::triggered, this, emitFilterChanged); |
| 26 | + connect(m_regexAction, &QAction::triggered, this, emitFilterChanged); |
| 27 | + |
| 28 | + QAction *optionsAction = new QAction(this); |
| 29 | + optionsAction->setIcon(QIcon(":/img/icons/cog_light.svg")); |
| 30 | + optionsAction->setMenu(optionsMenu); |
| 31 | + ui->lineEdit->addAction(optionsAction, QLineEdit::LeadingPosition); |
| 32 | + |
9 | 33 | debounceTimer = new QTimer(this); |
10 | 34 | debounceTimer->setSingleShot(true); |
11 | 35 |
|
12 | 36 | connect(debounceTimer, &QTimer::timeout, this, |
13 | | - [this]() { emit filterTextChanged(ui->lineEdit->text()); }); |
| 37 | + [this]() { emit filterChanged(ui->lineEdit->text(), filterOptions()); }); |
14 | 38 |
|
15 | 39 | connect(ui->lineEdit, &QLineEdit::textChanged, this, [this]() { debounceTimer->start(150); }); |
16 | 40 | } |
@@ -47,3 +71,18 @@ void ComboQuickFilterView::closeFilter() |
47 | 71 | hide(); |
48 | 72 | emit filterClosed(); |
49 | 73 | } |
| 74 | + |
| 75 | +int ComboQuickFilterView::filterOptions() const |
| 76 | +{ |
| 77 | + int options = 0; |
| 78 | + if (m_caseSensitiveAction->isChecked()) { |
| 79 | + options |= CaseSensitive; |
| 80 | + } |
| 81 | + if (m_wholeWordsAction->isChecked()) { |
| 82 | + options |= WholeWords; |
| 83 | + } |
| 84 | + if (m_regexAction->isChecked()) { |
| 85 | + options |= RegExp; |
| 86 | + } |
| 87 | + return options; |
| 88 | +} |
0 commit comments