mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-09 06:52:50 -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"
|
#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)
|
SearchWidget::SearchWidget(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_ui(new Ui::SearchWidget())
|
, 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_ui->searchIcon, SIGNAL(triggered(QAction*)), m_ui->searchEdit, SLOT(setFocus()));
|
||||||
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(startSearch()));
|
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(startSearch()));
|
||||||
connect(this, SIGNAL(escapePressed()), m_ui->searchEdit, SLOT(clear()));
|
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);
|
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)
|
void SearchWidget::connectSignals(SignalMultiplexer& mx)
|
||||||
{
|
{
|
||||||
mx.connect(this, SIGNAL(search(QString)), SLOT(search(QString)));
|
mx.connect(this, SIGNAL(search(QString)), SLOT(search(QString)));
|
||||||
mx.connect(this, SIGNAL(caseSensitiveChanged(bool)), SLOT(setSearchCaseSensitive(bool)));
|
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)
|
void SearchWidget::databaseChanged(DatabaseWidget *dbWidget)
|
||||||
{
|
{
|
||||||
m_dbWidget = dbWidget;
|
|
||||||
|
|
||||||
if (dbWidget != nullptr) {
|
if (dbWidget != nullptr) {
|
||||||
// Set current search text from this database
|
// Set current search text from this database
|
||||||
m_ui->searchEdit->setText(dbWidget->getCurrentSearch());
|
m_ui->searchEdit->setText(dbWidget->getCurrentSearch());
|
||||||
|
@ -141,15 +138,3 @@ void SearchWidget::setCaseSensitive(bool state)
|
||||||
m_actionCaseSensitive->setChecked(state);
|
m_actionCaseSensitive->setChecked(state);
|
||||||
updateCaseSensitive();
|
updateCaseSensitive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchWidget::copyPassword()
|
|
||||||
{
|
|
||||||
if (m_dbWidget)
|
|
||||||
m_dbWidget->copyPassword();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchWidget::setFocusToEntry()
|
|
||||||
{
|
|
||||||
if (m_dbWidget)
|
|
||||||
m_dbWidget->setFocus();
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ namespace Ui {
|
||||||
class SearchWidget;
|
class SearchWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SearchWidget : public QWidget
|
class SearchWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -40,6 +39,9 @@ public:
|
||||||
void connectSignals(SignalMultiplexer& mx);
|
void connectSignals(SignalMultiplexer& mx);
|
||||||
void setCaseSensitive(bool state);
|
void setCaseSensitive(bool state);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void search(const QString &text);
|
void search(const QString &text);
|
||||||
void caseSensitiveChanged(bool state);
|
void caseSensitiveChanged(bool state);
|
||||||
|
@ -54,21 +56,13 @@ private slots:
|
||||||
void startSearchTimer();
|
void startSearchTimer();
|
||||||
void startSearch();
|
void startSearch();
|
||||||
void updateCaseSensitive();
|
void updateCaseSensitive();
|
||||||
void copyPassword();
|
|
||||||
void setFocusToEntry();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QScopedPointer<Ui::SearchWidget> m_ui;
|
const QScopedPointer<Ui::SearchWidget> m_ui;
|
||||||
QTimer* m_searchTimer;
|
QTimer* m_searchTimer;
|
||||||
DatabaseWidget *m_dbWidget;
|
|
||||||
|
|
||||||
QAction *m_actionCaseSensitive;
|
QAction *m_actionCaseSensitive;
|
||||||
|
|
||||||
Q_DISABLE_COPY(SearchWidget)
|
Q_DISABLE_COPY(SearchWidget)
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SEARCHWIDGET_H
|
#endif // SEARCHWIDGET_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue