From f11da5db7d5134774d9dbac6d9514c1d4f3573b1 Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Mon, 8 Nov 2021 12:37:33 +0100 Subject: [PATCH] improve moving of layers --- GUI/View/SampleDesigner/WidgetMoverButton.cpp | 17 ++++++++++++++--- GUI/View/SampleDesigner/WidgetMoverButton.h | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/GUI/View/SampleDesigner/WidgetMoverButton.cpp b/GUI/View/SampleDesigner/WidgetMoverButton.cpp index c903f66212f..8be15af68a0 100644 --- a/GUI/View/SampleDesigner/WidgetMoverButton.cpp +++ b/GUI/View/SampleDesigner/WidgetMoverButton.cpp @@ -48,6 +48,9 @@ void WidgetMoverButton::mousePressEvent(QMouseEvent* event) void WidgetMoverButton::mouseReleaseEvent(QMouseEvent*) { + qDeleteAll(m_animations.values()); + m_animations.clear(); + m_dragScrollTimer.stop(); m_started = false; if (m_layoutToDeactivate != nullptr) { @@ -107,14 +110,22 @@ void WidgetMoverButton::mouseMoveEvent(QMouseEvent* event) QWidget* w = layoutItem->widget(); if (w == nullptr) { layoutItem->setGeometry(r); - } else { - QPropertyAnimation* animation = new QPropertyAnimation(w, "geometry"); + } else if (!m_animations.contains(w)) { + auto animation = new QPropertyAnimation(w, "geometry"); animation->setDuration(100); animation->setEasingCurve(QEasingCurve::OutQuad); animation->setStartValue(w->geometry()); animation->setEndValue(r); - animation->start(); + m_animations[w] = animation; + } else { + auto animation = m_animations[w]; + if (animation->endValue() != r) { + animation->stop(); + animation->setStartValue(w->geometry()); + animation->setEndValue(r); + animation->start(); + } } } diff --git a/GUI/View/SampleDesigner/WidgetMoverButton.h b/GUI/View/SampleDesigner/WidgetMoverButton.h index 1b4fa1217f1..b344fbb61e9 100644 --- a/GUI/View/SampleDesigner/WidgetMoverButton.h +++ b/GUI/View/SampleDesigner/WidgetMoverButton.h @@ -15,10 +15,12 @@ #ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_WIDGETMOVERBUTTON_H #define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_WIDGETMOVERBUTTON_H +#include <QMap> #include <QTimer> #include <QToolButton> class QScrollArea; +class QPropertyAnimation; //! Button to move a widget vertically in a layout. //! @@ -65,6 +67,7 @@ private: QTimer m_dragScrollTimer; QScrollArea* m_scrollArea; QPoint m_hotSpot; //!< The mouse-down coordinates in the widget to move + QMap<QWidget*, QPropertyAnimation*> m_animations; }; -- GitLab