mainwindow: Add search history. Allow going up/down with arrow keys
This commit is contained in:
parent
c0f4087937
commit
2885e40a3a
@ -70,6 +70,8 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath)
|
|||||||
policy.setRetainSizeWhenHidden(true);
|
policy.setRetainSizeWhenHidden(true);
|
||||||
ui->btnOpenFailed->setSizePolicy(policy);
|
ui->btnOpenFailed->setSizePolicy(policy);
|
||||||
|
|
||||||
|
ui->txtSearch->installEventFilter(this);
|
||||||
|
|
||||||
this->ipcClientThread.start();
|
this->ipcClientThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,6 +439,60 @@ void MainWindow::processShortcut(int key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainWindow::eventFilter(QObject *object, QEvent *event)
|
||||||
|
{
|
||||||
|
if(object == ui->txtSearch && !searchHistory.empty())
|
||||||
|
{
|
||||||
|
if(event->type() == QEvent::KeyPress)
|
||||||
|
{
|
||||||
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||||
|
if(keyEvent->key() == Qt::Key_Up)
|
||||||
|
{
|
||||||
|
if(this->currentSavedSearchText.isEmpty())
|
||||||
|
{
|
||||||
|
this->currentSavedSearchText = ui->txtSearch->text();
|
||||||
|
}
|
||||||
|
if(this->currentSearchHistoryIndex <= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
--this->currentSearchHistoryIndex;
|
||||||
|
QString text = this->searchHistory.at(this->currentSearchHistoryIndex);
|
||||||
|
ui->txtSearch->setText(text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(keyEvent->key() == Qt::Key_Down)
|
||||||
|
{
|
||||||
|
if(this->currentSearchHistoryIndex == searchHistory.size() - 1)
|
||||||
|
{
|
||||||
|
if(!this->currentSavedSearchText.isEmpty())
|
||||||
|
{
|
||||||
|
ui->txtSearch->setText(this->currentSavedSearchText);
|
||||||
|
this->currentSavedSearchText.clear();
|
||||||
|
++this->currentSearchHistoryIndex;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(this->currentSearchHistoryIndex < searchHistory.size() - 1)
|
||||||
|
{
|
||||||
|
++this->currentSearchHistoryIndex;
|
||||||
|
QString text = this->searchHistory.at(this->currentSearchHistoryIndex);
|
||||||
|
ui->txtSearch->setText(text);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->currentSavedSearchText.clear();
|
||||||
|
/* Off by one on purpose so Key_Up decrements it again and lands at
|
||||||
|
* the last entry */
|
||||||
|
this->currentSearchHistoryIndex = this->searchHistory.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QMainWindow::eventFilter(object, event);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::keyPressEvent(QKeyEvent *event)
|
void MainWindow::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
bool quit =
|
bool quit =
|
||||||
@ -600,6 +656,14 @@ void MainWindow::lineEditReturnPressed()
|
|||||||
ui->tabWidget->setCurrentIndex(0);
|
ui->tabWidget->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
// TODO: validate q;
|
// TODO: validate q;
|
||||||
|
while(this->searchHistory.size() > 30)
|
||||||
|
{
|
||||||
|
this->searchHistory.removeFirst();
|
||||||
|
}
|
||||||
|
this->searchHistory.append(q);
|
||||||
|
this->currentSearchHistoryIndex = this->searchHistory.size();
|
||||||
|
this->currentSavedSearchText.clear();
|
||||||
|
|
||||||
ui->treeResultsList->clear();
|
ui->treeResultsList->clear();
|
||||||
ui->lblSearchResults->setText("Searching...");
|
ui->lblSearchResults->setText("Searching...");
|
||||||
this->ui->txtSearch->setEnabled(false);
|
this->ui->txtSearch->setEnabled(false);
|
||||||
|
@ -64,6 +64,10 @@ class MainWindow : public QMainWindow
|
|||||||
void initSettingsTabs();
|
void initSettingsTabs();
|
||||||
int currentSelectedScale();
|
int currentSelectedScale();
|
||||||
void processShortcut(int key);
|
void processShortcut(int key);
|
||||||
|
bool eventFilter(QObject *object, QEvent *event);
|
||||||
|
QVector<QString> searchHistory;
|
||||||
|
int currentSearchHistoryIndex = 0;
|
||||||
|
QString currentSavedSearchText;
|
||||||
private slots:
|
private slots:
|
||||||
void lineEditReturnPressed();
|
void lineEditReturnPressed();
|
||||||
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
||||||
|
Loading…
Reference in New Issue
Block a user