From ea6f2477ef5a62727dcee210e2f295b6b525c872 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Wed, 16 May 2012 09:56:18 +0200 Subject: [PATCH] Add button to clear search field. --- src/gui/DatabaseWidget.cpp | 30 +++++++++++++++++++++++------- src/gui/DatabaseWidget.h | 3 +++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 8b9051f01..272478fdb 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -54,22 +54,31 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) policy.setHorizontalStretch(30); m_groupView->setSizePolicy(policy); - QWidget* widget = new QWidget(); - policy = widget->sizePolicy(); + QWidget* rightHandSideWidget = new QWidget(); + policy = rightHandSideWidget->sizePolicy(); policy.setHorizontalStretch(70); - widget->setSizePolicy(policy); - - splitter->addWidget(m_groupView); + rightHandSideWidget->setSizePolicy(policy); QVBoxLayout* vLayout = new QVBoxLayout(); QHBoxLayout* hLayout = new QHBoxLayout(); + hLayout->addWidget(new QLabel("Find:")); + m_searchEdit = new QLineEdit(); + m_searchEdit->setObjectName("searchEdit"); hLayout->addWidget(m_searchEdit); + + m_clearSearchButton = new QPushButton("Clear"); + m_clearSearchButton->setObjectName("clearSearchButton"); + hLayout->addWidget(m_clearSearchButton); + vLayout->addLayout(hLayout); vLayout->addWidget(m_entryView); - widget->setLayout(vLayout); - splitter->addWidget(widget); + + rightHandSideWidget->setLayout(vLayout); + + splitter->addWidget(m_groupView); + splitter->addWidget(rightHandSideWidget); layout->addWidget(splitter); m_mainWidget->setLayout(layout); @@ -100,6 +109,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) connect(m_databaseSettingsWidget, SIGNAL(editFinished(bool)), SLOT(updateSettings(bool))); connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitCurrentModeChanged())); connect(m_searchEdit, SIGNAL(returnPressed()), this, SLOT(search())); + connect(m_clearSearchButton, SIGNAL(clicked()), this, SLOT(clearSearchEdit())); setCurrentIndex(0); } @@ -374,3 +384,9 @@ void DatabaseWidget::clearLastGroup(Group* group) m_lastGroup = 0; } } + +void DatabaseWidget::clearSearchEdit() +{ + m_searchEdit->clear(); + m_searchEdit->setFocus(); +} diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 669014258..2ab526968 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -18,6 +18,7 @@ #ifndef KEEPASSX_DATABASEWIDGET_H #define KEEPASSX_DATABASEWIDGET_H +#include #include class QLineEdit; @@ -78,6 +79,7 @@ private Q_SLOTS: void updateSettings(bool accepted); void emitCurrentModeChanged(); void clearLastGroup(Group* group); + void clearSearchEdit(); private: void truncateHistories(); @@ -94,6 +96,7 @@ private: Entry* m_newEntry; Group* m_newParent; QLineEdit* m_searchEdit; + QPushButton* m_clearSearchButton; Group* m_lastGroup; };