diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index 5c70844bb1..0bb4f6c5eb 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -32,6 +32,7 @@ # include # include # include +# include # include # include # include @@ -277,6 +278,8 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSizeF& size, const ColorMap& colorMapping) const { + static qreal dpr = getMaximumDPR(); + // If an absolute path is given QPixmap icon; QString iconPath; @@ -304,21 +307,15 @@ QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSizeF& size, QFile file(iconPath); if (file.open(QFile::ReadOnly | QFile::Text)) { QByteArray content = file.readAll(); - icon = pixmapFromSvg(content, size, colorMapping); + icon = pixmapFromSvg(content, size * dpr, colorMapping); } } - return icon; -} + if (!icon.isNull()) { + icon.setDevicePixelRatio(dpr); + } -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; + return icon; } QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& originalContents, const QSizeF& size, @@ -677,3 +674,14 @@ QIcon BitmapFactoryInst::mergePixmap (const QIcon &base, const QPixmap &px, Gui: return overlayedIcon; } + +qreal BitmapFactoryInst::getMaximumDPR() +{ + qreal dpr = 1.0F; + + for (QScreen* screen: QGuiApplication::screens()) { + dpr = std::max(screen->devicePixelRatio(), dpr); + } + + return dpr; +} diff --git a/src/Gui/BitmapFactory.h b/src/Gui/BitmapFactory.h index 23288589af..22c79251ae 100644 --- a/src/Gui/BitmapFactory.h +++ b/src/Gui/BitmapFactory.h @@ -87,14 +87,6 @@ public: */ QPixmap pixmapFromSvg(const char* name, const QSizeF& size, 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. @@ -149,6 +141,8 @@ public: /// Helper method to merge a pixmap into one corner of a QIcon static QIcon mergePixmap (const QIcon &base, const QPixmap &px, Gui::BitmapFactoryInst::Position position); + static qreal getMaximumDPR(); + private: bool loadPixmap(const QString& path, QPixmap&) const; void restoreCustomPaths();