Engauge Digitizer 2
Loading...
Searching...
No Matches
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
15
17 QLabel (parent),
18 m_enabled (false)
19{
20 // Note the size is set externally by the layout engine
21}
22
23QPixmap ViewPointStyle::pixmapForCurrentSettings () const
24{
25 LOG4CPP_INFO_S ((*mainCat)) << "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
37 for (int i = 0; i < polygonUnscaled.length(); 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);
54
55 painter.fillRect (0,
56 0,
57 width (),
58 height (),
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
73{
74 LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::setEnabled"
75 << " enabled=" << (enabled ? "true" : "false");
76
77 m_enabled = enabled;
78 setPixmap (pixmapForCurrentSettings ());
79}
80
82{
83 LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::setPointStyle";
84
85 m_pointStyle = pointStyle;
86 setPixmap (pixmapForCurrentSettings ());
87}
88
90{
91 LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::unsetPointStyle";
92
93 QPixmap pEmpty (width (),
94 height ());
96
97 setPixmap (pEmpty);
98}
const int INNER_RADIUS_MIN
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:15
log4cpp::Category * mainCat
Definition Logger.cpp:14
const QColor COLOR_FOR_BRUSH_DISABLED(Qt::gray)
const QColor COLOR_FOR_BRUSH_ENABLED(Qt::white)
Details for a specific Point.
Definition PointStyle.h:21
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius.
ColorPalette paletteColor() const
Get method for point color.
int lineWidth() const
Get method for line width.
ViewPointStyle(QWidget *parent=0)
Single constructor.
void unsetPointStyle()
Apply no PointStyle.
void setPointStyle(const PointStyle &pointStyle)
Apply the PointStyle of the currently selected curve.
void setEnabled(bool enabled)
Show the style with semi-transparency or full-transparency to indicate if associated Curve is active ...
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18