MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / createThemedIcon

Function createThemedIcon

widgets/QuickRefactorDialog.cpp:45–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43namespace QodeAssist {
44
45static QIcon createThemedIcon(const QString &svgPath, const QColor &color)
46{
47 QSvgRenderer renderer(svgPath);
48 if (!renderer.isValid()) {
49 return QIcon();
50 }
51
52 QSize iconSize(16, 16);
53 QPixmap pixmap(iconSize);
54 pixmap.fill(Qt::transparent);
55
56 QPainter painter(&pixmap);
57 renderer.render(&painter);
58 painter.end();
59
60 QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
61
62 uchar *bits = image.bits();
63 const int bytesPerPixel = 4;
64 const int totalBytes = image.width() * image.height() * bytesPerPixel;
65
66 const int newR = color.red();
67 const int newG = color.green();
68 const int newB = color.blue();
69
70 for (int i = 0; i < totalBytes; i += bytesPerPixel) {
71 int alpha = bits[i + 3];
72 if (alpha > 0) {
73 bits[i] = newB;
74 bits[i + 1] = newG;
75 bits[i + 2] = newR;
76 }
77 }
78
79 return QIcon(QPixmap::fromImage(image));
80}
81
82QuickRefactorDialog::QuickRefactorDialog(QWidget *parent, const QString &lastInstructions)
83 : QDialog(parent)

Callers 1

setupUiMethod · 0.85

Calls 1

isValidMethod · 0.45

Tested by

no test coverage detected