]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistwidget.cpp
Revert the 2.0 decision to always use KB for file-sizes
[dolphin.git] / src / kitemviews / kitemlistwidget.cpp
index 24a3f079a9005cd6dd790330cf7e3f92960ea1ef..b703fbfe233f5ad184df35ddb7d520f20c130ac9 100644 (file)
@@ -40,11 +40,11 @@ KItemListWidget::KItemListWidget(QGraphicsItem* parent) :
     m_selected(false),
     m_current(false),
     m_hovered(false),
-    m_alternatingBackgroundColors(false),
+    m_alternateBackground(false),
     m_enabledSelectionToggle(false),
     m_data(),
     m_visibleRoles(),
-    m_visibleRolesSizes(),
+    m_columnWidths(),
     m_styleOption(),
     m_siblingsInfo(),
     m_hoverOpacity(0),
@@ -105,9 +105,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
 {
     Q_UNUSED(option);
 
-    painter->setRenderHint(QPainter::Antialiasing);
-
-    if (m_alternatingBackgroundColors && (m_index & 0x1)) {
+    if (m_alternateBackground) {
         const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase);
         const QRectF backgroundRect(0, 0, size().width(), size().height());
         painter->fillRect(backgroundRect, backgroundColor);
@@ -124,17 +122,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
     if (isCurrent()) {
         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.rect = textFocusRect().toRect();
         focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
         if (m_selected) {
             focusRectOption.state |= QStyle::State_Selected;
@@ -179,18 +167,20 @@ QList<QByteArray> KItemListWidget::visibleRoles() const
     return m_visibleRoles;
 }
 
-void KItemListWidget::setVisibleRolesSizes(const QHash<QByteArray, QSizeF> rolesSizes)
-{
-    const QHash<QByteArray, QSizeF> previousRolesSizes = m_visibleRolesSizes;
-    m_visibleRolesSizes = rolesSizes;
 
-    visibleRolesSizesChanged(rolesSizes, previousRolesSizes);
-    update();
+void KItemListWidget::setColumnWidth(const QByteArray& role, qreal width)
+{
+    if (m_columnWidths.value(role) != width) {
+        const qreal previousWidth = width;
+        m_columnWidths.insert(role, width);
+        columnWidthChanged(role, width, previousWidth);
+        update();
+    }
 }
 
-QHash<QByteArray, QSizeF> KItemListWidget::visibleRolesSizes() const
+qreal KItemListWidget::columnWidth(const QByteArray& role) const
 {
-    return m_visibleRolesSizes;
+    return m_columnWidths.value(role);
 }
 
 void KItemListWidget::setStyleOption(const KItemListStyleOption& option)
@@ -249,7 +239,7 @@ void KItemListWidget::setHovered(bool hovered)
 
     if (!m_hoverAnimation) {
         m_hoverAnimation = new QPropertyAnimation(this, "hoverOpacity", this);
-        const int duration = (KGlobalSettings::graphicEffectsLevel() == KGlobalSettings::NoEffects) ? 1 : 200;       
+        const int duration = (KGlobalSettings::graphicEffectsLevel() == KGlobalSettings::NoEffects) ? 1 : 200;
         m_hoverAnimation->setDuration(duration);
         connect(m_hoverAnimation, SIGNAL(finished()), this, SLOT(slotHoverAnimationFinished()));
     }
@@ -278,18 +268,18 @@ bool KItemListWidget::isHovered() const
     return m_hovered;
 }
 
-void KItemListWidget::setAlternatingBackgroundColors(bool enable)
+void KItemListWidget::setAlternateBackground(bool enable)
 {
-    if (m_alternatingBackgroundColors != enable) {
-        m_alternatingBackgroundColors = enable;
-        alternatingBackgroundColorsChanged(enable);
+    if (m_alternateBackground != enable) {
+        m_alternateBackground = enable;
+        alternateBackgroundChanged(enable);
         update();
     }
 }
 
-bool KItemListWidget::alternatingBackgroundColors() const
+bool KItemListWidget::alternateBackground() const
 {
-    return m_alternatingBackgroundColors;
+    return m_alternateBackground;
 }
 
 void KItemListWidget::setEnabledSelectionToggle(bool enable)
@@ -330,6 +320,11 @@ bool KItemListWidget::contains(const QPointF& point) const
            selectionToggleRect().contains(point);
 }
 
+QRectF KItemListWidget::textFocusRect() const
+{
+    return textRect();
+}
+
 QRectF KItemListWidget::selectionToggleRect() const
 {
     return QRectF();
@@ -354,9 +349,11 @@ void KItemListWidget::visibleRolesChanged(const QList<QByteArray>& current,
     Q_UNUSED(previous);
 }
 
-void KItemListWidget::visibleRolesSizesChanged(const QHash<QByteArray, QSizeF>& current,
-                                               const QHash<QByteArray, QSizeF>& previous)
+void KItemListWidget::columnWidthChanged(const QByteArray& role,
+                                         qreal current,
+                                         qreal previous)
 {
+    Q_UNUSED(role);
     Q_UNUSED(current);
     Q_UNUSED(previous);
 }
@@ -383,7 +380,7 @@ void KItemListWidget::hoveredChanged(bool hovered)
     Q_UNUSED(hovered);
 }
 
-void KItemListWidget::alternatingBackgroundColorsChanged(bool enabled)
+void KItemListWidget::alternateBackgroundChanged(bool enabled)
 {
     Q_UNUSED(enabled);
 }
@@ -451,14 +448,12 @@ void KItemListWidget::clearHoverCache()
 
 void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState)
 {
-    const QRect textBounds = textRect().toRect();
-
     QStyleOptionViewItemV4 viewItemOption;
     viewItemOption.initFrom(widget);
     viewItemOption.state = styleState;
     viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
     viewItemOption.showDecorationSelected = true;
-    viewItemOption.rect = textBounds.adjusted(1, 0, -1, 0);
+    viewItemOption.rect = textRect().toRect();
     widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
 }