- Add hover effect of labels/categories to animate drag'n drop

This commit is contained in:
Christophe Dumez 2009-12-16 22:06:24 +00:00
parent 5d60295db3
commit 38cc55ea09
3 changed files with 43 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 B

View file

@ -166,6 +166,7 @@
<file>Icons/oxygen/network-server.png</file>
<file>Icons/oxygen/folder.png</file>
<file>Icons/oxygen/urlseed.png</file>
<file>Icons/oxygen/folder-documents.png</file>
<file>Icons/oxygen/edit-cut.png</file>
<file>Icons/oxygen/unsubscribe.png</file>
<file>Icons/oxygen/feed-subscribe.png</file>

View file

@ -47,8 +47,12 @@
class LabelFiltersList: public QListWidget {
Q_OBJECT
private:
QListWidgetItem *itemHover;
public:
LabelFiltersList(QWidget *parent): QListWidget(parent){
LabelFiltersList(QWidget *parent): QListWidget(parent) {
itemHover = 0;
// Accept drop
setAcceptDrops(true);
}
@ -57,12 +61,24 @@ signals:
void torrentDropped(int label_row);
protected:
void dragMoveEvent(QDragMoveEvent* event) {
void dragMoveEvent(QDragMoveEvent *event) {
//qDebug("filters, dragmoveevent");
if(itemAt(event->pos()) && row(itemAt(event->pos())) > 0) {
//qDebug("Name: %s", itemAt(event->pos())->text().toLocal8Bit().data());
if(itemHover) {
if(itemHover != itemAt(event->pos())) {
setItemHover(false);
itemHover = itemAt(event->pos());
setItemHover(true);
}
} else {
itemHover = itemAt(event->pos());
setItemHover(true);
}
event->acceptProposedAction();
} else {
if(itemHover)
setItemHover(false);
event->ignore();
}
}
@ -73,6 +89,29 @@ protected:
emit torrentDropped(row(itemAt(event->pos())));
}
event->ignore();
setItemHover(false);
// Select current item again
currentItem()->setSelected(true);
}
void dragLeaveEvent(QDragLeaveEvent*) {
if(itemHover)
setItemHover(false);
// Select current item again
currentItem()->setSelected(true);
}
void setItemHover(bool hover) {
Q_ASSERT(itemHover);
if(hover) {
itemHover->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/folder-documents.png"));
itemHover->setSelected(true);
//setCurrentItem(itemHover);
} else {
itemHover->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/folder.png"));
//itemHover->setSelected(false);
itemHover = 0;
}
}
};
@ -144,6 +183,7 @@ public:
newLabel->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/folder.png"));
}
labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select);
labelFilters->setCurrentItem(labelFilters->item(0));
// Label menu
labelFilters->setContextMenuPolicy(Qt::CustomContextMenu);
connect(labelFilters, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showLabelMenu(QPoint)));