##// END OF EJS Templates
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
trabillard -
r887:f5851ce3ff09
parent child
Show More
@@ -25,6 +25,8 public:
25 static const QString MIME_TYPE_GRAPH;
25 static const QString MIME_TYPE_GRAPH;
26 static const QString MIME_TYPE_ZONE;
26 static const QString MIME_TYPE_ZONE;
27
27
28 enum class PlaceHolderType { Default, Graph, Zone };
29
28 DragDropHelper();
30 DragDropHelper();
29 virtual ~DragDropHelper();
31 virtual ~DragDropHelper();
30
32
@@ -40,7 +42,8 public:
40 VisualizationDragWidget *getCurrentDragWidget() const;
42 VisualizationDragWidget *getCurrentDragWidget() const;
41
43
42 QWidget &placeHolder() const;
44 QWidget &placeHolder() const;
43 void insertPlaceHolder(QVBoxLayout *layout, int index);
45 void insertPlaceHolder(QVBoxLayout *layout, int index, PlaceHolderType type,
46 const QString &topLabelText);
44 void removePlaceHolder();
47 void removePlaceHolder();
45 bool isPlaceHolderSet() const;
48 bool isPlaceHolderSet() const;
46
49
@@ -9,6 +9,8
9
9
10 #include <functional>
10 #include <functional>
11
11
12 #include <DragDropHelper.h>
13
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer)
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer)
13
15
14 class VisualizationDragWidget;
16 class VisualizationDragWidget;
@@ -35,6 +37,9 public:
35
37
36 void setAcceptMimeDataFunction(AcceptMimeDataFunction fun);
38 void setAcceptMimeDataFunction(AcceptMimeDataFunction fun);
37
39
40 void setPlaceHolderType(DragDropHelper::PlaceHolderType type,
41 const QString &placeHolderText = QString());
42
38 protected:
43 protected:
39 void dragEnterEvent(QDragEnterEvent *event);
44 void dragEnterEvent(QDragEnterEvent *event);
40 void dragLeaveEvent(QDragLeaveEvent *event);
45 void dragLeaveEvent(QDragLeaveEvent *event);
@@ -14,6 +14,7
14 #include <QDir>
14 #include <QDir>
15 #include <QDragEnterEvent>
15 #include <QDragEnterEvent>
16 #include <QDragMoveEvent>
16 #include <QDragMoveEvent>
17 #include <QLabel>
17 #include <QScrollArea>
18 #include <QScrollArea>
18 #include <QScrollBar>
19 #include <QScrollBar>
19 #include <QTimer>
20 #include <QTimer>
@@ -144,6 +145,8 struct DragDropHelper::DragDropHelperPrivate {
144
145
145 VisualizationDragWidget *m_CurrentDragWidget = nullptr;
146 VisualizationDragWidget *m_CurrentDragWidget = nullptr;
146 std::unique_ptr<QWidget> m_PlaceHolder = nullptr;
147 std::unique_ptr<QWidget> m_PlaceHolder = nullptr;
148 QLabel *m_PlaceHolderLabel;
149 QWidget *m_PlaceBackground;
147 std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr;
150 std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr;
148 QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using
151 QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using
149 // QTemporaryFile to have a name which is not generated.
152 // QTemporaryFile to have a name which is not generated.
@@ -157,14 +160,25 struct DragDropHelper::DragDropHelperPrivate {
157 : m_PlaceHolder{std::make_unique<QWidget>()},
160 : m_PlaceHolder{std::make_unique<QWidget>()},
158 m_DragDropScroller{std::make_unique<DragDropScroller>()}
161 m_DragDropScroller{std::make_unique<DragDropScroller>()}
159 {
162 {
160 m_PlaceHolder->setStyleSheet("background-color: #BBD5EE; border:2px solid #2A7FD4");
161 sqpApp->installEventFilter(m_DragDropScroller.get());
162
163
164 auto layout = new QVBoxLayout{m_PlaceHolder.get()};
165 layout->setSpacing(0);
166 layout->setContentsMargins(0, 0, 0, 0);
167
168 m_PlaceHolderLabel = new QLabel{"", m_PlaceHolder.get()};
169 m_PlaceHolderLabel->setMinimumHeight(25);
170 layout->addWidget(m_PlaceHolderLabel);
171
172 m_PlaceBackground = new QWidget{m_PlaceHolder.get()};
173 m_PlaceBackground->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
174 layout->addWidget(m_PlaceBackground);
175
176 sqpApp->installEventFilter(m_DragDropScroller.get());
163
177
164 m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png");
178 m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png");
165 }
179 }
166
180
167 void preparePlaceHolder() const
181 void preparePlaceHolder(DragDropHelper::PlaceHolderType type, const QString &topLabelText) const
168 {
182 {
169 if (m_CurrentDragWidget) {
183 if (m_CurrentDragWidget) {
170 m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
184 m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
@@ -177,6 +191,22 struct DragDropHelper::DragDropHelperPrivate {
177 m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT);
191 m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT);
178 m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
192 m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
179 }
193 }
194
195 switch (type) {
196 case DragDropHelper::PlaceHolderType::Graph:
197 m_PlaceBackground->setStyleSheet(
198 "background-color: #BBD5EE; border: 1px solid #2A7FD4");
199 break;
200 case DragDropHelper::PlaceHolderType::Zone:
201 case DragDropHelper::PlaceHolderType::Default:
202 m_PlaceBackground->setStyleSheet(
203 "background-color: #BBD5EE; border: 2px solid #2A7FD4");
204 m_PlaceHolderLabel->setStyleSheet("color: #2A7FD4");
205 break;
206 }
207
208 m_PlaceHolderLabel->setText(topLabelText);
209 m_PlaceHolderLabel->setVisible(!topLabelText.isEmpty());
180 }
210 }
181 };
211 };
182
212
@@ -218,16 +248,16 VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const
218 return impl->m_CurrentDragWidget;
248 return impl->m_CurrentDragWidget;
219 }
249 }
220
250
221
222 QWidget &DragDropHelper::placeHolder() const
251 QWidget &DragDropHelper::placeHolder() const
223 {
252 {
224 return *impl->m_PlaceHolder;
253 return *impl->m_PlaceHolder;
225 }
254 }
226
255
227 void DragDropHelper::insertPlaceHolder(QVBoxLayout *layout, int index)
256 void DragDropHelper::insertPlaceHolder(QVBoxLayout *layout, int index, PlaceHolderType type,
257 const QString &topLabelText)
228 {
258 {
229 removePlaceHolder();
259 removePlaceHolder();
230 impl->preparePlaceHolder();
260 impl->preparePlaceHolder(type, topLabelText);
231 layout->insertWidget(index, impl->m_PlaceHolder.get());
261 layout->insertWidget(index, impl->m_PlaceHolder.get());
232 impl->m_PlaceHolder->show();
262 impl->m_PlaceHolder->show();
233 }
263 }
@@ -18,6 +18,8 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
18
18
19 QVBoxLayout *m_Layout;
19 QVBoxLayout *m_Layout;
20 QHash<QString, VisualizationDragDropContainer::DropBehavior> m_AcceptedMimeTypes;
20 QHash<QString, VisualizationDragDropContainer::DropBehavior> m_AcceptedMimeTypes;
21 QString m_PlaceHolderText;
22 DragDropHelper::PlaceHolderType m_PlaceHolderType = DragDropHelper::PlaceHolderType::Graph;
21
23
22 VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun
24 VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun
23 = [](auto mimeData) { return true; };
25 = [](auto mimeData) { return true; };
@@ -166,6 +168,13 void VisualizationDragDropContainer::setAcceptMimeDataFunction(
166 impl->m_AcceptMimeDataFun = fun;
168 impl->m_AcceptMimeDataFun = fun;
167 }
169 }
168
170
171 void VisualizationDragDropContainer::setPlaceHolderType(DragDropHelper::PlaceHolderType type,
172 const QString &placeHolderText)
173 {
174 impl->m_PlaceHolderType = type;
175 impl->m_PlaceHolderText = placeHolderText;
176 }
177
169 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidget,
178 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidget,
170 const QPoint &dragPosition)
179 const QPoint &dragPosition)
171 {
180 {
@@ -192,7 +201,8 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidg
192
201
193 if (impl->cursorIsInContainer(this)) {
202 if (impl->cursorIsInContainer(this)) {
194 auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget);
203 auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget);
195 helper.insertPlaceHolder(impl->m_Layout, dragWidgetIndex);
204 helper.insertPlaceHolder(impl->m_Layout, dragWidgetIndex, impl->m_PlaceHolderType,
205 impl->m_PlaceHolderText);
196 dragWidget->setVisible(false);
206 dragWidget->setVisible(false);
197 }
207 }
198 else {
208 else {
@@ -367,7 +377,7 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
367
377
368 if (countDragWidget(container, true) == 0) {
378 if (countDragWidget(container, true) == 0) {
369 // Drop on an empty container, just add the placeHolder at the top
379 // Drop on an empty container, just add the placeHolder at the top
370 helper.insertPlaceHolder(m_Layout, 0);
380 helper.insertPlaceHolder(m_Layout, 0, m_PlaceHolderType, m_PlaceHolderText);
371 }
381 }
372 else if (!isOnPlaceHolder) {
382 else if (!isOnPlaceHolder) {
373 auto nbDragWidget = countDragWidget(container);
383 auto nbDragWidget = countDragWidget(container);
@@ -408,7 +418,8 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
408 }
418 }
409
419
410 if (dropIndex != placeHolderIndex) {
420 if (dropIndex != placeHolderIndex) {
411 helper.insertPlaceHolder(m_Layout, dropIndex);
421 helper.insertPlaceHolder(m_Layout, dropIndex, m_PlaceHolderType,
422 m_PlaceHolderText);
412 }
423 }
413
424
414 helper.setHightlightedDragWidget(nullptr);
425 helper.setHightlightedDragWidget(nullptr);
@@ -422,17 +433,17 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
422 helper.setHightlightedDragWidget(dragWidgetHovered);
433 helper.setHightlightedDragWidget(dragWidgetHovered);
423 }
434 }
424 else {
435 else {
425 qCWarning(LOG_VisualizationDragDropContainer()) << tr(
436 qCWarning(LOG_VisualizationDragDropContainer())
426 "VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop "
437 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop "
427 "action.");
438 "action.");
428 Q_ASSERT(false);
439 Q_ASSERT(false);
429 }
440 }
430 }
441 }
431 else {
442 else {
432 qCWarning(LOG_VisualizationDragDropContainer())
443 qCWarning(LOG_VisualizationDragDropContainer())
433 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no widget "
444 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no widget "
434 "found in the "
445 "found in the "
435 "container");
446 "container");
436 }
447 }
437 }
448 }
438 else {
449 else {
@@ -68,6 +68,8 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par
68 {
68 {
69 ui->setupUi(this);
69 ui->setupUi(this);
70
70
71 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone");
72 ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 5);
71 ui->dragDropContainer->addAcceptedMimeType(
73 ui->dragDropContainer->addAcceptedMimeType(
72 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
74 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
73 ui->dragDropContainer->addAcceptedMimeType(
75 ui->dragDropContainer->addAcceptedMimeType(
@@ -101,6 +101,7 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p
101
101
102 ui->zoneNameLabel->setText(name);
102 ui->zoneNameLabel->setText(name);
103
103
104 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Graph);
104 ui->dragDropContainer->addAcceptedMimeType(
105 ui->dragDropContainer->addAcceptedMimeType(
105 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
106 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
106 ui->dragDropContainer->addAcceptedMimeType(
107 ui->dragDropContainer->addAcceptedMimeType(
General Comments 3
Under Review
author

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 1 added
  * 0 removed

Changed files:
  * A core/tests/meson.build
You need to be logged in to leave comments. Login now