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
This commit is contained in:
parent
6e5effe43e
commit
aeeba6a916
|
@ -997,16 +997,41 @@ else{ int n=0; //Counter for direct (first-level) childs
|
|||
if(n==pos)break;
|
||||
if(Groups[DstIndex+1+i].Level==DstGroup->Level+1)n++;
|
||||
}
|
||||
DstIndex+=n;
|
||||
DstIndex+=(n+1);
|
||||
}
|
||||
|
||||
|
||||
for(i=NumSubGroups; i>=0; 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){
|
||||
if(!group)return Groups.size();
|
||||
int GroupIndex=Groups.indexOf(*group);
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
void deleteGroup(CGroup* pGroup);
|
||||
void deleteGroup(unsigned long ID);
|
||||
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(unsigned long ID);
|
||||
int getNumberOfChilds(CGroup* pGroup);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <QBrush>
|
||||
#include "main.h"
|
||||
#include "GroupView.h"
|
||||
|
||||
#define INSERT_AREA_WIDTH 4
|
||||
|
||||
KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
|
||||
InsertionMarker=QLine();
|
||||
|
@ -64,7 +64,7 @@ InsertionMarker=QLine();
|
|||
if(item){
|
||||
QRect ItemRect=visualItemRect(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);
|
||||
f.setBold(true);
|
||||
item->setFont(0,f);
|
||||
|
@ -73,8 +73,12 @@ if(item){
|
|||
}
|
||||
else{
|
||||
LastHoverItem=NULL;
|
||||
InsertionMarker=QLine(ItemRect.x(),ItemRect.y()+ItemRect.height(),
|
||||
ItemRect.x()+ItemRect.width(),ItemRect.y()+ItemRect.height());
|
||||
if(event->pos().y() > INSERT_AREA_WIDTH)
|
||||
InsertionMarker=QLine(ItemRect.x(),ItemRect.y()+ItemRect.height(),
|
||||
ItemRect.x()+ItemRect.width(),ItemRect.y()+ItemRect.height());
|
||||
else
|
||||
InsertionMarker=QLine(ItemRect.x(),0,
|
||||
ItemRect.x()+ItemRect.width(),0);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -109,10 +113,22 @@ if(LastHoverItem){
|
|||
|
||||
}
|
||||
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
|
||||
if(item)
|
||||
db->moveGroup(DragItem->pGroup,item->pGroup);
|
||||
else
|
||||
db->moveGroup(DragItem->pGroup,NULL);
|
||||
if(item){
|
||||
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
|
||||
db->moveGroupDirectly(DragItem->pGroup,item->pGroup);
|
||||
}
|
||||
else db->moveGroupDirectly(DragItem->pGroup,NULL);
|
||||
}
|
||||
}
|
||||
else db->moveGroup(DragItem->pGroup,NULL);
|
||||
|
||||
updateItems();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue