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