From: Piruzzolo Piruzzolo Date: Mon, 13 Nov 2023 10:09:57 +0000 (+0000) Subject: Remove hover fadein/fadeout animation for KItemListWidget X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/384e4c9cced91b28674328f621d3b66ee860441f Remove hover fadein/fadeout animation for KItemListWidget Removes hover fade animations for the file item. Hovering is more effective when it provides instant feedback. Over the years, we have moved in the direction of removing animations entirely from our hover-based list and grid views to alleviate a perceived sluggishness. --- diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index 901b2ac15..c4fa1f2cc 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -45,7 +45,6 @@ KItemListWidget::KItemListWidget(KItemListWidgetInformant *informant, QGraphicsI , m_siblingsInfo() , m_hoverOpacity(0) , m_hoverCache(nullptr) - , m_hoverAnimation(nullptr) , m_hoverSequenceIndex(0) , m_selectionToggle(nullptr) , m_editedRole() @@ -65,10 +64,8 @@ void KItemListWidget::setIndex(int index) delete m_selectionToggle; m_selectionToggle = nullptr; - if (m_hoverAnimation) { - m_hoverAnimation->stop(); - m_hoverOpacity = 0; - } + m_hoverOpacity = 0; + clearHoverCache(); m_index = index; @@ -116,6 +113,7 @@ void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o backgroundColor = backgroundColor.darker(101); } } + const QRectF backgroundRect(0, 0, size().width(), size().height()); painter->fillRect(backgroundRect, backgroundColor); } @@ -256,20 +254,11 @@ void KItemListWidget::setHovered(bool hovered) m_hovered = hovered; - if (!m_hoverAnimation) { - m_hoverAnimation = new QPropertyAnimation(this, "hoverOpacity", this); - const int duration = style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1; - m_hoverAnimation->setDuration(duration); - connect(m_hoverAnimation, &QPropertyAnimation::finished, this, &KItemListWidget::slotHoverAnimationFinished); - } - m_hoverAnimation->stop(); - m_hoverSequenceIndex = 0; if (hovered) { - const qreal startValue = qMax(hoverOpacity(), qreal(0.1)); - m_hoverAnimation->setStartValue(startValue); - m_hoverAnimation->setEndValue(1.0); + setHoverOpacity(1.0); + if (m_enabledSelectionToggle && !(QApplication::mouseButtons() & Qt::LeftButton)) { initializeSelectionToggle(); } @@ -281,15 +270,17 @@ void KItemListWidget::setHovered(bool hovered) m_hoverSequenceTimer.start(interval); } else { - m_hoverAnimation->setStartValue(hoverOpacity()); - m_hoverAnimation->setEndValue(0.0); + setHoverOpacity(0.0); + + if (m_selectionToggle) { + m_selectionToggle->deleteLater(); + m_selectionToggle = nullptr; + } hoverSequenceEnded(); m_hoverSequenceTimer.stop(); } - m_hoverAnimation->start(); - hoveredChanged(hovered); update(); } @@ -554,14 +545,6 @@ int KItemListWidget::hoverSequenceIndex() const return m_hoverSequenceIndex; } -void KItemListWidget::slotHoverAnimationFinished() -{ - if (!m_hovered && m_selectionToggle) { - m_selectionToggle->deleteLater(); - m_selectionToggle = nullptr; - } -} - void KItemListWidget::slotHoverSequenceTimerTimeout() { m_hoverSequenceIndex++; diff --git a/src/kitemviews/kitemlistwidget.h b/src/kitemviews/kitemlistwidget.h index 4634ecc0d..9f99b9d95 100644 --- a/src/kitemviews/kitemlistwidget.h +++ b/src/kitemviews/kitemlistwidget.h @@ -235,7 +235,6 @@ protected: const KItemListWidgetInformant *informant() const; private Q_SLOTS: - void slotHoverAnimationFinished(); void slotHoverSequenceTimerTimeout(); private: @@ -263,7 +262,6 @@ private: qreal m_hoverOpacity; mutable QPixmap *m_hoverCache; - QPropertyAnimation *m_hoverAnimation; int m_hoverSequenceIndex; QTimer m_hoverSequenceTimer;