2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2024 Felix Ernst <felixernst@kde.org>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #ifndef ANIMATEDHEIGHTWIDGET_H
9 #define ANIMATEDHEIGHTWIDGET_H
16 class QPropertyAnimation
;
20 * @brief An abstract base class which facilitates animated showing and hiding of sub-classes
22 class AnimatedHeightWidget
: public QWidget
25 AnimatedHeightWidget(QWidget
*parent
);
28 * Plays a show or hide animation while changing visibility.
29 * Therefore, if this method is used to hide this widget, the actual hiding will be delayed until the animation finished.
31 * @param visible Whether this bar is supposed to be visible long-term
32 * @param animated Whether this should be animated. The animation is skipped if the users' settings are configured that way.
34 * @see QWidget::setVisible()
36 void setVisible(bool visible
, Animated animated
);
39 * @returns a QSize with a width of 1 to make sure that this bar never causes side panels to shrink.
40 * The returned height equals preferredHeight().
42 QSize
sizeHint() const override
;
46 * AnimatedHeightWidget always requires a singular main child which we call the "contentsContainer".
47 * Use this method to register such an object.
49 * @returns a "contentsContainer" which is a QWidget that consists of/contains all visible contents of this AnimatedHeightWidget.
50 * It will be the only grandchild of this AnimatedHeightWidget.
51 * @param contentsContainer The object that should be used as the "contentsContainer".
53 QWidget
*prepareContentsContainer(QWidget
*contentsContainer
= new QWidget
);
55 /** @returns whether this object is currently animating a visibility change. */
56 bool isAnimationRunning() const;
59 using QWidget::hide
; // Use QAbstractAnimation::setVisible() instead.
60 using QWidget::setVisible
; // Makes sure that the setVisible() declaration above doesn't fully hide the one from QWidget so we can still use it privately.
61 using QWidget::show
; // Use QAbstractAnimation::setVisible() instead.
63 /** @returns the full preferred height this widget should have when it is done animating and visible. */
64 virtual int preferredHeight() const = 0;
67 /** @see contentsContainerParent() */
68 QScrollArea
*m_contentsContainerParent
= nullptr;
70 /** @see AnimatedHeightWidget::setVisible() */
71 QPointer
<QPropertyAnimation
> m_heightAnimation
;
74 #endif // ANIMATEDHEIGHTWIDGET_H