diff options
| author | Felix Ernst <[email protected]> | 2024-03-13 15:39:00 +0000 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2024-03-13 15:39:00 +0000 |
| commit | f588a7d48b7cef5351d8b0f030a6ec5e76229976 (patch) | |
| tree | 086c0743d3dd63e5ca11cd84e55b527f58cbe5ea /src/animatedheightwidget.h | |
| parent | 73ea5fd8450cdd097a47ede9d740cbbcf9f9df10 (diff) | |
Animate most of the bars
When a bar is toggled visible this usually happens because the
user might want to use its functionality now. However, if bars
appear without animation or at a location the user is not
currently looking at, they might not notice that they have appeared
at all.
An animation makes it more likely that the user notices the change
and can then use the newly made visible component.
Another reason for animations for showing or hiding of components
is that it can be disorienting for users when panels or bars
suddenly appear or disappear without animation. There is no visible
movement then, so the user might not know what happened if they
didn't concentrate or blink at that moment. The newly appearing or
disappearing component might also displace other components which
can make it difficult to find what one was just looking at.
These bars animate now after this change:
- Search panel
- Filter bar
- Status bar
This is implemented by extracting the animation code from
SelectionMode::TopBar into a new abstract base class
AnimatedHeightWidget. This class is now also used in
SelectionMode::BottomBar and the animating code there was removed.
These bars are left in Dolphin that stay without animation:
- Menu bar (Would probably need to be implemented in KXmlGui)
- Tool bar (Would probably need to be implemented in KXmlGui)
- Tab bar (Needs a different appraoch because it already inherits
QTabBar and therefore can not inherit AnimatedHeightWidget)
Diffstat (limited to 'src/animatedheightwidget.h')
| -rw-r--r-- | src/animatedheightwidget.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/animatedheightwidget.h b/src/animatedheightwidget.h new file mode 100644 index 000000000..8f040d571 --- /dev/null +++ b/src/animatedheightwidget.h @@ -0,0 +1,74 @@ +/* + This file is part of the KDE project + SPDX-FileCopyrightText: 2024 Felix Ernst <[email protected]> + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef ANIMATEDHEIGHTWIDGET_H +#define ANIMATEDHEIGHTWIDGET_H + +#include "global.h" + +#include <QPointer> +#include <QWidget> + +class QPropertyAnimation; +class QScrollArea; + +/** + * @brief An abstract base class which facilitates animated showing and hiding of sub-classes + */ +class AnimatedHeightWidget : public QWidget +{ +public: + AnimatedHeightWidget(QWidget *parent); + + /** + * Plays a show or hide animation while changing visibility. + * Therefore, if this method is used to hide this widget, the actual hiding will be delayed until the animation finished. + * + * @param visible Whether this bar is supposed to be visible long-term + * @param animated Whether this should be animated. The animation is skipped if the users' settings are configured that way. + * + * @see QWidget::setVisible() + */ + void setVisible(bool visible, Animated animated); + + /** + * @returns a QSize with a width of 1 to make sure that this bar never causes side panels to shrink. + * The returned height equals preferredHeight(). + */ + QSize sizeHint() const override; + +protected: + /** + * AnimatedHeightWidget always requires a singular main child which we call the "contentsContainer". + * Use this method to register such an object. + * + * @returns a "contentsContainer" which is a QWidget that consists of/contains all visible contents of this AnimatedHeightWidget. + * It will be the only grandchild of this AnimatedHeightWidget. + * @param contentsContainer The object that should be used as the "contentsContainer". + */ + QWidget *prepareContentsContainer(QWidget *contentsContainer = new QWidget); + + /** @returns whether this object is currently animating a visibility change. */ + bool isAnimationRunning() const; + +private: + using QWidget::hide; // Use QAbstractAnimation::setVisible() instead. + 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. + using QWidget::show; // Use QAbstractAnimation::setVisible() instead. + + /** @returns the full preferred height this widget should have when it is done animating and visible. */ + virtual int preferredHeight() const = 0; + +private: + /** @see contentsContainerParent() */ + QScrollArea *m_contentsContainerParent = nullptr; + + /** @see AnimatedHeightWidget::setVisible() */ + QPointer<QPropertyAnimation> m_heightAnimation; +}; + +#endif // ANIMATEDHEIGHTWIDGET_H |
