-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
185 lines (152 loc) · 4.26 KB
/
mainwindow.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSettings>
#include <QDebug>
#include <QTimer>
#include <QTime>
#include <QIcon>
#include <QList>
#include "modes/onefixedcolor.h"
#include "modes/individualfixedcolor.h"
#include "modes/worm.h"
#include "modes/flaschendrehen.h"
#include "settingsdialog.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_mode(0)
{
ui->setupUi(this);
connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(on_aboutToQuit()));
// App name
QApplication::setOrganizationName("Jan Wiele");
QApplication::setOrganizationDomain("wiele.org");
QApplication::setApplicationName("AtmoLin");
//
// Atmolights
loadAtmoLights();
//
// Systray
m_tray = new QSystemTrayIcon(this);
connect(m_tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(on_systemTrayActivated(QSystemTrayIcon::ActivationReason)));
m_tray->setContextMenu(ui->menuBar->findChildren<QMenu*>().first());
m_tray->setIcon(QIcon(":/img/icon"));
m_tray->show();
//
// Fill Combobox
connect(ui->comboBox_mode, SIGNAL(currentTextChanged(QString)), this, SLOT(on_modeChanged(QString)));
ui->comboBox_mode->addItems(QStringList()
<< "One Fixed Color"
<< "Individual Fixed Color"
<< "Worm"
<< "Flaschendrehen"
);
//
loadSettings();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadSettings()
{
qDebug() << this << "Loading Settings";
QSettings s;
}
void MainWindow::loadAtmoLights()
{
qDebug() << this << "Loading Atmolights";
QSettings s;
s.beginGroup("AtmoLights");
QStringList keys = s.childGroups();
foreach(QString key, keys){
s.beginGroup(key);
QString port = s.value("port", "").toString();
QStringList orderAsStrings = s.value("order").toStringList();
QList<int> orderAsInts;
foreach (QString orderItem, orderAsStrings) {
orderAsInts << orderItem.toInt();
}
qDebug() << this << "Creating Atmolight" << port << "with order" << orderAsStrings;
m_atmoLightList.append(new AtmoLight(port, orderAsInts, this));
s.endGroup();
}
// Create ordered list
foreach(AtmoLight *al, m_atmoLightList){
for(int i = 0; i < al->ledAreaList().size(); i++){
m_ledAreaListOrdered.append(al->ledAreaList().at(al->ledAreaOrderList()[i]));
}
}
qDebug() << this << "Created Ordered List" << m_ledAreaListOrdered;
//
}
void MainWindow::on_systemTrayActivated(QSystemTrayIcon::ActivationReason reason)
{
qDebug() << this << "SystemTray activated. Reason:" << reason;
switch(reason){
case QSystemTrayIcon::Unknown:{
}
case QSystemTrayIcon::Context:{
}
case QSystemTrayIcon::DoubleClick:{
}
case QSystemTrayIcon::Trigger:{
this->show();
}
case QSystemTrayIcon::MiddleClick:{
}
default:{
}
}
}
void MainWindow::on_updateLEDs()
{
foreach (AtmoLight *al, m_atmoLightList) {
al->sendLightState();
}
}
void MainWindow::on_aboutToQuit()
{
if(m_mode) delete m_mode;
saveSettings();
}
void MainWindow::on_modeChanged(QString mode)
{
if(m_mode){
delete m_mode;
m_mode = 0;
}
//
if(mode == "One Fixed Color"){
m_mode = new OneFixedColor(m_ledAreaListOrdered);
}
if(mode == "Individual Fixed Color"){
m_mode = new IndividualFixedColor(m_ledAreaListOrdered);
}
if(mode == "Worm"){
m_mode = new Worm(m_ledAreaListOrdered);
}
if(mode == "Flaschendrehen"){
m_mode = new Flaschendrehen(m_ledAreaListOrdered);
}
//
if(m_mode){
connect(m_mode, SIGNAL(updateLEDs()), this, SLOT(on_updateLEDs()));
ui->verticalLayout_modeLayout->addWidget(m_mode->widget());
}
}
void MainWindow::saveSettings()
{
qDebug() << this << "Saving Settings";
QSettings s;
}
void MainWindow::on_actionQuit_triggered()
{
QApplication::instance()->quit();
}
void MainWindow::on_actionSettings_triggered()
{
SettingsDialog settings;
settings.exec();
}