-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformsinglelight.cpp
107 lines (95 loc) · 2.15 KB
/
formsinglelight.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "formsinglelight.h"
#include "ui_formsinglelight.h"
#include <QDebug>
#include <QTimer>
#include "group.h"
FormSingleLight::FormSingleLight(QWidget *parent) :
QWidget(parent),
ui(new Ui::FormSingleLight),
dirty_(false)
{
emitTimer_ = new QTimer(this);
connect(emitTimer_, &QTimer::timeout, [this]{
if(dirty_){
changed(l_, index_);
dirty_ = false;
}
});
emitTimer_->start(TIMER);
ui->setupUi(this);
}
void FormSingleLight::setLight(Light l, QModelIndex index)
{
l_ = l;
index_ = index;
refreshUI();
}
void FormSingleLight::refreshUI(){
ui->lineEdit->setText(l_.name());
ui->briSlider->setValue(l_.bri()/255.0*100);
ui->hueDial->setValue(l_.hue()/255.0*100);
ui->satDial->setValue(l_.sat()/255.0*100);
ui->onOffButton->setChecked(l_.on());
if(l_.isGroup()){
ui->checkBox->hide();
ui->groups->hide();
} else {
ui->checkBox->show();
ui->checkBox->setChecked(l_.isAmbi());
auto group = l_.parentGroup().lock();
if(group){
ui->groups->show();
ui->groupsLabel->setText(group->name());
}
else ui->groups->hide();
}
}
FormSingleLight::~FormSingleLight()
{
delete ui;
}
void FormSingleLight::on_lineEdit_textChanged(const QString &arg1)
{
if(l_.name() != arg1){
l_.setName(arg1);
change();
}
}
void FormSingleLight::change()
{
dirty_ = true;
}
void FormSingleLight::on_briSlider_valueChanged(int value)
{
if(l_.bri() != value){
l_.setBri(value*2.55);
change();
}
}
void FormSingleLight::on_hueDial_valueChanged(int value)
{
if(l_.hue() != value){
l_.setHue(value*2.55);
change();
}
}
void FormSingleLight::on_satDial_valueChanged(int value)
{
if(l_.sat() != value){
l_.setSat(value*2.55);
change();
}
}
void FormSingleLight::on_onOffButton_toggled(bool checked)
{
if(l_.on() != checked){
l_.setOn(checked);
change();
}
}
void FormSingleLight::on_checkBox_toggled(bool checked)
{
if(l_.isAmbi() != checked){
addAsAmbi(checked, index_);
}
}