3
#include "worldtimeclock.h"
5
WorldTimeClock::WorldTimeClock(QWidget *parent)
10
QTimer *timer = new QTimer(this);
11
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
14
setWindowTitle(tr("World Time Clock"));
18
void WorldTimeClock::paintEvent(QPaintEvent *)
20
static const int hourHand[6] = { 7, 8, -7, 8, 0, -40 };
21
static const int minuteHand[6] = { 7, 8, -7, 8, 0, -70 };
22
QColor hourColor(127, 0, 127);
23
QColor minuteColor(0, 127, 127, 191);
25
int side = qMin(width(), height());
26
QTime time = QTime::currentTime();
27
time = time.addSecs(timeZoneOffset);
29
QPainter painter(this);
30
painter.setRenderHint(QPainter::Antialiasing);
31
painter.translate(width() / 2, height() / 2);
32
painter.scale(side / 200.0, side / 200.0);
34
painter.setPen(Qt::NoPen);
35
painter.setBrush(hourColor);
38
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
39
painter.drawConvexPolygon(QPolygon(3, hourHand));
42
painter.setPen(hourColor);
44
for (int i = 0; i < 12; ++i) {
45
painter.drawLine(88, 0, 96, 0);
49
painter.setPen(Qt::NoPen);
50
painter.setBrush(minuteColor);
53
painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
54
painter.drawConvexPolygon(QPolygon(3, minuteHand));
57
painter.setPen(minuteColor);
59
for (int j = 0; j < 60; ++j) {
61
painter.drawLine(92, 0, 96, 0);
68
void WorldTimeClock::setTimeZone(int hourOffset)
70
timeZoneOffset = qMin(qMax(-12, hourOffset), 12) * 3600;