##// END OF EJS Templates
code improvements
trabillard -
r980:53840da09aee
parent child
Show More
@@ -1,18 +1,18
1 1 #ifndef SCIQLOP_MACSCROLLBARSTYLE_H
2 2 #define SCIQLOP_MACSCROLLBARSTYLE_H
3 3
4 4 #include <QProxyStyle>
5 5
6 6 /**
7 7 * @brief Special style to always display the scrollbars on MAC.
8 8 */
9 9 class MacScrollBarStyle : public QProxyStyle {
10 10
11 11 public:
12 12 int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
13 QStyleHintReturn *returnData) const;
13 QStyleHintReturn *returnData) const override;
14 14
15 15 void selfInstallOn(QWidget *widget, bool installOnSubWidgets);
16 16 };
17 17
18 18 #endif // SCIQLOP_MACSCROLLBARSTYLE_H
@@ -1,154 +1,154
1 1 #include "TimeWidget/TimeWidget.h"
2 2 #include "ui_TimeWidget.h"
3 3
4 4 #include <Common/DateUtils.h>
5 5 #include <Common/MimeTypesDef.h>
6 6
7 7 #include <DragAndDrop/DragDropHelper.h>
8 8 #include <SqpApplication.h>
9 9 #include <Time/TimeController.h>
10 10
11 11 #include <QDrag>
12 12 #include <QDragEnterEvent>
13 13 #include <QDropEvent>
14 14 #include <QMimeData>
15 15
16 16
17 17 struct TimeWidget::TimeWidgetPrivate {
18 18
19 19 explicit TimeWidgetPrivate() {}
20 20
21 21 QPoint m_DragStartPosition;
22 22 };
23 23
24 24 TimeWidget::TimeWidget(QWidget *parent)
25 25 : QWidget{parent},
26 26 ui{new Ui::TimeWidget},
27 27 impl{spimpl::make_unique_impl<TimeWidgetPrivate>()}
28 28 {
29 29 ui->setupUi(this);
30 30
31 31 ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton));
32 32
33 33 // Connection
34 34 connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
35 35 &TimeWidget::onTimeUpdateRequested);
36 36
37 37 connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
38 38 &TimeWidget::onTimeUpdateRequested);
39 39
40 40
41 41 connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(),
42 42 &TimeController::onTimeNotify);
43 43
44 44 // Initialisation
45 45 auto endDateTime = QDateTime::currentDateTimeUtc();
46 46 auto startDateTime = endDateTime.addSecs(-3600); // one hour before
47 47
48 48 ui->startDateTimeEdit->setDateTime(startDateTime);
49 49 ui->endDateTimeEdit->setDateTime(endDateTime);
50 50
51 51 auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(startDateTime),
52 52 DateUtils::secondsSinceEpoch(endDateTime)};
53 53
54 54 sqpApp->timeController().onTimeToUpdate(dateTime);
55 55 }
56 56
57 57
58 58 TimeWidget::~TimeWidget()
59 59 {
60 60 delete ui;
61 61 }
62 62
63 63 void TimeWidget::setTimeRange(SqpRange time)
64 64 {
65 65 auto startDateTime = DateUtils::dateTime(time.m_TStart);
66 66 auto endDateTime = DateUtils::dateTime(time.m_TEnd);
67 67
68 68 ui->startDateTimeEdit->setDateTime(startDateTime);
69 69 ui->endDateTimeEdit->setDateTime(endDateTime);
70 70 }
71 71
72 72 SqpRange TimeWidget::timeRange() const
73 73 {
74 74 return SqpRange{DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()),
75 75 DateUtils::secondsSinceEpoch(ui->endDateTimeEdit->dateTime())};
76 76 }
77 77
78 78 void TimeWidget::onTimeUpdateRequested()
79 79 {
80 80 auto dateTime = timeRange();
81 81 emit timeUpdated(std::move(dateTime));
82 82 }
83 83
84 84 void TimeWidget::dragEnterEvent(QDragEnterEvent *event)
85 85 {
86 86 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
87 87 event->acceptProposedAction();
88 88 setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}");
89 89 }
90 90 else {
91 91 event->ignore();
92 92 }
93 93 }
94 94
95 95 void TimeWidget::dragLeaveEvent(QDragLeaveEvent *event)
96 96 {
97 setStyleSheet(QString());
97 setStyleSheet(QString{});
98 98 }
99 99
100 100 void TimeWidget::dropEvent(QDropEvent *event)
101 101 {
102 102 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
103 103 auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE);
104 104 auto timeRange = TimeController::timeRangeForMimeData(mimeData);
105 105
106 106 setTimeRange(timeRange);
107 107 }
108 108 else {
109 109 event->ignore();
110 110 }
111 111
112 setStyleSheet(QString());
112 setStyleSheet(QString{});
113 113 }
114 114
115 115
116 116 void TimeWidget::mousePressEvent(QMouseEvent *event)
117 117 {
118 118 if (event->button() == Qt::LeftButton) {
119 119 impl->m_DragStartPosition = event->pos();
120 120 }
121 121
122 122 QWidget::mousePressEvent(event);
123 123 }
124 124
125 125 void TimeWidget::mouseMoveEvent(QMouseEvent *event)
126 126 {
127 127 if (!(event->buttons() & Qt::LeftButton)) {
128 128 return;
129 129 }
130 130
131 131 if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
132 132 < QApplication::startDragDistance()) {
133 133 return;
134 134 }
135 135
136 136 // Note: The management of the drag object is done by Qt
137 137 auto drag = new QDrag{this};
138 138
139 139 auto mimeData = new QMimeData;
140 140 auto timeData = TimeController::mimeDataForTimeRange(timeRange());
141 141 mimeData->setData(MIME_TYPE_TIME_RANGE, timeData);
142 142
143 143 drag->setMimeData(mimeData);
144 144
145 145 auto pixmap = QPixmap{":/icones/time.png"};
146 146 drag->setPixmap(pixmap.scaledToWidth(22));
147 147
148 148 sqpApp->dragDropHelper().resetDragAndDrop();
149 149
150 150 // Note: The exec() is blocking on windows but not on linux and macOS
151 151 drag->exec(Qt::MoveAction | Qt::CopyAction);
152 152
153 153 QWidget::mouseMoveEvent(event);
154 154 }
@@ -1,472 +1,472
1 1 #include "Visualization/VisualizationDragDropContainer.h"
2 2 #include "DragAndDrop/DragDropHelper.h"
3 3 #include "SqpApplication.h"
4 4 #include "Visualization/VisualizationDragWidget.h"
5 5
6 6 #include "Common/VisualizationDef.h"
7 7
8 8 #include <QDrag>
9 9 #include <QDragEnterEvent>
10 10 #include <QVBoxLayout>
11 11
12 12 #include <cmath>
13 13 #include <memory>
14 14
15 15 Q_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer, "VisualizationDragDropContainer")
16 16
17 17 auto DRAGGED_MINIATURE_WIDTH = 200; // in pixels
18 18
19 19 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
20 20
21 21 QVBoxLayout *m_Layout;
22 22 QHash<QString, VisualizationDragDropContainer::DropBehavior> m_AcceptedMimeTypes;
23 23 QString m_PlaceHolderText;
24 24 DragDropHelper::PlaceHolderType m_PlaceHolderType = DragDropHelper::PlaceHolderType::Graph;
25 25
26 26 VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun
27 27 = [](auto mimeData) { return true; };
28 28
29 29 int m_MinContainerHeight = 0;
30 30
31 31 explicit VisualizationDragDropContainerPrivate(QWidget *widget)
32 32 {
33 33 m_Layout = new QVBoxLayout(widget);
34 34 m_Layout->setContentsMargins(0, 0, 0, 0);
35 35 }
36 36
37 37 bool acceptMimeData(const QMimeData *data) const
38 38 {
39 39 auto accepted = false;
40 40 for (auto it = m_AcceptedMimeTypes.constBegin(); it != m_AcceptedMimeTypes.constEnd();
41 41 ++it) {
42 42 const auto &type = it.key();
43 43 const auto &behavior = it.value();
44 44
45 45 if (data->hasFormat(type)) {
46 46 if (behavior != DropBehavior::Forbidden) {
47 47 accepted = true;
48 48 }
49 49 else {
50 50 accepted = false;
51 51 break;
52 52 }
53 53 }
54 54 }
55 55
56 56 if (accepted) {
57 57 accepted = m_AcceptMimeDataFun(data);
58 58 }
59 59
60 60 return accepted;
61 61 }
62 62
63 63 bool allowMergeForMimeData(const QMimeData *data) const
64 64 {
65 bool result = false;
65 auto result = false;
66 66 for (auto it = m_AcceptedMimeTypes.constBegin(); it != m_AcceptedMimeTypes.constEnd();
67 67 ++it) {
68 68
69 69 if (data->hasFormat(it.key())
70 70 && (it.value() == VisualizationDragDropContainer::DropBehavior::Merged
71 71 || it.value()
72 72 == VisualizationDragDropContainer::DropBehavior::InsertedAndMerged)) {
73 73 result = true;
74 74 }
75 75 else if (data->hasFormat(it.key())
76 76 && it.value() == VisualizationDragDropContainer::DropBehavior::Inserted) {
77 77 // Merge is forbidden if the mime data contain an acceptable type which cannot be
78 78 // merged
79 79 result = false;
80 80 break;
81 81 }
82 82 }
83 83
84 84 return result;
85 85 }
86 86
87 87 bool allowInsertForMimeData(const QMimeData *data) const
88 88 {
89 89 for (auto it = m_AcceptedMimeTypes.constBegin(); it != m_AcceptedMimeTypes.constEnd();
90 90 ++it) {
91 91 if (data->hasFormat(it.key())
92 92 && (it.value() == VisualizationDragDropContainer::DropBehavior::Inserted
93 93 || it.value()
94 94 == VisualizationDragDropContainer::DropBehavior::InsertedAndMerged)) {
95 95 return true;
96 96 }
97 97 }
98 98
99 99 return false;
100 100 }
101 101
102 102 bool hasPlaceHolder() const
103 103 {
104 104 return sqpApp->dragDropHelper().placeHolder().parentWidget() == m_Layout->parentWidget();
105 105 }
106 106
107 107 VisualizationDragWidget *getChildDragWidgetAt(const QWidget *parent, const QPoint &pos) const
108 108 {
109 109 VisualizationDragWidget *dragWidget = nullptr;
110 110
111 111 for (auto child : parent->children()) {
112 112 auto widget = qobject_cast<VisualizationDragWidget *>(child);
113 113 if (widget && widget->isVisible()) {
114 114 if (widget->frameGeometry().contains(pos)) {
115 115 dragWidget = widget;
116 116 break;
117 117 }
118 118 }
119 119 }
120 120
121 121 return dragWidget;
122 122 }
123 123
124 124 bool cursorIsInContainer(QWidget *container) const
125 125 {
126 126 auto widgetUnderMouse = sqpApp->widgetAt(QCursor::pos());
127 127 return container->isAncestorOf(widgetUnderMouse) && widgetUnderMouse != container
128 128 && sqpApp->dragDropHelper().placeHolder().isAncestorOf(widgetUnderMouse);
129 129 }
130 130
131 131 int countDragWidget(const QWidget *parent, bool onlyVisible = false) const
132 132 {
133 133 auto nbGraph = 0;
134 134 for (auto child : parent->children()) {
135 135 if (qobject_cast<VisualizationDragWidget *>(child)) {
136 136 if (!onlyVisible || qobject_cast<VisualizationDragWidget *>(child)->isVisible()) {
137 137 nbGraph += 1;
138 138 }
139 139 }
140 140 }
141 141
142 142 return nbGraph;
143 143 }
144 144
145 145 void findPlaceHolderPosition(const QPoint &pos, bool canInsert, bool canMerge,
146 146 const VisualizationDragDropContainer *container);
147 147 };
148 148
149 149 VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent)
150 150 : QFrame{parent},
151 151 impl{spimpl::make_unique_impl<VisualizationDragDropContainerPrivate>(this)}
152 152 {
153 153 setAcceptDrops(true);
154 154 }
155 155
156 156 void VisualizationDragDropContainer::addDragWidget(VisualizationDragWidget *dragWidget)
157 157 {
158 158 impl->m_Layout->addWidget(dragWidget);
159 159 disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr);
160 160 connect(dragWidget, &VisualizationDragWidget::dragDetected, this,
161 161 &VisualizationDragDropContainer::startDrag);
162 162 }
163 163
164 164 void VisualizationDragDropContainer::insertDragWidget(int index,
165 165 VisualizationDragWidget *dragWidget)
166 166 {
167 167 impl->m_Layout->insertWidget(index, dragWidget);
168 168 disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr);
169 169 connect(dragWidget, &VisualizationDragWidget::dragDetected, this,
170 170 &VisualizationDragDropContainer::startDrag);
171 171 }
172 172
173 173 void VisualizationDragDropContainer::setMimeType(
174 174 const QString &mimeType, VisualizationDragDropContainer::DropBehavior behavior)
175 175 {
176 176 impl->m_AcceptedMimeTypes[mimeType] = behavior;
177 177 }
178 178
179 179 int VisualizationDragDropContainer::countDragWidget() const
180 180 {
181 181 return impl->countDragWidget(this);
182 182 }
183 183
184 184 void VisualizationDragDropContainer::setAcceptMimeDataFunction(
185 185 VisualizationDragDropContainer::AcceptMimeDataFunction fun)
186 186 {
187 187 impl->m_AcceptMimeDataFun = fun;
188 188 }
189 189
190 190 void VisualizationDragDropContainer::setPlaceHolderType(DragDropHelper::PlaceHolderType type,
191 191 const QString &placeHolderText)
192 192 {
193 193 impl->m_PlaceHolderType = type;
194 194 impl->m_PlaceHolderText = placeHolderText;
195 195 }
196 196
197 197 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidget,
198 198 const QPoint &dragPosition)
199 199 {
200 200 auto &helper = sqpApp->dragDropHelper();
201 201 helper.resetDragAndDrop();
202 202
203 203 // Note: The management of the drag object is done by Qt
204 204 auto drag = new QDrag{dragWidget};
205 205
206 206 auto mimeData = dragWidget->mimeData();
207 207 drag->setMimeData(mimeData);
208 208
209 209 auto pixmap = QPixmap(dragWidget->size());
210 210 dragWidget->render(&pixmap);
211 211 drag->setPixmap(pixmap.scaled(DRAGGED_MINIATURE_WIDTH, DRAGGED_MINIATURE_WIDTH,
212 212 Qt::KeepAspectRatio, Qt::SmoothTransformation));
213 213
214 214 auto image = pixmap.toImage();
215 215 mimeData->setImageData(image);
216 216 mimeData->setUrls({helper.imageTemporaryUrl(image)});
217 217
218 218 if (impl->m_Layout->indexOf(dragWidget) >= 0) {
219 219 helper.setCurrentDragWidget(dragWidget);
220 220
221 221 if (impl->cursorIsInContainer(this)) {
222 222 auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget);
223 223 helper.insertPlaceHolder(impl->m_Layout, dragWidgetIndex, impl->m_PlaceHolderType,
224 224 impl->m_PlaceHolderText);
225 225 dragWidget->setVisible(false);
226 226 }
227 227 else {
228 228 // The drag starts directly outside the drop zone
229 229 // do not add the placeHolder
230 230 }
231 231
232 232 drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);
233 233
234 234 helper.doCloseWidgets();
235 235 }
236 236 else {
237 237 qCWarning(LOG_VisualizationDragDropContainer())
238 238 << tr("VisualizationDragDropContainer::startDrag, drag aborted, the specified "
239 239 "VisualizationDragWidget is not found in this container.");
240 240 }
241 241 }
242 242
243 243 void VisualizationDragDropContainer::dragEnterEvent(QDragEnterEvent *event)
244 244 {
245 245 if (impl->acceptMimeData(event->mimeData())) {
246 246 event->acceptProposedAction();
247 247
248 248 auto &helper = sqpApp->dragDropHelper();
249 249
250 250 if (!impl->hasPlaceHolder()) {
251 251 auto dragWidget = helper.getCurrentDragWidget();
252 252
253 253 if (dragWidget) {
254 254 // If the drag&drop is internal to the visualization, entering the container hide
255 255 // the dragWidget which was made visible by the dragLeaveEvent
256 256 auto parentWidget
257 257 = qobject_cast<VisualizationDragDropContainer *>(dragWidget->parentWidget());
258 258 if (parentWidget) {
259 259 dragWidget->setVisible(false);
260 260 }
261 261 }
262 262
263 263 auto canMerge = impl->allowMergeForMimeData(event->mimeData());
264 264 auto canInsert = impl->allowInsertForMimeData(event->mimeData());
265 265 impl->findPlaceHolderPosition(event->pos(), canInsert, canMerge, this);
266 266 }
267 267 else {
268 268 // do nothing
269 269 }
270 270 }
271 271 else {
272 272 event->ignore();
273 273 }
274 274
275 275 QWidget::dragEnterEvent(event);
276 276 }
277 277
278 278 void VisualizationDragDropContainer::dragLeaveEvent(QDragLeaveEvent *event)
279 279 {
280 280 Q_UNUSED(event);
281 281
282 282 auto &helper = sqpApp->dragDropHelper();
283 283
284 284 if (!impl->cursorIsInContainer(this)) {
285 285 helper.removePlaceHolder();
286 286 helper.setHightlightedDragWidget(nullptr);
287 287 impl->m_MinContainerHeight = 0;
288 288
289 289 auto dragWidget = helper.getCurrentDragWidget();
290 290 if (dragWidget) {
291 291 // dragWidget has a value only if the drag is started from the visualization
292 292 // In that case, shows the drag widget at its original place
293 293 // So the drag widget doesn't stay hidden if the drop occurs outside the visualization
294 294 // drop zone (It is not possible to catch a drop event outside of the application)
295 295
296 296 if (dragWidget) {
297 297 dragWidget->setVisible(true);
298 298 }
299 299 }
300 300 }
301 301 else {
302 302 // Leave event probably received for a child widget.
303 303 // Do nothing.
304 304 // Note: The DragLeave event, doesn't have any mean to determine who sent it.
305 305 }
306 306
307 307 QWidget::dragLeaveEvent(event);
308 308 }
309 309
310 310 void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event)
311 311 {
312 312 if (impl->acceptMimeData(event->mimeData())) {
313 313 auto canMerge = impl->allowMergeForMimeData(event->mimeData());
314 314 auto canInsert = impl->allowInsertForMimeData(event->mimeData());
315 315 impl->findPlaceHolderPosition(event->pos(), canInsert, canMerge, this);
316 316 }
317 317 else {
318 318 event->ignore();
319 319 }
320 320
321 321 QWidget::dragMoveEvent(event);
322 322 }
323 323
324 324 void VisualizationDragDropContainer::dropEvent(QDropEvent *event)
325 325 {
326 326 auto &helper = sqpApp->dragDropHelper();
327 327
328 328 if (impl->acceptMimeData(event->mimeData())) {
329 329 auto dragWidget = helper.getCurrentDragWidget();
330 330 if (impl->hasPlaceHolder()) {
331 331 // drop where the placeHolder is located
332 332
333 333 auto canInsert = impl->allowInsertForMimeData(event->mimeData());
334 334 if (canInsert) {
335 335 auto droppedIndex = impl->m_Layout->indexOf(&helper.placeHolder());
336 336
337 337 if (dragWidget) {
338 338 auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget);
339 339 if (dragWidgetIndex >= 0 && dragWidgetIndex < droppedIndex) {
340 340 // Correction of the index if the drop occurs in the same container
341 341 // and if the drag is started from the visualization (in that case, the
342 342 // dragWidget is hidden)
343 343 droppedIndex -= 1;
344 344 }
345 345
346 346 dragWidget->setVisible(true);
347 347 }
348 348
349 349 event->acceptProposedAction();
350 350
351 351 helper.removePlaceHolder();
352 352
353 353 emit dropOccuredInContainer(droppedIndex, event->mimeData());
354 354 }
355 355 else {
356 356 qCWarning(LOG_VisualizationDragDropContainer()) << tr(
357 357 "VisualizationDragDropContainer::dropEvent, dropping on the placeHolder, but "
358 358 "the insertion is forbidden.");
359 359 Q_ASSERT(false);
360 360 }
361 361 }
362 362 else if (helper.getHightlightedDragWidget()) {
363 363 // drop on the highlighted widget
364 364
365 365 auto canMerge = impl->allowMergeForMimeData(event->mimeData());
366 366 if (canMerge) {
367 367 event->acceptProposedAction();
368 368 emit dropOccuredOnWidget(helper.getHightlightedDragWidget(), event->mimeData());
369 369 }
370 370 else {
371 371 qCWarning(LOG_VisualizationDragDropContainer())
372 372 << tr("VisualizationDragDropContainer::dropEvent, dropping on a widget, but "
373 373 "the merge is forbidden.");
374 374 Q_ASSERT(false);
375 375 }
376 376 }
377 377 }
378 378 else {
379 379 event->ignore();
380 380 }
381 381
382 382 sqpApp->dragDropHelper().setHightlightedDragWidget(nullptr);
383 383 impl->m_MinContainerHeight = 0;
384 384
385 385 QWidget::dropEvent(event);
386 386 }
387 387
388 388
389 389 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::findPlaceHolderPosition(
390 390 const QPoint &pos, bool canInsert, bool canMerge,
391 391 const VisualizationDragDropContainer *container)
392 392 {
393 393 auto &helper = sqpApp->dragDropHelper();
394 394
395 395 auto absPos = container->mapToGlobal(pos);
396 396 auto isOnPlaceHolder = helper.placeHolder().isAncestorOf(sqpApp->widgetAt(absPos));
397 397
398 398 if (countDragWidget(container, true) == 0) {
399 399 // Drop on an empty container, just add the placeHolder at the top
400 400 helper.insertPlaceHolder(m_Layout, 0, m_PlaceHolderType, m_PlaceHolderText);
401 401 }
402 402 else if (!isOnPlaceHolder) {
403 403 auto nbDragWidget = countDragWidget(container);
404 404 if (nbDragWidget > 0) {
405 405
406 406 if (m_MinContainerHeight == 0) {
407 407 m_MinContainerHeight = container->size().height();
408 408 }
409 409
410 410 m_MinContainerHeight = qMin(m_MinContainerHeight, container->size().height());
411 411 auto graphHeight = qMax(m_MinContainerHeight / nbDragWidget, GRAPH_MINIMUM_HEIGHT);
412 412
413 413 auto posY = pos.y();
414 414 auto dropIndex = floor(posY / graphHeight);
415 415 auto zoneSize = qMin(graphHeight / 4.0, 75.0);
416 416
417 417
418 418 auto isOnTop = posY < dropIndex * graphHeight + zoneSize;
419 419 auto isOnBottom = posY > (dropIndex + 1) * graphHeight - zoneSize;
420 420
421 421 auto placeHolderIndex = m_Layout->indexOf(&(helper.placeHolder()));
422 422
423 423 auto dragWidgetHovered = getChildDragWidgetAt(container, pos);
424 424
425 425 if (canInsert && (isOnTop || isOnBottom || !canMerge)) {
426 426 if (isOnBottom) {
427 427 dropIndex += 1;
428 428 }
429 429
430 430 if (helper.getCurrentDragWidget()) {
431 431 auto dragWidgetIndex = m_Layout->indexOf(helper.getCurrentDragWidget());
432 432 if (dragWidgetIndex >= 0 && dragWidgetIndex <= dropIndex) {
433 433 // Correction of the index if the drop occurs in the same container
434 434 // and if the drag is started from the visualization (in that case, the
435 435 // dragWidget is hidden)
436 436 dropIndex += 1;
437 437 }
438 438 }
439 439
440 440 if (dropIndex != placeHolderIndex) {
441 441 helper.insertPlaceHolder(m_Layout, dropIndex, m_PlaceHolderType,
442 442 m_PlaceHolderText);
443 443 }
444 444
445 445 helper.setHightlightedDragWidget(nullptr);
446 446 }
447 447 else if (canMerge && dragWidgetHovered) {
448 448 // drop on the middle -> merge
449 449 if (hasPlaceHolder()) {
450 450 helper.removePlaceHolder();
451 451 }
452 452
453 453 helper.setHightlightedDragWidget(dragWidgetHovered);
454 454 }
455 455 else {
456 456 qCWarning(LOG_VisualizationDragDropContainer())
457 457 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop "
458 458 "action.");
459 459 }
460 460 }
461 461 else {
462 462 qCWarning(LOG_VisualizationDragDropContainer())
463 463 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no widget "
464 464 "found in the "
465 465 "container");
466 466 }
467 467 }
468 468 else {
469 469 // the mouse is hover the placeHolder
470 470 // Do nothing
471 471 }
472 472 }
General Comments 1
Under Review
author

Auto status change to "Under Review"

You need to be logged in to leave comments. Login now