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/filterbar | |
| 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/filterbar')
| -rw-r--r-- | src/filterbar/filterbar.cpp | 19 | ||||
| -rw-r--r-- | src/filterbar/filterbar.h | 7 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/filterbar/filterbar.cpp b/src/filterbar/filterbar.cpp index 9d25869ba..e4aea4b61 100644 --- a/src/filterbar/filterbar.cpp +++ b/src/filterbar/filterbar.cpp @@ -17,10 +17,12 @@ #include <QToolButton> FilterBar::FilterBar(QWidget *parent) - : QWidget(parent) + : AnimatedHeightWidget{parent} { + QWidget *contentsContainer = prepareContentsContainer(); + // Create button to lock text when changing folders - m_lockButton = new QToolButton(this); + m_lockButton = new QToolButton(contentsContainer); m_lockButton->setAutoRaise(true); m_lockButton->setCheckable(true); m_lockButton->setIcon(QIcon::fromTheme(QStringLiteral("object-unlocked"))); @@ -28,7 +30,7 @@ FilterBar::FilterBar(QWidget *parent) connect(m_lockButton, &QToolButton::toggled, this, &FilterBar::slotToggleLockButton); // Create filter editor - m_filterInput = new QLineEdit(this); + m_filterInput = new QLineEdit(contentsContainer); m_filterInput->setLayoutDirection(Qt::LeftToRight); m_filterInput->setClearButtonEnabled(true); m_filterInput->setPlaceholderText(i18n("Filter…")); @@ -36,14 +38,14 @@ FilterBar::FilterBar(QWidget *parent) setFocusProxy(m_filterInput); // Create close button - QToolButton *closeButton = new QToolButton(this); + QToolButton *closeButton = new QToolButton(contentsContainer); closeButton->setAutoRaise(true); closeButton->setIcon(QIcon::fromTheme(QStringLiteral("dialog-close"))); closeButton->setToolTip(i18nc("@info:tooltip", "Hide Filter Bar")); connect(closeButton, &QToolButton::clicked, this, &FilterBar::closeRequest); // Apply layout - QHBoxLayout *hLayout = new QHBoxLayout(this); + QHBoxLayout *hLayout = new QHBoxLayout(contentsContainer); hLayout->setContentsMargins(0, 0, 0, 0); hLayout->addWidget(m_lockButton); hLayout->addWidget(m_filterInput); @@ -59,7 +61,7 @@ FilterBar::~FilterBar() void FilterBar::closeFilterBar() { - hide(); + setVisible(false, WithAnimation); clear(); if (m_lockButton) { m_lockButton->setChecked(false); @@ -135,4 +137,9 @@ void FilterBar::keyPressEvent(QKeyEvent *event) QWidget::keyPressEvent(event); } +int FilterBar::preferredHeight() const +{ + return std::max(m_filterInput->sizeHint().height(), m_lockButton->sizeHint().height()); +} + #include "moc_filterbar.cpp" diff --git a/src/filterbar/filterbar.h b/src/filterbar/filterbar.h index 353055883..1424f4cb8 100644 --- a/src/filterbar/filterbar.h +++ b/src/filterbar/filterbar.h @@ -9,7 +9,7 @@ #ifndef FILTERBAR_H #define FILTERBAR_H -#include <QWidget> +#include "animatedheightwidget.h" class QLineEdit; class QToolButton; @@ -19,7 +19,7 @@ class QToolButton; * * @author Gregor Kališnik <[email protected]> */ -class FilterBar : public QWidget +class FilterBar : public AnimatedHeightWidget { Q_OBJECT @@ -64,6 +64,9 @@ protected: void showEvent(QShowEvent *event) override; void keyPressEvent(QKeyEvent *event) override; + /** @see AnimatedHeightWidget::preferredHeight() */ + int preferredHeight() const override; + private: QLineEdit *m_filterInput; QToolButton *m_lockButton; |
