context menu for EntryView

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@42 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent d093eec4b0
commit a1e30fef1c
  1. 31
      src/lib/EntryView.cpp
  2. 5
      src/lib/EntryView.h
  3. 10
      src/mainwindow.cpp

@ -32,8 +32,39 @@ KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){
CurrentGroup=0; CurrentGroup=0;
updateColumns(); updateColumns();
header()->setResizeMode(QHeaderView::Stretch); header()->setResizeMode(QHeaderView::Stretch);
ContextMenu=new QMenu(this);
} }
void KeepassEntryView::contextMenuEvent(QContextMenuEvent* e){
if(itemAt(e->pos())){
EntryViewItem* item=(EntryViewItem*)itemAt(e->pos());
if(selectedItems().size()==0){
setItemSelected(item,true);}
else{
bool AlreadySelected=false;
for(int i=0;i<selectedItems().size();i++){
if(selectedItems()[i]==item){AlreadySelected=true; break;}
}
if(!AlreadySelected){
while(selectedItems().size()){
setItemSelected(selectedItems()[0],false);
}
setItemSelected(item,true);
}
}
}
else
{while(selectedItems().size()){
setItemSelected(selectedItems()[0],false);}
}
e->accept();
ContextMenu->popup(e->globalPos());
}
void KeepassEntryView::updateItems(){ void KeepassEntryView::updateItems(){
clear(); clear();
Items.clear(); Items.clear();

@ -20,7 +20,9 @@
#ifndef _ENTRY_VIEW_H_ #ifndef _ENTRY_VIEW_H_
#define _ENTRY_VIEW_H_ #define _ENTRY_VIEW_H_
#include <QMenu>
#include <QTreeWidget> #include <QTreeWidget>
#include <QContextMenuEvent>
#include "../PwManager.h" #include "../PwManager.h"
class EntryViewItem; class EntryViewItem;
@ -35,8 +37,11 @@ public:
void showSearchResults(QList<Q_UINT32>& results); void showSearchResults(QList<Q_UINT32>& results);
PwDatabase* db; PwDatabase* db;
vector<EntryViewItem*>Items; vector<EntryViewItem*>Items;
QMenu *ContextMenu;
private: private:
int CurrentGroup; int CurrentGroup;
protected:
virtual void contextMenuEvent(QContextMenuEvent *event);
}; };

@ -169,6 +169,16 @@ void KeepassMainWindow::setupMenus(){
GroupView->ContextMenu->addSeparator(); GroupView->ContextMenu->addSeparator();
GroupView->ContextMenu->addAction(EditGroupSearchAction); GroupView->ContextMenu->addAction(EditGroupSearchAction);
EntryView->ContextMenu->addAction(EditPasswordToClipboardAction);
EntryView->ContextMenu->addAction(EditUsernameToClipboardAction);
EntryView->ContextMenu->addAction(EditOpenUrlAction);
EntryView->ContextMenu->addAction(EditSaveAttachmentAction);
EntryView->ContextMenu->addSeparator();
EntryView->ContextMenu->addAction(EditNewEntryAction);
EntryView->ContextMenu->addAction(EditEditEntryAction);
EntryView->ContextMenu->addAction(EditCloneEntryAction);
EntryView->ContextMenu->addAction(EditDeleteEntryAction);
ViewHidePasswordsAction->setChecked(config.ListView_HidePasswords); ViewHidePasswordsAction->setChecked(config.ListView_HidePasswords);
ViewHideUsernamesAction->setChecked(config.ListView_HideUsernames); ViewHideUsernamesAction->setChecked(config.ListView_HideUsernames);
ViewColumnsTitleAction->setChecked(config.Columns[0]); ViewColumnsTitleAction->setChecked(config.Columns[0]);