From 22d394eb4cba90de1a94ae8db545a362f5d6e1d1 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 3 Jun 2010 17:50:06 +0200 Subject: Styled item view backgrounds in Gtk+ These were currently never themed but used a fake gradient to mimick ClearLooks. I had to add a workaround for the case where you were using custom QItemDelegates since this could result in styled background on tree branches but flat items. Task-number: QTBUG-11209 Reviewed-by: thorbjorn (cherry picked from commit 29e294aee281b7a4dcdd1277eef0fe1552015536) --- src/gui/styles/qgtkstyle.cpp | 56 ++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index 022cfa1..767253b 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #undef signals // Collides with GTK stymbols #include @@ -815,24 +816,49 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, option->state & State_Open ? openState : closedState , gtkTreeView->style); } break; + + case PE_PanelItemViewRow: + // This primitive is only used to draw selection behind selected expander arrows. + // We try not to decorate the tree branch background unless you inherit from StyledItemDelegate + // The reason for this is that a lot of code that relies on custom item delegates will look odd having + // a gradient on the branch but a flat shaded color on the item itself. + QCommonStyle::drawPrimitive(element, option, painter, widget); + if (!option->state & State_Selected) { + break; + } else { + if (const QAbstractItemView *view = qobject_cast(widget)) { + if (!qobject_cast(view->itemDelegate())) + break; + } + } // fall through + case PE_PanelItemViewItem: if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast(option)) { - if (vopt->state & State_Selected) { - QLinearGradient gradient; - gradient.setStart(option->rect.left(), option->rect.top()); - gradient.setFinalStop(option->rect.left(), option->rect.bottom()); - gradient.setColorAt(0, option->palette.highlight().color().lighter(105)); - gradient.setColorAt(0.5, option->palette.highlight().color().lighter(101)); - gradient.setColorAt(0.51, option->palette.highlight().color().darker(101)); - gradient.setColorAt(1, option->palette.highlight().color().darker(105)); - painter->fillRect(option->rect, gradient); - } else { - if (vopt->backgroundBrush.style() != Qt::NoBrush) { - QPointF oldBO = painter->brushOrigin(); - painter->setBrushOrigin(vopt->rect.topLeft()); - painter->fillRect(vopt->rect, vopt->backgroundBrush); - painter->setBrushOrigin(oldBO); + if (vopt->backgroundBrush.style() != Qt::NoBrush) { + QPointF oldBO = painter->brushOrigin(); + painter->setBrushOrigin(vopt->rect.topLeft()); + painter->fillRect(vopt->rect, vopt->backgroundBrush); + painter->setBrushOrigin(oldBO); + if (!(option->state & State_Selected)) + break; + } + if (GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView")) { + const char *detail = "cell_even_ruled"; + if (vopt && vopt->features & QStyleOptionViewItemV2::Alternate) + detail = "cell_odd_ruled"; + bool isActive = option->state & State_Active; + QString key; + if (isActive ) { + // Required for active/non-active window appearance + key = QLS("a"); + GTK_WIDGET_SET_FLAGS(gtkTreeView, GTK_HAS_FOCUS); } + gtkPainter.paintFlatBox(gtkTreeView, detail, option->rect, + option->state & State_Selected ? GTK_STATE_SELECTED : + option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, + GTK_SHADOW_OUT, gtkTreeView->style, key); + if (isActive ) + GTK_WIDGET_UNSET_FLAGS(gtkTreeView, GTK_HAS_FOCUS); } } break; -- cgit v0.12