-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiconproxystyle.cpp
More file actions
52 lines (46 loc) · 1.25 KB
/
iconproxystyle.cpp
File metadata and controls
52 lines (46 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "iconproxystyle.h"
#include <QDebug>
#include <QLabel>
#include <QPainter>
#include <QStyleOption>
IconProxyStyle::IconProxyStyle(QStyle *style) : QProxyStyle(style)
{
}
QIcon IconProxyStyle::standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
{
switch (standardIcon)
{
case QStyle::SP_MessageBoxWarning:
{
return QIcon(colorizedPixmap(QPixmap(":/images/warning")));
}
case QStyle::SP_DialogCancelButton:
{
return QIcon(colorizedPixmap(QPixmap(":/images/cancel")));
}
case QStyle::SP_DialogSaveButton:
{
return QIcon(colorizedPixmap(QPixmap(":/images/save_file")));
}
case QStyle::SP_DialogDiscardButton:
{
return QIcon(colorizedPixmap(QPixmap(":/icons/material/discard_changes.svg")));
}
default: break;
}
return QProxyStyle::standardIcon(standardIcon, option, widget);
}
QPixmap IconProxyStyle::colorizedPixmap(const QPixmap &pixmap, QColor color) const
{
QImage image = pixmap.toImage().alphaChannel();
if (color == Qt::transparent)
{
color.setRgb(qrand() % 256, qrand() % 256, qrand() % 256);
}
for (int i = 0; i < image.colorCount(); i++)
{
color.setAlpha(qGray(image.color(i)));
image.setColor(i, color.rgba());
}
return QPixmap::fromImage(image);
}