Drag'n'Drop: GroupView now prevents parent items from being moved into their own child items.

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@18 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 18 years ago
parent a1a9330f46
commit 16060b08e4
  1. 13
      src/PwManager.cpp
  2. 1
      src/PwManager.h
  3. 31
      src/lib/GroupView.cpp
  4. 1
      src/lib/GroupView.h

@ -909,6 +909,19 @@ for(int i=0;i<Entries.size();i++)
return false;
}
bool PwDatabase::isParentGroup(CGroup* child, CGroup* parent){
if(child==parent)return true; //maybe a bad idea
int ChildIndex=getGroupIndex(child->ID);
int ParentIndex=getGroupIndex(parent->ID);
if(ParentIndex > ChildIndex) return false;
for(int i=ChildIndex; i>ParentIndex;i--){
if(Groups[i].Level<=parent->Level)return false;
}
return true;
}
Q_UINT32 PwDatabase::getNewGroupId(){
Q_UINT32 id;

@ -62,6 +62,7 @@ public:
void moveEntry(CEntry* pEntry,CGroup* pDstGroup);
CEntry* addEntry();
void merge(PwDatabase* db2);
bool isParentGroup(CGroup* Group,CGroup* PotenialParent);
QString getError(); //get first error
QString getErrors(); //get all errors in a \n seperated String

@ -53,11 +53,17 @@ if(LastHoverItem){
f.setBold(false);
LastHoverItem->setFont(0,f);
}
if(item){
QFont f=item->font(0);
f.setBold(true);
item->setFont(0,f);
LastHoverItem=item;}
if(!db->isParentGroup(item->pGroup,DragItem->pGroup) && DragItem!=item){
QFont f=item->font(0);
f.setBold(true);
item->setFont(0,f);
LastHoverItem=item;
event->setAccepted(true);}
else
event->setAccepted(false);
}
else{
LastHoverItem=NULL;}
@ -96,22 +102,21 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){
return;
if ((event->pos() - DragStartPos).manhattanLength() < QApplication::startDragDistance())
return;
GroupViewItem* item=(GroupViewItem*)itemAt(DragStartPos);
if(!item)return;
DragItem=(GroupViewItem*)itemAt(DragStartPos);
if(!DragItem)return;
QDrag *drag = new QDrag(this);
QFontMetrics fontmet(item->font(0));
QFontMetrics fontmet(DragItem->font(0));
int DragPixmHeight=16;
if(fontmet.height()>16)DragPixmHeight=fontmet.height();
DragPixmap = QPixmap(fontmet.width(item->text(0))+19,DragPixmHeight);
DragPixmap = QPixmap(fontmet.width(DragItem->text(0))+19,DragPixmHeight);
DragPixmap.fill(QColor(255,255,255));
QPainter painter(&DragPixmap);
painter.setPen(QColor(0,0,0));
painter.setFont(item->font(0));
painter.drawPixmap(0,0,item->icon(0).pixmap());
painter.drawText(19,DragPixmHeight-fontmet.strikeOutPos(),item->text(0));
painter.setFont(DragItem->font(0));
painter.drawPixmap(0,0,DragItem->icon(0).pixmap());
painter.drawText(19,DragPixmHeight-fontmet.strikeOutPos(),DragItem->text(0));
QMimeData *mimeData = new QMimeData;
mimeData->setData("keepass/group",QByteArray((char*)&(item->pGroup),sizeof(void*)));
mimeData->setData("keepass/group",QByteArray((char*)&(DragItem->pGroup),sizeof(void*)));
drag->setMimeData(mimeData);
drag->setPixmap(DragPixmap);
drag->start();

@ -43,6 +43,7 @@ protected:
private:
QPoint DragStartPos;
QPixmap DragPixmap;
GroupViewItem* DragItem;
GroupViewItem* LastHoverItem;
GroupViewItem* getLastSameLevelItem(int level);
};