Repository navigation
Expand file tree
/
Copy pathCircle.cpp
More file actions
107 lines (95 loc) · 2.44 KB
/
Copy pathCircle.cpp
File metadata and controls
107 lines (95 loc) · 2.44 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
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
107
#include "wplot/Circle.h"
#include "wplot/Plot2D.h"
#include <QPainter>
namespace WPlot {
///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION //
///////////////////////////////////////////////////////////////////////////////
Circle::Circle() :
Item2D(),
m_radius(1.0),
m_fillColor(Qt::white),
m_lineColor(Qt::black),
m_lineStyle(Qt::SolidLine),
m_lineWidth(1.0)
{
m_pen.setColor(m_lineColor);
m_pen.setWidthF(m_lineWidth);
m_pen.setStyle(m_lineStyle);
m_brush.setColor(m_fillColor);
m_brush.setStyle(Qt::SolidPattern);
}
/**
* Set circle radius.
*
* @param[in] radius Radius.
*/
void Circle::setRadius(const double &radius) {
m_radius = radius;
}
/**
* Set the color of the circumference.
*
* @param[in] color Color.
*/
void Circle::setLineColor(const QColor &color) {
m_lineColor = color;
m_pen.setColor(color);
}
/**
* @brief Circle::setFillColor
* @param color
*/
void Circle::setFillColor(const QColor &color) {
m_fillColor = color;
m_brush.setColor(color);
}
/**
* Set the width of circunference line in pixels.
*
* @param[in] width Width.
*/
void Circle::setLineWidth(const double &width) {
m_lineWidth = width;
m_pen.setWidthF(width);
}
/**
* Set the style of circunference line.
*
* @param[in] style Style.
*/
void Circle::setLineStyle(const Qt::PenStyle &style) {
m_lineStyle = style;
m_pen.setStyle(style);
}
///////////////////////////////////////////////////////////////////////////////
// VIRTUAL PUBLIC SECTION //
///////////////////////////////////////////////////////////////////////////////
/**
* Set the item color.
*
* It's an implementation of pure virtual method of base class used when in the
* Item2D the color is needed.
*
* @param[in] color Color.
*/
void Circle::setColor(const QColor &color) {
setFillColor(color);
}
/**
* Draw the circle in specified plot.
*
* @param[in] plot Plot where circle must be drawn.
*/
void Circle::draw(Plot2D *plot) {
QPainter painter(plot);
plot->initializePainter(painter);
limitPainterInPaddingArea(painter, plot);
painter.setPen(m_pen);
painter.setBrush(m_brush);
const QPointF center = getScaledPosition(m_pivot, plot);
const double radiusX = getScaledDimensionX(m_radius, plot);
const double radiusY = getScaledDimensionY(m_radius, plot);
painter.drawEllipse(center, radiusX, radiusY);
}
} // namespace WPlot