##// END OF EJS Templates
Fix some glitches which occurred when dragging in the visualization something from the sides.
trabillard -
r886:4ed691514436
parent child
Show More
@@ -2,10 +2,10
2 2 #define SCIQLOP_VISUALIZATIONDRAGDROPCONTAINER_H
3 3
4 4 #include <Common/spimpl.h>
5 #include <QFrame>
5 6 #include <QLoggingCategory>
6 7 #include <QMimeData>
7 8 #include <QVBoxLayout>
8 #include <QWidget>
9 9
10 10 #include <functional>
11 11
@@ -13,7 +13,7 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer)
13 13
14 14 class VisualizationDragWidget;
15 15
16 class VisualizationDragDropContainer : public QWidget {
16 class VisualizationDragDropContainer : public QFrame {
17 17 Q_OBJECT
18 18
19 19 signals:
@@ -107,12 +107,14 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
107 107 return container->isAncestorOf(sqpApp->widgetAt(QCursor::pos()));
108 108 }
109 109
110 int countDragWidget(const QWidget *parent) const
110 int countDragWidget(const QWidget *parent, bool onlyVisible = false) const
111 111 {
112 112 auto nbGraph = 0;
113 113 for (auto child : parent->children()) {
114 114 if (qobject_cast<VisualizationDragWidget *>(child)) {
115 nbGraph += 1;
115 if (!onlyVisible || qobject_cast<VisualizationDragWidget *>(child)->isVisible()) {
116 nbGraph += 1;
117 }
116 118 }
117 119 }
118 120
@@ -124,7 +126,7 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
124 126 };
125 127
126 128 VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent)
127 : QWidget{parent},
129 : QFrame{parent},
128 130 impl{spimpl::make_unique_impl<VisualizationDragDropContainerPrivate>(this)}
129 131 {
130 132 setAcceptDrops(true);
@@ -360,8 +362,14 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
360 362 {
361 363 auto &helper = sqpApp->dragDropHelper();
362 364
363 auto dragWidgetHovered = getChildDragWidgetAt(container, pos);
364 if (dragWidgetHovered) {
365 auto absPos = container->mapToGlobal(pos);
366 auto isOnPlaceHolder = sqpApp->widgetAt(absPos) == &(helper.placeHolder());
367
368 if (countDragWidget(container, true) == 0) {
369 // Drop on an empty container, just add the placeHolder at the top
370 helper.insertPlaceHolder(m_Layout, 0);
371 }
372 else if (!isOnPlaceHolder) {
365 373 auto nbDragWidget = countDragWidget(container);
366 374 if (nbDragWidget > 0) {
367 375
@@ -382,6 +390,8 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
382 390
383 391 auto placeHolderIndex = m_Layout->indexOf(&(helper.placeHolder()));
384 392
393 auto dragWidgetHovered = getChildDragWidgetAt(container, pos);
394
385 395 if (canInsert && (isOnTop || isOnBottom || !canMerge)) {
386 396 if (isOnBottom) {
387 397 dropIndex += 1;
@@ -403,7 +413,7 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
403 413
404 414 helper.setHightlightedDragWidget(nullptr);
405 415 }
406 else if (canMerge) {
416 else if (canMerge && dragWidgetHovered) {
407 417 // drop on the middle -> merge
408 418 if (hasPlaceHolder()) {
409 419 helper.removePlaceHolder();
@@ -412,24 +422,21 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find
412 422 helper.setHightlightedDragWidget(dragWidgetHovered);
413 423 }
414 424 else {
415 qCWarning(LOG_VisualizationDragDropContainer())
416 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop "
417 "action.");
425 qCWarning(LOG_VisualizationDragDropContainer()) << tr(
426 "VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop "
427 "action.");
418 428 Q_ASSERT(false);
419 429 }
420 430 }
421 431 else {
422 qCWarning(LOG_VisualizationDragDropContainer()) << tr(
423 "VisualizationDragDropContainer::findPlaceHolderPosition, no widget found in the "
424 "container");
432 qCWarning(LOG_VisualizationDragDropContainer())
433 << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no widget "
434 "found in the "
435 "container");
425 436 }
426 437 }
427 else if (!hasPlaceHolder() && canInsert) {
428 // Drop on an empty container, just add the placeHolder at the top
429 helper.insertPlaceHolder(m_Layout, 0);
430 }
431 438 else {
432 // No hovered drag widget, the mouse is probably hover the placeHolder
439 // the mouse is hover the placeHolder
433 440 // Do nothing
434 441 }
435 442 }
@@ -63,7 +63,11
63 63 <number>0</number>
64 64 </property>
65 65 <item>
66 <widget class="VisualizationDragDropContainer" name="dragDropContainer" native="true"/>
66 <widget class="VisualizationDragDropContainer" name="dragDropContainer">
67 <property name="lineWidth">
68 <number>0</number>
69 </property>
70 </widget>
67 71 </item>
68 72 </layout>
69 73 </widget>
@@ -74,7 +78,7
74 78 <customwidgets>
75 79 <customwidget>
76 80 <class>VisualizationDragDropContainer</class>
77 <extends>QWidget</extends>
81 <extends>QFrame</extends>
78 82 <header>Visualization/VisualizationDragDropContainer.h</header>
79 83 <container>1</container>
80 84 </customwidget>
@@ -78,7 +78,7
78 78 </widget>
79 79 </item>
80 80 <item>
81 <widget class="QFrame" name="visualizationZoneFrame">
81 <widget class="VisualizationDragDropContainer" name="dragDropContainer">
82 82 <property name="sizePolicy">
83 83 <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
84 84 <horstretch>0</horstretch>
@@ -107,9 +107,6
107 107 <property name="bottomMargin">
108 108 <number>0</number>
109 109 </property>
110 <item>
111 <widget class="VisualizationDragDropContainer" name="dragDropContainer" native="true"/>
112 </item>
113 110 </layout>
114 111 </widget>
115 112 </item>
@@ -118,7 +115,7
118 115 <customwidgets>
119 116 <customwidget>
120 117 <class>VisualizationDragDropContainer</class>
121 <extends>QWidget</extends>
118 <extends>QFrame</extends>
122 119 <header>Visualization/VisualizationDragDropContainer.h</header>
123 120 <container>1</container>
124 121 </customwidget>
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