┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/selectionmode/topbar.cpp
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2024-03-13 15:39:00 +0000
committerFelix Ernst <[email protected]>2024-03-13 15:39:00 +0000
commitf588a7d48b7cef5351d8b0f030a6ec5e76229976 (patch)
tree086c0743d3dd63e5ca11cd84e55b527f58cbe5ea /src/selectionmode/topbar.cpp
parent73ea5fd8450cdd097a47ede9d740cbbcf9f9df10 (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/selectionmode/topbar.cpp')
-rw-r--r--src/selectionmode/topbar.cpp50
1 files changed, 3 insertions, 47 deletions
diff --git a/src/selectionmode/topbar.cpp b/src/selectionmode/topbar.cpp
index abe9f74a5..5d77a4c00 100644
--- a/src/selectionmode/topbar.cpp
+++ b/src/selectionmode/topbar.cpp
@@ -16,18 +16,13 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
-#include <QScrollArea>
#include <QStyle>
using namespace SelectionMode;
TopBar::TopBar(QWidget *parent)
- : QWidget{parent}
+ : AnimatedHeightWidget{parent}
{
- // Showing of this widget is normally animated. We hide it for now and make it small.
- hide();
- setMaximumHeight(0);
-
setToolTip(KToolTipHelper::whatsThisHintOnly());
setWhatsThis(xi18nc("@info:whatsthis",
"<title>Selection Mode</title><para>Select files or folders to manage or manipulate them."
@@ -36,25 +31,10 @@ TopBar::TopBar(QWidget *parent)
"<item>Selection rectangles (created by dragging from an empty area) invert the selection status of items within.</item></list></para>"
"<para>The available action buttons at the bottom change depending on the current selection.</para>"));
- auto fillParentLayout = new QGridLayout(this);
- fillParentLayout->setContentsMargins(0, 0, 0, 0);
-
- // Put the contents into a QScrollArea. This prevents increasing the view width
- // in case that not enough width for the contents is available. (this trick is also used in bottombar.cpp.)
- auto scrollArea = new QScrollArea(this);
- fillParentLayout->addWidget(scrollArea);
- scrollArea->setFrameShape(QFrame::NoFrame);
- scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- scrollArea->setWidgetResizable(true);
-
- auto contentsContainer = new QWidget(scrollArea);
- scrollArea->setWidget(contentsContainer);
+ QWidget *contentsContainer = prepareContentsContainer();
BackgroundColorHelper::instance()->controlBackgroundColor(this);
- setMinimumWidth(0);
-
m_fullLabelString = i18nc("@info label above the view explaining the state", "Selection Mode: Click on files or folders to select or deselect them.");
m_shortLabelString = i18nc("@info label above the view explaining the state", "Selection Mode");
m_label = new QLabel(contentsContainer);
@@ -69,7 +49,6 @@ TopBar::TopBar(QWidget *parent)
QHBoxLayout *layout = new QHBoxLayout(contentsContainer);
auto contentsMargins = layout->contentsMargins();
m_preferredHeight = contentsMargins.top() + m_label->sizeHint().height() + contentsMargins.bottom();
- scrollArea->setMaximumHeight(m_preferredHeight);
m_closeButton->setFixedHeight(m_preferredHeight);
layout->setContentsMargins(0, 0, 0, 0);
@@ -79,33 +58,10 @@ TopBar::TopBar(QWidget *parent)
layout->addWidget(m_closeButton);
}
-void TopBar::setVisible(bool visible, Animated animated)
-{
- Q_ASSERT_X(animated == WithAnimation, "SelectionModeTopBar::setVisible", "This wasn't implemented.");
-
- if (m_heightAnimation) {
- m_heightAnimation->stop(); // deletes because of QAbstractAnimation::DeleteWhenStopped.
- }
- m_heightAnimation = new QPropertyAnimation(this, "maximumHeight");
- m_heightAnimation->setDuration(2 * style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, this) * GlobalConfig::animationDurationFactor());
-
- m_heightAnimation->setStartValue(height());
- m_heightAnimation->setEasingCurve(QEasingCurve::OutCubic);
- if (visible) {
- show();
- m_heightAnimation->setEndValue(m_preferredHeight);
- } else {
- m_heightAnimation->setEndValue(0);
- connect(m_heightAnimation, &QAbstractAnimation::finished, this, &QWidget::hide);
- }
-
- m_heightAnimation->start(QAbstractAnimation::DeleteWhenStopped);
-}
-
void TopBar::resizeEvent(QResizeEvent *resizeEvent)
{
updateLabelString();
- return QWidget::resizeEvent(resizeEvent);
+ return AnimatedHeightWidget::resizeEvent(resizeEvent);
}
void TopBar::updateLabelString()