Skip to content

Commit a24674a

Browse files
committed
Add alarm change
1 parent cba778e commit a24674a

File tree

6 files changed

+347
-3
lines changed

6 files changed

+347
-3
lines changed

SmartTimer/SmartTimer.pro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ SOURCES += \
3535
smarttimerlog.cpp \
3636
toggleswitch.cpp \
3737
alertwidget.cpp \
38-
addalarmdialog.cpp
38+
addalarmdialog.cpp \
39+
changealarmdialog.cpp
3940

4041
HEADERS += \
4142
mainwindow.h \
@@ -45,15 +46,17 @@ HEADERS += \
4546
smarttimerlog.h \
4647
toggleswitch.h \
4748
alertwidget.h \
48-
addalarmdialog.h
49+
addalarmdialog.h \
50+
changealarmdialog.h
4951

5052
FORMS += \
5153
mainwindow.ui \
5254
timerwidget.ui \
5355
addtimerdialog.ui \
5456
changetimerdialog.ui \
5557
alertwidget.ui \
56-
addalarmdialog.ui
58+
addalarmdialog.ui \
59+
changealarmdialog.ui
5760

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

SmartTimer/alertwidget.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "alertwidget.h"
22
#include "ui_alertwidget.h"
3+
#include "changealarmdialog.h"
4+
35

46
#include <iostream>
57

@@ -167,7 +169,11 @@ void alertwidget::closeAlarm()
167169

168170
void alertwidget::changeAlarm()
169171
{
172+
ChangeAlarmDialog *dial = new ChangeAlarmDialog(this);
173+
174+
connect(dial, SIGNAL(changeAlarmSignal(int,QString)),this,SLOT(setAlarm(int,QString)));
170175

176+
dial->exec();
171177
}
172178

173179
void alertwidget::ShowContextMenu(const QPoint &pos)
@@ -184,6 +190,18 @@ void alertwidget::ShowContextMenu(const QPoint &pos)
184190
contextMenu.exec(mapToGlobal(pos));
185191
}
186192

193+
void alertwidget::setAlarm(int msecs, const QString & _name)
194+
{
195+
ui->timeLabel->setText(QTime::fromMSecsSinceStartOfDay(msecs).toString("hh:mm"));
196+
ui->alarmNameLabel->setText(_name);
197+
198+
alertTime = QTime::fromMSecsSinceStartOfDay(msecs);
199+
alertName = _name;
200+
201+
statusChanged(true);
202+
203+
}
204+
187205

188206
void alertwidget::mousePressEvent(QMouseEvent *e)
189207
{

SmartTimer/alertwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public slots:
3636

3737
void ShowContextMenu(const QPoint &);
3838

39+
void setAlarm(int,const QString&);
40+
3941
signals:
4042
void alarmFinished();
4143
void del(const alertwidget*);

SmartTimer/changealarmdialog.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "changealarmdialog.h"
2+
#include "ui_changealarmdialog.h"
3+
#include "alertwidget.h"
4+
5+
ChangeAlarmDialog::ChangeAlarmDialog(alertwidget *parent) :
6+
QDialog(parent),
7+
ui(new Ui::ChangeAlarmDialog)
8+
{
9+
ui->setupUi(this);
10+
11+
ui->alarmName->setText(parent->getName());
12+
ui->time->setTime(QTime::fromMSecsSinceStartOfDay(parent->getAlertTime()));
13+
14+
connect(ui->changeButton,SIGNAL(clicked()), this, SLOT(changeAlarm()));
15+
}
16+
17+
ChangeAlarmDialog::~ChangeAlarmDialog()
18+
{
19+
delete ui;
20+
21+
22+
}
23+
24+
void ChangeAlarmDialog::changeAlarm()
25+
{
26+
emit changeAlarmSignal(getMsecs(ui->time->time()), ui->alarmName->text());
27+
28+
this->close();
29+
}

SmartTimer/changealarmdialog.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef CHANGEALARMDIALOG_H
2+
#define CHANGEALARMDIALOG_H
3+
4+
#include "alertwidget.h"
5+
6+
#include <QDialog>
7+
8+
namespace Ui {
9+
class ChangeAlarmDialog;
10+
}
11+
12+
class ChangeAlarmDialog : public QDialog
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit ChangeAlarmDialog(alertwidget *parent = nullptr);
18+
~ChangeAlarmDialog();
19+
20+
public slots:
21+
void changeAlarm();
22+
signals:
23+
void changeAlarmSignal(int, const QString &);
24+
25+
private:
26+
Ui::ChangeAlarmDialog *ui;
27+
};
28+
29+
#endif // CHANGEALARMDIALOG_H

0 commit comments

Comments
 (0)