diff options
Diffstat (limited to 'src/gui/styles/qs60style.cpp')
-rw-r--r-- | src/gui/styles/qs60style.cpp | 78 |
1 files changed, 49 insertions, 29 deletions
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index f02c798..9116a1e 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -491,6 +491,24 @@ QPalette* QS60StylePrivate::themePalette() return m_themePalette; } +bool QS60StylePrivate::equalToThemePalette(QColor color, QPalette::ColorRole role) +{ + if (!m_themePalette) + return false; + if (color == m_themePalette->color(role)) + return true; + return false; +} + +bool QS60StylePrivate::equalToThemePalette(qint64 cacheKey, QPalette::ColorRole role) +{ + if (!m_themePalette) + return false; + if (cacheKey == m_themePalette->brush(role).texture().cacheKey()) + return true; + return false; +} + void QS60StylePrivate::setBackgroundTexture(QApplication *app) const { Q_UNUSED(app) @@ -1430,11 +1448,25 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, const QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &voptAdj, widget); QRect textRect = subElementRect(SE_ItemViewItemText, &voptAdj, widget); const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget); + const bool singleSelection = + (itemView->selectionMode() == QAbstractItemView::SingleSelection || + itemView->selectionMode() == QAbstractItemView::NoSelection); + const bool selectItems = (itemView->selectionBehavior() == QAbstractItemView::SelectItems); - // draw themed background for table unless background brush has been defined. + // draw themed background for itemview unless background brush has been defined. if (vopt->backgroundBrush == Qt::NoBrush) { if (itemView) { + //With single item selection, use highlight focus as selection indicator. + if (singleSelection && isSelected){ + voptAdj.state = voptAdj.state | State_HasFocus; + if (!hasFocus && selectItems) { + painter->save(); + painter->setOpacity(0.5); + } + } drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget); + if (singleSelection && isSelected && !hasFocus && selectItems) + painter->restore(); } } else { QCommonStyle::drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);} @@ -1443,28 +1475,20 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, const QIcon::State state = (voptAdj.state & State_Open) ? QIcon::On : QIcon::Off; voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state); - // Draw selection check mark. Show check mark only in multi selection modes. - if (itemView) { - const bool singleSelection = - (itemView->selectionMode() == QAbstractItemView::SingleSelection || - itemView->selectionMode() == QAbstractItemView::NoSelection)|| - (itemView->selectionModel()->selectedIndexes().count() < 2 ); - - const bool selectItemsOnly = (itemView->selectionBehavior() == QAbstractItemView::SelectItems); - + // Draw selection check mark or checkbox + if (itemView && (!singleSelection || (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator))) { const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget); QStyleOptionViewItemV4 checkMarkOption(voptAdj); if (selectionRect.isValid()) checkMarkOption.rect = selectionRect; // Draw selection mark. - if (isSelected && !singleSelection && selectItemsOnly) { + if (isSelected && selectItems) { proxy()->drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget); // @todo: this should happen in the rect retrievel i.e. subElementRect() if (textRect.right() > selectionRect.left()) textRect.setRight(selectionRect.left()); - } else if (singleSelection && - voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator) { + } else if (voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator) { checkMarkOption.state = checkMarkOption.state & ~State_HasFocus; switch (vopt->checkState) { @@ -1484,7 +1508,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, // draw the text if (!voptAdj.text.isEmpty()) { - if (isSelected || hasFocus ) + if (hasFocus) painter->setPen(voptAdj.palette.highlightedText().color()); else painter->setPen(voptAdj.palette.text().color()); @@ -2044,7 +2068,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, } break; case CE_Splitter: - if (option->state & State_Sunken && option->state & State_Enabled) { + if (option->state & State_Sunken && option->state & State_Enabled && QS60StylePrivate::themePalette()) { painter->save(); painter->setOpacity(0.5); painter->setBrush(QS60StylePrivate::themePalette()->light()); @@ -2071,7 +2095,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti case PE_FrameFocusRect: { //Draw themed highlight to radiobuttons and checkboxes. //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle. - if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) { + if (QS60StylePrivate::equalToThemePalette(option->palette.highlight().color(), QPalette::Highlight)) { if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) && (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget)))) QS60StylePrivate::drawSkinElement( @@ -2103,11 +2127,8 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti QS60StyleEnums::SP_QgnIndiCheckboxOn : QS60StyleEnums::SP_QgnIndiCheckboxOff; painter->save(); - const QColor themeColor = QS60StylePrivate::themePalette()->windowText().color(); - const QColor windowTextColor = option->palette.windowText().color(); - - if (themeColor != windowTextColor) - painter->setPen(windowTextColor); + if (QS60StylePrivate::equalToThemePalette(option->palette.windowText().color(), QPalette::WindowText)) + painter->setPen(option->palette.windowText().color()); QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags | QS60StylePrivate::SF_ColorSkinned ); painter->restore(); @@ -2260,8 +2281,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti ) { //Need extra check since dialogs have their own theme background if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget) && - option->palette.window().texture().cacheKey() == - QS60StylePrivate::m_themePalette->window().texture().cacheKey()) + QS60StylePrivate::equalToThemePalette(option->palette.window().texture().cacheKey(), QPalette::Window)) //todo: for combobox listviews, the background should include area for menu scrollers, //but this produces drawing issues as we need to turn clipping off. QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_PopupBackground, painter, option->rect, flags); @@ -2308,13 +2328,13 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti const bool hasFocus = (vopt->state & State_HasFocus); const bool isPressed = QS60StylePrivate::isWidgetPressed(widget); - if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) { + if (QS60StylePrivate::equalToThemePalette(option->palette.highlight().color(), QPalette::Highlight)) { QRect highlightRect = vopt->rect.adjusted(1,1,-1,-1); const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget); QAbstractItemView::SelectionBehavior selectionBehavior = itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems; // Set the draw area for highlights (focus, select rect or pressed rect) - if (hasFocus || isSelected || isPressed) { + if (hasFocus || isPressed) { if (selectionBehavior != QAbstractItemView::SelectItems) { // set highlight rect so that it is continuous from cell to cell, yet sligthly // smaller than cell rect @@ -2344,7 +2364,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti QRect elementRect = option->rect; //draw item is drawn as pressed, if it already has focus. - if (isPressed && (hasFocus || isSelected)) { + if (isPressed && hasFocus) { themeGraphicDefined = true; element = tableView ? QS60StylePrivate::SE_TableItemPressed : QS60StylePrivate::SE_ListItemPressed; } else if (hasFocus || (isSelected && selectionBehavior != QAbstractItemView::SelectItems)) { @@ -2433,7 +2453,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti case PE_PanelItemViewRow: // ### Qt 5: remove #ifndef QT_NO_ITEMVIEWS if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) { - if (vopt->palette.base().texture().cacheKey() != QS60StylePrivate::m_themePalette->base().texture().cacheKey()) { + if (QS60StylePrivate::equalToThemePalette(vopt->palette.base().texture().cacheKey(), QPalette::Base)) { //QPalette::Base has been changed, let commonstyle draw the item commonStyleDraws = true; } else { @@ -2984,7 +3004,7 @@ QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, con case SE_ItemViewItemText: case SE_ItemViewItemDecoration: if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { - const QListWidget *listItem = qobject_cast<const QListWidget *>(widget); + const QAbstractItemView *listItem = qobject_cast<const QAbstractItemView *>(widget); const bool multiSelection = !listItem ? false : listItem->selectionMode() == QAbstractItemView::MultiSelection || listItem->selectionMode() == QAbstractItemView::ExtendedSelection || @@ -3054,7 +3074,7 @@ QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, con break; case SE_ItemViewItemCheckIndicator: if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(opt)) { - const QListWidget *listItem = qobject_cast<const QListWidget *>(widget); + const QAbstractItemView *listItem = qobject_cast<const QAbstractItemView *>(widget); const bool singleSelection = listItem && (listItem->selectionMode() == QAbstractItemView::SingleSelection || |