Gui: add overloaded method pixmapFromSvg() to pass the device pixel ratio of a widget
This commit is contained in:
@@ -285,7 +285,7 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const
|
||||
}
|
||||
|
||||
QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSizeF& size,
|
||||
const std::map<unsigned long, unsigned long>& colorMapping) const
|
||||
const ColorMap& colorMapping) const
|
||||
{
|
||||
// If an absolute path is given
|
||||
QPixmap icon;
|
||||
@@ -321,8 +321,18 @@ QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSizeF& size,
|
||||
return icon;
|
||||
}
|
||||
|
||||
QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSizeF& size, qreal dpr,
|
||||
const ColorMap& colorMapping) const
|
||||
{
|
||||
qreal width = size.width() * dpr;
|
||||
qreal height = size.height() * dpr;
|
||||
QPixmap px(pixmapFromSvg(name, QSizeF(width, height), colorMapping));
|
||||
px.setDevicePixelRatio(dpr);
|
||||
return px;
|
||||
}
|
||||
|
||||
QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& originalContents, const QSizeF& size,
|
||||
const std::map<unsigned long, unsigned long>& colorMapping) const
|
||||
const ColorMap& colorMapping) const
|
||||
{
|
||||
QString stringContents = QString::fromUtf8(originalContents);
|
||||
for ( const auto &colorToColor : colorMapping ) {
|
||||
|
||||
@@ -34,6 +34,8 @@ class QImage;
|
||||
|
||||
namespace Gui {
|
||||
|
||||
using ColorMap = std::map<unsigned long, unsigned long>;
|
||||
|
||||
/** The Bitmap Factory
|
||||
* the main purpose is to collect all build in Bitmaps and
|
||||
* hold all paths for the extern bitmaps (files) to serve
|
||||
@@ -82,14 +84,22 @@ public:
|
||||
* Can be used to customize icon color scheme, e.g. crosshair color
|
||||
*/
|
||||
QPixmap pixmapFromSvg(const char* name, const QSizeF& size,
|
||||
const std::map<unsigned long, unsigned long>& colorMapping = std::map<unsigned long, unsigned long>()) const;
|
||||
const ColorMap& colorMapping = ColorMap()) const;
|
||||
/** Retrieves a pixmap by name and size created by an
|
||||
* scalable vector graphics (SVG) and a device pixel ratio
|
||||
*
|
||||
* @param colorMapping - a dictionary of substitute colors.
|
||||
* Can be used to customize icon color scheme, e.g. crosshair color
|
||||
*/
|
||||
QPixmap pixmapFromSvg(const char* name, const QSizeF& size, qreal dpr,
|
||||
const ColorMap& colorMapping = ColorMap()) const;
|
||||
/** This method is provided for convenience and does the same
|
||||
* as the method above except that it creates the pixmap from
|
||||
* a byte array.
|
||||
* @param colorMapping - see above.
|
||||
*/
|
||||
QPixmap pixmapFromSvg(const QByteArray& contents, const QSizeF& size,
|
||||
const std::map<unsigned long, unsigned long>& colorMapping = std::map<unsigned long, unsigned long>()) const;
|
||||
const ColorMap& colorMapping = ColorMap()) const;
|
||||
/** Returns the names of all registered pixmaps.
|
||||
* To get the appropriate pixmaps call pixmap() for each name.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user