-
Notifications
You must be signed in to change notification settings - Fork 9
/
myaroundcircle.cpp
106 lines (82 loc) · 2.69 KB
/
myaroundcircle.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "myaroundcircle.h"
myAroundCircle::myAroundCircle(QWidget *parent) :
QWidget(parent)
{
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(10);
connect(m_updateTimer,SIGNAL(timeout()),this,SLOT(UpdateAngle()));
m_updateTimer->start();
m_angle = 0;
m_outerRadius = 0;
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
}
void myAroundCircle::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing|QPainter::HighQualityAntialiasing);
drawUnderCircle(&painter);
drawBMW(&painter);
}
void myAroundCircle::drawUnderCircle(QPainter *painter)
{
painter->save();
m_outerRadius = width() > height() ? (qreal)height()/2 : (qreal)width()/2;
QPointF TopLeft(rect().center().x() - m_outerRadius,rect().center().y() - m_outerRadius);
QPointF BottomRight(rect().center().x() + m_outerRadius,rect().center().y() + m_outerRadius);
QRectF CircleRect(TopLeft,BottomRight);
painter->setPen(Qt::NoPen);
QRadialGradient CircleGradient(CircleRect.center(),m_outerRadius,CircleRect.center());
CircleGradient.setColorAt(0.0,PYB_OUTER_CIRCLE_START_COLOR);
CircleGradient.setColorAt(1.0,PYB_OUTER_CIRCLE_END_COLOR);
painter->setBrush(CircleGradient);
painter->drawEllipse(CircleRect);
painter->restore();
}
void myAroundCircle::drawBMW(QPainter *painter)
{
// move to center
// painter->translate(rect().center());
painter->save();
// setup transform
QTransform t;
t.translate(rect().center().x(),rect().center().y());
t.rotate(m_angle,Qt::ZAxis);
painter->setTransform(t);
qreal InnerRadius = m_outerRadius * PYB_RADIUS_FACTOR;
QPointF tTopLeft( -InnerRadius,-InnerRadius);
QPointF tBottomRight(InnerRadius,InnerRadius);
QRectF tRect(tTopLeft,tBottomRight);
qreal dAngle = 90 * 16;
qreal StartAngle = 0;
painter->setPen(Qt::NoPen);
for(int AngleIndex = 0; AngleIndex < 4;AngleIndex++)
{
if(AngleIndex%2)
{
QRadialGradient PieGradient(tRect.center(),m_outerRadius,tRect.center());
PieGradient.setColorAt(0.0,PYB_BLUE_CIRCLE_START_COLOR);
PieGradient.setColorAt(1.0,PYB_BLUE_CIRCLE_END_COLOR);
painter->setBrush(PieGradient);
}else{
QRadialGradient PieGradient(tRect.center(),m_outerRadius,tRect.center());
PieGradient.setColorAt(0.0,PYB_WHITE_CIRCLE_START_COLOR);
PieGradient.setColorAt(1.0,PYB_WHITE_CIRCLE_END_COLOR);
painter->setBrush(PieGradient);
}
painter->drawPie(tRect,StartAngle,dAngle);
/// increment StartAngle
StartAngle += dAngle;
}
painter->restore();
//
}
void myAroundCircle::UpdateAngle()
{
m_angle += 1;
if(m_angle > 360)
{
m_angle = 0;
}
update();
}