context menu for EntryView

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@42 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 18 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;
updateColumns();
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(){
clear();
Items.clear();

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

@ -169,6 +169,16 @@ void KeepassMainWindow::setupMenus(){
GroupView->ContextMenu->addSeparator();
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);
ViewHideUsernamesAction->setChecked(config.ListView_HideUsernames);
ViewColumnsTitleAction->setChecked(config.Columns[0]);