]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Remove workaround to draw the focus indicator manually
authorPeter Penz <peter.penz19@gmail.com>
Mon, 10 Oct 2011 21:26:08 +0000 (23:26 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 10 Oct 2011 21:30:33 +0000 (23:30 +0200)
In Oxygen the focus-indicator has only been drawn for widget
instances derived from QAbstractItemView and Q3ListView, so it
was not possible in Dolphin to use the style for drawing.

This has been fixed now in Oxygen, so using the style works now.

The custom code for drawing the text background will be removed
and replaced by a style-code later.

CCMAIL: hugo@oxygen-icons.org

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

index 5aa6e1baa7762c5d26917588aa56fc57ce3c99a5..025b8e883f6fab59842384c5f1b02076edb6d800 100644 (file)
@@ -117,7 +117,12 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
     }
 
     if (isCurrent()) {
-        drawFocusIndicator(painter);
+        QStyleOptionViewItemV4 viewItemOption;
+        viewItemOption.initFrom(widget);
+        viewItemOption.rect = textBoundingRect().toRect();
+        viewItemOption.state = QStyle::State_Enabled | QStyle::State_Item;
+        viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
+        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &viewItemOption, painter, widget);
     }
 
     if (m_hoverOpacity <= 0.0) {
@@ -357,31 +362,6 @@ void KItemListWidget::clearHoverCache()
     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();
index b1df7bff4264704f9d8509c136344337f20fadc8..eae4c39dabc92de9bd565cf8e45d37c1bb531d84 100644 (file)
@@ -132,7 +132,6 @@ protected:
 private:
     void setHoverOpacity(qreal opacity);
     void clearHoverCache();
-    void drawFocusIndicator(QPainter* painter);
     void drawTextBackground(QPainter* painter);
 
 private: