From da3e89e8d98a4d3322eae94aafd38ddb444f144e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Tue, 20 Oct 2009 13:31:33 +0300 Subject: QT-693 QS60Style does not regard selection beahviors with itemviews QS60Style disregards all selection behaviors for itemviews. This leads to error when showing a highlighted selection rect; rect is only shown for cell having focus. Fixed by setting the highlight to all 'selected' cells. Task-number: QT-693 Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 4fa1d03..6d95336 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -1313,7 +1313,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, painter->save(); painter->setClipRect(voptAdj.rect); - const bool isSelected = (voptAdj.state & QStyle::State_HasFocus); + const bool isSelected = (vopt->state & QStyle::State_Selected); bool isVisible = false; int scrollBarWidth = 0; @@ -1358,7 +1358,27 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, // draw the focus rect if (isSelected) { - const QRect highlightRect = option->rect.adjusted(1,1,-1,-1); + QRect highlightRect = option->rect.adjusted(1,1,-1,-1); + const QAbstractItemView *view = qobject_cast(widget); + if (view && view->selectionBehavior() != QAbstractItemView::SelectItems) { + // set highlight rect so that it is continuous from cell to cell, yet sligthly + // smaller than cell rect + int xBeginning = 0, yBeginning = 0, xEnd = 0, yEnd = 0; + if (view->selectionBehavior() == QAbstractItemView::SelectRows) { + yBeginning = 1; yEnd = -1; + if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning) + xBeginning = 1; + else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End) + xEnd = -1; + } else if (view->selectionBehavior() == QAbstractItemView::SelectColumns) { + xBeginning = 1; xEnd = -1; + if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning) + yBeginning = 1; + else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End) + yEnd = -1; + } + highlightRect = option->rect.adjusted(xBeginning, yBeginning, xEnd, xBeginning); + } QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, highlightRect, flags); } -- cgit v0.12