##// 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 -
r881:f5851ce3ff09
parent child
Show More
@@ -25,6 +25,8 public:
25 25 static const QString MIME_TYPE_GRAPH;
26 26 static const QString MIME_TYPE_ZONE;
27 27
28 enum class PlaceHolderType { Default, Graph, Zone };
29
28 30 DragDropHelper();
29 31 virtual ~DragDropHelper();
30 32
@@ -40,7 +42,8 public:
40 42 VisualizationDragWidget *getCurrentDragWidget() const;
41 43
42 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 47 void removePlaceHolder();
45 48 bool isPlaceHolderSet() const;
46 49
@@ -9,6 +9,8
9 9
10 10 #include <functional>
11 11
12 #include <DragDropHelper.h>
13
12 14 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer)
13 15
14 16 class VisualizationDragWidget;
@@ -35,6 +37,9 public:
35 37
36 38 void setAcceptMimeDataFunction(AcceptMimeDataFunction fun);
37 39
40 void setPlaceHolderType(DragDropHelper::PlaceHolderType type,
41 const QString &placeHolderText = QString());
42
38 43 protected:
39 44 void dragEnterEvent(QDragEnterEvent *event);
40 45 void dragLeaveEvent(QDragLeaveEvent *event);
@@ -14,6 +14,7
14 14 #include <QDir>
15 15 #include <QDragEnterEvent>
16 16 #include <QDragMoveEvent>
17 #include <QLabel>
17 18 #include <QScrollArea>
18 19 #include <QScrollBar>
19 20 #include <QTimer>
@@ -144,6 +145,8 struct DragDropHelper::DragDropHelperPrivate {
144 145
145 146 VisualizationDragWidget *m_CurrentDragWidget = nullptr;
146 147 std::unique_ptr<QWidget> m_PlaceHolder = nullptr;
148 QLabel *m_PlaceHolderLabel;
149 QWidget *m_PlaceBackground;
147 150 std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr;
148 151 QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using
149 152 // QTemporaryFile to have a name which is not generated.
@@ -157,14 +160,25 struct DragDropHelper::DragDropHelperPrivate {
157 160 : m_PlaceHolder{std::make_unique<QWidget>()},
158 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 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 183 if (m_CurrentDragWidget) {
170 184 m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
@@ -177,6 +191,22 struct DragDropHelper::DragDropHelperPrivate {
177 191 m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT);
178 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 248 return impl->m_CurrentDragWidget;
219 249 }
220 250
221
222 251 QWidget &DragDropHelper::placeHolder() const
223 252 {
224 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 259 removePlaceHolder();
230 impl->preparePlaceHolder();
260 impl->preparePlaceHolder(type, topLabelText);
231 261 layout->insertWidget(index, impl->m_PlaceHolder.get());
232 262 impl->m_PlaceHolder->show();
233 263 }
@@ -18,6 +18,8 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
18 18
19 19 QVBoxLayout *m_Layout;
20 20 QHash<QString, VisualizationDragDropContainer::DropBehavior> m_AcceptedMimeTypes;
21 QString m_PlaceHolderText;
22 DragDropHelper::PlaceHolderType m_PlaceHolderType = DragDropHelper::PlaceHolderType::Graph;
21 23
22 24 VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun
23 25 = [](auto mimeData) { return true; };
@@ -166,6 +168,13 void VisualizationDragDropContainer::setAcceptMimeDataFunction(
166 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 178 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidget,
170 179 const QPoint &dragPosition)
171 180 {
@@ -192,7 +201,8 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidg
192 201
193 202 if (impl->cursorIsInContainer(this)) {
194 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 206 dragWidget->setVisible(false);
197 207 }
198 208 else {
@@ -367,7 +377,7 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
367 377
368 378 if (countDragWidget(container, true) == 0) {
369 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 382 else if (!isOnPlaceHolder) {
373 383 auto nbDragWidget = countDragWidget(container);
@@ -408,7 +418,8 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
408 418 }
409 419
410 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 425 helper.setHightlightedDragWidget(nullptr);
@@ -422,8 +433,8 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
422 433 helper.setHightlightedDragWidget(dragWidgetHovered);
423 434 }
424 435 else {
425 qCWarning(LOG_VisualizationDragDropContainer()) << tr(
426 "VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop "
436 qCWarning(LOG_VisualizationDragDropContainer())
437 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop "
427 438 "action.");
428 439 Q_ASSERT(false);
429 440 }
@@ -68,6 +68,8 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par
68 68 {
69 69 ui->setupUi(this);
70 70
71 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone");
72 ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 5);
71 73 ui->dragDropContainer->addAcceptedMimeType(
72 74 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
73 75 ui->dragDropContainer->addAcceptedMimeType(
@@ -101,6 +101,7 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p
101 101
102 102 ui->zoneNameLabel->setText(name);
103 103
104 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Graph);
104 105 ui->dragDropContainer->addAcceptedMimeType(
105 106 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
106 107 ui->dragDropContainer->addAcceptedMimeType(
General Comments 0
You need to be logged in to leave comments. Login now