┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/search
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/search
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/search')
-rw-r--r--src/search/dolphinsearchbox.cpp63
-rw-r--r--src/search/dolphinsearchbox.h17
2 files changed, 56 insertions, 24 deletions
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp
index 5f5577006..8962bd3d2 100644
--- a/src/search/dolphinsearchbox.cpp
+++ b/src/search/dolphinsearchbox.cpp
@@ -36,7 +36,7 @@
#include <QUrlQuery>
DolphinSearchBox::DolphinSearchBox(QWidget *parent)
- : QWidget(parent)
+ : AnimatedHeightWidget(parent)
, m_startedSearching(false)
, m_active(true)
, m_topLayout(nullptr)
@@ -51,6 +51,7 @@ DolphinSearchBox::DolphinSearchBox(QWidget *parent)
, m_facetsWidget(nullptr)
, m_searchPath()
, m_startSearchTimer(nullptr)
+ , m_initialized(false)
{
}
@@ -176,12 +177,12 @@ bool DolphinSearchBox::isActive() const
return m_active;
}
-bool DolphinSearchBox::event(QEvent *event)
+void DolphinSearchBox::setVisible(bool visible, Animated animated)
{
- if (event->type() == QEvent::Polish) {
+ if (visible) {
init();
}
- return QWidget::event(event);
+ AnimatedHeightWidget::setVisible(visible, animated);
}
void DolphinSearchBox::showEvent(QShowEvent *event)
@@ -329,15 +330,23 @@ void DolphinSearchBox::loadSettings()
void DolphinSearchBox::saveSettings()
{
- SearchSettings::setLocation(m_fromHereButton->isChecked() ? QStringLiteral("FromHere") : QStringLiteral("Everywhere"));
- SearchSettings::setWhat(m_fileNameButton->isChecked() ? QStringLiteral("FileName") : QStringLiteral("Content"));
- SearchSettings::self()->save();
+ if (m_initialized) {
+ SearchSettings::setLocation(m_fromHereButton->isChecked() ? QStringLiteral("FromHere") : QStringLiteral("Everywhere"));
+ SearchSettings::setWhat(m_fileNameButton->isChecked() ? QStringLiteral("FileName") : QStringLiteral("Content"));
+ SearchSettings::self()->save();
+ }
}
void DolphinSearchBox::init()
{
+ if (m_initialized) {
+ return; // This object is already initialised.
+ }
+
+ QWidget *contentsContainer = prepareContentsContainer();
+
// Create search box
- m_searchInput = new QLineEdit(this);
+ m_searchInput = new QLineEdit(contentsContainer);
m_searchInput->setPlaceholderText(i18n("Search…"));
m_searchInput->installEventFilter(this);
m_searchInput->setClearButtonEnabled(true);
@@ -355,7 +364,7 @@ void DolphinSearchBox::init()
connect(m_saveSearchAction, &QAction::triggered, this, &DolphinSearchBox::slotSearchSaved);
// 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", "Quit searching"));
@@ -368,7 +377,7 @@ void DolphinSearchBox::init()
searchInputLayout->addWidget(closeButton);
// Create "Filename" and "Content" button
- m_fileNameButton = new QToolButton(this);
+ m_fileNameButton = new QToolButton(contentsContainer);
m_fileNameButton->setText(i18nc("action:button", "Filename"));
initButton(m_fileNameButton);
@@ -376,25 +385,25 @@ void DolphinSearchBox::init()
m_contentButton->setText(i18nc("action:button", "Content"));
initButton(m_contentButton);
- QButtonGroup *searchWhatGroup = new QButtonGroup(this);
+ QButtonGroup *searchWhatGroup = new QButtonGroup(contentsContainer);
searchWhatGroup->addButton(m_fileNameButton);
searchWhatGroup->addButton(m_contentButton);
- m_separator = new KSeparator(Qt::Vertical, this);
+ m_separator = new KSeparator(Qt::Vertical, contentsContainer);
// Create "From Here" and "Your files" buttons
- m_fromHereButton = new QToolButton(this);
+ m_fromHereButton = new QToolButton(contentsContainer);
m_fromHereButton->setText(i18nc("action:button", "From Here"));
initButton(m_fromHereButton);
- m_everywhereButton = new QToolButton(this);
+ m_everywhereButton = new QToolButton(contentsContainer);
m_everywhereButton->setText(i18nc("action:button", "Your files"));
m_everywhereButton->setToolTip(i18nc("action:button", "Search in your home directory"));
m_everywhereButton->setIcon(QIcon::fromTheme(QStringLiteral("user-home")));
m_everywhereButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
initButton(m_everywhereButton);
- QButtonGroup *searchLocationGroup = new QButtonGroup(this);
+ QButtonGroup *searchLocationGroup = new QButtonGroup(contentsContainer);
searchLocationGroup->addButton(m_fromHereButton);
searchLocationGroup->addButton(m_everywhereButton);
@@ -402,7 +411,7 @@ void DolphinSearchBox::init()
QToolButton *kfindToolsButton = nullptr;
if (kfind) {
- kfindToolsButton = new QToolButton(this);
+ kfindToolsButton = new QToolButton(contentsContainer);
kfindToolsButton->setAutoRaise(true);
kfindToolsButton->setPopupMode(QToolButton::InstantPopup);
kfindToolsButton->setIcon(QIcon::fromTheme("arrow-down-double"));
@@ -418,7 +427,7 @@ void DolphinSearchBox::init()
}
// Create "Facets" widget
- m_facetsWidget = new DolphinFacetsWidget(this);
+ m_facetsWidget = new DolphinFacetsWidget(contentsContainer);
m_facetsWidget->installEventFilter(this);
m_facetsWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
m_facetsWidget->layout()->setSpacing(Dolphin::LAYOUT_SPACING_SMALL);
@@ -426,7 +435,7 @@ void DolphinSearchBox::init()
// Put the options into a QScrollArea. This prevents increasing the view width
// in case that not enough width for the options is available.
- QWidget *optionsContainer = new QWidget(this);
+ QWidget *optionsContainer = new QWidget(contentsContainer);
// Apply layout for the options
QHBoxLayout *optionsLayout = new QHBoxLayout(optionsContainer);
@@ -437,13 +446,13 @@ void DolphinSearchBox::init()
optionsLayout->addWidget(m_separator);
optionsLayout->addWidget(m_fromHereButton);
optionsLayout->addWidget(m_everywhereButton);
- optionsLayout->addWidget(new KSeparator(Qt::Vertical, this));
+ optionsLayout->addWidget(new KSeparator(Qt::Vertical, contentsContainer));
if (kfindToolsButton) {
optionsLayout->addWidget(kfindToolsButton);
}
optionsLayout->addStretch(1);
- m_optionsScrollArea = new QScrollArea(this);
+ m_optionsScrollArea = new QScrollArea(contentsContainer);
m_optionsScrollArea->setFrameShape(QFrame::NoFrame);
m_optionsScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_optionsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -452,7 +461,7 @@ void DolphinSearchBox::init()
m_optionsScrollArea->setWidget(optionsContainer);
m_optionsScrollArea->setWidgetResizable(true);
- m_topLayout = new QVBoxLayout(this);
+ m_topLayout = new QVBoxLayout(contentsContainer);
m_topLayout->setContentsMargins(0, Dolphin::LAYOUT_SPACING_SMALL, 0, 0);
m_topLayout->setSpacing(Dolphin::LAYOUT_SPACING_SMALL);
m_topLayout->addLayout(searchInputLayout);
@@ -467,6 +476,8 @@ void DolphinSearchBox::init()
m_startSearchTimer->setSingleShot(true);
m_startSearchTimer->setInterval(500);
connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest);
+
+ m_initialized = true;
}
QString DolphinSearchBox::queryTitle(const QString &text) const
@@ -539,6 +550,11 @@ void DolphinSearchBox::updateFacetsVisible()
const bool indexingEnabled = isIndexingEnabled();
m_facetsWidget->setEnabled(indexingEnabled);
m_facetsWidget->setVisible(indexingEnabled);
+
+ // The m_facetsWidget might have changed visibility. We smoothly animate towards the updated height.
+ if (isVisible() && isEnabled()) {
+ setVisible(true, WithAnimation);
+ }
}
bool DolphinSearchBox::isIndexingEnabled() const
@@ -551,4 +567,9 @@ bool DolphinSearchBox::isIndexingEnabled() const
#endif
}
+int DolphinSearchBox::preferredHeight() const
+{
+ return m_initialized ? m_topLayout->sizeHint().height() : 0;
+}
+
#include "moc_dolphinsearchbox.cpp"
diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h
index 9f1ad2952..6a847ba57 100644
--- a/src/search/dolphinsearchbox.h
+++ b/src/search/dolphinsearchbox.h
@@ -7,8 +7,9 @@
#ifndef DOLPHINSEARCHBOX_H
#define DOLPHINSEARCHBOX_H
+#include "animatedheightwidget.h"
+
#include <QUrl>
-#include <QWidget>
class DolphinFacetsWidget;
class DolphinQuery;
@@ -29,7 +30,7 @@ class QVBoxLayout;
* If Baloo is available and the current folder is indexed, further
* options are offered.
*/
-class DolphinSearchBox : public QWidget
+class DolphinSearchBox : public AnimatedHeightWidget
{
Q_OBJECT
@@ -86,8 +87,13 @@ public:
*/
bool isActive() const;
+ /*
+ * @see AnimatedHeightWidget::setVisible()
+ * @see QWidget::setVisible()
+ */
+ void setVisible(bool visible, Animated animated);
+
protected:
- bool event(QEvent *event) override;
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
@@ -152,6 +158,9 @@ private:
bool isIndexingEnabled() const;
+ /** @see AnimatedHeightWidget::preferredHeight() */
+ int preferredHeight() const override;
+
private:
QString queryTitle(const QString &text) const;
@@ -173,6 +182,8 @@ private:
QUrl m_searchPath;
QTimer *m_startSearchTimer;
+
+ bool m_initialized;
};
#endif