Drag'n'Drop: added insertion marks for group sorting
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@21 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
265104133b
commit
ed93603383
|
@ -328,16 +328,16 @@
|
||||||
<pixmapfunction></pixmapfunction>
|
<pixmapfunction></pixmapfunction>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>KeepassGroupView</class>
|
<class>KeepassEntryView</class>
|
||||||
<extends>QTreeWidget</extends>
|
<extends>QTreeWidget</extends>
|
||||||
<header>../../src/lib/GroupView.h</header>
|
<header>../../src/lib/EntryView.h</header>
|
||||||
<container>0</container>
|
<container>0</container>
|
||||||
<pixmap></pixmap>
|
<pixmap></pixmap>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>KeepassEntryView</class>
|
<class>KeepassGroupView</class>
|
||||||
<extends>QTreeWidget</extends>
|
<extends>QTreeWidget</extends>
|
||||||
<header>../../src/lib/EntryView.h</header>
|
<header>../../src/lib/GroupView.h</header>
|
||||||
<container>0</container>
|
<container>0</container>
|
||||||
<pixmap></pixmap>
|
<pixmap></pixmap>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QDragMoveEvent>
|
#include <QDragMoveEvent>
|
||||||
#include <QDragLeaveEvent>
|
#include <QDragLeaveEvent>
|
||||||
#include <QDropEvent>
|
#include <QDropEvent>
|
||||||
|
#include <QPaintEvent>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
@ -34,8 +35,10 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "GroupView.h"
|
#include "GroupView.h"
|
||||||
|
|
||||||
|
|
||||||
KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
|
KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
|
||||||
db=0;
|
InsertionMarker=QLine();
|
||||||
|
db=NULL;
|
||||||
LastHoverItem=NULL;
|
LastHoverItem=NULL;
|
||||||
setHeaderLabels(QStringList()<<tr("Gruppen"));
|
setHeaderLabels(QStringList()<<tr("Gruppen"));
|
||||||
}
|
}
|
||||||
|
@ -49,43 +52,61 @@ event->accept();
|
||||||
|
|
||||||
void KeepassGroupView:: dragMoveEvent ( QDragMoveEvent * event ){
|
void KeepassGroupView:: dragMoveEvent ( QDragMoveEvent * event ){
|
||||||
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
|
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
|
||||||
|
|
||||||
if(LastHoverItem){
|
if(LastHoverItem){
|
||||||
QFont f=LastHoverItem->font(0);
|
QFont f=LastHoverItem->font(0);
|
||||||
f.setBold(false);
|
f.setBold(false);
|
||||||
LastHoverItem->setFont(0,f);
|
LastHoverItem->setFont(0,f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertionMarker=QLine();
|
||||||
|
|
||||||
if(item){
|
if(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){
|
||||||
QFont f=item->font(0);
|
QFont f=item->font(0);
|
||||||
f.setBold(true);
|
f.setBold(true);
|
||||||
item->setFont(0,f);
|
item->setFont(0,f);
|
||||||
LastHoverItem=item;
|
LastHoverItem=item;
|
||||||
event->setAccepted(true);}
|
event->setAccepted(true);
|
||||||
else
|
|
||||||
event->setAccepted(false);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
LastHoverItem=NULL;}
|
LastHoverItem=NULL;
|
||||||
|
InsertionMarker=QLine(ItemRect.x(),ItemRect.y()+ItemRect.height(),
|
||||||
|
ItemRect.x()+ItemRect.width(),ItemRect.y()+ItemRect.height());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
event->setAccepted(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
LastHoverItem=NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void KeepassGroupView:: dragLeaveEvent ( QDragLeaveEvent * event ){
|
void KeepassGroupView:: dragLeaveEvent ( QDragLeaveEvent * event ){
|
||||||
|
InsertionMarker=QLine();
|
||||||
if(LastHoverItem){
|
if(LastHoverItem){
|
||||||
QFont f=LastHoverItem->font(0);
|
QFont f=LastHoverItem->font(0);
|
||||||
f.setBold(false);
|
f.setBold(false);
|
||||||
LastHoverItem->setFont(0,f);
|
LastHoverItem->setFont(0,f);
|
||||||
}
|
}
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KeepassGroupView::dropEvent( QDropEvent * event ){
|
void KeepassGroupView::dropEvent( QDropEvent * event ){
|
||||||
|
InsertionMarker=QLine();
|
||||||
if(LastHoverItem){
|
if(LastHoverItem){
|
||||||
QFont f=LastHoverItem->font(0);
|
QFont f=LastHoverItem->font(0);
|
||||||
f.setBold(false);
|
f.setBold(false);
|
||||||
LastHoverItem->setFont(0,f);
|
LastHoverItem->setFont(0,f);
|
||||||
LastHoverItem=NULL;
|
LastHoverItem=NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
|
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
|
||||||
if(item)
|
if(item)
|
||||||
|
@ -132,6 +153,7 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeepassGroupView::updateItems(){
|
void KeepassGroupView::updateItems(){
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
Items.clear();
|
Items.clear();
|
||||||
for(int i=0; i<db->Groups.size();i++){
|
for(int i=0; i<db->Groups.size();i++){
|
||||||
|
@ -168,10 +190,23 @@ for(int i=Items.size()-1;i>=0;i--){
|
||||||
if(Items[i]->pGroup->Level==level){
|
if(Items[i]->pGroup->Level==level){
|
||||||
return Items[i];}
|
return Items[i];}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Items.back();
|
return Items.back();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeepassGroupView::paintEvent(QPaintEvent* event){
|
||||||
|
QTreeWidget::paintEvent(event);
|
||||||
|
QPainter painter(viewport());
|
||||||
|
QPen pen(QColor(100,100,100));
|
||||||
|
pen.setWidth(2);
|
||||||
|
pen.setStyle(Qt::DotLine);
|
||||||
|
painter.setPen(pen);
|
||||||
|
if(!InsertionMarker.isNull()){
|
||||||
|
painter.drawLine(InsertionMarker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GroupViewItem::GroupViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){
|
GroupViewItem::GroupViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){
|
||||||
|
|
|
@ -39,12 +39,17 @@ protected:
|
||||||
virtual void dropEvent ( QDropEvent * event );
|
virtual void dropEvent ( QDropEvent * event );
|
||||||
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 );
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
QLine InsertionMarker;
|
||||||
QPoint DragStartPos;
|
QPoint DragStartPos;
|
||||||
QPixmap DragPixmap;
|
QPixmap DragPixmap;
|
||||||
GroupViewItem* DragItem;
|
GroupViewItem* DragItem;
|
||||||
GroupViewItem* LastHoverItem;
|
GroupViewItem* LastHoverItem;
|
||||||
|
|
||||||
GroupViewItem* getLastSameLevelItem(int level);
|
GroupViewItem* getLastSameLevelItem(int level);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue