-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsunlight.cpp
75 lines (67 loc) · 1.68 KB
/
sunlight.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
#include "sunlight.h"
#include <QDebug>
// #include "timer.h"
SunLight::SunLight(QWidget *parent) :
QWidget(parent),sunLight(1000)
{
lcd = new QLCDNumber(4);// for debug
connect(this,SIGNAL(updateSun(int)),lcd,SLOT(display(int)));
QPushButton* button = new QPushButton(tr("add sunlight"));
// QPushButton* button1 = new QPushButton(tr("pause"));
// QPushButton* button2 = new QPushButton(tr("restore"));
connect(button, SIGNAL(clicked()),this,SLOT(addSunLight()));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(lcd);
layout->addWidget(button);
// layout->addWidget(button1);
// layout->addWidget(button2);
addSunLight(0);// dirty code
this->setLayout(layout);
// Timer* timer = new Timer(10);
// connect(timer,SIGNAL(timeout()),this,SLOT(addSunLight()));
// connect(button1,SIGNAL(clicked()),timer,SLOT(pause()));
// connect(button2,SIGNAL(clicked()),timer,SLOT(restore()));
// timer->start();
}
void SunLight::restart()
{
sunLight = 1000;
emit updateSun(sunLight);
paused = false;
}
void SunLight::pause()
{
paused = true;
}
void SunLight::restore()
{
paused = false;
}
void SunLight::addSunLight(int num)
{
sunLight += num;
if (sunLight > 9990)
sunLight = 9990;
emit updateSun(sunLight);
}
void SunLight::addSunLight()// for debug
{
if (paused)
return;
sunLight += 25;
if (sunLight > 9990)
sunLight = 9990;
emit updateSun(sunLight);
}
bool SunLight::sufficientSunLight(int num)
{
if (num <= sunLight)
return true;
else
return false;
}
void SunLight::subtractSunLight(int num)
{
sunLight -= num;
emit updateSun(sunLight);
}