Slightly reorganized the menubar

Added menu action to sort the groups (Bug #2268672)

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@268 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 15 years ago
parent 688bfe44c7
commit dbb6e00a4a
  1. 42
      src/forms/MainWindow.ui
  2. 87
      src/lib/GroupView.cpp
  3. 11
      src/lib/GroupView.h
  4. 3
      src/mainwindow.cpp

@ -167,14 +167,15 @@
<addaction name="FileUnLockWorkspaceAction" />
<addaction name="FileExitAction" />
</widget>
<widget class="QMenu" name="menuBearbeiten" >
<widget class="QMenu" name="menuEntries" >
<property name="title" >
<string>&amp;Edit</string>
<string>&amp;Entries</string>
</property>
<addaction name="EditNewGroupAction" />
<addaction name="EditNewSubgroupAction" />
<addaction name="EditEditGroupAction" />
<addaction name="EditDeleteGroupAction" />
<addaction name="EditNewEntryAction" />
<addaction name="EditCloneEntryAction" />
<addaction name="EditEditEntryAction" />
<addaction name="EditDeleteEntryAction" />
<addaction name="EditAutoTypeAction" />
<addaction name="separator" />
<addaction name="EditUsernameToClipboardAction" />
<addaction name="EditPasswordToClipboardAction" />
@ -182,12 +183,6 @@
<addaction name="EditCopyUrlAction" />
<addaction name="EditSaveAttachmentAction" />
<addaction name="separator" />
<addaction name="EditNewEntryAction" />
<addaction name="EditEditEntryAction" />
<addaction name="EditCloneEntryAction" />
<addaction name="EditDeleteEntryAction" />
<addaction name="EditAutoTypeAction" />
<addaction name="separator" />
<addaction name="EditSearchAction" />
<addaction name="EditGroupSearchAction" />
</widget>
@ -240,8 +235,19 @@
<addaction name="separator" />
<addaction name="ExtrasSettingsAction" />
</widget>
<widget class="QMenu" name="menuGroups" >
<property name="title" >
<string>&amp;Groups</string>
</property>
<addaction name="EditNewGroupAction" />
<addaction name="EditNewSubgroupAction" />
<addaction name="EditEditGroupAction" />
<addaction name="EditDeleteGroupAction" />
<addaction name="EditGroupSortAction" />
</widget>
<addaction name="menuDatei" />
<addaction name="menuBearbeiten" />
<addaction name="menuEntries" />
<addaction name="menuGroups" />
<addaction name="ViewMenu" />
<addaction name="menuExtras" />
<addaction name="menuHilfe" />
@ -593,6 +599,16 @@
<string>Add New Group...</string>
</property>
</action>
<action name="EditGroupSortAction" >
<property name="text" >
<string>Sort groups</string>
</property>
</action>
<action name="EditGroupSortDesc" >
<property name="text" >
<string>Sort in descending oder</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

@ -23,6 +23,7 @@
#include "dialogs/EditGroupDlg.h"
#include <QBrush>
#include <QHeaderView>
#define INSERT_AREA_WIDTH 4
@ -36,7 +37,7 @@ KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
}
void KeepassGroupView::createItems(){
void KeepassGroupView::createItems(){
clear();
Items.clear();
InsLinePos=-1;
@ -177,7 +178,7 @@ void KeepassGroupView::OnCurrentGroupChanged(QTreeWidgetItem* cur){
emit groupChanged(((GroupViewItem*)cur)->GroupHandle);
}
else
emit groupChanged(NULL);
emit groupChanged(NULL);
}
@ -187,11 +188,11 @@ void KeepassGroupView::setCurrentGroup(IGroupHandle* group){
for(i=0;i<Items.size();i++)
if(Items[i]->GroupHandle==group){found=true; break;}
if(!found)return;
setCurrentItem(Items[i]);
setCurrentItem(Items[i]);
}
void KeepassGroupView::dragEnterEvent ( QDragEnterEvent * event ){
LastHoverItem=NULL;
LastHoverItem=NULL;
InsLinePos=-1;
if(event->mimeData()->hasFormat("application/x-keepassx-group")){
@ -299,15 +300,15 @@ void KeepassGroupView::dropEvent( QDropEvent * event ){
if(event->pos().y()>ItemRect.y()+2){
qDebug("Insert behind sibling '%s'",((char*)Item->text(0).toUtf8().data()));
if(DragItem->parent()){
DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
}
else{
takeTopLevelItem(indexOfTopLevelItem(DragItem));
takeTopLevelItem(indexOfTopLevelItem(DragItem));
}
if(Item->parent()){
int index=Item->parent()->indexOfChild(Item)+1;
db->moveGroup(DragItem->GroupHandle,((GroupViewItem*)Item->parent())->GroupHandle,index);
Item->parent()->insertChild(index,DragItem);
Item->parent()->insertChild(index,DragItem);
}
else{
int index=indexOfTopLevelItem(Item)+1;
@ -319,15 +320,15 @@ void KeepassGroupView::dropEvent( QDropEvent * event ){
else{
qDebug("Insert before sibling '%s'",((char*)Item->text(0).toUtf8().data()));
if(DragItem->parent()){
DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
}
else{
takeTopLevelItem(indexOfTopLevelItem(DragItem));
takeTopLevelItem(indexOfTopLevelItem(DragItem));
}
if(Item->parent()){
int index=Item->parent()->indexOfChild(Item);
db->moveGroup(DragItem->GroupHandle,((GroupViewItem*)Item->parent())->GroupHandle,index);
Item->parent()->insertChild(index,DragItem);
Item->parent()->insertChild(index,DragItem);
}
else{
int index=indexOfTopLevelItem(Item);
@ -343,7 +344,7 @@ void KeepassGroupView::dropEvent( QDropEvent * event ){
}
void KeepassGroupView::entryDragMoveEvent( QDragMoveEvent * event ){
void KeepassGroupView::entryDragMoveEvent(QDragMoveEvent* event){
GroupViewItem* Item=(GroupViewItem*)itemAt(event->pos());
if(!Item){
@ -378,7 +379,7 @@ void KeepassGroupView::entryDragMoveEvent( QDragMoveEvent * event ){
}
void KeepassGroupView::dragMoveEvent( QDragMoveEvent * event ){
void KeepassGroupView::dragMoveEvent(QDragMoveEvent* event){
if(DragType==EntryDrag){
entryDragMoveEvent(event);
return;
@ -435,7 +436,7 @@ void KeepassGroupView::dragMoveEvent( QDragMoveEvent * event ){
InsLinePos=ItemRect.y();
}
InsLineStart=ItemRect.x();
viewport()->update(QRegion(0,InsLinePos-2,viewport()->width(),4));
viewport()->update(QRegion(0,InsLinePos-2,viewport()->width(),4));
}
event->acceptProposedAction();
return;
@ -451,7 +452,7 @@ void KeepassGroupView::paintEvent(QPaintEvent* event){
if(InsLinePos != -1){
QPainter painter(viewport());
painter.setBrush(QBrush(QColor(0,0,0),Qt::Dense4Pattern));
painter.setPen(Qt::NoPen);
painter.setPen(Qt::NoPen);
painter.drawRect(InsLineStart,InsLinePos-2,viewport()->width(),4);
}
}
@ -494,11 +495,47 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){
}
void KeepassGroupView::OnItemExpanded(QTreeWidgetItem* item){
dynamic_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(true);
static_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(true);
}
void KeepassGroupView::OnItemCollapsed(QTreeWidgetItem* item){
dynamic_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(false);
static_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(false);
}
void KeepassGroupView::OnSort() {
QHash<QTreeWidgetItem*,int> oldIndex;
for (int i=0; i<Items.size(); i++) {
if (Items[i]->parent())
oldIndex.insert(Items[i], Items[i]->parent()->indexOfChild(Items[i]));
else
oldIndex.insert(Items[i], invisibleRootItem()->indexOfChild(Items[i]));
}
sortItems(0, Qt::AscendingOrder);
bool modified = false;
QMutableHashIterator<QTreeWidgetItem*, int> i(oldIndex);
while (i.hasNext()) {
i.next();
int newIndex;
IGroupHandle* parent;
if (i.key()->parent()) {
newIndex = i.key()->parent()->indexOfChild(i.key());
parent = static_cast<GroupViewItem*>(i.key()->parent())->GroupHandle;
}
else {
newIndex = invisibleRootItem()->indexOfChild(i.key());
parent = NULL;
}
if (newIndex != i.value()) {
db->moveGroup(static_cast<GroupViewItem*>(i.key())->GroupHandle, parent, newIndex);
modified = true;
}
}
if (modified)
emit fileModified();
}
@ -518,3 +555,21 @@ GroupViewItem::GroupViewItem(QTreeWidgetItem *parent):QTreeWidgetItem(parent){
GroupViewItem::GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){
}
bool GroupViewItem::operator<(const QTreeWidgetItem& other) const {
const GroupViewItem* otherItem = static_cast<const GroupViewItem*>(&other);
KeepassGroupView* groupView = static_cast<KeepassGroupView*>(treeWidget());
// Search result is always at the bottom
if (this == groupView->SearchResultItem)
return false;
if (otherItem == groupView->SearchResultItem)
return true;
// Backup group is always at the bottom but above search results
if (!parent() && text(0).compare("Backup", Qt::CaseInsensitive) == 0)
return false;
if (!otherItem->parent() && otherItem->text(0).compare("Backup", Qt::CaseInsensitive) == 0)
return true;
return QTreeWidgetItem::operator<(other);
}

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _GROUP_VIEW_H_
#define _GROUP_VIEW_H_
@ -44,13 +45,13 @@ class KeepassGroupView:public QTreeWidget{
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);
void entryDragMoveEvent(QDragMoveEvent* event);
virtual void dragLeaveEvent ( QDragLeaveEvent * event );
virtual void dropEvent ( QDropEvent * event );
virtual void dragLeaveEvent(QDragLeaveEvent* event);
virtual void dropEvent(QDropEvent* event);
void entryDropEvent(QDropEvent* event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void paintEvent ( QPaintEvent * event );
virtual void contextMenuEvent(QContextMenuEvent *event);
virtual void paintEvent (QPaintEvent* event);
virtual void contextMenuEvent(QContextMenuEvent* event);
void addChildren(GroupViewItem* item);
QPoint DragStartPos;
GroupViewItem* DragItem;
@ -71,6 +72,7 @@ class KeepassGroupView:public QTreeWidget{
void OnHideSearchResults();
void OnItemExpanded(QTreeWidgetItem*);
void OnItemCollapsed(QTreeWidgetItem*);
void OnSort();
signals:
void groupChanged(IGroupHandle* NewGroup);
@ -87,6 +89,7 @@ class GroupViewItem:public QTreeWidgetItem{
GroupViewItem(QTreeWidget *parent, QTreeWidgetItem * preceding);
GroupViewItem(QTreeWidgetItem *parent);
GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
bool operator<(const QTreeWidgetItem& other) const;
IGroupHandle* GroupHandle;
};

@ -152,6 +152,7 @@ void KeepassMainWindow::setupConnections(){
connect(EditNewSubgroupAction, SIGNAL(triggered()), GroupView, SLOT(OnNewSubgroup()));
connect(EditEditGroupAction, SIGNAL(triggered()), GroupView, SLOT(OnEditGroup()));
connect(EditDeleteGroupAction, SIGNAL(triggered()), GroupView, SLOT(OnDeleteGroup()));
connect(EditGroupSortAction, SIGNAL(triggered()), GroupView, SLOT(OnSort()));
connect(EditNewEntryAction, SIGNAL(triggered()), EntryView, SLOT(OnNewEntry()));
connect(EditEditEntryAction, SIGNAL(triggered()), EntryView, SLOT(OnEditEntry()));
connect(EntryView, SIGNAL(requestCreateGroup(QString,quint32,GroupViewItem*)), GroupView, SLOT(createGroup(QString,quint32,GroupViewItem*)));
@ -243,6 +244,7 @@ void KeepassMainWindow::setupIcons(){
EditNewEntryAction->setIcon(getIcon("newentry"));
EditEditEntryAction->setIcon(getIcon("editentry"));
EditDeleteEntryAction->setIcon(getIcon("deleteentry"));
EditGroupSortAction->setIcon(getIcon("swap"));
EditUsernameToClipboardAction->setIcon(getIcon("copyusername"));
EditPasswordToClipboardAction->setIcon(getIcon("copypwd"));
EditCloneEntryAction->setIcon(getIcon("cloneentry"));
@ -278,6 +280,7 @@ void KeepassMainWindow::setupMenus(){
GroupView->ContextMenu->addAction(EditNewSubgroupAction);
GroupView->ContextMenu->addAction(EditEditGroupAction);
GroupView->ContextMenu->addAction(EditDeleteGroupAction);
GroupView->ContextMenu->addAction(EditGroupSortAction);
GroupView->ContextMenu->addSeparator();
GroupView->ContextMenu->addAction(EditNewEntryAction);
GroupView->ContextMenu->addSeparator();