-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
changedatetime.cpp
78 lines (67 loc) · 2.32 KB
/
changedatetime.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
76
77
78
/** @file changedatetime.cpp
* Soubor s tridou ChangeDateTime dedici ze tridy QWidget obsahujici box pro posun casu fotografie
*/
#include "changedatetime.h"
#include "ui_changedatetime.h"
ChangeDateTime::ChangeDateTime(QWidget* parent)
: QWidget(parent)
, ui(new Ui::ChangeDateTime)
{
ui->setupUi(this);
connect(ui->dateTimeEdit->timer, SIGNAL(timeout()), this, SLOT(showDateTime()));
connect(ui->dateTimeEdit, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(processDateTimeChange(QDateTime)));
connect(ui->radioButtonNewTime, SIGNAL(toggled(bool)), ui->groupBox, SLOT(setEnabled(bool)));
}
void ChangeDateTime::retranslateUi()
{
ui->retranslateUi(this);
}
ChangeDateTime::~ChangeDateTime()
{
delete ui;
}
void ChangeDateTime::showDateTime()
{
ui->dateTimeEdit->timer->setInterval(1000);
ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime().addSecs(-timeShift()));
}
void ChangeDateTime::showEvent(QShowEvent*)
{
ui->hourSpinBox->setValue(0);
ui->minuteSpinBox->setValue(0);
ui->secondSpinBox->setValue(0);
}
void ChangeDateTime::processDateTimeChange(QDateTime)
{
int secChange = -(ui->dateTimeEdit->dateTime().toSecsSinceEpoch()
- QDateTime::currentDateTime().toSecsSinceEpoch());
if (-1 < secChange && secChange <= 1) {
return;
}
ui->hourSpinBox->setValue(secChange / 3600);
ui->minuteSpinBox->setValue((secChange % 3600) / 60);
ui->secondSpinBox->setValue(secChange % 60);
if (ui->secondSpinBox->value() >= 60 || ui->secondSpinBox->value() <= -60) {
ui->minuteSpinBox->setValue(ui->minuteSpinBox->value() + ui->secondSpinBox->value() / 60);
ui->secondSpinBox->setValue(ui->secondSpinBox->value() % 60);
}
if (ui->minuteSpinBox->value() >= 60 || ui->minuteSpinBox->value() <= -60) {
ui->hourSpinBox->setValue(ui->hourSpinBox->value() + ui->minuteSpinBox->value() / 60);
ui->minuteSpinBox->setValue(ui->minuteSpinBox->value() % 60);
}
}
int ChangeDateTime::timeShift()
{
long long int sec = ui->hourSpinBox->text().toInt() * 3600
+ ui->minuteSpinBox->text().toInt() * 60
+ ui->secondSpinBox->text().toInt();
return sec;
}
int ChangeDateTime::isSaveTime()
{
return ui->checkBox_isSaveTime->isChecked();
}
bool ChangeDateTime::isSetChange()
{
return ui->radioButtonNewTime->isChecked();
}