diff --git a/src/autotype/AutoTypeSelectDialog.cpp b/src/autotype/AutoTypeSelectDialog.cpp index 69f181765..997858f0d 100644 --- a/src/autotype/AutoTypeSelectDialog.cpp +++ b/src/autotype/AutoTypeSelectDialog.cpp @@ -75,6 +75,7 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent) connect(m_view, SIGNAL(clicked(QModelIndex)), SLOT(emitMatchActivated(QModelIndex))); connect(m_view->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(matchRemoved())); connect(m_view, SIGNAL(rejected()), SLOT(reject())); + connect(m_view, SIGNAL(matchTextCopied()), SLOT(reject())); // clang-format on QSortFilterProxyModel* proxy = qobject_cast(m_view->model()); diff --git a/src/gui/entry/AutoTypeMatchView.cpp b/src/gui/entry/AutoTypeMatchView.cpp index 9c4e81d92..180473fd3 100644 --- a/src/gui/entry/AutoTypeMatchView.cpp +++ b/src/gui/entry/AutoTypeMatchView.cpp @@ -18,8 +18,11 @@ #include "AutoTypeMatchView.h" +#include "core/Entry.h" +#include "gui/Clipboard.h" #include "gui/SortFilterHideProxyModel.h" +#include #include #include @@ -42,13 +45,35 @@ AutoTypeMatchView::AutoTypeMatchView(QWidget* parent) setSelectionMode(QAbstractItemView::SingleSelection); header()->setDefaultSectionSize(150); + setContextMenuPolicy(Qt::ActionsContextMenu); + auto* copyUserNameAction = new QAction(tr("Copy &username"), this); + auto* copyPasswordAction = new QAction(tr("Copy &password"), this); + addAction(copyUserNameAction); + addAction(copyPasswordAction); + + connect(copyUserNameAction, SIGNAL(triggered()), this, SLOT(userNameCopied())); + connect(copyPasswordAction, SIGNAL(triggered()), this, SLOT(passwordCopied())); + connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitMatchActivated(QModelIndex))); // clang-format off - connect( - selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(matchSelectionChanged())); + connect(selectionModel(), + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SIGNAL(matchSelectionChanged())); // clang-format on } +void AutoTypeMatchView::userNameCopied() +{ + clipboard()->setText(currentMatch().entry->username()); + emit matchTextCopied(); +} + +void AutoTypeMatchView::passwordCopied() +{ + clipboard()->setText(currentMatch().entry->password()); + emit matchTextCopied(); +} + void AutoTypeMatchView::keyPressEvent(QKeyEvent* event) { if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && currentIndex().isValid()) { diff --git a/src/gui/entry/AutoTypeMatchView.h b/src/gui/entry/AutoTypeMatchView.h index b9f3f3aa5..69d0795d9 100644 --- a/src/gui/entry/AutoTypeMatchView.h +++ b/src/gui/entry/AutoTypeMatchView.h @@ -42,12 +42,15 @@ public: signals: void matchActivated(AutoTypeMatch match); void matchSelectionChanged(); + void matchTextCopied(); protected: void keyPressEvent(QKeyEvent* event) override; private slots: void emitMatchActivated(const QModelIndex& index); + void userNameCopied(); + void passwordCopied(); private: AutoTypeMatchModel* const m_model;