-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestModeBtn.cpp
91 lines (77 loc) · 3.05 KB
/
TestModeBtn.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 "TestModeBtn.h"
TestModeBtn::TestModeBtn(const QString &name, const int min, const int max, QWidget *parent) : QWidget(parent), borne({min, max}) {
this->layout = new QHBoxLayout(this);
this->layout->setAlignment(Qt::AlignCenter);
this->textLabel = new QLabel(name, this);
textLabel->setStyleSheet("font-size: 24px; font-weight: bold; color: black;");
this->valueLabel = new QLabel(QString::number(this->value), this);
this->valueLabel->setStyleSheet("font-size: 24px; font-weight: bold; color: black;");
this->increment10 = new QPushButton("+10", this);
this->increment10->setStyleSheet("background-color: #5FC8E6; border-radius: 20px; height: 46px; width: 46px; color: black;");
this->increment10->setBaseSize(46, 46);
this->decrement10 = new QPushButton("-10", this);
this->decrement10->setStyleSheet("background-color: #5FC8E6; border-radius: 20px; height: 46px; width: 46px; color: black;");
this->decrement10->setBaseSize(46, 46);
this->increment100 = new QPushButton("+100", this);
this->increment100->setStyleSheet("background-color: #5FC8F6; border-radius: 20px; height: 46px; width: 46px; color: black;");
this->increment100->setBaseSize(46, 46);
this->decrement100 = new QPushButton("-100", this);
this->decrement100->setStyleSheet("background-color: #5FC8F6; border-radius: 20px; height: 46px; width: 46px; color: black;");
this->decrement100->setBaseSize(46, 46);
connect(this->decrement10, &QPushButton::pressed, this, [=]()
{
if (this->value - 10 > this->borne.min)
{
this->value-=10;
this->valueLabel->setText(QString::number(this->value));
}
});
connect(this->increment10, &QPushButton::pressed, this, [=]()
{
if (this->value + 10 < this->borne.max)
{
this->value+=10;
this->valueLabel->setText(QString::number(this->value));
}
});
connect(this->increment100, &QPushButton::pressed, this, [=]()
{
if (this->value + 100 <= this->borne.max)
{
this->value += 100;
this->valueLabel->setText(QString::number(this->value));
}
else
{
this->value = this->borne.max;
this->valueLabel->setText(QString::number(this->value));
}
});
connect(this->decrement100, &QPushButton::pressed, this, [=]()
{
if (this->value - 100 >= this->borne.min)
{
this->value -= 100;
this->valueLabel->setText(QString::number(this->value));
}
else
{
this->value = this->borne.min;
this->valueLabel->setText(QString::number(this->value));
}
});
layout->addWidget(textLabel);
layout->addWidget(decrement100);
layout->addWidget(decrement10);
layout->addWidget(valueLabel);
layout->addWidget(increment10);
layout->addWidget(increment100);
}
void TestModeBtn::setBorne(const int min, const int max)
{
this->borne = {min, max};
}
int TestModeBtn::getValue() const
{
return this->value;
}