/
purecolorlibrarywidget.cpp
92 lines (75 loc) · 1.9 KB
/
purecolorlibrarywidget.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <QPainter>
#include <QPen>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QApplication>
#include "purecolorlibrarywidget.h"
#include "glasscolor.h"
#include "globalbackgroundcolor.h"
PureColorLibraryWidget :: PureColorLibraryWidget(GlassColor* __color,
QWidget* parent): QLabel(parent)
{
setFixedSize(300, 40);
this->_color = __color;
isSelected = false;
QHBoxLayout* layout = new QHBoxLayout(this);
this->setLayout(layout);
layout->setContentsMargins(10, 0, 0, 0);
swatch = new QLabel(this);
swatch->setAttribute(Qt::WA_TransparentForMouseEvents);
swatch->setFixedSize(20, 20);
QPixmap pixmap(20, 20);
QPainter painter(&pixmap);
Color c = _color->color();
QColor qc;
qc.setRgbF(c.r, c.g, c.b, c.a);
painter.fillRect(QRect(0, 0, 20, 20), QBrush(qc));
painter.drawRect(QRect(0, 0, 19, 19));
swatch->setPixmap(pixmap);
layout->addWidget(swatch, 0);
QLabel* nameLabel = new QLabel(_color->longName().c_str(), this);
nameLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
nameLabel->setPalette(QPalette(Qt::black));
layout->addWidget(nameLabel, 1);
renderPixmap();
}
void PureColorLibraryWidget :: setSelected(bool s)
{
if (s != isSelected)
{
isSelected = s;
renderPixmap();
}
}
void PureColorLibraryWidget :: renderPixmap()
{
QPixmap pixmap(300, 40);
QPainter painter(&pixmap);
painter.fillRect(0, 0, 300, 40, GlobalBackgroundColor::qcolor);
if (isSelected) // do highlighting if selected
{
QPen pen;
pen.setColor(QColor(0, 0, 255));
pen.setWidth(2);
painter.setPen(pen);
painter.drawRect(1, 1, 298, 38);
}
painter.end();
this->setPixmap(pixmap);
}
GlassColor* PureColorLibraryWidget :: glassColorCopy()
{
return deep_copy(_color);
}
Color PureColorLibraryWidget :: color()
{
return _color->color();
}
string PureColorLibraryWidget :: shortName()
{
return _color->shortName();
}
string PureColorLibraryWidget :: longName()
{
return _color->longName();
}