From 1de1a50603a50fde4b9ac0400a66f54ff4a0cbb1 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Mon, 12 Mar 2012 21:14:37 +0100 Subject: take opportunity to use const Change-Id: Ief12d4b55e1705c758dae8078cf52948fcd9565b Reviewed-by: Richard J. Moore --- src/widgets/styles/qstylesheetstyle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 7a0cc09452..c909def969 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2505,7 +2505,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) // properties in the order they are specified. QHash propertyHash; QVector properties; - QVector decls = declarations(styleRules(w), QString()); + const QVector decls = declarations(styleRules(w), QString()); // run through the declarations in order for (int i = 0; i < decls.count(); i++) { @@ -2521,7 +2521,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) 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; -- cgit v1.2.3 From 6c2c6a48e730888760d2328f18f2be81d6dee6d3 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 13 Mar 2012 10:32:58 +0100 Subject: use QStringLiteral Change-Id: I0f2b6ff758524e872d38dcbdc9335264431e3dc6 Reviewed-by: Robin Burchell --- src/widgets/styles/qstylesheetstyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index c909def969..15e03af69b 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2511,7 +2511,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) for (int i = 0; i < decls.count(); i++) { const Declaration &decl = decls.at(i); QString property = decl.d->property; - if (!property.startsWith(QLatin1String("qproperty-"), Qt::CaseInsensitive)) + if (!property.startsWith(QStringLiteral("qproperty-"), Qt::CaseInsensitive)) continue; property.remove(0, 10); // strip "qproperty-" const QVariant value = w->property(property.toLatin1()); -- cgit v1.2.3 From e9fdfd746bc374b7b2cbccb875d36727b3946990 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Mon, 12 Mar 2012 21:16:40 +0100 Subject: improve declaration scope Change-Id: Id8d8f4e59793ba5fc2d3afa31674009af73a59c9 Reviewed-by: Robin Burchell --- src/widgets/styles/qstylesheetstyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 15e03af69b..0f53809215 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2514,7 +2514,6 @@ void QStyleSheetStyle::setProperties(QWidget *w) if (!property.startsWith(QStringLiteral("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) { @@ -2527,6 +2526,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) continue; } QVariant v; + const QVariant value = w->property(property.toLatin1()); switch (value.type()) { // ### Qt 5 // case QVariant::Icon: v = decl.iconValue(); break; -- cgit v1.2.3 From 2d68c8ee8d28556eb40eb576d30b64fdac9b388d Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 12 Mar 2012 13:36:25 +0200 Subject: Windows: Fix QSpinBox background setting via stylesheet When using stylesheets, palette mask for drawing the background of line edit child of spinbox is already correctly resolved to style options in QStyleSheetStyle::drawPrimitive(), so we cannot simply ignore that mask and check the palette mask of the parent spinbox. Fixed by using a union mask of the parent spinbox palette and the palette supplied by style option instead of simply using the mask from parent spinbox. If either specifies custom base color, use that to paint the background of the spinbox's line edit. Task-number: QTBUG-24323 Change-Id: I1e738192db83b16d9bd48da54d29779e18788ef7 Reviewed-by: Friedemann Kleint --- src/widgets/styles/qwindowsvistastyle.cpp | 6 ++++-- src/widgets/styles/qwindowsxpstyle.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/widgets/styles') 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(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(widget->parentWidget())) - resolve_mask = spinbox->palette().resolve(); + resolve_mask |= spinbox->palette().resolve(); } #endif // QT_NO_SPINBOX if (resolve_mask & (1 << QPalette::Base)) { -- cgit v1.2.3 From c8ba6a49da174982c881fef1b54b54bbe03405b7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 14 Mar 2012 10:53:00 +0100 Subject: QStyleSheetStyle: Fix icon properties. Convert icon structure returned by the CSS parser. Change-Id: I19b846c6cb0ec19045b6d07b3caa5ecfac75ca86 Reviewed-by: Mark Brand Reviewed-by: Friedemann Kleint --- src/widgets/styles/qstylesheetstyle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 0f53809215..a10a531b7d 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2528,8 +2528,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) 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; -- cgit v1.2.3 From 6d67ff4061c7648708cdc2e462f248a4a8f486db Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Mon, 12 Mar 2012 21:05:31 +0100 Subject: improve processing stylesheet properties By scanning the properties in reverse order we don't have to save properties in the list only to remove them later when the occur again. It's also unnecessary to cache the values since they can be easily plucked out of decls. Various other tests can be done once per property instead of once per property occurence in decls. Change-Id: I81cf60c59efaeed57fc9c12df98279d6cae116cd Reviewed-by: Robin Burchell Reviewed-by: Rick Stockton Reviewed-by: Girish Ramakrishnan Reviewed-by: John Brooks --- src/widgets/styles/qstylesheetstyle.cpp | 49 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index a10a531b7d..0e928b13c2 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2498,22 +2498,32 @@ 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 propertyHash; - QVector properties; + // 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 decls = declarations(styleRules(w), QString()); + QVector finals; // indices in reverse order of each property's final occurrence + + { + // scan decls for final occurence of each "qproperty" + QSet 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); + } + } + } - // run through the declarations in order - for (int i = 0; i < decls.count(); i++) { - const Declaration &decl = decls.at(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(QStringLiteral("qproperty-"), Qt::CaseInsensitive)) - continue; property.remove(0, 10); // strip "qproperty-" + const QMetaObject *metaObject = w->metaObject(); int index = metaObject->indexOfProperty(property.toLatin1()); if (index == -1) { @@ -2525,6 +2535,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) qWarning() << w << " cannot design property named " << property; continue; } + QVariant v; const QVariant value = w->property(property.toLatin1()); switch (value.type()) { @@ -2541,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); } } -- cgit v1.2.3 From 7e3c632e96dbbd6f577c2ba98464a54176c5b7b0 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Fri, 2 Mar 2012 12:17:24 +0100 Subject: Port QMacPrintEngine and QCoreGraphicsPaintEngine from Qt 4 to Qt 5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copy qprintengine_mac_p.h, qprintengine_mac.mm, qpaintengine_mac_p.h, and qpaintengine_mac.cpp (as qpaintengine_mac.mm) from src/gui/painting/ in the 4.8 branch of http://git.gitorious.org/qt/qt.git at commit e6bd33d4aef0e4538d7918e7ab130624c911b553. The following changes are necessary to port these files to the Qt 5 API: - The copyright notice on these files has been updated to match the header.LGPL template. - Fix #includes for qprintengine_mac* and qpaintengine_mac*, as some headers have moved in Qt 5. - Remove extern forward declarations for functions that no longer exist. - Remove friend declarations for classes/functions that are not part of the Cocoa platform plugin. - Remove QT_MAC_USE_COCOA blocks. Qt is always using Cocoa now, there is no need to keep the non-Cocoa code paths anymore. The QMacPrintEngine::shouldSuppressStatus() method was also removed, since it is no longer used. - Do not use Qt::UniteClip, it was removed in commit 01b72952c38b9193138eabdab6bdab632cd75ebd - Use QCocoaAutoReleasePool in qprintengine_mac.mm - Use QPlatformPrintSupport::convert*() functions in QMacPrintEngine, since we cannot use non-exported functions from QtPrintSupport in the Cocoa plugin. - Use qt_mac_image_to_cg_image() to convert QPixmap to CGImageRef. First convert QPixmap to QImage (cheap, since the Cocoa platform plugin uses QRasterPlatformPixmap), and then convert the QImage to CFImageRef using the existing helper function. - Copy qt_mac_cg_context() to the Cocoa platform plugin from qmacstyle_mac.mm, adding a note at each location about the duplication. - Add qt_mac_QRegionToHIMutableShape() helper. Adapt the Qt 4.x code for QRegion::toHIMutableShape(), and use this in QCoreGraphicsPaintEngine. - Add qt_mac_drawCGImage() and qt_mac_get_scalefactor() helper. These functions are copied directly from the 4.8 branch of http://git.gitorious.org/qt/qt.git at the same revision shown above. - Add qt_mac_create_imagemask() helper in qpaintengine_mac.cpp. This helper is based on the function with the same name from the 4.8 branch of http://git.gitorious.org/qt/qt.git at the same revision shown above. The correctness of the implementation has not yet been verified. Since these files use the QPrinter API from QtPrintSupport, the Cocoa plugin now needs to link to that library as well. Change-Id: I90b9bbe201327489ef9e1b3294e68e91ddda27bd Reviewed-by: Morten Johan Sørvig --- src/widgets/styles/qmacstyle_mac.mm | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets/styles') 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) -- cgit v1.2.3