]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistwidget.cpp
Make "open path" and "open path in new tab" scroll to the selected item
[dolphin.git] / src / kitemviews / kitemlistwidget.cpp
index 2c8ef70a57bfd8cff26801aea329480e8b39bc66..4c9f259861104b141f6a624b2bda788767ec08f2 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;
@@ -105,13 +102,24 @@ void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
     Q_UNUSED(option)
 
     if (m_alternateBackground) {
-        const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase);
+        QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase);
+        if (!widget->hasFocus()) {
+            QColor baseColor = m_styleOption.palette.color(QPalette::Base);
+            if (baseColor.lightnessF() > 0.5) {
+                // theme seems light
+                backgroundColor = backgroundColor.lighter(101);
+            } else {
+                // theme seems dark
+                backgroundColor = backgroundColor.darker(101);
+            }
+        }
+
         const QRectF backgroundRect(0, 0, size().width(), size().height());
         painter->fillRect(backgroundRect, backgroundColor);
     }
 
     if (m_selected && m_editedRole.isEmpty()) {
-        const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
+        const QStyle::State activeState(isActiveWindow() && widget->hasFocus() ? QStyle::State_Active : 0);
         drawItemStyleOption(painter, widget, activeState | QStyle::State_Enabled | QStyle::State_Selected | QStyle::State_Item);
     }
 
@@ -120,7 +128,7 @@ void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
         initStyleOption(&focusRectOption);
         focusRectOption.rect = textFocusRect().toRect();
         focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
-        if (m_selected) {
+        if (m_selected && widget->hasFocus()) {
             focusRectOption.state |= QStyle::State_Selected;
         }
 
@@ -135,8 +143,8 @@ void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
             m_hoverCache->fill(Qt::transparent);
 
             QPainter pixmapPainter(m_hoverCache);
-            const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
-            drawItemStyleOption(&pixmapPainter, widget, activeState | QStyle::State_Enabled | QStyle::State_MouseOver | QStyle::State_Item);
+            const QStyle::State activeState(isActiveWindow() && widget->hasFocus() ? QStyle::State_Active | QStyle::State_Enabled : 0);
+            drawItemStyleOption(&pixmapPainter, widget, activeState | QStyle::State_MouseOver | QStyle::State_Item);
         }
 
         const qreal opacity = painter->opacity();
@@ -246,40 +254,33 @@ 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();
         }
 
         hoverSequenceStarted();
 
-        const KConfigGroup globalConfig(KSharedConfig::openConfig(), "PreviewSettings");
+        const KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings"));
         const int interval = globalConfig.readEntry("HoverSequenceInterval", 700);
 
         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();
 }
@@ -437,6 +438,11 @@ QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem *option
     return pixmap;
 }
 
+void KItemListWidget::startActivateSoonAnimation(int timeUntilActivation)
+{
+    Q_UNUSED(timeUntilActivation)
+}
+
 void KItemListWidget::dataChanged(const QHash<QByteArray, QVariant> &current, const QSet<QByteArray> &roles)
 {
     Q_UNUSED(current)
@@ -544,14 +550,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++;
@@ -604,3 +602,5 @@ void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QS
     viewItemOption.rect = selectionRect().toRect();
     style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
 }
+
+#include "moc_kitemlistwidget.cpp"