Details
-
Suggestion
-
Resolution: Unresolved
-
P4: Low
-
None
-
4.6.3
-
None
Description
There are usecases in which a static SVG theme needs to be manipulated at runtime, for example:
- Amarok replaces certain colors in their application theme by colors from QApplication::palette() to adapt to the system colors.
- Several game developers have approached me (as the developer of KGameRenderer, a high-level SVG rendering stack powered by QSvgRenderer, which has recently been added to libkdegames trunk) because they want to inject custom colors into a complex SVG element. The most common example is an element representing a player, which contains at a prominent position the color of the player who controls this figure.
QSvgRenderer does not provide API to do these manipulations, which is why developers have to resort to hacks: Amarok uses string manipulation in the XML file before passing the file contents on to QSvgRenderer. This does not work for the KGameRenderer case, because one would want to render the same SVG element with different colors. I chose to implement a proxy QPaintDevice which replaces colors in brushes and pens as needed. This approach is cumbersome, unnecessarily complicated and slow as hell (at least 10% longer rendering time, more in real-world scenarios).
I therefore request that API be added to QSvgRenderer to accommodate these usecases. The API should be designed such that designers can still paint complete themes which do not depend on elements which are added only at runtime. For example, I could imagine a method that sets a custom stylesheet which is applied to the underlying SVG document.