-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.cpp
More file actions
37 lines (34 loc) · 1000 Bytes
/
variable.cpp
File metadata and controls
37 lines (34 loc) · 1000 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
31
32
33
34
35
36
37
#include <variable.h>
Variable::Variable(QWidget *parent) : Component(parent) {
resize(85,35);
setValue(0);
var = new QLineEdit(this);
var->setPlaceholderText("0");
//var->setFixedWidth(width()-20);
var->resize(width()-20,var->y());
var->setAlignment(Qt::AlignCenter);
QVBoxLayout *l = new QVBoxLayout();
l->addWidget(var);
setLayout(l);
connect(var, SIGNAL(textChanged(QString)), this, SLOT(textChangedSlot(QString)));
setComponentType(3);
}
void Variable::paintEvent(QPaintEvent*) {
QPainter p(this);
p.fillRect(rect(), Qt::darkGreen);
QPen linePen;
linePen.setWidth(2);
linePen.setBrush(Qt::black);
linePen.setCapStyle(Qt::RoundCap);
linePen.setJoinStyle(Qt::RoundJoin);
p.setPen(linePen);
p.drawRect(rect().x(), rect().y(), rect().width()-1, rect().height()-1);
}
void Variable::textChangedSlot(QString text) {
// retrieving text and setting val
int val = getValue();
sscanf(text.toStdString().c_str(), "%d", &val);
if(text.size() == 0)
val = 0;
setValue(val);
}