From: Peter Penz Date: Mon, 10 Oct 2011 21:26:08 +0000 (+0200) Subject: Remove workaround to draw the focus indicator manually X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/d7c4fdedd0dcca4465eaf68a1904cde46c33a74c Remove workaround to draw the focus indicator manually 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 --- diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index 5aa6e1baa..025b8e883 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -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 - // 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(); diff --git a/src/kitemviews/kitemlistwidget.h b/src/kitemviews/kitemlistwidget.h index b1df7bff4..eae4c39da 100644 --- a/src/kitemviews/kitemlistwidget.h +++ b/src/kitemviews/kitemlistwidget.h @@ -132,7 +132,6 @@ protected: private: void setHoverOpacity(qreal opacity); void clearHoverCache(); - void drawFocusIndicator(QPainter* painter); void drawTextBackground(QPainter* painter); private: