From 4ed69151443609947b897ba8828a8bd4d5060b94 2017-11-03 16:38:12 From: Thibaud Rabillard Date: 2017-11-03 16:38:12 Subject: [PATCH] Fix some glitches which occurred when dragging in the visualization something from the sides. --- diff --git a/gui/include/Visualization/VisualizationDragDropContainer.h b/gui/include/Visualization/VisualizationDragDropContainer.h index 911c650..c118d36 100644 --- a/gui/include/Visualization/VisualizationDragDropContainer.h +++ b/gui/include/Visualization/VisualizationDragDropContainer.h @@ -2,10 +2,10 @@ #define SCIQLOP_VISUALIZATIONDRAGDROPCONTAINER_H #include +#include #include #include #include -#include #include @@ -13,7 +13,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer) class VisualizationDragWidget; -class VisualizationDragDropContainer : public QWidget { +class VisualizationDragDropContainer : public QFrame { Q_OBJECT signals: diff --git a/gui/src/Visualization/VisualizationDragDropContainer.cpp b/gui/src/Visualization/VisualizationDragDropContainer.cpp index 3687b53..4a24902 100644 --- a/gui/src/Visualization/VisualizationDragDropContainer.cpp +++ b/gui/src/Visualization/VisualizationDragDropContainer.cpp @@ -107,12 +107,14 @@ struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { return container->isAncestorOf(sqpApp->widgetAt(QCursor::pos())); } - int countDragWidget(const QWidget *parent) const + int countDragWidget(const QWidget *parent, bool onlyVisible = false) const { auto nbGraph = 0; for (auto child : parent->children()) { if (qobject_cast(child)) { - nbGraph += 1; + if (!onlyVisible || qobject_cast(child)->isVisible()) { + nbGraph += 1; + } } } @@ -124,7 +126,7 @@ struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { }; VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent) - : QWidget{parent}, + : QFrame{parent}, impl{spimpl::make_unique_impl(this)} { setAcceptDrops(true); @@ -360,8 +362,14 @@ void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find { auto &helper = sqpApp->dragDropHelper(); - auto dragWidgetHovered = getChildDragWidgetAt(container, pos); - if (dragWidgetHovered) { + auto absPos = container->mapToGlobal(pos); + auto isOnPlaceHolder = sqpApp->widgetAt(absPos) == &(helper.placeHolder()); + + if (countDragWidget(container, true) == 0) { + // Drop on an empty container, just add the placeHolder at the top + helper.insertPlaceHolder(m_Layout, 0); + } + else if (!isOnPlaceHolder) { auto nbDragWidget = countDragWidget(container); if (nbDragWidget > 0) { @@ -382,6 +390,8 @@ void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find auto placeHolderIndex = m_Layout->indexOf(&(helper.placeHolder())); + auto dragWidgetHovered = getChildDragWidgetAt(container, pos); + if (canInsert && (isOnTop || isOnBottom || !canMerge)) { if (isOnBottom) { dropIndex += 1; @@ -403,7 +413,7 @@ void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find helper.setHightlightedDragWidget(nullptr); } - else if (canMerge) { + else if (canMerge && dragWidgetHovered) { // drop on the middle -> merge if (hasPlaceHolder()) { helper.removePlaceHolder(); @@ -412,24 +422,21 @@ void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find helper.setHightlightedDragWidget(dragWidgetHovered); } else { - qCWarning(LOG_VisualizationDragDropContainer()) - << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop " - "action."); + qCWarning(LOG_VisualizationDragDropContainer()) << tr( + "VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop " + "action."); Q_ASSERT(false); } } else { - qCWarning(LOG_VisualizationDragDropContainer()) << tr( - "VisualizationDragDropContainer::findPlaceHolderPosition, no widget found in the " - "container"); + qCWarning(LOG_VisualizationDragDropContainer()) + << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no widget " + "found in the " + "container"); } } - else if (!hasPlaceHolder() && canInsert) { - // Drop on an empty container, just add the placeHolder at the top - helper.insertPlaceHolder(m_Layout, 0); - } else { - // No hovered drag widget, the mouse is probably hover the placeHolder + // the mouse is hover the placeHolder // Do nothing } } diff --git a/gui/ui/Visualization/VisualizationTabWidget.ui b/gui/ui/Visualization/VisualizationTabWidget.ui index afdd13e..3710bf7 100644 --- a/gui/ui/Visualization/VisualizationTabWidget.ui +++ b/gui/ui/Visualization/VisualizationTabWidget.ui @@ -63,7 +63,11 @@ 0 - + + + 0 + + @@ -74,7 +78,7 @@ VisualizationDragDropContainer - QWidget + QFrame
Visualization/VisualizationDragDropContainer.h
1
diff --git a/gui/ui/Visualization/VisualizationZoneWidget.ui b/gui/ui/Visualization/VisualizationZoneWidget.ui index 9746ca6..4cd71e7 100644 --- a/gui/ui/Visualization/VisualizationZoneWidget.ui +++ b/gui/ui/Visualization/VisualizationZoneWidget.ui @@ -78,7 +78,7 @@ - + 0 @@ -107,9 +107,6 @@ 0 - - - @@ -118,7 +115,7 @@ VisualizationDragDropContainer - QWidget + QFrame
Visualization/VisualizationDragDropContainer.h
1