]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Move drawing of textbackground to KItemListWidget
authorPeter Penz <peter.penz19@gmail.com>
Sun, 14 Aug 2011 14:10:11 +0000 (16:10 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 14 Aug 2011 14:11:57 +0000 (16:11 +0200)
As the textbounding-rectangle is now a property of KItemListWidget
also the default visual appearance is moved now from
KFileItemListWidget to KItemListWidget.

src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kfileitemlistwidget.h
src/kitemviews/kitemlistwidget.cpp
src/kitemviews/kitemlistwidget.h

index 36a7d65da67c448c54014fa30c190470679ce135..a8fe36c08c18acd9a6e6444c6617b18cf05f18e1 100644 (file)
@@ -86,8 +86,6 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
 {
     KItemListWidget::paint(painter, option, widget);
 
-    painter->setRenderHint(QPainter::Antialiasing);
-
     if (m_dirtyContent || m_dirtyLayout) {
         const_cast<KFileItemListWidget*>(this)->updateCache();
     }
@@ -112,25 +110,11 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
         const qreal opacity = painter->opacity();
         painter->setOpacity(hoverOpacity() * opacity);
         drawPixmap(painter, m_hoverPixmap);
-
-        // Draw the hover background for the text
-        QRectF textsBoundingRect = m_textBoundingRect;
-        const qreal marginDiff = itemListStyleOption.margin / 2;
-        textsBoundingRect.adjust(marginDiff, marginDiff, -marginDiff, -marginDiff);
-        painter->setOpacity(hoverOpacity() * opacity * 0.1);
-        painter->setPen(Qt::NoPen);
-        painter->setBrush(itemListStyleOption.palette.text());
-        painter->drawRoundedRect(textsBoundingRect, 4, 4);
-
         painter->setOpacity(opacity);
     } else {
         drawPixmap(painter, m_pixmap);
     }
 
-    if (isCurrent()) {
-        drawFocusIndicator(painter);
-    }
-
     painter->setFont(itemListStyleOption.font);
     painter->setPen(itemListStyleOption.palette.text().color());
     painter->drawStaticText(m_textPos[Name], m_text[Name]);
@@ -687,31 +671,6 @@ void KFileItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
     }
 }
 
-void KFileItemListWidget::drawFocusIndicator(QPainter* painter)
-{
-    // Ideally style()->drawPrimitive(QStyle::PE_FrameFocusRect...)
-    // should be used, but Oxygen only draws indicators within classes
-    // derived from QAbstractItemView or Q3ListView. As a workaround
-    // the indicator is drawn manually. Code copied from oxygenstyle.cpp
-    // Copyright ( C ) 2009-2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
-    // TODO: Clarify with Oxygen maintainers how to proceed with this.
-
-    const KItemListStyleOption& option = styleOption();
-    const QPalette palette = option.palette;
-    const QRect rect = m_textBoundingRect.toRect().adjusted(0, 0, 0, -1);
-
-    QLinearGradient gradient(rect.bottomLeft(), rect.bottomRight());
-    gradient.setColorAt(0.0, Qt::transparent);
-    gradient.setColorAt(1.0, Qt::transparent);
-    gradient.setColorAt(0.2, palette.color(QPalette::Text));
-    gradient.setColorAt(0.8, palette.color(QPalette::Text));
-
-    painter->setRenderHint(QPainter::Antialiasing, false);
-    painter->setPen(QPen(gradient, 1));
-    painter->drawLine(rect.bottomLeft(), rect.bottomRight());
-    painter->setRenderHint(QPainter::Antialiasing, true);
-}
-
 QPixmap KFileItemListWidget::pixmapForIcon(const QString& name, int size)
 {
     const KIcon icon(name);
index e48d31aa90e665a2c4f845dd5ee123ff864d2313..03ab17b54ac8287b4d4ec2436e04d200c91b7413 100644 (file)
@@ -86,7 +86,6 @@ private:
     QString roleText(TextId textId, const QVariant& roleValue) const;
 
     void drawPixmap(QPainter* painter, const QPixmap& pixmap);
-    void drawFocusIndicator(QPainter* painter);
 
     static QPixmap pixmapForIcon(const QString& name, int size);
     static TextId roleTextId(const QByteArray& role);
index c9c62ad4aed1faf21e91df4eb5a43de1fec4afdb..86febed97c71b1666a8be53c234a20f7b1dc0c27 100644 (file)
@@ -95,6 +95,8 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
 {
     Q_UNUSED(option);
 
+    painter->setRenderHint(QPainter::Antialiasing);
+
     const QRect iconBounds = iconBoundingRect().toRect();
     if (m_selected) {
         QStyleOptionViewItemV4 viewItemOption;
@@ -103,6 +105,12 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
         viewItemOption.state = QStyle::State_Enabled | QStyle::State_Selected | QStyle::State_Item;
         viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
         widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
+
+        drawTextBackground(painter);
+    }
+
+    if (isCurrent()) {
+        drawFocusIndicator(painter);
     }
 
     if (m_hoverOpacity <= 0.0) {
@@ -110,6 +118,8 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
     }
 
     if (!m_hoverCache) {
+        // Initialize the m_hoverCache pixmap to improve the drawing performance
+        // when fading the hover background
         m_hoverCache = new QPixmap(iconBounds.size());
         m_hoverCache->fill(Qt::transparent);
 
@@ -127,6 +137,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
     const qreal opacity = painter->opacity();
     painter->setOpacity(m_hoverOpacity * opacity);
     painter->drawPixmap(iconBounds.topLeft(), *m_hoverCache);
+    drawTextBackground(painter);
     painter->setOpacity(opacity);
 }
 
@@ -320,4 +331,44 @@ void KItemListWidget::clearCache()
     m_hoverCache = 0;
 }
 
+void KItemListWidget::drawFocusIndicator(QPainter* painter)
+{
+    // Ideally style()->drawPrimitive(QStyle::PE_FrameFocusRect...)
+    // should be used, but Oxygen only draws indicators within classes
+    // derived from QAbstractItemView or Q3ListView. As a workaround
+    // the indicator is drawn manually. Code copied from oxygenstyle.cpp
+    // Copyright ( C ) 2009-2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
+    // TODO: Clarify with Oxygen maintainers how to proceed with this.
+
+    const KItemListStyleOption& option = styleOption();
+    const QPalette palette = option.palette;
+    const QRect rect = textBoundingRect().toRect().adjusted(0, 0, 0, -1);
+
+    QLinearGradient gradient(rect.bottomLeft(), rect.bottomRight());
+    gradient.setColorAt(0.0, Qt::transparent);
+    gradient.setColorAt(1.0, Qt::transparent);
+    gradient.setColorAt(0.2, palette.color(QPalette::Text));
+    gradient.setColorAt(0.8, palette.color(QPalette::Text));
+
+    painter->setRenderHint(QPainter::Antialiasing, false);
+    painter->setPen(QPen(gradient, 1));
+    painter->drawLine(rect.bottomLeft(), rect.bottomRight());
+    painter->setRenderHint(QPainter::Antialiasing, true);
+}
+
+void KItemListWidget::drawTextBackground(QPainter* painter)
+{
+    const qreal opacity = painter->opacity();
+
+    QRectF textBounds = textBoundingRect();
+    const qreal marginDiff = m_styleOption.margin / 2;
+    textBounds.adjust(marginDiff, marginDiff, -marginDiff, -marginDiff);
+    painter->setOpacity(opacity * 0.1);
+    painter->setPen(Qt::NoPen);
+    painter->setBrush(m_styleOption.palette.text());
+    painter->drawRoundedRect(textBounds, 4, 4);
+
+    painter->setOpacity(opacity);
+}
+
 #include "kitemlistwidget.moc"
index 6b766d1da2928dcf955e34c1e7e7801ef86d0b10..e3f3cb5788fa186d55c3c0edf8991a3b8a2e2397 100644 (file)
@@ -132,6 +132,8 @@ protected:
 private:
     void setHoverOpacity(qreal opacity);
     void clearCache();
+    void drawFocusIndicator(QPainter* painter);
+    void drawTextBackground(QPainter* painter);
 
 private:
     Q_PROPERTY(qreal hoverOpacity READ hoverOpacity WRITE setHoverOpacity)