-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.cpp
More file actions
122 lines (100 loc) · 2.06 KB
/
light.cpp
File metadata and controls
122 lines (100 loc) · 2.06 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "light.h"
#include <math.h>
#include <tuple>
#include <algorithm>
#include <QDebug>
Light::Light(int id, QString name, bool on, double bri, double hue, double sat, bool isAmbi, bool isGroup)
: id_(id), name_(name), on_(on), bri_(bri), hue_(hue), sat_(sat), isAmbi_(isAmbi), isGroup_(isGroup)
{
}
bool Light::on() const
{
return on_;
}
void Light::setOn(bool on)
{
on_ = on;
}
double Light::bri() const
{
return bri_;
}
void Light::setBri(double bri)
{
bri_ = bri;
}
double Light::sat() const
{
return sat_;
}
void Light::setSat(double sat)
{
sat_ = sat;
}
QString Light::name() const
{
return name_;
}
void Light::setName(QString name)
{
name_ = name;
}
int Light::id() const
{
return id_;
}
void Light::setId(int id)
{
id_ = id;
}
double Light::hue() const
{
return hue_/182.0;
}
double Light::pHue() const {
return hue_;
}
void Light::setHue(double hue)
{
hue_ = hue*182;
}
bool Light::operator==(const Light& l){
return l.bri_ == bri_ && l.hue_ == hue_ && l.sat_ == sat_ && l.id_ == id_ && l.on_ == on_;
}
bool Light::isAmbi() const
{
return isAmbi_;
}
void Light::setIsAmbi(bool isAmbi)
{
isAmbi_ = isAmbi;
}
bool Light::appendStateChanges(const Light& other)
{
bool dirty = false;
if(isAmbi_ != other.isAmbi_) { setIsAmbi(other.isAmbi()); dirty = true; }
if(hue_ != other.hue_) { setHue(other.hue()); dirty = true; }
if(sat_ != other.sat_) { setSat(other.sat()); dirty = true; }
if(bri_ != other.bri_) { setBri(other.bri()); dirty = true; }
if(on_ != other.on_) { setOn(other.on()); dirty = true; }
return dirty;
}
bool Light::appendNameChange(const Light& other){
if(!other.name_.trimmed().isEmpty() && name_ != other.name_){
name_ = other.name_;
return true;
}
return false;
}
bool Light::isGroup() const
{
return isGroup_;
}
std::weak_ptr<Group> Light::parentGroup() const
{
return parentGroup_;
}
void Light::setParentGroup(const std::weak_ptr<Group> &parentGroup)
{
parentGroup_ = parentGroup;
}