-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadder.cpp
More file actions
30 lines (28 loc) · 907 Bytes
/
adder.cpp
File metadata and controls
30 lines (28 loc) · 907 Bytes
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
#include <adder.h>
Adder::Adder(QWidget *parent) : Component(parent) {
resize(50,50);
setComponentType(1);
setValue(0);
}
void Adder::paintEvent(QPaintEvent*) {
// painter and symbol settings
QPainter p(this);
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QString plus = "+";
// font customization
QFont font;
font.setPointSize(12);
font.setBold(true);
p.setFont(font);
// pen and brush customizations
QPen linePen;
linePen.setWidth(2);
linePen.setBrush(Qt::black);
linePen.setCapStyle(Qt::RoundCap);
linePen.setJoinStyle(Qt::RoundJoin);
p.setPen(linePen);
p.setBrush(Qt::green);
// drawing border, ellipse and symbol, the offset is needed beacuse the pen's font is 2px wide
p.drawEllipse(rect().x()+1, rect().y()+1, rect().width()-2, rect().height()-2);
p.drawText(rect().x(), rect().y(), rect().width()-1, rect().height()-1, Qt::AlignCenter, plus);
}