diff options
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 1 | ||||
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 60 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 6 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsxpstyle.cpp | 6 |
4 files changed, 38 insertions, 35 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 1f91fa4d00..7e07cc1532 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -6390,6 +6390,7 @@ CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice) CGContextRelease the context when finished using it. \warning This function is only available on Mac OS X. + \warning This function is duplicated in the Cocoa platform plugin. */ CGContextRef qt_mac_cg_context(const QPaintDevice *pdev) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 7a0cc09452..0e928b13c2 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2498,38 +2498,48 @@ void QStyleSheetStyle::setGeometry(QWidget *w) void QStyleSheetStyle::setProperties(QWidget *w) { - // we have two data structures here: a hash of property -> value for lookup, - // and a vector giving properties in the order they are specified. - // - // this means we only set a property once (thanks to the hash) but we set - // properties in the order they are specified. - QHash<QString, QVariant> propertyHash; - QVector<QString> properties; - QVector<Declaration> decls = declarations(styleRules(w), QString()); - - // run through the declarations in order - for (int i = 0; i < decls.count(); i++) { - const Declaration &decl = decls.at(i); + // The final occurrence of each property is authoritative. + // Set value for each property in the order of property final occurrence + // since properties interact. + + const QVector<Declaration> decls = declarations(styleRules(w), QString()); + QVector<int> finals; // indices in reverse order of each property's final occurrence + + { + // scan decls for final occurence of each "qproperty" + QSet<const QString> propertySet; + for (int i = decls.count() - 1; i >= 0; --i) { + const QString property = decls.at(i).d->property; + if (!property.startsWith(QStringLiteral("qproperty-"), Qt::CaseInsensitive)) + continue; + if (!propertySet.contains(property)) { + propertySet.insert(property); + finals.append(i); + } + } + } + + for (int i = finals.count() - 1; i >= 0; --i) { + const Declaration &decl = decls.at(finals[i]); QString property = decl.d->property; - if (!property.startsWith(QLatin1String("qproperty-"), Qt::CaseInsensitive)) - continue; property.remove(0, 10); // strip "qproperty-" - const QVariant value = w->property(property.toLatin1()); + const QMetaObject *metaObject = w->metaObject(); int index = metaObject->indexOfProperty(property.toLatin1()); if (index == -1) { qWarning() << w << " does not have a property named " << property; continue; } - QMetaProperty metaProperty = metaObject->property(index); + const QMetaProperty metaProperty = metaObject->property(index); if (!metaProperty.isWritable() || !metaProperty.isDesignable()) { qWarning() << w << " cannot design property named " << property; continue; } + QVariant v; + const QVariant value = w->property(property.toLatin1()); switch (value.type()) { - // ### Qt 5 -// case QVariant::Icon: v = decl.iconValue(); break; + case QVariant::Icon: v = cssIconValueToIcon(decl.iconValue()); break; case QVariant::Image: v = QImage(decl.uriValue()); break; case QVariant::Pixmap: v = QPixmap(decl.uriValue()); break; case QVariant::Rect: v = decl.rectValue(); break; @@ -2542,19 +2552,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) default: v = decl.d->values.at(0).variant; break; } - if (propertyHash.contains(property)) { - // we're ignoring the original appearance of this property - properties.remove(properties.indexOf(property)); - } - - propertyHash[property] = v; - properties.append(property); - } - - // apply the values from left to right order - for (int i = 0; i < properties.count(); i++) { - const QString &property = properties.at(i); - w->setProperty(property.toLatin1(), propertyHash[property]); + w->setProperty(property.toLatin1(), v); } } diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 1aecb64acf..c18b2266b8 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -586,10 +586,12 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt bool isEnabled = option->state & State_Enabled; uint resolve_mask = panel->palette.resolve(); if (widget) { - //Since spin box and combo box includes a line edit we need to resolve the palette on the parent instead + // Since spin box includes a line edit we need to resolve the palette mask also from + // the parent, as while the color is always correct on the palette supplied by panel, + // the mask can still be empty. If either mask specifies custom base color, use that. #ifndef QT_NO_SPINBOX if (QAbstractSpinBox *spinbox = qobject_cast<QAbstractSpinBox*>(widget->parentWidget())) - resolve_mask = spinbox->palette().resolve(); + resolve_mask |= spinbox->palette().resolve(); #endif // QT_NO_SPINBOX } if (resolve_mask & (1 << QPalette::Base)) { diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 5aab69983c..8b745ba114 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -1583,10 +1583,12 @@ case PE_Frame: uint resolve_mask = panel->palette.resolve(); #ifndef QT_NO_SPINBOX - //Since spin box includes a line edit we need to resolve the palette on the spin box instead + // Since spin box includes a line edit we need to resolve the palette mask also from + // the parent, as while the color is always correct on the palette supplied by panel, + // the mask can still be empty. If either mask specifies custom base color, use that. if (widget) { if (QAbstractSpinBox *spinbox = qobject_cast<QAbstractSpinBox*>(widget->parentWidget())) - resolve_mask = spinbox->palette().resolve(); + resolve_mask |= spinbox->palette().resolve(); } #endif // QT_NO_SPINBOX if (resolve_mask & (1 << QPalette::Base)) { |