Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
View
ViewPointStyle.cpp
Go to the documentation of this file.
1
/******************************************************************************************************
2
* (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3
* under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4
* LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5
******************************************************************************************************/
6
7
#include "
EnumsToQt.h
"
8
#include "
Logger.h
"
9
#include <QPainter>
10
#include "
ViewPointStyle.h
"
11
12
// Use solid background since transparency approach never worked, even with an alpha channel
13
const
QColor
COLOR_FOR_BRUSH_ENABLED
(Qt::white);
14
const
QColor
COLOR_FOR_BRUSH_DISABLED
(Qt::gray);
15
16
ViewPointStyle::ViewPointStyle
(QWidget *parent) :
17
QLabel (parent),
18
m_enabled (false)
19
{
20
// Note the size is set externally by the layout engine
21
}
22
23
QPixmap ViewPointStyle::pixmapForCurrentSettings ()
const
24
{
25
qCInfo(ENGAUGE_LOG) <<
"ViewPointStyle::pixmapForCurrentSettings"
;
26
27
// Polygon that is sized for the main drawing window.
28
QPolygonF polygonUnscaled = m_pointStyle.
polygon
();
29
30
// Resize polygon to fit icon, by builiding a new scaled polygon from the unscaled polygon
31
double
xMinGot = polygonUnscaled.boundingRect().left();
32
double
xMaxGot = polygonUnscaled.boundingRect().right();
33
double
yMinGot = polygonUnscaled.boundingRect().top();
34
double
yMaxGot = polygonUnscaled.boundingRect().bottom();
35
36
QPolygonF polygonScaled;
37
for
(
int
i = 0; i < polygonUnscaled.length(); i++) {
38
QPointF pOld = polygonUnscaled.at(i);
39
polygonScaled.append (QPointF ((width () - 1) * (pOld.x() - xMinGot) / (xMaxGot - xMinGot),
40
(height () - 1) * (pOld.y() - yMinGot) / (yMaxGot - yMinGot)));
41
}
42
43
// Color
44
QColor color =
ColorPaletteToQColor
(m_pointStyle.paletteColor());
45
if
(!m_enabled) {
46
color = QColor (Qt::black);
47
}
48
49
// Image for drawing
50
QImage img (width (),
51
height (),
52
QImage::Format_RGB32);
53
QPainter painter (&img);
54
55
painter.fillRect (0,
56
0,
57
width (),
58
height (),
59
QBrush (m_enabled ?
COLOR_FOR_BRUSH_ENABLED
:
COLOR_FOR_BRUSH_DISABLED
));
60
61
if
(m_enabled) {
62
painter.setPen (QPen (color, m_pointStyle.lineWidth()));
63
painter.drawPolygon (polygonScaled);
64
}
65
66
// Create pixmap from image
67
QPixmap pixmap = QPixmap::fromImage (img);
68
69
return
pixmap;
70
}
71
72
void
ViewPointStyle::setEnabled
(
bool
enabled)
73
{
74
qCInfo(ENGAUGE_LOG) <<
"ViewPointStyle::setEnabled"
75
<<
" enabled="
<< (enabled ?
"true"
:
"false"
);
76
77
m_enabled = enabled;
78
setPixmap (pixmapForCurrentSettings ());
79
}
80
81
void
ViewPointStyle::setPointStyle
(
const
PointStyle
&pointStyle)
82
{
83
qCInfo(ENGAUGE_LOG) <<
"ViewPointStyle::setPointStyle"
;
84
85
m_pointStyle = pointStyle;
86
setPixmap (pixmapForCurrentSettings ());
87
}
88
89
void
ViewPointStyle::unsetPointStyle
()
90
{
91
qCInfo(ENGAUGE_LOG) <<
"ViewPointStyle::unsetPointStyle"
;
92
93
QPixmap pEmpty (width (),
94
height ());
95
pEmpty.fill (
COLOR_FOR_BRUSH_DISABLED
);
96
97
setPixmap (pEmpty);
98
}
ColorPaletteToQColor
QColor ColorPaletteToQColor(ColorPalette color)
Definition
EnumsToQt.cpp:16
EnumsToQt.h
Logger.h
COLOR_FOR_BRUSH_DISABLED
const QColor COLOR_FOR_BRUSH_DISABLED(Qt::gray)
COLOR_FOR_BRUSH_ENABLED
const QColor COLOR_FOR_BRUSH_ENABLED(Qt::white)
ViewPointStyle.h
PointStyle
Details for a specific Point.
Definition
PointStyle.h:21
PointStyle::polygon
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius.
Definition
PointStyle.cpp:158
ViewPointStyle::ViewPointStyle
ViewPointStyle(QWidget *parent=0)
Single constructor.
Definition
ViewPointStyle.cpp:16
ViewPointStyle::unsetPointStyle
void unsetPointStyle()
Apply no PointStyle.
Definition
ViewPointStyle.cpp:89
ViewPointStyle::setPointStyle
void setPointStyle(const PointStyle &pointStyle)
Apply the PointStyle of the currently selected curve.
Definition
ViewPointStyle.cpp:81
ViewPointStyle::setEnabled
void setEnabled(bool enabled)
Show the style with semi-transparency or full-transparency to indicate if associated Curve is active ...
Definition
ViewPointStyle.cpp:72
Generated on
for Engauge Digitizer by
1.17.0