-
Notifications
You must be signed in to change notification settings - Fork 0
/
DigitalClock.cpp
43 lines (36 loc) · 1020 Bytes
/
DigitalClock.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
#include "DigitalClock.h"
const char DAYS_OF_WEEK[7][4] =
{"Man", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
DigitalClock::DigitalClock(QWidget* parent)
: QDialog(parent)
{
label = new QLabel(tr("") );
updateClock();
QPalette palette = label->palette();
palette.setColor(QPalette::WindowText, QColor("#000000"));
label->setPalette(palette);
layout = new QHBoxLayout;
layout->addWidget(label);
setLayout(layout);
timer = new QTimer( this );
connect(timer, SIGNAL(timeout()),
this, SLOT(updateClock()) );
timer->start(1000);
}
DigitalClock::~DigitalClock()
{
delete layout;
delete timer;
delete label;
}
void DigitalClock::updateClock()
{
char str[30];
sprintf(str, "%s\n%s %s"
, QDate::currentDate().toString("yyyy/MM/dd").toStdString().c_str()
, QTime::currentTime().toString("hh:mm").toStdString().c_str()
, DAYS_OF_WEEK[QDate::currentDate().dayOfWeek() - 1]
);
label->setText(str);
}
//Copyright (C) 2013 OHTA Yuusuke