Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) CNRS |
3 |
|
|
// Authors: Joseph Mirabel and Heidy Dallard |
4 |
|
|
// |
5 |
|
|
|
6 |
|
|
#include "configurationlist.hh" |
7 |
|
|
|
8 |
|
|
#include <QDropEvent> |
9 |
|
|
#include <QShortcut> |
10 |
|
|
#include <QUrl> |
11 |
|
|
#include <iostream> |
12 |
|
|
|
13 |
|
|
#include "configurationlistwidget.hh" |
14 |
|
|
|
15 |
|
|
namespace hpp { |
16 |
|
|
namespace gui { |
17 |
|
✗ |
ConfigurationList::ConfigurationList(QWidget* parent) |
18 |
|
✗ |
: QListWidget(parent), singleItemOnly(false) {} |
19 |
|
|
|
20 |
|
✗ |
ConfigurationList::~ConfigurationList() {} |
21 |
|
|
|
22 |
|
✗ |
void ConfigurationList::setSingleItemOnly(bool set) { |
23 |
|
✗ |
singleItemOnly = set; |
24 |
|
✗ |
if (set) { |
25 |
|
|
QListWidgetItem* fakeItem = |
26 |
|
✗ |
ConfigurationListWidget::makeItem("", hpp::floatSeq()); |
27 |
|
✗ |
addItem(fakeItem); |
28 |
|
✗ |
setFixedHeight(sizeHintForRow(0) + 5); |
29 |
|
✗ |
deleteItem(fakeItem); |
30 |
|
|
} else { |
31 |
|
✗ |
setFixedHeight(QWIDGETSIZE_MAX); |
32 |
|
|
} |
33 |
|
|
} |
34 |
|
|
|
35 |
|
✗ |
void ConfigurationList::bindDeleteKey() { |
36 |
|
✗ |
QShortcut* shortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this); |
37 |
|
✗ |
connect(shortcut, SIGNAL(activated()), this, SLOT(deleteSelection())); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
✗ |
void ConfigurationList::dragEnterEvent(QDragEnterEvent* event) { |
41 |
|
✗ |
if (event->mimeData()->hasFormat("application/configuration-data")) |
42 |
|
✗ |
event->accept(); |
43 |
|
|
else |
44 |
|
✗ |
event->ignore(); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
✗ |
void ConfigurationList::dragMoveEvent(QDragMoveEvent* event) { |
48 |
|
✗ |
if (event->mimeData()->hasFormat("application/configuration-data")) { |
49 |
|
✗ |
event->setDropAction(Qt::MoveAction); |
50 |
|
✗ |
event->accept(); |
51 |
|
|
} else |
52 |
|
✗ |
event->ignore(); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
✗ |
void ConfigurationList::dropEvent(QDropEvent* event) { |
56 |
|
✗ |
if (event->source() == this) |
57 |
|
✗ |
event->ignore(); |
58 |
|
✗ |
else if (event->mimeData()->hasFormat("application/configuration-data")) { |
59 |
|
✗ |
QByteArray data = event->mimeData()->data("application/configuration-data"); |
60 |
|
✗ |
QDataStream dataStream(&data, QIODevice::ReadOnly); |
61 |
|
✗ |
hpp::floatSeq input; |
62 |
|
✗ |
dataStream >> input; |
63 |
|
|
|
64 |
|
✗ |
if (singleItemOnly) clear(); |
65 |
|
|
|
66 |
|
✗ |
addItem( |
67 |
|
✗ |
ConfigurationListWidget::makeItem(event->mimeData()->text(), input)); |
68 |
|
✗ |
event->setDropAction(Qt::MoveAction); |
69 |
|
✗ |
event->accept(); |
70 |
|
✗ |
} else |
71 |
|
✗ |
event->ignore(); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
✗ |
void ConfigurationList::startDrag(Qt::DropActions /*supportedActions*/) { |
75 |
|
✗ |
QListWidgetItem* item = currentItem(); |
76 |
|
|
|
77 |
|
✗ |
QByteArray itemData; |
78 |
|
✗ |
QDataStream dataStream(&itemData, QIODevice::WriteOnly); |
79 |
|
|
|
80 |
|
✗ |
dataStream << ConfigurationListWidget::getConfig(item); |
81 |
|
|
|
82 |
|
✗ |
QMimeData* mimeData = new QMimeData; |
83 |
|
✗ |
mimeData->setData("application/configuration-data", itemData); |
84 |
|
|
|
85 |
|
✗ |
QDrag* drag = new QDrag(this); |
86 |
|
✗ |
drag->setMimeData(mimeData); |
87 |
|
✗ |
mimeData->setText(item->text()); |
88 |
|
✗ |
if (drag->exec() == Qt::MoveAction) { |
89 |
|
✗ |
if (currentRow() == row(item)) setCurrentRow(-1); |
90 |
|
✗ |
deleteItem(item); |
91 |
|
✗ |
emit configurationChanged(); |
92 |
|
|
} |
93 |
|
|
} |
94 |
|
|
|
95 |
|
✗ |
void ConfigurationList::deleteItem(QListWidgetItem* item) { |
96 |
|
✗ |
delete takeItem(row(item)); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
✗ |
void ConfigurationList::deleteSelection() { |
100 |
|
✗ |
foreach (QListWidgetItem* item, selectedItems()) { |
101 |
|
✗ |
deleteItem(item); |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
} // namespace gui |
105 |
|
|
} // namespace hpp |
106 |
|
|
|