summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qcssparser.cpp32
-rw-r--r--src/gui/text/qcssparser_p.h2
2 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index ce7c7610c1..793ef5774b 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -123,6 +123,7 @@ static const QCssKnownValue properties[NumProperties - 1] = {
{ "font-variant", FontVariant },
{ "font-weight", FontWeight },
{ "height", Height },
+ { "icon", QtIcon },
{ "image", QtImage },
{ "image-position", QtImageAlignment },
{ "left", Left },
@@ -1379,6 +1380,37 @@ bool ValueExtractor::extractImage(QIcon *icon, Qt::Alignment *a, QSize *size)
return hit;
}
+bool ValueExtractor::extractIcon(QIcon *icon, QSize *size)
+{
+ // Find last declaration that specifies an icon
+ const auto declaration = std::find_if(
+ declarations.rbegin(), declarations.rend(),
+ [](const Declaration &decl) { return decl.d->propertyId == QtIcon; });
+ if (declaration == declarations.rend())
+ return false;
+
+ *icon = declaration->iconValue();
+
+ // If the value contains a URI, try to get the size of the icon
+ if (declaration->d->values.isEmpty())
+ return true;
+
+ const auto &propertyValue = declaration->d->values.constFirst();
+ if (propertyValue.type != Value::Uri)
+ return true;
+
+ // First try to read just the size from the image without loading it
+ const QString url(propertyValue.variant.toString());
+ QImageReader imageReader(url);
+ *size = imageReader.size();
+ if (!size->isNull())
+ return true;
+
+ // Get the size by loading the image instead
+ *size = imageReader.read().size();
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////
// Declaration
QColor Declaration::colorValue(const QPalette &pal) const
diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h
index ab85e76cf3..b8bf259dda 100644
--- a/src/gui/text/qcssparser_p.h
+++ b/src/gui/text/qcssparser_p.h
@@ -198,6 +198,7 @@ enum Property {
QtLineHeightType,
FontKerning,
QtForegroundTextureCacheKey,
+ QtIcon,
NumProperties
};
@@ -855,6 +856,7 @@ struct Q_GUI_EXPORT ValueExtractor
bool extractPalette(QBrush *fg, QBrush *sfg, QBrush *sbg, QBrush *abg);
int extractStyleFeatures();
bool extractImage(QIcon *icon, Qt::Alignment *a, QSize *size);
+ bool extractIcon(QIcon *icon, QSize *size);
int lengthValue(const Declaration &decl);