]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistwidget.cpp
Fix current-item indicator in combination with the cleanlooks style
[dolphin.git] / src / kitemviews / kitemlistwidget.cpp
index 1934222593a3418f7b8c64fedea98cedefa5c6f2..cd2bf4d40ce6851414aad5a9c34c77e2badf3a9b 100644 (file)
@@ -119,12 +119,25 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
     }
 
     if (isCurrent()) {
-        QStyleOptionViewItemV4 viewItemOption;
-        viewItemOption.initFrom(widget);
-        viewItemOption.rect = textRect().toRect();
-        viewItemOption.state = QStyle::State_Enabled | QStyle::State_Item;
-        viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
-        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &viewItemOption, painter, widget);
+        QStyleOptionFocusRect focusRectOption;
+        focusRectOption.initFrom(widget);
+
+        const QRect iconBounds = iconRect().toRect();
+        const QRect textBounds = textRect().toRect();
+        if (iconBounds.bottom() > textBounds.top()) {
+            focusRectOption.rect = textBounds;
+        } else {
+            // See KItemListWidget::drawItemStyleOption(): The selection rectangle
+            // gets decreased.
+            focusRectOption.rect = textBounds.adjusted(1, 1, -1, -1);
+        }
+
+        focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
+        if (m_selected) {
+            focusRectOption.state |= QStyle::State_Selected;
+        }
+
+        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusRectOption, painter, widget);
     }
 
     if (m_hoverOpacity > 0.0) {
@@ -424,18 +437,16 @@ void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QS
     viewItemOption.initFrom(widget);
     viewItemOption.state = styleState;
     viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
+    viewItemOption.showDecorationSelected = true;
 
-    const bool drawMerged = (iconBounds.top()    == textBounds.top() &&
-                             iconBounds.bottom() == textBounds.bottom());
-
-    if (drawMerged) {
+    if (iconBounds.bottom() > textBounds.top()) {
         viewItemOption.rect = iconBounds | textBounds;
         widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
     } else {
         viewItemOption.rect = iconBounds;
         widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
 
-        viewItemOption.rect = textBounds.adjusted(2, 2, -2, -2);
+        viewItemOption.rect = textBounds.adjusted(1, 1, -1, -1);
         widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
     }
 }