-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimepage.cpp
75 lines (65 loc) · 2.08 KB
/
timepage.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 "timepage.h"
#include "ui_timepage.h"
#include <QtCore/QDebug>
#include <QtCore/QTime>
TimePage::TimePage(QWidget *parent) :
QWizardPage(parent),
_ui(new Ui::TimePage)
{
_ui->setupUi(this);
registerField("hour", _ui->hourEdit);
registerField("minute", _ui->minEdit);
}
void TimePage::initializePage()
{
if ( ! field("hour").toString().isEmpty() )
{
qDebug() << "loaded time:" << field("hour").toString() << field("minute").toString();
_ui->hourEdit->setText(QString::number(field("hour").toInt()).rightJustified(2, '0'));
_ui->minEdit->setText(QString::number(field("minute").toInt()).rightJustified(2, '0'));
} else {
QTime now = QTime::currentTime();
_ui->hourEdit->setText(QString::number(now.hour()).rightJustified(2, '0'));
_ui->minEdit->setText(QString::number(now.minute()).rightJustified(2, '0'));
}
connect(_ui->hourUp, SIGNAL(clicked()), this, SLOT(hourUp()));
connect(_ui->hourDown, SIGNAL(clicked()), this, SLOT(hourDown()));
connect(_ui->minUp, SIGNAL(clicked()), this, SLOT(minuteUp()));
connect(_ui->minDown, SIGNAL(clicked()), this, SLOT(minuteDown()));
}
TimePage::~TimePage()
{
delete _ui;
}
void TimePage::hourUp()
{
int hour = _ui->hourEdit->text().toInt();
if ( hour < 23 )
_ui->hourEdit->setText(QString::number(hour+1).rightJustified(2, '0'));
else
_ui->hourEdit->setText("00");
}
void TimePage::hourDown()
{
int hour = _ui->hourEdit->text().toInt();
if ( hour > 0 )
_ui->hourEdit->setText(QString::number(hour-1).rightJustified(2, '0'));
else
_ui->hourEdit->setText("23");
}
void TimePage::minuteUp()
{
int minute = _ui->minEdit->text().toInt();
if ( minute < 59 )
_ui->minEdit->setText(QString::number(minute+1).rightJustified(2, '0'));
else
_ui->minEdit->setText("00");
}
void TimePage::minuteDown()
{
int minute = _ui->minEdit->text().toInt();
if ( minute > 0 )
_ui->minEdit->setText(QString::number(minute-1).rightJustified(2, '0'));
else
_ui->minEdit->setText("59");
}