]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemlistwidget.cpp
Fix wrong position of selection-toggle
[dolphin.git] / src / kitemviews / kfileitemlistwidget.cpp
index 710253ae8d636529d95701f95bb12b5114f32406..5a522f410a636a26e3c2655544535a0a79a13916 100644 (file)
@@ -58,8 +58,7 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
     m_expansionArea(),
     m_customTextColor(),
     m_additionalInfoTextColor(),
-    m_overlay(),
-    m_selectionTogglePos()
+    m_overlay()
 {
     for (int i = 0; i < TextIdCount; ++i) {
         m_text[i].setTextFormat(Qt::PlainText);
@@ -186,7 +185,7 @@ QRectF KFileItemListWidget::selectionToggleRect() const
         toggleSize = KIconLoader::SizeSmallMedium;
     }
 
-    QPointF pos = m_selectionTogglePos;
+    QPointF pos = iconRect().topLeft();
 
     // If the selection toggle has a very small distance to the
     // widget borders, the size of the selection toggle will get
@@ -279,7 +278,13 @@ void KFileItemListWidget::setTextColor(const QColor& color)
 
 QColor KFileItemListWidget::textColor() const
 {
-    return m_customTextColor.isValid() ? m_customTextColor : styleOption().palette.text().color();
+    if (m_customTextColor.isValid()) {
+        return m_customTextColor;
+    } else if (isSelected()) {
+        return styleOption().palette.highlightedText().color();
+    } else {
+        return styleOption().palette.text().color();
+    }
 }
 
 void KFileItemListWidget::setOverlay(const QPixmap& overlay)
@@ -345,6 +350,12 @@ void KFileItemListWidget::hoveredChanged(bool hovered)
     m_dirtyLayout = true;
 }
 
+void KFileItemListWidget::selectedChanged(bool selected)
+{
+    Q_UNUSED(selected);
+    updateAdditionalInfoTextColor();
+}
+
 void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
 {
     KItemListWidget::resizeEvent(event);
@@ -417,10 +428,6 @@ void KFileItemListWidget::updatePixmapCache()
     }
 
     if (updatePixmap) {
-        // The selection toggle should always be applied to the top/left
-        // of the pixmap
-        m_selectionTogglePos = QPointF(-option.margin, -option.margin);
-
         m_pixmap = values["iconPixmap"].value<QPixmap>();
         if (m_pixmap.isNull()) {
             // Use the icon that fits to the MIME-type
@@ -458,7 +465,6 @@ void KFileItemListWidget::updatePixmapCache()
                 y = (iconHeight - m_pixmap.height()) / 2; // Center vertically
                 painter.drawPixmap(x, y, m_pixmap);
             }
-            m_selectionTogglePos += QPointF(x, y);
 
             m_pixmap = squarePixmap;
         } else {
@@ -481,10 +487,6 @@ void KFileItemListWidget::updatePixmapCache()
     }
     m_pixmapPos.setY(option.margin);
 
-    if (updatePixmap) {
-      m_selectionTogglePos += m_pixmapPos;
-    }
-
     // Center the hover rectangle horizontally and align it on bottom
     const qreal x = m_pixmapPos.x() + (m_scaledPixmapSize.width() - m_hoverPixmapRect.width()) / 2.0;
     const qreal y = m_pixmapPos.y() + m_scaledPixmapSize.height() - m_hoverPixmapRect.height();
@@ -741,10 +743,18 @@ void KFileItemListWidget::updateDetailsLayoutTextCache()
 
 void KFileItemListWidget::updateAdditionalInfoTextColor()
 {
+    QColor c1;
+    if (m_customTextColor.isValid()) {
+        c1 = m_customTextColor;
+    } else if (isSelected() && m_layout != DetailsLayout) {
+        c1 = styleOption().palette.highlightedText().color();
+    } else {
+        c1 = styleOption().palette.text().color();
+    }
+
     // For the color of the additional info the inactive text color
     // is not used as this might lead to unreadable text for some color schemes. Instead
-    // the text color is slightly mixed with the background color.
-    const QColor c1 = textColor();
+    // the text color c1 is slightly mixed with the background color.
     const QColor c2 = styleOption().palette.base().color();
     const int p1 = 70;
     const int p2 = 100 - p1;