]> cloud.milkyroute.net Git - dolphin.git/commitdiff
New selection effects
authorAkseli Lahtinen <akselmo@akselmo.dev>
Thu, 19 Jun 2025 21:15:31 +0000 (00:15 +0300)
committerAkseli Lahtinen <akselmo@akselmo.dev>
Thu, 19 Jun 2025 21:15:31 +0000 (00:15 +0300)
This adds a new selection effect that is similar to what we have in QtQuick file item views.

There are also changes to some usability: Instead of only the icon and text being the clickable area in icon and details mode, the whole selection is now the clickable area.

Otherwise the usability should stay the same, it's mostly a visual change.

See also: https://invent.kde.org/teams/vdg/issues/-/issues/94

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistwidget.cpp
src/kitemviews/kitemlistwidget.h
src/kitemviews/kstandarditemlistwidget.cpp
src/kitemviews/kstandarditemlistwidget.h
src/views/dolphinitemlistview.cpp

index cd60c3a41b8ab96ad479d3cf74a5d9910df532d2..fdde48abcdd83056a007aeed7f5cde5606b6135d 100644 (file)
@@ -675,6 +675,10 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, con
         return false;
     }
 
+    for (KItemListWidget *widget : m_view->visibleItemListWidgets()) {
+        widget->setPressed(false);
+    }
+
     if (m_view->m_tapAndHoldIndicator->isActive()) {
         m_view->m_tapAndHoldIndicator->setActive(false);
     }
@@ -990,7 +994,7 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent *event, const
             // we also unhover any old expansion toggle hovers, in case the mouse movement from expansion toggle to icon+text is too fast (i.e. newHoveredWidget is never null between the transition)
             unhoverOldExpansionWidget();
 
-            const bool isOverIconAndText = newHoveredWidget->iconRect().contains(mappedPos) || newHoveredWidget->textRect().contains(mappedPos);
+            const bool isOverIconAndText = newHoveredWidget->selectionRectCore().contains(mappedPos);
             const bool hasMultipleSelection = m_selectionManager->selectedItems().count() > 1;
 
             if (hasMultipleSelection && !isOverIconAndText) {
@@ -1029,6 +1033,7 @@ bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent *event, const
 
     const auto widgets = m_view->visibleItemListWidgets();
     for (KItemListWidget *widget : widgets) {
+        widget->setPressed(false);
         if (widget->isHovered()) {
             widget->setHovered(false);
             Q_EMIT itemUnhovered(widget->index());
@@ -1365,9 +1370,8 @@ void KItemListController::slotRubberBandChanged()
         const QRectF widgetRect = m_view->itemRect(index);
         if (widgetRect.intersects(rubberBandRect)) {
             // Select the full row intersecting with the rubberband rectangle
-            const QRectF selectionRect = widget->selectionRect().translated(widgetRect.topLeft());
-            const QRectF iconRect = widget->iconRect().translated(widgetRect.topLeft());
-            if (selectionRect.intersects(rubberBandRect) || iconRect.intersects(rubberBandRect)) {
+            const QRectF selectionRect = widget->selectionRectFull().translated(widgetRect.topLeft());
+            if (selectionRect.intersects(rubberBandRect)) {
                 selectedItems.insert(index);
             }
         }
@@ -1467,7 +1471,7 @@ KItemListWidget *KItemListController::widgetForPos(const QPointF &pos) const
     const auto widgets = m_view->visibleItemListWidgets();
     for (KItemListWidget *widget : widgets) {
         const QPointF mappedPos = widget->mapFromItem(m_view, pos);
-        if (widget->contains(mappedPos) || widget->selectionRect().contains(mappedPos)) {
+        if (widget->contains(mappedPos)) {
             return widget;
         }
     }
@@ -1486,7 +1490,7 @@ KItemListWidget *KItemListController::widgetForDropPos(const QPointF &pos) const
     const auto widgets = m_view->visibleItemListWidgets();
     for (KItemListWidget *widget : widgets) {
         const QPointF mappedPos = widget->mapFromItem(m_view, pos);
-        if (widget->contains(mappedPos)) {
+        if (widget->selectionRectCore().contains(mappedPos)) {
             return widget;
         }
     }
@@ -1641,6 +1645,7 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
                                                                                       // simplify the overall logic and possibilities both for users and devs.
     const bool leftClick = buttons & Qt::LeftButton;
     const bool rightClick = buttons & Qt::RightButton;
+    const bool singleClickActivation = m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick);
 
     // The previous selection is cleared if either
     // 1. The selection mode is SingleSelection, or
@@ -1661,11 +1666,11 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
         if (selectedItemsCount > 1 && m_pressedIndex.has_value()) {
             const auto row = m_view->m_visibleItems.value(m_pressedIndex.value());
             const auto mappedPos = row->mapFromItem(m_view, pos);
-            if (pressedItemAlreadySelected || row->iconRect().contains(mappedPos) || row->textRect().contains(mappedPos)) {
+            if (row->selectionRectCore().contains(mappedPos)) {
                 // we are indeed inside the text/icon rect, keep m_pressedIndex what it is
                 // and short-circuit for single-click activation (it will then propagate to onRelease and activate the item)
                 // or we just keep going for double-click activation
-                if (m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) {
+                if (singleClickActivation || m_singleClickActivationEnforced) {
                     if (!pressedItemAlreadySelected) {
                         // An unselected item was clicked directly while deselecting multiple other items so we mark it "current".
                         m_selectionManager->setCurrentItem(m_pressedIndex.value());
@@ -1676,6 +1681,9 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
                             m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle);
                         }
                     }
+                    if (leftClick) {
+                        row->setPressed(true);
+                    }
                     return true; // event handled, don't create rubber band
                 }
             } else {
@@ -1723,11 +1731,16 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
     if (m_pressedIndex.has_value()) {
         // The hover highlight area of an item is being pressed.
         const auto row = m_view->m_visibleItems.value(m_pressedIndex.value()); // anything outside of row.contains() will be the empty region of the row rect
-        const bool hitTargetIsRowEmptyRegion = !row->contains(row->mapFromItem(m_view, pos));
+
+        const bool hitTargetIsRowEmptyRegion = !row->selectionRectCore().contains(row->mapFromItem(m_view, pos));
         // again, when this method returns false, a rubberBand selection is created as the event is not consumed;
         // createRubberBand here tells us whether to return true or false.
         bool createRubberBand = (hitTargetIsRowEmptyRegion && m_selectionManager->selectedItems().isEmpty());
 
+        if (leftClick) {
+            row->setPressed(true);
+        }
+
         if (rightClick && hitTargetIsRowEmptyRegion) {
             // We have a right click outside the icon and text rect but within the hover highlight area.
             // We don't want items to get selected through this, so we return now.
@@ -1741,8 +1754,7 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
             break;
 
         case SingleSelection:
-            if (!leftClick || shiftOrControlPressed
-                || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) {
+            if (!leftClick || shiftOrControlPressed || (!singleClickActivation && !m_singleClickActivationEnforced)) {
                 m_selectionManager->setSelected(m_pressedIndex.value());
             }
             break;
@@ -1755,7 +1767,7 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
                 // We rule out the latter, if the item is not clicked directly and was unselected previously.
                 const auto row = m_view->m_visibleItems.value(m_pressedIndex.value());
                 const auto mappedPos = row->mapFromItem(m_view, pos);
-                if (!row->iconRect().contains(mappedPos) && !row->textRect().contains(mappedPos) && !pressedItemAlreadySelected) {
+                if (!row->selectionRectCore().contains(mappedPos)) {
                     createRubberBand = true;
                 } else {
                     m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle);
@@ -1765,8 +1777,7 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
                 }
             } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) {
                 // Select the pressed item and start a new anchored selection
-                if (!leftClick || shiftOrControlPressed
-                    || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) {
+                if (!leftClick || shiftOrControlPressed || (!singleClickActivation && !m_singleClickActivationEnforced)) {
                     m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Select);
                 }
                 m_selectionManager->beginAnchoredSelection(m_pressedIndex.value());
index 265e41e6ca3dfec63542e19bb91c45498d481608..3ed4df3e7bb13f9b410574a85c0fde6dcca7cdcc 100644 (file)
@@ -425,7 +425,7 @@ std::optional<int> KItemListView::itemAt(const QPointF &pos) const
 
         const KItemListWidget *widget = it.value();
         const QPointF mappedPos = widget->mapFromItem(this, pos);
-        if (widget->contains(mappedPos) || widget->selectionRect().contains(mappedPos)) {
+        if (widget->contains(mappedPos)) {
             return it.key();
         }
     }
@@ -542,7 +542,7 @@ QRectF KItemListView::itemContextRect(int index) const
 
     const KItemListWidget *widget = m_visibleItems.value(index);
     if (widget) {
-        contextRect = widget->iconRect() | widget->textRect();
+        contextRect = widget->selectionRectCore();
         contextRect.translate(itemRect(index).topLeft());
     }
 
index baf2445726d1e18255619306613ae7202551dda6..c06e46339f6e6a0ff413900162b5dc570c07fdd8 100644 (file)
@@ -37,6 +37,7 @@ KItemListWidget::KItemListWidget(KItemListWidgetInformant *informant, QGraphicsI
     , m_expansionAreaHovered(false)
     , m_alternateBackground(false)
     , m_enabledSelectionToggle(false)
+    , m_clickHighlighted(false)
     , m_data()
     , m_visibleRoles()
     , m_columnWidths()
@@ -124,23 +125,11 @@ void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
         painter->fillRect(backgroundRect, backgroundColor);
     }
 
-    if (m_selected && m_editedRole.isEmpty()) {
+    if ((m_selected || m_current) && m_editedRole.isEmpty()) {
         const QStyle::State activeState(isActiveWindow() && widget->hasFocus() ? QStyle::State_Active : 0);
         drawItemStyleOption(painter, widget, activeState | QStyle::State_Enabled | QStyle::State_Selected | QStyle::State_Item);
     }
 
-    if (m_current && m_editedRole.isEmpty()) {
-        QStyleOptionFocusRect focusRectOption;
-        initStyleOption(&focusRectOption);
-        focusRectOption.rect = textFocusRect().toRect();
-        focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
-        if (m_selected && widget->hasFocus()) {
-            focusRectOption.state |= QStyle::State_Selected;
-        }
-
-        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusRectOption, painter, widget);
-    }
-
     if (m_hoverOpacity > 0.0) {
         if (!m_hoverCache) {
             // Initialize the m_hoverCache pixmap to improve the drawing performance
@@ -419,7 +408,7 @@ bool KItemListWidget::contains(const QPointF &point) const
         return false;
     }
 
-    return iconRect().contains(point) || textRect().contains(point) || expansionToggleRect().contains(point) || selectionToggleRect().contains(point);
+    return selectionRectFull().contains(point) || expansionToggleRect().contains(point);
 }
 
 QRectF KItemListWidget::textFocusRect() const
@@ -616,15 +605,66 @@ void KItemListWidget::clearHoverCache()
     m_hoverCache = nullptr;
 }
 
+bool KItemListWidget::isPressed() const
+{
+    return m_clickHighlighted;
+}
+
+void KItemListWidget::setPressed(bool enabled)
+{
+    if (m_clickHighlighted != enabled) {
+        m_clickHighlighted = enabled;
+        clearHoverCache();
+        update();
+    }
+}
+
 void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QStyle::State styleState)
 {
     QStyleOptionViewItem viewItemOption;
+    constexpr int roundness = 5; // From Breeze style.
+    constexpr qreal penWidth = 1.5;
     initStyleOption(&viewItemOption);
     viewItemOption.state = styleState;
     viewItemOption.viewItemPosition = QStyleOptionViewItem::OnlyOne;
     viewItemOption.showDecorationSelected = true;
-    viewItemOption.rect = selectionRect().toRect();
-    style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
+    viewItemOption.rect = selectionRectFull().toRect();
+    QPainterPath path;
+    path.addRoundedRect(selectionRectFull().adjusted(penWidth, penWidth, -penWidth, -penWidth), roundness, roundness);
+    QColor backgroundColor{widget->palette().color(QPalette::Accent)};
+    painter->setRenderHint(QPainter::Antialiasing);
+    bool current = m_current && styleState & QStyle::State_Active;
+
+    // Background item, alpha values are from
+    // https://invent.kde.org/plasma/libplasma/-/blob/master/src/desktoptheme/breeze/widgets/viewitem.svg
+    backgroundColor.setAlphaF(0.0);
+
+    if (m_clickHighlighted) {
+        backgroundColor.setAlphaF(1.0);
+    } else {
+        if (m_selected && m_hovered) {
+            backgroundColor.setAlphaF(0.40);
+        } else if (m_selected) {
+            backgroundColor.setAlphaF(0.32);
+        } else if (m_hovered) {
+            backgroundColor = widget->palette().color(QPalette::Text);
+            backgroundColor.setAlphaF(0.06);
+        }
+    }
+
+    painter->fillPath(path, backgroundColor);
+
+    // Focus decoration
+    if (current) {
+        QColor focusColor{widget->palette().color(QPalette::Accent)};
+        focusColor = m_styleOption.palette.color(QPalette::Base).lightnessF() > 0.5 ? focusColor.darker(110) : focusColor.lighter(110);
+        focusColor.setAlphaF(m_selected || m_hovered ? 0.8 : 0.6);
+        // Set the pen color lighter or darker depending on background color
+        QPen pen{focusColor, penWidth};
+        pen.setCosmetic(true);
+        painter->setPen(pen);
+        painter->drawPath(path);
+    }
 }
 
 #include "moc_kitemlistwidget.cpp"
index 0e07d7ab559d155166cbf82fe4f5514db384e0ec..b87a3b34e65f98e78c0bbcf6609a55953981c5ee 100644 (file)
@@ -98,6 +98,10 @@ public:
     void setHovered(bool hovered);
     bool isHovered() const;
 
+    /** Sets a purely visual pressed highlight effect. */
+    void setPressed(bool enabled);
+    bool isPressed() const;
+
     void setExpansionAreaHovered(bool hover);
     bool expansionAreaHovered() const;
 
@@ -137,18 +141,13 @@ public:
     int iconSize() const;
 
     /**
-     * @return True if \a point is inside KItemListWidget::hoverRect(),
-     *         KItemListWidget::textRect(), KItemListWidget::selectionToggleRect()
+     * @return True if \a point is inside KItemListWidget::selectionRectFull(),
+     *         KItemListWidget::selectionToggleRect()
      *         or KItemListWidget::expansionToggleRect().
      * @reimp
      */
     bool contains(const QPointF &point) const override;
 
-    /**
-     * @return Rectangle for the area that shows the icon.
-     */
-    virtual QRectF iconRect() const = 0;
-
     /**
      * @return Rectangle for the area that contains the text-properties.
      */
@@ -164,9 +163,17 @@ public:
     virtual QRectF textFocusRect() const;
 
     /**
-     * @return Rectangle around which a selection box should be drawn if the item is selected.
+     * Used for drawing the visuals, and situations where we want the behavior of the
+     * selection to match the visuals.
+     *
+     * @return The rectangle around selection.
+     */
+    virtual QRectF selectionRectFull() const = 0;
+
+    /**
+     * @return The core area of the item. All of it reacts exactly the same way to mouse clicks.
      */
-    virtual QRectF selectionRect() const = 0;
+    virtual QRectF selectionRectCore() const = 0;
 
     /**
      * @return Rectangle for the selection-toggle that is used to select or deselect an item.
@@ -258,6 +265,7 @@ private:
     bool m_expansionAreaHovered;
     bool m_alternateBackground;
     bool m_enabledSelectionToggle;
+    bool m_clickHighlighted;
     QHash<QByteArray, QVariant> m_data;
     QList<QByteArray> m_visibleRoles;
     QHash<QByteArray, qreal> m_columnWidths;
index 49d2f26bfd945db1feedf96f15607abe8487541b..d078b06573f3f5a35a3d0fba3b1699cc29a6acf9 100644 (file)
@@ -271,7 +271,6 @@ KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant *infor
     , m_scaledPixmapSize()
     , m_columnWidthSum()
     , m_iconRect()
-    , m_hoverPixmap()
     , m_textRect()
     , m_sortedVisibleRoles()
     , m_expansionArea()
@@ -346,7 +345,7 @@ void KStandardItemListWidget::paint(QPainter *painter, const QStyleOptionGraphic
         drawSiblingsInformation(painter);
     }
 
-    auto pixmap = isHovered() ? m_hoverPixmap : m_pixmap;
+    auto pixmap = m_pixmap;
     if (!m_overlays.isEmpty()) {
         const qreal dpr = KItemViewsUtils::devicePixelRatio(this);
 
@@ -388,7 +387,7 @@ void KStandardItemListWidget::paint(QPainter *painter, const QStyleOptionGraphic
             {
                 QPainter p(&pixmap2);
                 p.setOpacity(hoverOpacity());
-                p.drawPixmap(0, 0, m_hoverPixmap);
+                p.drawPixmap(0, 0, m_pixmap);
             }
 
             // Paint pixmap2 on pixmap1 using CompositionMode_Plus
@@ -484,12 +483,6 @@ void KStandardItemListWidget::paint(QPainter *painter, const QStyleOptionGraphic
 #endif
 }
 
-QRectF KStandardItemListWidget::iconRect() const
-{
-    const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing();
-    return m_iconRect;
-}
-
 QRectF KStandardItemListWidget::textRect() const
 {
     const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing();
@@ -537,35 +530,36 @@ QRectF KStandardItemListWidget::textFocusRect() const
     return m_textRect;
 }
 
-QRectF KStandardItemListWidget::selectionRect() const
+QRectF KStandardItemListWidget::selectionRectFull() const
 {
     const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing();
-
-    switch (m_layout) {
-    case IconsLayout:
-        return m_textRect;
-
-    case CompactLayout:
-    case DetailsLayout: {
-        const int padding = styleOption().padding;
-        QRectF adjustedIconRect = iconRect().adjusted(-padding, -padding, padding, padding);
-        QRectF result = adjustedIconRect | m_textRect;
+    const int padding = styleOption().padding;
+    if (m_layout == DetailsLayout) {
+        auto rect = m_iconRect | m_textRect;
         if (m_highlightEntireRow) {
             if (layoutDirection() == Qt::LeftToRight) {
-                result.setRight(leftPadding() + m_columnWidthSum);
+                rect.setRight(leftPadding() + m_columnWidthSum);
             } else {
-                result.setLeft(size().width() - m_columnWidthSum - rightPadding());
+                rect.setLeft(size().width() - m_columnWidthSum - rightPadding());
             }
         }
-        return result;
+        return rect.adjusted(-padding, 0, padding, 0);
+    } else {
+        if (m_layout == CompactLayout) {
+            return rect().adjusted(-padding, 0, padding, 0);
+        }
+        return rect();
     }
+}
 
-    default:
-        Q_ASSERT(false);
-        break;
+QRectF KStandardItemListWidget::selectionRectCore() const
+{
+    // Allow dragging from selection area in details view.
+    if (m_layout == DetailsLayout && highlightEntireRow() && !isSelected()) {
+        QRectF result = m_iconRect | m_textRect;
+        return result;
     }
-
-    return m_textRect;
+    return selectionRectFull();
 }
 
 QRectF KStandardItemListWidget::expansionToggleRect() const
@@ -578,7 +572,6 @@ QRectF KStandardItemListWidget::selectionToggleRect() const
 {
     const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing();
 
-    const QRectF widgetIconRect = iconRect();
     const int widgetIconSize = iconSize();
     int toggleSize = KIconLoader::SizeSmall;
     if (widgetIconSize >= KIconLoader::SizeEnormous) {
@@ -587,29 +580,11 @@ QRectF KStandardItemListWidget::selectionToggleRect() const
         toggleSize = KIconLoader::SizeSmallMedium;
     }
 
-    QPointF pos = widgetIconRect.topLeft();
-
-    // If the selection toggle has a very small distance to the
-    // widget borders, the size of the selection toggle will get
-    // increased to prevent an accidental clicking of the item
-    // when trying to hit the toggle.
-    const int widgetHeight = size().height();
-    const int widgetWidth = size().width();
-    const int minMargin = 2;
-
-    if (toggleSize + minMargin * 2 >= widgetHeight) {
-        pos.rx() -= (widgetHeight - toggleSize) / 2;
-        toggleSize = widgetHeight;
-        pos.setY(0);
-    }
-    if (toggleSize + minMargin * 2 >= widgetWidth) {
-        pos.ry() -= (widgetWidth - toggleSize) / 2;
-        toggleSize = widgetWidth;
-        pos.setX(0);
-    }
-
+    const int padding = styleOption().padding;
+    const QRectF selectionRectMinusPadding = selectionRectFull().adjusted(padding, padding, -padding, -padding);
+    QPointF pos = selectionRectMinusPadding.topLeft();
     if (QApplication::isRightToLeft()) {
-        pos.setX(widgetIconRect.right() - (pos.x() + toggleSize - widgetIconRect.left()));
+        pos.setX(selectionRectMinusPadding.right() - (pos.x() + toggleSize - selectionRectMinusPadding.left()));
     }
 
     return QRectF(pos, QSizeF(toggleSize, toggleSize));
@@ -725,7 +700,11 @@ QFont KStandardItemListWidget::customizedFont(const QFont &baseFont) const
 
 QPalette::ColorRole KStandardItemListWidget::normalTextColorRole() const
 {
-    return QPalette::Text;
+    if (isPressed()) {
+        return QPalette::HighlightedText;
+    } else {
+        return QPalette::Text;
+    }
 }
 
 void KStandardItemListWidget::setTextColor(const QColor &color)
@@ -748,7 +727,7 @@ QColor KStandardItemListWidget::textColor(const QWidget &widget) const
     }
 
     const QPalette::ColorGroup group = isActiveWindow() && widget.hasFocus() ? QPalette::Active : QPalette::Inactive;
-    const QPalette::ColorRole role = isSelected() ? QPalette::HighlightedText : normalTextColorRole();
+    const QPalette::ColorRole role = normalTextColorRole();
     return styleOption().palette.color(group, role);
 }
 
@@ -1136,7 +1115,6 @@ void KStandardItemListWidget::updatePixmapCache()
         }
 
         if (m_pixmap.isNull()) {
-            m_hoverPixmap = QPixmap();
             return;
         }
 
@@ -1147,17 +1125,6 @@ void KStandardItemListWidget::updatePixmapCache()
         if (m_isHidden) {
             KIconEffect::semiTransparent(m_pixmap);
         }
-
-        if (m_layout == IconsLayout && isSelected()) {
-            const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
-            QImage image = m_pixmap.toImage();
-            if (image.isNull()) {
-                m_hoverPixmap = QPixmap();
-                return;
-            }
-            KIconEffect::colorize(image, color, 0.8f);
-            m_pixmap = QPixmap::fromImage(image);
-        }
     }
 
     int scaledIconSize = 0;
@@ -1205,15 +1172,6 @@ void KStandardItemListWidget::updatePixmapCache()
         const QSizeF squareIconSize(widgetIconSize, widgetIconSize);
         m_iconRect = QRectF(squareIconPos, squareIconSize);
     }
-
-    // Prepare the pixmap that is used when the item gets hovered
-    if (isHovered()) {
-        m_hoverPixmap = m_pixmap;
-        KIconEffect::toActive(m_hoverPixmap);
-    } else if (hoverOpacity() <= 0.0) {
-        // No hover animation is ongoing. Clear m_hoverPixmap to save memory.
-        m_hoverPixmap = QPixmap();
-    }
 }
 
 void KStandardItemListWidget::updateTextsCache()
@@ -1571,7 +1529,7 @@ void KStandardItemListWidget::updateAdditionalInfoTextColor()
     } else if (isSelected() && hasFocus && (m_layout != DetailsLayout || m_highlightEntireRow)) {
         // The detail text color needs to match the main text (HighlightedText) for the same level
         // of readability. We short circuit early here to avoid interpolating with another color.
-        m_additionalInfoTextColor = styleOption().palette.color(QPalette::HighlightedText);
+        m_additionalInfoTextColor = styleOption().palette.color(normalTextColorRole());
         return;
     } else {
         c1 = styleOption().palette.text().color();
index 594d3e492806d5aa977da86dc3d3213a3b4aa21d..cabe3a8c963a0aa24c1a28803deb92610f054bf6 100644 (file)
@@ -105,10 +105,10 @@ public:
 
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
 
-    QRectF iconRect() const override;
     QRectF textRect() const override;
     QRectF textFocusRect() const override;
-    QRectF selectionRect() const override;
+    QRectF selectionRectFull() const override;
+    QRectF selectionRectCore() const override;
     QRectF expansionToggleRect() const override;
     QRectF selectionToggleRect() const override;
     QPixmap createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
@@ -280,7 +280,6 @@ private:
 
     qreal m_columnWidthSum;
     QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
-    QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
 
     QRectF m_textRect;
 
index d31dc11bae7510ef3c54b6aacef0ae834cabeb3c..8529f23a769965252bbc8a1d4c844a5a12b62f90 100644 (file)
@@ -194,8 +194,9 @@ void DolphinItemListView::updateGridSize()
 
         itemHeight = padding * 3 + iconSize + option.fontMetrics.lineSpacing();
 
-        horizontalMargin = 4;
-        verticalMargin = 8;
+        const auto margin = style()->pixelMetric(QStyle::PM_SizeGripSize);
+        horizontalMargin = margin;
+        verticalMargin = margin;
         maxTextLines = IconsModeSettings::maximumTextLines();
         break;
     }