-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectioncontroller.cpp
87 lines (63 loc) · 2.62 KB
/
directioncontroller.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
79
80
81
82
83
84
85
86
87
#include "directioncontroller.h"
#include <QPainter>
#include <QSvgRenderer>
DirectionController::DirectionController(QWidget *parent) : QWidget(parent)
{
m_svgArrowDown = new QSvgRenderer(this);
m_svgArrowLeft = new QSvgRenderer(this);
m_svgArrowUp = new QSvgRenderer(this);
m_svgArrowRight = new QSvgRenderer(this);
m_svgHome = new QSvgRenderer(this);
m_svgArrowDown->load(QString(":/icons/arrowdown.svg"));
m_svgArrowLeft->load(QString(":/icons/arrowleft.svg"));
m_svgArrowUp->load(QString(":/icons/arrowup.svg"));
m_svgArrowRight->load(QString(":/icons/arrowright.svg"));
m_svgHome->load(QString(":/icons/home.svg"));
}
void DirectionController::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPen pen;
pen.setCapStyle(Qt::FlatCap);
pen.setColor(QColor("white"));
pen.setWidthF(1);
//painter.setPen(pen);
QRect rect = this->rect();
QPoint center = rect.center();
center.setX(MARGIN_LEFT+CIRCLE_DIAMETER/2);
int nCircle = CIRCLE_DIAMETER - CIRCLE_THICK;
QRect rect1(center.x()-nCircle/2,center.y()-nCircle/2,nCircle,nCircle);
pen.setWidthF(CIRCLE_THICK);
painter.setPen(pen);
int nStartAngle = 45;
while(nStartAngle<=360){
painter.drawArc(rect1,(nStartAngle+CIRCLE_OFFSET)*16,(90-CIRCLE_OFFSET)*16);
nStartAngle+=90;
}
pen.setWidthF(1);
painter.setPen(pen);
QRect rectBounding = QRect(center.x()-CIRCLE_DIAMETER/2,
center.y()-CIRCLE_DIAMETER/2,
CIRCLE_DIAMETER,
CIRCLE_DIAMETER);
//painter.drawRect(rectBounding);
m_svgHome->render(&painter,QRect(center.x()-12,center.y()-12,24,24));
m_svgArrowUp->render(&painter,
QRect(rectBounding.topLeft().x()+rectBounding.width()/2-12,
rectBounding.topLeft().y()+rectBounding.height()/10-12,
24,24));
m_svgArrowDown->render(&painter,
QRect(rectBounding.topLeft().x()+rectBounding.width()/2-12,
rectBounding.topLeft().y()+rectBounding.height()*9/10-12,
24,24));
m_svgArrowLeft->render(&painter,
QRect(rectBounding.topLeft().x()+rectBounding.width()/10-12,
rectBounding.topLeft().y()+rectBounding.height()/2-12,
24,24));
m_svgArrowRight->render(&painter,
QRect(rectBounding.topLeft().x()+rectBounding.width()*9/10-12,
rectBounding.topLeft().y()+rectBounding.height()/2-12,
24,24));
}