]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Remove hover fadein/fadeout animation for KItemListWidget
authorPiruzzolo Piruzzolo <svlmrc@gmail.com>
Mon, 13 Nov 2023 10:09:57 +0000 (10:09 +0000)
committerFelix Ernst <felixernst@kde.org>
Mon, 13 Nov 2023 10:09:57 +0000 (10:09 +0000)
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.

src/kitemviews/kitemlistwidget.cpp
src/kitemviews/kitemlistwidget.h

index 901b2ac15d2abb46bd59f120fd8d423bd2a3eaf7..c4fa1f2ccf2691e4bc6b95dca15231e82e2aef34 100644 (file)
@@ -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++;
index 4634ecc0d61d7875d21f942d2b170a8bd7d2d294..9f99b9d951c0d860490741ae0b110e66a2250b97 100644 (file)
@@ -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;