From 5c7c7f54fae984e0966fc39fdcdead9ad726c265 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Mon, 5 Jan 2015 18:50:04 +0900 Subject: [PATCH 1/2] Improve UI of the search edit. - The copy action (Control+C) when no text is selected copies the password of the current entry. This should be reasonable when Control+B copies the username. - Down at EOL moves the focus to the entry view. Enter and Tab should do that, but it would be handy for user to be able to get to the third entry by hitting Down three times. --- src/gui/DatabaseWidget.cpp | 32 ++++++++++++++++++++++++++++++++ src/gui/DatabaseWidget.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 31ef9c780..088f83af9 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) m_searchUi->closeSearchButton->setShortcut(Qt::Key_Escape); m_searchWidget->hide(); m_searchUi->caseSensitiveCheckBox->setVisible(false); + m_searchUi->searchEdit->installEventFilter(this); QVBoxLayout* vLayout = new QVBoxLayout(rightHandSideWidget); vLayout->setMargin(0); @@ -982,3 +984,33 @@ bool DatabaseWidget::currentEntryHasNotes() } return !currentEntry->notes().isEmpty(); } + +bool DatabaseWidget::eventFilter(QObject* object, QEvent* event) +{ + if (object == m_searchUi->searchEdit) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent* keyEvent = static_cast(event); + 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. + Entry* currentEntry = m_entryView->currentEntry(); + if (currentEntry && !m_searchUi->searchEdit->hasSelectedText()) { + setClipboardTextAndMinimize(currentEntry->password()); + 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. + if (!m_searchUi->searchEdit->hasSelectedText() && + m_searchUi->searchEdit->cursorPosition() == m_searchUi->searchEdit->text().length()) { + m_entryView->setFocus(); + return true; + } + } + } + } + + return false; +} diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 1ba3dd1f5..653c1fcae 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -102,6 +102,9 @@ Q_SIGNALS: void splitterSizesChanged(); void entryColumnSizesChanged(); +protected: + bool eventFilter(QObject* object, QEvent* event); + public Q_SLOTS: void createEntry(); void cloneEntry(); From b773dbe6458cfca9b43365964caf3e248cf616b1 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Mon, 5 Jan 2015 22:37:37 +0900 Subject: [PATCH 2/2] Test if hitting the Down key moves the focus to the entry view. --- tests/gui/TestGui.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 6443ea5d2..6aa49b836 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -210,6 +210,10 @@ void TestGui::testSearch() // Search for "some" QTest::keyClicks(searchEdit, "some"); QTRY_COMPARE(entryView->model()->rowCount(), 4); + // Press Down to focus on the entry view + QVERIFY(!entryView->hasFocus()); + QTest::keyClick(searchEdit, Qt::Key_Down); + QVERIFY(entryView->hasFocus()); clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton); QAction* entryEditAction = m_mainWindow->findChild("actionEntryEdit");