context menu for group view

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@40 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent 69c3c401dd
commit 9fb1f983bf
  1. 10
      src/lib/GroupView.cpp
  2. 3
      src/lib/GroupView.h
  3. 75
      src/mainwindow.cpp

@ -32,6 +32,7 @@
#include <QPainter> #include <QPainter>
#include <QPen> #include <QPen>
#include <QBrush> #include <QBrush>
#include <QMenu>
#include "main.h" #include "main.h"
#include "GroupView.h" #include "GroupView.h"
#define INSERT_AREA_WIDTH 4 #define INSERT_AREA_WIDTH 4
@ -42,6 +43,7 @@ db=NULL;
LastHoverItem=NULL; LastHoverItem=NULL;
setHeaderLabels(QStringList()<<tr("Gruppen")); setHeaderLabels(QStringList()<<tr("Gruppen"));
ShowSearchGroup=false; ShowSearchGroup=false;
ContextMenu=new QMenu(this);
} }
void KeepassGroupView::selectSearchGroup(){ void KeepassGroupView::selectSearchGroup(){
@ -248,6 +250,13 @@ if(ShowSearchGroup && (item == Items.back()))return true;
else return false; else return false;
} }
void KeepassGroupView::contextMenuEvent(QContextMenuEvent* e){
if(!(GroupViewItem*)itemAt(e->pos()) && selectedItems().size()){
setItemSelected(selectedItems()[0],false);
}
e->accept();
ContextMenu->popup(e->globalPos());
}
GroupViewItem::GroupViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){ GroupViewItem::GroupViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){
} }
@ -260,3 +269,4 @@ GroupViewItem::GroupViewItem(QTreeWidgetItem *parent):QTreeWidgetItem(parent){
GroupViewItem::GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){ GroupViewItem::GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){
} }

@ -22,6 +22,7 @@
#include <QTreeWidget> #include <QTreeWidget>
#include <QLine> #include <QLine>
#include <QContextMenuEvent>
#include "../PwManager.h" #include "../PwManager.h"
class GroupViewItem; class GroupViewItem;
@ -37,6 +38,7 @@ public:
PwDatabase *db; PwDatabase *db;
bool ShowSearchGroup; //needs a "updateItems()" after a change! bool ShowSearchGroup; //needs a "updateItems()" after a change!
vector<GroupViewItem*>Items; vector<GroupViewItem*>Items;
QMenu *ContextMenu;
signals: signals:
void fileModified(); void fileModified();
@ -49,6 +51,7 @@ protected:
virtual void mousePressEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event);
virtual void paintEvent ( QPaintEvent * event ); virtual void paintEvent ( QPaintEvent * event );
virtual void contextMenuEvent(QContextMenuEvent *event);
private: private:
QLine InsertionMarker; QLine InsertionMarker;

@ -61,43 +61,13 @@
KeepassMainWindow::KeepassMainWindow(QWidget *parent, Qt::WFlags flags):QMainWindow(parent,flags){ KeepassMainWindow::KeepassMainWindow(QWidget *parent, Qt::WFlags flags):QMainWindow(parent,flags){
setupUi(this); setupUi(this);
FileNewAction->setShortcut(tr("Ctrl+N"));
FileOpenAction->setShortcut(tr("Ctrl+O"));
FileSaveAction->setShortcut(tr("Ctrl+S"));
EditNewGroupAction->setShortcut(tr("Ctrl+G"));
EditPasswordToClipboardAction->setShortcut(tr("Ctrl+C"));
EditUsernameToClipboardAction->setShortcut(tr("Ctrl+B"));
EditOpenUrlAction->setShortcut(tr("Ctrl+U"));
EditNewEntryAction->setShortcut(tr("Ctrl+Y"));
EditEditEntryAction->setShortcut(tr("Ctrl+E"));
EditDeleteEntryAction->setShortcut(tr("Ctrl+D"));
EditCloneEntryAction->setShortcut(tr("Ctrl+K"));
EditSearchAction->setShortcut(tr("Ctrl+F"));
#ifdef Q_WS_MAC
FileCloseAction->setShortcut(tr("Ctrl+W"));
FileSaveAsAction->setShortcut(tr("Shift+Ctrl+S"));
EditGroupSearchAction->setShortcut(tr("Shift+Ctrl+F"));
#endif
ViewHidePasswordsAction->setChecked(config.ListView_HidePasswords);
ViewHideUsernamesAction->setChecked(config.ListView_HideUsernames);
ViewColumnsTitleAction->setChecked(config.Columns[0]);
ViewColumnsUsernameAction->setChecked(config.Columns[1]);
ViewColumnsUrlAction->setChecked(config.Columns[2]);
ViewColumnsPasswordAction->setChecked(config.Columns[3]);
ViewColumnsCommentAction->setChecked(config.Columns[4]);
ViewColumnsExpireAction->setChecked(config.Columns[5]);
ViewColumnsCreationAction->setChecked(config.Columns[6]);
ViewColumnsLastChangeAction->setChecked(config.Columns[7]);
ViewColumnsLastAccessAction->setChecked(config.Columns[8]);
ViewColumnsAttachmentAction->setChecked(config.Columns[9]);
QuickSearchEdit=new QLineEdit(toolBar); QuickSearchEdit=new QLineEdit(toolBar);
QuickSearchEdit->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); QuickSearchEdit->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
setupConnections();
setupIcons(); setupIcons();
setupToolbar(); setupToolbar();
setStateFileOpen(false); setStateFileOpen(false);
setupMenus();
setupConnections();
FileOpen=false; FileOpen=false;
Clipboard=QApplication::clipboard(); Clipboard=QApplication::clipboard();
} }
@ -190,6 +160,47 @@ EditSearchAction->setIcon(*Icon_EditSearch);
EditGroupSearchAction->setIcon(*Icon_EditSearch); EditGroupSearchAction->setIcon(*Icon_EditSearch);
} }
void KeepassMainWindow::setupMenus(){
GroupView->ContextMenu->addAction(EditNewGroupAction);
GroupView->ContextMenu->addAction(EditEditGroupAction);
GroupView->ContextMenu->addAction(EditDeleteGroupAction);
GroupView->ContextMenu->addSeparator();
GroupView->ContextMenu->addAction(EditNewEntryAction);
GroupView->ContextMenu->addSeparator();
GroupView->ContextMenu->addAction(EditGroupSearchAction);
ViewHidePasswordsAction->setChecked(config.ListView_HidePasswords);
ViewHideUsernamesAction->setChecked(config.ListView_HideUsernames);
ViewColumnsTitleAction->setChecked(config.Columns[0]);
ViewColumnsUsernameAction->setChecked(config.Columns[1]);
ViewColumnsUrlAction->setChecked(config.Columns[2]);
ViewColumnsPasswordAction->setChecked(config.Columns[3]);
ViewColumnsCommentAction->setChecked(config.Columns[4]);
ViewColumnsExpireAction->setChecked(config.Columns[5]);
ViewColumnsCreationAction->setChecked(config.Columns[6]);
ViewColumnsLastChangeAction->setChecked(config.Columns[7]);
ViewColumnsLastAccessAction->setChecked(config.Columns[8]);
ViewColumnsAttachmentAction->setChecked(config.Columns[9]);
FileNewAction->setShortcut(tr("Ctrl+N"));
FileOpenAction->setShortcut(tr("Ctrl+O"));
FileSaveAction->setShortcut(tr("Ctrl+S"));
EditNewGroupAction->setShortcut(tr("Ctrl+G"));
EditPasswordToClipboardAction->setShortcut(tr("Ctrl+C"));
EditUsernameToClipboardAction->setShortcut(tr("Ctrl+B"));
EditOpenUrlAction->setShortcut(tr("Ctrl+U"));
EditNewEntryAction->setShortcut(tr("Ctrl+Y"));
EditEditEntryAction->setShortcut(tr("Ctrl+E"));
EditDeleteEntryAction->setShortcut(tr("Ctrl+D"));
EditCloneEntryAction->setShortcut(tr("Ctrl+K"));
EditSearchAction->setShortcut(tr("Ctrl+F"));
#ifdef Q_WS_MAC
FileCloseAction->setShortcut(tr("Ctrl+W"));
FileSaveAsAction->setShortcut(tr("Shift+Ctrl+S"));
EditGroupSearchAction->setShortcut(tr("Shift+Ctrl+F"));
#endif
}
void KeepassMainWindow::openDatabase(QString filename){ void KeepassMainWindow::openDatabase(QString filename){
Q_ASSERT(!FileOpen); Q_ASSERT(!FileOpen);