Repository navigation
Expand file tree
/
Copy pathBackground.cpp
More file actions
96 lines (82 loc) · 2.11 KB
/
Copy pathBackground.cpp
File metadata and controls
96 lines (82 loc) · 2.11 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
#include "wplot/Background.h"
#include "wplot/Plot.h"
namespace WPlot {
///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION //
///////////////////////////////////////////////////////////////////////////////
Background::Background() :
Layer(),
m_color(),
m_gradient(),
m_type(FLAT)
{}
/**
* Set the color that must be used with flat color.
*
* @param[in] color Color.
*/
void Background::setColor(const QColor &color) {
m_color = color;
m_type = Background::FLAT;
}
/**
* Set the gradient that must be used with gradient mode.
*
* @param[in] gradient Gradient.
*/
void Background::setGradient(const QGradient &gradient) {
m_gradient = gradient;
m_type = Background::GRADIENT;
}
/**
* Fills the widget with the background.
*
* @param[inout] plot Plot that should be filled.
*/
void Background::draw(Plot *plot) {
switch (m_type) {
case FLAT : {
drawFlatBackground(plot);
} break;
case GRADIENT : {
drawGradientBackground(plot);
} break;
default : {
drawFlatBackground(plot);
}
}
}
QColor Background::getColor() const {
return m_color;
}
QGradient Background::getGradient() const {
return m_gradient;
}
Background::Type Background::getType() const {
return m_type;
}
//////////////////////////////////////////////////////////////////////////////
// PRIVATE SECTION //
//////////////////////////////////////////////////////////////////////////////
/**
* Fills the widget with a flat background.
*
* @param[inout] plot Plot.
*/
void Background::drawFlatBackground(Plot *plot) {
plot->setAutoFillBackground(true);
QPalette plotPalette(plot->palette());
plotPalette.setColor(QPalette::Background, m_color);
plot->setPalette(plotPalette);
}
/**
* Fills the widget with the gradient background.
*
* @param[inout] plot Plot.
*/
void Background::drawGradientBackground(Plot *plot) {
QPalette plotPalette(plot->palette());
plotPalette.setBrush(QPalette::Window, *(new QBrush(m_gradient)));
plot->setPalette(plotPalette);
}
} // namespace WPlot