mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-08 22:42:34 -04:00
Cleaned up SearchWidget code
This commit is contained in:
parent
298665e32a
commit
9660510cc7
2 changed files with 37 additions and 58 deletions
|
@ -24,39 +24,6 @@
|
|||
|
||||
#include "core/FilePath.h"
|
||||
|
||||
bool SearchWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
||||
if (keyEvent->key() == Qt::Key_Escape) {
|
||||
emit escapePressed();
|
||||
return true;
|
||||
}
|
||||
else if (keyEvent->matches(QKeySequence::Copy)) {
|
||||
// If Control+C is pressed in the search edit when no
|
||||
// text is selected, copy the password of the current
|
||||
// entry.
|
||||
if (!m_ui->searchEdit->hasSelectedText()) {
|
||||
emit copyPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (keyEvent->matches(QKeySequence::MoveToNextLine)) {
|
||||
// If Down is pressed at EOL in the search edit, move
|
||||
// the focus to the entry view.
|
||||
QLineEdit* searchEdit = m_ui->searchEdit;
|
||||
if (!searchEdit->hasSelectedText() &&
|
||||
searchEdit->cursorPosition() == searchEdit->text().length()) {
|
||||
emit downPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
|
||||
SearchWidget::SearchWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_ui(new Ui::SearchWidget())
|
||||
|
@ -71,8 +38,6 @@ SearchWidget::SearchWidget(QWidget *parent)
|
|||
connect(m_ui->searchIcon, SIGNAL(triggered(QAction*)), m_ui->searchEdit, SLOT(setFocus()));
|
||||
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(startSearch()));
|
||||
connect(this, SIGNAL(escapePressed()), m_ui->searchEdit, SLOT(clear()));
|
||||
connect(this, SIGNAL(copyPressed()), SLOT(copyPassword()));
|
||||
connect(this, SIGNAL(downPressed()), SLOT(setFocusToEntry()));
|
||||
|
||||
new QShortcut(Qt::CTRL + Qt::Key_F, m_ui->searchEdit, SLOT(setFocus()), nullptr, Qt::ApplicationShortcut);
|
||||
|
||||
|
@ -93,16 +58,48 @@ SearchWidget::~SearchWidget()
|
|||
|
||||
}
|
||||
|
||||
bool SearchWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
||||
if (keyEvent->key() == Qt::Key_Escape) {
|
||||
emit escapePressed();
|
||||
return true;
|
||||
}
|
||||
else if (keyEvent->matches(QKeySequence::Copy)) {
|
||||
// If Control+C is pressed in the search edit when no
|
||||
// text is selected, copy the password of the current
|
||||
// entry.
|
||||
if (!m_ui->searchEdit->hasSelectedText()) {
|
||||
emit copyPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (keyEvent->matches(QKeySequence::MoveToNextLine)) {
|
||||
// If Down is pressed at EOL in the search edit, move
|
||||
// the focus to the entry view.
|
||||
QLineEdit* searchEdit = m_ui->searchEdit;
|
||||
if (!searchEdit->hasSelectedText() &&
|
||||
searchEdit->cursorPosition() == searchEdit->text().length()) {
|
||||
emit downPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void SearchWidget::connectSignals(SignalMultiplexer& mx)
|
||||
{
|
||||
mx.connect(this, SIGNAL(search(QString)), SLOT(search(QString)));
|
||||
mx.connect(this, SIGNAL(caseSensitiveChanged(bool)), SLOT(setSearchCaseSensitive(bool)));
|
||||
mx.connect(this, SIGNAL(copyPressed()), SLOT(copyPassword()));
|
||||
mx.connect(this, SIGNAL(downPressed()), SLOT(setFocus()));
|
||||
}
|
||||
|
||||
void SearchWidget::databaseChanged(DatabaseWidget *dbWidget)
|
||||
{
|
||||
m_dbWidget = dbWidget;
|
||||
|
||||
if (dbWidget != nullptr) {
|
||||
// Set current search text from this database
|
||||
m_ui->searchEdit->setText(dbWidget->getCurrentSearch());
|
||||
|
@ -141,15 +138,3 @@ void SearchWidget::setCaseSensitive(bool state)
|
|||
m_actionCaseSensitive->setChecked(state);
|
||||
updateCaseSensitive();
|
||||
}
|
||||
|
||||
void SearchWidget::copyPassword()
|
||||
{
|
||||
if (m_dbWidget)
|
||||
m_dbWidget->copyPassword();
|
||||
}
|
||||
|
||||
void SearchWidget::setFocusToEntry()
|
||||
{
|
||||
if (m_dbWidget)
|
||||
m_dbWidget->setFocus();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue