Merge pull request #20594 from captain0xff/icon-res

Gui: make BitmapFactory::pixmapFromSvg dpi aware
This commit is contained in:
Kacper Donat
2025-04-05 00:32:21 +02:00
committed by GitHub
11 changed files with 37 additions and 68 deletions

View File

@@ -1129,8 +1129,8 @@ private:
auto colorMapping = std::map<unsigned long, unsigned long>();
colorMapping[defaultCrosshairColor] = color;
qreal fullIconWidth = 32 * pixelRatio;
qreal iconWidth = 16 * pixelRatio;
constexpr qreal fullIconWidth = 32;
constexpr qreal iconWidth = 16;
QPixmap cursorPixmap =
Gui::BitmapFactory().pixmapFromSvg("Sketcher_Crosshair",
QSizeF(fullIconWidth, fullIconWidth),
@@ -1143,7 +1143,6 @@ private:
cursorPainter.end();
int hotX = 8;
int hotY = 8;
cursorPixmap.setDevicePixelRatio(pixelRatio);
// only X11 needs hot point coordinates to be scaled
if (qGuiApp->platformName() == QLatin1String("xcb")) {
hotX *= pixelRatio;
@@ -1422,17 +1421,16 @@ public:
auto colorMapping = std::map<unsigned long, unsigned long>();
colorMapping[defaultCrosshairColor] = color;
qreal fullIconWidth = 32 * pixelRatio;
qreal iconWidth = 16 * pixelRatio;
QPixmap cursorPixmap = Gui::BitmapFactory().pixmapFromSvg("Sketcher_Crosshair", QSizeF(fullIconWidth, fullIconWidth), colorMapping),
icon = Gui::BitmapFactory().pixmapFromSvg("Constraint_Dimension", QSizeF(iconWidth, iconWidth));
constexpr qreal fullIconWidth = 32;
constexpr qreal iconWidth = 16;
QPixmap cursorPixmap = Gui::BitmapFactory().pixmapFromSvg("Sketcher_Crosshair", QSizeF(fullIconWidth, fullIconWidth), colorMapping);
QPixmap icon = Gui::BitmapFactory().pixmapFromSvg("Constraint_Dimension", QSizeF(iconWidth, iconWidth));
QPainter cursorPainter;
cursorPainter.begin(&cursorPixmap);
cursorPainter.drawPixmap(16 * pixelRatio, 16 * pixelRatio, icon);
cursorPainter.end();
int hotX = 8;
int hotY = 8;
cursorPixmap.setDevicePixelRatio(pixelRatio);
// only X11 needs hot point coordinates to be scaled
if (qGuiApp->platformName() == QLatin1String("xcb")) {
hotX *= pixelRatio;

View File

@@ -406,12 +406,7 @@ DrawSketchHandler::suggestedConstraintsPixmaps(std::vector<AutoConstraint>& sugg
break;
}
if (!iconType.isEmpty()) {
qreal pixelRatio = 1;
Gui::View3DInventorViewer* viewer = getViewer();
if (viewer) {
pixelRatio = viewer->devicePixelRatio();
}
int iconWidth = 16 * pixelRatio;
constexpr int iconWidth = 16;
QPixmap icon = Gui::BitmapFactory().pixmapFromSvg(iconType.toStdString().c_str(),
QSize(iconWidth, iconWidth));
pixmaps.push_back(icon);