From 035271d469dd5572aac82376728be9686de32ef3 Mon Sep 17 00:00:00 2001 From: Jens Dieskau Date: Sun, 29 Sep 2013 17:33:45 +0200 Subject: [PATCH] Only edit entries on doubleclick (not single) or with enter key. https://github.com/keepassx/keepassx/pull/19 --- src/gui/entry/EntryView.cpp | 14 +++++++++++++- src/gui/entry/EntryView.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 5c051df9..90384795 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -17,6 +17,8 @@ #include "EntryView.h" +#include + #include "gui/SortFilterHideProxyModel.h" EntryView::EntryView(QWidget* parent) @@ -42,12 +44,22 @@ EntryView::EntryView(QWidget* parent) // QAbstractItemView::startDrag() uses this property as the default drag action setDefaultDropAction(Qt::MoveAction); - connect(this, SIGNAL(activated(QModelIndex)), SLOT(emitEntryActivated(QModelIndex))); + connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitEntryActivated(QModelIndex))); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged())); connect(m_model, SIGNAL(switchedToEntryListMode()), SLOT(switchToEntryListMode())); connect(m_model, SIGNAL(switchedToGroupMode()), SLOT(switchToGroupMode())); } +void EntryView::keyPressEvent(QKeyEvent* event) +{ + if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && currentIndex().isValid()) { + Q_EMIT emitEntryActivated(currentIndex()); + } + else { + QTreeView::keyPressEvent(event); + } +} + void EntryView::setGroup(Group* group) { m_model->setGroup(group); diff --git a/src/gui/entry/EntryView.h b/src/gui/entry/EntryView.h index 134622bb..45187a9e 100644 --- a/src/gui/entry/EntryView.h +++ b/src/gui/entry/EntryView.h @@ -50,6 +50,9 @@ Q_SIGNALS: void entryActivated(Entry* entry, EntryModel::ModelColumn column); void entrySelectionChanged(); +protected: + void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE; + private Q_SLOTS: void emitEntryActivated(const QModelIndex& index); void switchToEntryListMode();