From 8340b6105f3f544b48a0bd7fce4d12dbe5bbb1bc Mon Sep 17 00:00:00 2001
From: Matthias Puchner <github@mpuchner.de>
Date: Mon, 23 Aug 2021 08:14:50 +0200
Subject: [PATCH] rm animation from GroupBoxCollapser

because it makes problems with height-for-width contents like a label with wordwrapping
---
 GUI/Views/CommonWidgets/GroupBoxCollapser.cpp | 72 ++-----------------
 GUI/Views/CommonWidgets/GroupBoxCollapser.h   | 14 +---
 2 files changed, 5 insertions(+), 81 deletions(-)

diff --git a/GUI/Views/CommonWidgets/GroupBoxCollapser.cpp b/GUI/Views/CommonWidgets/GroupBoxCollapser.cpp
index 728ff7a6e65..851d73dbf64 100644
--- a/GUI/Views/CommonWidgets/GroupBoxCollapser.cpp
+++ b/GUI/Views/CommonWidgets/GroupBoxCollapser.cpp
@@ -14,10 +14,9 @@
 
 #include "GroupBoxCollapser.h"
 #include <QBoxLayout>
-#include <QEvent>
 #include <QGroupBox>
-#include <QPropertyAnimation>
 #include <QToolButton>
+#include <QVariant>
 
 void GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, bool expanded)
 {
@@ -27,28 +26,11 @@ void GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, bool expanded)
         QSignalBlocker b(p->m_toggleButton);
         p->m_toggleButton->setChecked(false);
         p->m_toggleButton->setArrowType(Qt::ArrowType::RightArrow);
-        // this is necessary if contained widgets are resized while collapsed (tableView). It
-        // increases the layout, and therefore the title gets "compressed"
         p->m_contentArea->hide();
-        // groupBox->setFixedHeight(p->m_collapsedHeight);
     }
-
-    groupBox->installEventFilter(p);
-}
-
-
-bool GroupBoxCollapser::eventFilter(QObject* obj, QEvent* event)
-{
-    if (event->type() == QEvent::StyleChange) {
-        initSizes();
-        initAnimation();
-        const bool isExpanded = m_toggleButton->isChecked();
-        m_groupBox->setFixedHeight(isExpanded ? m_expandedHeight : m_collapsedHeight);
-    }
-    return false;
 }
 
-GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m_groupBox(groupBox)
+GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox)
 {
     QVBoxLayout* mainLayout = new QVBoxLayout;
     mainLayout->setSpacing(0);
@@ -56,7 +38,6 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m
 
     m_contentArea = new QWidget(groupBox);
     m_contentArea->setLayout(groupBox->layout());
-    m_contentArea->layout()->setSizeConstraint(QLayout::SetMinimumSize);
 
     mainLayout->addWidget(m_contentArea);
     groupBox->setLayout(mainLayout);
@@ -73,62 +54,17 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m
 
     groupBox->layout()->setMenuBar(m_toggleButton);
     groupBox->setTitle("");
-    groupBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
-    groupBox->setProperty("collapsible", true);
-
-    initSizes();
-    initAnimation();
+    groupBox->setProperty("collapsible", true); // helps to distinguish GroupBoxes in stylesheets
 
     connect(m_toggleButton, &QAbstractButton::clicked, this, &GroupBoxCollapser::toggle);
-    connect(&m_toggleAnimation, &QAbstractAnimation::finished, this,
-            &GroupBoxCollapser::onAnimationFinished);
 }
 
 void GroupBoxCollapser::toggle(bool checked)
 {
     m_toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
-    m_toggleAnimation.setDirection(checked ? QAbstractAnimation::Forward
-                                           : QAbstractAnimation::Backward);
 
     if (m_toggleButton->isChecked())
         m_contentArea->show();
-
-    m_toggleAnimation.start();
-}
-
-void GroupBoxCollapser::onAnimationFinished()
-{
-    if (!m_toggleButton->isChecked())
+    else
         m_contentArea->hide();
 }
-
-void GroupBoxCollapser::initAnimation()
-{
-    m_toggleAnimation.clear();
-
-    // Add animations, to let the entire widget grow and shrink with its content
-    const auto addAnimation = [=](QObject* target, const QByteArray propertyName, int start,
-                                  int end) {
-        auto a = new QPropertyAnimation(target, propertyName);
-        a->setDuration(m_animationDuration);
-        a->setStartValue(start);
-        a->setEndValue(end);
-        m_toggleAnimation.addAnimation(a);
-    };
-
-    addAnimation(m_groupBox, "minimumHeight", m_collapsedHeight, m_expandedHeight);
-    addAnimation(m_groupBox, "maximumHeight", m_collapsedHeight, m_expandedHeight);
-    addAnimation(m_contentArea, "minimumHeight", 0, m_contentHeight);
-    addAnimation(m_contentArea, "maximumHeight", 0, m_contentHeight);
-
-    m_groupBox->setUpdatesEnabled(true);
-}
-
-void GroupBoxCollapser::initSizes()
-{
-    m_contentHeight = m_contentArea->layout()->sizeHint().height();
-    m_collapsedHeight =
-        m_groupBox->sizeHint().height() - m_contentHeight
-        + 1; // this is very likely necessary because of pressed state of toggle button?!
-    m_expandedHeight = m_collapsedHeight + m_contentHeight;
-}
diff --git a/GUI/Views/CommonWidgets/GroupBoxCollapser.h b/GUI/Views/CommonWidgets/GroupBoxCollapser.h
index 04612ce9973..e17fc6a661f 100644
--- a/GUI/Views/CommonWidgets/GroupBoxCollapser.h
+++ b/GUI/Views/CommonWidgets/GroupBoxCollapser.h
@@ -15,7 +15,7 @@
 #ifndef BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_GROUPBOXCOLLAPSER_H
 #define BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_GROUPBOXCOLLAPSER_H
 
-#include <QParallelAnimationGroup>
+#include <QObject>
 
 class QToolButton;
 class QGroupBox;
@@ -25,24 +25,12 @@ class GroupBoxCollapser : public QObject {
 public:
     static void installIntoGroupBox(QGroupBox* groupBox, bool expanded = true);
 
-protected:
-    bool eventFilter(QObject* obj, QEvent* event) override;
-
 private:
     GroupBoxCollapser(QGroupBox* groupBox);
     void toggle(bool checked);
-    void onAnimationFinished();
-    void initAnimation();
-    void initSizes();
 
     QToolButton* m_toggleButton;
-    QParallelAnimationGroup m_toggleAnimation;
     QWidget* m_contentArea;
-    QGroupBox* m_groupBox;
-    int m_collapsedHeight;
-    int m_expandedHeight;
-    int m_contentHeight;
-    const int m_animationDuration{200};
 };
 
 
-- 
GitLab