-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyScene.cpp
More file actions
51 lines (40 loc) · 1.46 KB
/
myScene.cpp
File metadata and controls
51 lines (40 loc) · 1.46 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
#include "myScene.h"
#include <QGraphicsItem>
#include <QtCore>
myScene::myScene(QObject *parent) : QGraphicsScene(parent), GMT(0)
{
QImage clockImage("clock.png")
, hourImage("hourHand.png")
, minuteImage("minuteHand.png");
QGraphicsPixmapItem *clockFace = new QGraphicsPixmapItem(QPixmap::fromImage(clockImage))
, *hour = new QGraphicsPixmapItem(QPixmap::fromImage(hourImage))
, *minute = new QGraphicsPixmapItem(QPixmap::fromImage(minuteImage));
QTime time = QTime::currentTime();
hourHand = hour;
minuteHand = minute;
clockFace->setScale(0.3);
addItem(clockFace);
hourHand->setScale(0.3);
hourHand->setTransformOriginPoint(53, 397);
hourHand->setPos(142, -200);
hourHand->setRotation(30.0 * ((time.hour() + time.minute() / 60.0)) - GMT);
addItem(hourHand);
minuteHand->setTransformOriginPoint(43, 521);
minuteHand->setScale(0.3);
minuteHand->setPos(151, -326);
minuteHand->setRotation(6.0 * (time.minute() + time.second() / 60.0));
addItem(minuteHand);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(changeTime()));
timer->start(1000);
}
void myScene::changeGMT()
{
GMT = abs(GMT - 90);
}
void myScene::changeTime()
{
QTime time = QTime::currentTime();
hourHand->setRotation(30.0 * ((time.hour() + time.minute() / 60.0)) - GMT);
minuteHand->setRotation(6.0 * (time.minute() + time.second() / 60.0));
}