finished drag and drop implementation for groups

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@23 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent 6e5effe43e
commit aeeba6a916
  1. 29
      src/PwManager.cpp
  2. 1
      src/PwManager.h
  3. 26
      src/lib/GroupView.cpp

@ -997,16 +997,41 @@ else{ int n=0; //Counter for direct (first-level) childs
if(n==pos)break; if(n==pos)break;
if(Groups[DstIndex+1+i].Level==DstGroup->Level+1)n++; if(Groups[DstIndex+1+i].Level==DstGroup->Level+1)n++;
} }
DstIndex+=n; DstIndex+=(n+1);
} }
for(i=NumSubGroups; i>=0; i--) for(i=NumSubGroups; i>=0; i--)
Groups.insert(DstIndex,tmp[i]); Groups.insert(DstIndex,tmp[i]);
}
void PwDatabase::moveGroupDirectly(CGroup* group, CGroup* DstGroup){
int NumSubGroups=getNumberOfChilds(group);
int GroupIndex=Groups.indexOf(*group);
int DstIndex, LevelDiff, i;
QList<CGroup> tmp;
if(DstGroup)
LevelDiff=DstGroup->Level - group->Level;
else
LevelDiff=-group->Level;
for(i=GroupIndex; i<=GroupIndex+NumSubGroups; i++){
tmp << Groups[i];
tmp.back().Level+=LevelDiff;
}
for(i=0; i<=NumSubGroups; i++)
Groups.removeAt(GroupIndex);
if(DstGroup)
DstIndex=Groups.indexOf(*DstGroup)+1;
else
DstIndex=0;
for(i=NumSubGroups; i>=0; i--)
Groups.insert(DstIndex,tmp[i]);
} }
int PwDatabase::getNumberOfChilds(CGroup* group){ int PwDatabase::getNumberOfChilds(CGroup* group){
if(!group)return Groups.size(); if(!group)return Groups.size();
int GroupIndex=Groups.indexOf(*group); int GroupIndex=Groups.indexOf(*group);

@ -58,6 +58,7 @@ public:
void deleteGroup(CGroup* pGroup); void deleteGroup(CGroup* pGroup);
void deleteGroup(unsigned long ID); void deleteGroup(unsigned long ID);
void moveGroup(CGroup* group, CGroup* DstGroup, int pos=-1); void moveGroup(CGroup* group, CGroup* DstGroup, int pos=-1);
void moveGroupDirectly(CGroup* group, CGroup* DstGroup); //inserts group directly behind DstGroup on the same level
int getGroupIndex(CGroup* group); int getGroupIndex(CGroup* group);
int getGroupIndex(unsigned long ID); int getGroupIndex(unsigned long ID);
int getNumberOfChilds(CGroup* pGroup); int getNumberOfChilds(CGroup* pGroup);

@ -34,7 +34,7 @@
#include <QBrush> #include <QBrush>
#include "main.h" #include "main.h"
#include "GroupView.h" #include "GroupView.h"
#define INSERT_AREA_WIDTH 4
KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){ KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
InsertionMarker=QLine(); InsertionMarker=QLine();
@ -64,7 +64,7 @@ InsertionMarker=QLine();
if(item){ if(item){
QRect ItemRect=visualItemRect(item); QRect ItemRect=visualItemRect(item);
if(!db->isParentGroup(item->pGroup,DragItem->pGroup) && DragItem!=item){ if(!db->isParentGroup(item->pGroup,DragItem->pGroup) && DragItem!=item){
if((ItemRect.height()+ItemRect.y())-event->pos().y() > 4){ if((ItemRect.height()+ItemRect.y())-event->pos().y() > INSERT_AREA_WIDTH && event->pos().y() > INSERT_AREA_WIDTH){
QFont f=item->font(0); QFont f=item->font(0);
f.setBold(true); f.setBold(true);
item->setFont(0,f); item->setFont(0,f);
@ -73,8 +73,12 @@ if(item){
} }
else{ else{
LastHoverItem=NULL; LastHoverItem=NULL;
if(event->pos().y() > INSERT_AREA_WIDTH)
InsertionMarker=QLine(ItemRect.x(),ItemRect.y()+ItemRect.height(), InsertionMarker=QLine(ItemRect.x(),ItemRect.y()+ItemRect.height(),
ItemRect.x()+ItemRect.width(),ItemRect.y()+ItemRect.height()); ItemRect.x()+ItemRect.width(),ItemRect.y()+ItemRect.height());
else
InsertionMarker=QLine(ItemRect.x(),0,
ItemRect.x()+ItemRect.width(),0);
} }
} }
else else
@ -109,10 +113,22 @@ if(LastHoverItem){
} }
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos()); GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
if(item) if(item){
db->moveGroup(DragItem->pGroup,item->pGroup); QRect ItemRect=visualItemRect(item);
if((ItemRect.height()+ItemRect.y())-event->pos().y() > INSERT_AREA_WIDTH && event->pos().y() > INSERT_AREA_WIDTH){
db->moveGroup(DragItem->pGroup,item->pGroup);}
else{
if(event->pos().y() > INSERT_AREA_WIDTH){
if(db->getNumberOfChilds(item->pGroup) > 0)
db->moveGroup(DragItem->pGroup,item->pGroup,0);
else else
db->moveGroup(DragItem->pGroup,NULL); db->moveGroupDirectly(DragItem->pGroup,item->pGroup);
}
else db->moveGroupDirectly(DragItem->pGroup,NULL);
}
}
else db->moveGroup(DragItem->pGroup,NULL);
updateItems(); updateItems();
} }