configdatetimedlg.cpp 1.45 KB
#include <QDateTime>
#include "configdatetimedlg.h"
#include "ui_configdatetimedlg.h"
#include "system.h"
#include "soundplayer.h"


ConfigDateTimeDlg::ConfigDateTimeDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConfigDateTimeDlg)
{
    ui->setupUi(this);
    this->setWindowFlags( Qt::FramelessWindowHint);
    this->setAttribute( Qt::WA_DeleteOnClose);

    foreach (QPushButton *button, findChildren<QPushButton *>())
        connect(button, &QPushButton::pressed, SoundPlayer::playClick);

    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();
}