configdatetimedlg.cpp
1.29 KB
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
#include <QDateTime>
#include "configdatetimedlg.h"
#include "ui_configdatetimedlg.h"
#include "system.h"
ConfigDateTimeDlg::ConfigDateTimeDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigDateTimeDlg)
{
ui->setupUi(this);
this->setWindowFlags( Qt::FramelessWindowHint);
this->setAttribute( Qt::WA_DeleteOnClose);
ui->ctrSpBxYear->setFormatterWidth(4);
QDateTime dt_tm = QDateTime::currentDateTime();
QDate dt_ = dt_tm.date();
QTime tm_ = dt_tm.time();
ui->ctrSpBxYear->setValue(dt_.year());
ui->ctrSpBxMonth->setValue(dt_.month());
ui->ctrSpBxDay->setValue(dt_.day());
ui->ctrSpBxHour->setValue(tm_.hour());
ui->ctrSpBxMin->setValue(tm_.minute());
}
ConfigDateTimeDlg::~ConfigDateTimeDlg()
{
delete ui;
}
void ConfigDateTimeDlg::on_ctrBtnOk_clicked()
{
time_t tm_t;
QDate dt_(ui->ctrSpBxYear->value(), ui->ctrSpBxMonth->value(), ui->ctrSpBxDay->value());
QTime tm_(ui->ctrSpBxHour->value(), ui->ctrSpBxMin->value());
QDateTime dt_tm;
dt_tm.setTime(tm_);
dt_tm.setDate(dt_);
tm_t = (time_t)dt_tm.toTime_t();
System::setRtcTime(dt_tm);
stime(&tm_t);
this->accept();
}
void ConfigDateTimeDlg::on_spinBox_valueChanged(int arg1)
{
}
void ConfigDateTimeDlg::on_ctrBtnCancel_clicked()
{
this->reject();
}