Skip to content

Commit 336585d

Browse files
authored
Merge pull request #2 from secondYearProjects/dev
Settings module
2 parents c57fc75 + fa4345e commit 336585d

15 files changed

+800
-271
lines changed

SmartTimer/SmartTimer.pro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ SOURCES += \
3636
toggleswitch.cpp \
3737
alertwidget.cpp \
3838
addalarmdialog.cpp \
39-
changealarmdialog.cpp
39+
changealarmdialog.cpp \
40+
globalsettingsdialog.cpp
4041

4142
HEADERS += \
4243
mainwindow.h \
@@ -48,7 +49,8 @@ HEADERS += \
4849
alertwidget.h \
4950
addalarmdialog.h \
5051
changealarmdialog.h \
51-
widgetsettings.h
52+
widgetsettings.h \
53+
globalsettingsdialog.h
5254

5355
FORMS += \
5456
mainwindow.ui \
@@ -57,7 +59,8 @@ FORMS += \
5759
changetimerdialog.ui \
5860
alertwidget.ui \
5961
addalarmdialog.ui \
60-
changealarmdialog.ui
62+
changealarmdialog.ui \
63+
globalsettingsdialog.ui
6164

6265
# Default rules for deployment.
6366
qnx: target.path = /tmp/$${TARGET}/bin

SmartTimer/alertwidget.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ void alertwidget::statusChanged(bool stat)
107107
}
108108
else
109109
{
110+
if (blinkTimer.isActive())
111+
emit blinkInfo("Alarms",false);
112+
110113
alertTick.stop();
111114
blinkTimer.stop();
112115
blinking = false;
@@ -154,6 +157,9 @@ void alertwidget::blink()
154157

155158
void alertwidget::stopBlinking()
156159
{
160+
if (blinkTimer.isActive())
161+
emit blinkInfo("Alarms",false);
162+
157163
alertTick.stop();
158164
blinkTimer.stop();
159165
blinking = false;
@@ -170,13 +176,16 @@ void alertwidget::stopBlinking()
170176

171177
void alertwidget::closeAlarm()
172178
{
179+
if (blinkTimer.isActive())
180+
emit blinkInfo("Alarms",false);
181+
173182
alertTick.stop();
174183
blinkTimer.stop();
175184
player->stop();
176185

177186

178187
emit del(this);
179-
emit blinkInfo("Alarms",false);
188+
180189

181190
this->close();
182191
}
@@ -220,7 +229,7 @@ void alertwidget::setAlarm(int msecs, const QString & _name)
220229

221230
void alertwidget::mousePressEvent(QMouseEvent *e)
222231
{
223-
if (e->button() == Qt::RightButton)
232+
if (e->button() == Qt::RightButton && !blinkTimer.isActive())
224233
{
225234
player->stop();
226235
ShowContextMenu(e->pos());
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "globalsettingsdialog.h"
2+
#include "ui_globalsettingsdialog.h"
3+
4+
#include <QFile>
5+
#include <QSlider>
6+
7+
GlobalSettingsDialog::GlobalSettingsDialog(GlobalSettings old, QWidget *parent) :
8+
QDialog(parent),
9+
ui(new Ui::GlobalSettingsDialog)
10+
{
11+
ui->setupUi(this);
12+
13+
QFile file(":/stylesheet.qss");
14+
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
15+
{
16+
this->setStyleSheet(file.readAll());
17+
file.close();
18+
}
19+
20+
oldSettings = old;
21+
22+
ui->opacitySlider->setValue(static_cast<int>(old.windowOpacity*100));
23+
ui->SliderValue->setText(QString::number(static_cast<int>(old.windowOpacity*100))+"%");
24+
25+
connect(ui->cancelButton,SIGNAL(clicked()),this,SLOT(close()));
26+
connect(ui->confirmButton,SIGNAL(clicked()),this, SLOT(confirmed()));
27+
connect( ui->opacitySlider,SIGNAL(valueChanged(int)),this,SLOT(opacityChanged()));
28+
29+
}
30+
31+
GlobalSettingsDialog::~GlobalSettingsDialog()
32+
{
33+
delete ui;
34+
}
35+
36+
void GlobalSettingsDialog::confirmed()
37+
{
38+
GlobalSettings newSettings(ui->opacitySlider->value()/100.0,ui->alarmFormat->text(), ui->TimerFormat->text());
39+
emit changeSettings(newSettings);
40+
this->close();
41+
}
42+
43+
void GlobalSettingsDialog::canceled()
44+
{
45+
emit changeSettings(oldSettings);
46+
this->close();
47+
}
48+
49+
void GlobalSettingsDialog::opacityChanged()
50+
{
51+
GlobalSettings newSettings(ui->opacitySlider->value()/100.0,ui->alarmFormat->text(), ui->TimerFormat->text());
52+
53+
ui->SliderValue->setText(QString::number(static_cast<int>(newSettings.windowOpacity*100))+"%");
54+
55+
emit changeSettings(newSettings);
56+
}

SmartTimer/globalsettingsdialog.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef GLOBALSETTINGSDIALOG_H
2+
#define GLOBALSETTINGSDIALOG_H
3+
4+
#include "widgetsettings.h"
5+
6+
#include <QDialog>
7+
8+
namespace Ui {
9+
class GlobalSettingsDialog;
10+
}
11+
12+
class GlobalSettingsDialog : public QDialog
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit GlobalSettingsDialog(GlobalSettings old, QWidget *parent = nullptr);
18+
~GlobalSettingsDialog();
19+
public slots:
20+
void confirmed();
21+
void canceled();
22+
void opacityChanged();
23+
signals:
24+
void changeSettings(GlobalSettings settings);
25+
26+
private:
27+
Ui::GlobalSettingsDialog *ui;
28+
29+
GlobalSettings oldSettings;
30+
};
31+
32+
#endif // GLOBALSETTINGSDIALOG_H

SmartTimer/globalsettingsdialog.ui

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>GlobalSettingsDialog</class>
4+
<widget class="QDialog" name="GlobalSettingsDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>420</width>
10+
<height>465</height>
11+
</rect>
12+
</property>
13+
<property name="minimumSize">
14+
<size>
15+
<width>420</width>
16+
<height>0</height>
17+
</size>
18+
</property>
19+
<property name="maximumSize">
20+
<size>
21+
<width>420</width>
22+
<height>16777215</height>
23+
</size>
24+
</property>
25+
<property name="windowTitle">
26+
<string>Global settings</string>
27+
</property>
28+
<property name="windowIcon">
29+
<iconset resource="resources.qrc">
30+
<normaloff>:/icons/change-icon.png</normaloff>:/icons/change-icon.png</iconset>
31+
</property>
32+
<layout class="QGridLayout" name="gridLayout">
33+
<item row="0" column="0">
34+
<layout class="QVBoxLayout" name="verticalLayout">
35+
<item>
36+
<layout class="QHBoxLayout" name="horizontalLayout_2">
37+
<item>
38+
<widget class="QLabel" name="label">
39+
<property name="text">
40+
<string>Window opacity:</string>
41+
</property>
42+
</widget>
43+
</item>
44+
<item>
45+
<spacer name="horizontalSpacer">
46+
<property name="orientation">
47+
<enum>Qt::Horizontal</enum>
48+
</property>
49+
<property name="sizeHint" stdset="0">
50+
<size>
51+
<width>20</width>
52+
<height>20</height>
53+
</size>
54+
</property>
55+
</spacer>
56+
</item>
57+
<item>
58+
<widget class="QLabel" name="SliderValue">
59+
<property name="text">
60+
<string/>
61+
</property>
62+
</widget>
63+
</item>
64+
<item>
65+
<widget class="QSlider" name="opacitySlider">
66+
<property name="minimumSize">
67+
<size>
68+
<width>200</width>
69+
<height>0</height>
70+
</size>
71+
</property>
72+
<property name="minimum">
73+
<number>20</number>
74+
</property>
75+
<property name="maximum">
76+
<number>100</number>
77+
</property>
78+
<property name="pageStep">
79+
<number>0</number>
80+
</property>
81+
<property name="orientation">
82+
<enum>Qt::Horizontal</enum>
83+
</property>
84+
</widget>
85+
</item>
86+
</layout>
87+
</item>
88+
<item>
89+
<layout class="QHBoxLayout" name="horizontalLayout_3">
90+
<item>
91+
<widget class="QLabel" name="label_2">
92+
<property name="text">
93+
<string>Alarm Time format:</string>
94+
</property>
95+
</widget>
96+
</item>
97+
<item>
98+
<spacer name="horizontalSpacer_2">
99+
<property name="orientation">
100+
<enum>Qt::Horizontal</enum>
101+
</property>
102+
<property name="sizeHint" stdset="0">
103+
<size>
104+
<width>40</width>
105+
<height>20</height>
106+
</size>
107+
</property>
108+
</spacer>
109+
</item>
110+
<item>
111+
<widget class="QLineEdit" name="alarmFormat"/>
112+
</item>
113+
</layout>
114+
</item>
115+
<item>
116+
<layout class="QHBoxLayout" name="horizontalLayout_4">
117+
<item>
118+
<widget class="QLabel" name="label_3">
119+
<property name="text">
120+
<string>Timer Time format:</string>
121+
</property>
122+
</widget>
123+
</item>
124+
<item>
125+
<spacer name="horizontalSpacer_3">
126+
<property name="orientation">
127+
<enum>Qt::Horizontal</enum>
128+
</property>
129+
<property name="sizeHint" stdset="0">
130+
<size>
131+
<width>40</width>
132+
<height>20</height>
133+
</size>
134+
</property>
135+
</spacer>
136+
</item>
137+
<item>
138+
<widget class="QLineEdit" name="TimerFormat"/>
139+
</item>
140+
</layout>
141+
</item>
142+
<item>
143+
<layout class="QHBoxLayout" name="horizontalLayout">
144+
<item>
145+
<widget class="QPushButton" name="confirmButton">
146+
<property name="text">
147+
<string>Confirtm</string>
148+
</property>
149+
</widget>
150+
</item>
151+
<item>
152+
<widget class="QPushButton" name="cancelButton">
153+
<property name="text">
154+
<string>Cancel</string>
155+
</property>
156+
</widget>
157+
</item>
158+
</layout>
159+
</item>
160+
</layout>
161+
</item>
162+
</layout>
163+
</widget>
164+
<resources>
165+
<include location="resources.qrc"/>
166+
</resources>
167+
<connections/>
168+
</ui>

SmartTimer/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ int main(int argc, char *argv[])
88

99
MainWindow w;
1010

11+
1112
w.show();
1213

1314
return QApplication::exec();

0 commit comments

Comments
 (0)