diff options
author | Sami Merila <sami.merila@nokia.com> | 2010-09-17 09:42:05 (GMT) |
---|---|---|
committer | Sami Merila <sami.merila@nokia.com> | 2010-09-17 09:42:05 (GMT) |
commit | 616d84ddb2a07191d2754b0f3e7296cae472b738 (patch) | |
tree | 3dad43b50186c4103321862bbea0e38348f3ebb0 /src | |
parent | e969212de0b2ac816a46db8897d54e9ed78d57b8 (diff) | |
download | Qt-616d84ddb2a07191d2754b0f3e7296cae472b738.zip Qt-616d84ddb2a07191d2754b0f3e7296cae472b738.tar.gz Qt-616d84ddb2a07191d2754b0f3e7296cae472b738.tar.bz2 |
Panic in qs60style.cpp while drawing a QTreeView
QS60Style crashes when running a test application that modifies
active style AND application's palette. After switching to
other style, setting palette to application default, re-enabling the
style's palette and activating QS60Style, causes a crash. This is
due to that internal theme palette is tried to access, before it is
constructed.
Fixed by making sure that when theme palette is accessed, it is
not NULL.
Task-number: QTBUG-13553
Reviewed-by: Miikka Heikkinen
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/styles/qs60style.cpp | 36 | ||||
-rw-r--r-- | src/gui/styles/qs60style_p.h | 2 |
2 files changed, 27 insertions, 11 deletions
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 971e1e3..d529dd5 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) @@ -2050,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()); @@ -2077,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( @@ -2109,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(); @@ -2266,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); @@ -2314,7 +2328,7 @@ 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 = @@ -2439,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 { diff --git a/src/gui/styles/qs60style_p.h b/src/gui/styles/qs60style_p.h index 51ced96..b3f4160 100644 --- a/src/gui/styles/qs60style_p.h +++ b/src/gui/styles/qs60style_p.h @@ -598,6 +598,8 @@ private: void setThemePaletteHash(QPalette *palette) const; static void storeThemePalette(QPalette *palette); static void deleteThemePalette(); + static bool equalToThemePalette(QColor color, QPalette::ColorRole role); + static bool equalToThemePalette(qint64 cacheKey, QPalette::ColorRole role); static QSize partSize(QS60StyleEnums::SkinParts part, SkinElementFlags flags = KDefaultSkinElementFlags); |