mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-14 16:57:32 -05:00
Cleaned up SearchWidget code
This commit is contained in:
parent
298665e32a
commit
9660510cc7
@ -24,6 +24,40 @@
|
|||||||
|
|
||||||
#include "core/FilePath.h"
|
#include "core/FilePath.h"
|
||||||
|
|
||||||
|
SearchWidget::SearchWidget(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, m_ui(new Ui::SearchWidget())
|
||||||
|
{
|
||||||
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
m_searchTimer = new QTimer(this);
|
||||||
|
m_searchTimer->setSingleShot(true);
|
||||||
|
|
||||||
|
connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), SLOT(startSearchTimer()));
|
||||||
|
connect(m_ui->searchEdit, SIGNAL(returnPressed()), SLOT(startSearch()));
|
||||||
|
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()));
|
||||||
|
|
||||||
|
new QShortcut(Qt::CTRL + Qt::Key_F, m_ui->searchEdit, SLOT(setFocus()), nullptr, Qt::ApplicationShortcut);
|
||||||
|
|
||||||
|
m_ui->searchEdit->installEventFilter(this);
|
||||||
|
|
||||||
|
QMenu *searchMenu = new QMenu();
|
||||||
|
m_actionCaseSensitive = searchMenu->addAction(tr("Case Sensitive"), this, SLOT(updateCaseSensitive()));
|
||||||
|
m_actionCaseSensitive->setObjectName("actionSearchCaseSensitive");
|
||||||
|
m_actionCaseSensitive->setCheckable(true);
|
||||||
|
|
||||||
|
m_ui->searchIcon->setIcon(filePath()->icon("actions", "system-search"));
|
||||||
|
m_ui->searchIcon->setMenu(searchMenu);
|
||||||
|
m_ui->searchIcon->setPopupMode(QToolButton::MenuButtonPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchWidget::~SearchWidget()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool SearchWidget::eventFilter(QObject *obj, QEvent *event)
|
bool SearchWidget::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::KeyPress) {
|
if (event->type() == QEvent::KeyPress) {
|
||||||
@ -56,53 +90,16 @@ bool SearchWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
return QObject::eventFilter(obj, event);
|
return QObject::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SearchWidget::SearchWidget(QWidget *parent)
|
|
||||||
: QWidget(parent)
|
|
||||||
, m_ui(new Ui::SearchWidget())
|
|
||||||
{
|
|
||||||
m_ui->setupUi(this);
|
|
||||||
|
|
||||||
m_searchTimer = new QTimer(this);
|
|
||||||
m_searchTimer->setSingleShot(true);
|
|
||||||
|
|
||||||
connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), SLOT(startSearchTimer()));
|
|
||||||
connect(m_ui->searchEdit, SIGNAL(returnPressed()), SLOT(startSearch()));
|
|
||||||
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);
|
|
||||||
|
|
||||||
m_ui->searchEdit->installEventFilter(this);
|
|
||||||
|
|
||||||
QMenu *searchMenu = new QMenu();
|
|
||||||
m_actionCaseSensitive = searchMenu->addAction(tr("Case Sensitive"), this, SLOT(updateCaseSensitive()));
|
|
||||||
m_actionCaseSensitive->setObjectName("actionSearchCaseSensitive");
|
|
||||||
m_actionCaseSensitive->setCheckable(true);
|
|
||||||
|
|
||||||
m_ui->searchIcon->setIcon(filePath()->icon("actions", "system-search"));
|
|
||||||
m_ui->searchIcon->setMenu(searchMenu);
|
|
||||||
m_ui->searchIcon->setPopupMode(QToolButton::MenuButtonPopup);
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchWidget::~SearchWidget()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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…
Reference in New Issue
Block a user