Engauge Digitizer 2
Loading...
Searching...
No Matches
ViewProfileScale.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 "EngaugeAssert.h"
8#include "Logger.h"
9#include "ViewProfileScale.h"
10#include <QPainter>
11
13 QWidget *parent) :
14 QLabel (parent),
15 m_colorFilterMode (COLOR_FILTER_MODE_FOREGROUND)
16{
17 setMinimumWidth(minimumWidth);
18}
19
20void ViewProfileScale::paintEvent (QPaintEvent *event)
21{
22 switch (m_colorFilterMode) {
24 paintForeground ();
25 break;
26
28 paintHue ();
29 break;
30
32 paintIntensity ();
33 break;
34
36 paintSaturation ();
37 break;
38
40 paintValue ();
41 break;
42
43 default:
44 LOG4CPP_ERROR_S ((*mainCat)) << "ViewProfileScale::paintEvent unexpected color filter mode " << m_colorFilterMode;
45 ENGAUGE_ASSERT (false);
46 }
47
48 QLabel::paintEvent (event);
49}
50
51void ViewProfileScale::paintForeground ()
52{
53 if (qGray (m_rgbBackground) < 127) {
54 // Go from blackish to white
55 paintOneSpectrum (QColor (m_rgbBackground), QColor (Qt::white));
56 } else {
57 // Go from whitish to black
58 paintOneSpectrum (QColor (m_rgbBackground), QColor (Qt::black));
59 }
60}
61
62void ViewProfileScale::paintHue ()
63{
64 // Create two spectrums:
65 // 1) one spectrum from red to green
66 // 2) another from green to blue
67 QLinearGradient gradient (QPointF (0.0,
68 height() / 2.0),
69 QPointF (width (),
70 height () / 2.0));
71 gradient.setColorAt (0.0000, Qt::red);
72 gradient.setColorAt (0.3333, Qt::green);
73 gradient.setColorAt (0.6666, Qt::blue);
74 gradient.setColorAt (1.0000, Qt::red);
75
76 QPainter painter (this);
77 painter.setPen (Qt::NoPen);
78
79 QBrush brush (gradient);
80
81 painter.setBrush (brush);
82 painter.drawRect (0,
83 0,
84 rect().width (),
85 rect().height ());
86}
87
88void ViewProfileScale::paintIntensity ()
89{
90 paintOneSpectrum (QColor (Qt::black), QColor (Qt::white));
91}
92
93void ViewProfileScale::paintOneSpectrum (const QColor &colorStart,
94 const QColor &colorStop)
95{
96 QLinearGradient gradient (QPointF (0.0,
97 height() / 2.0),
98 QPointF (width (),
99 height () / 2.0));
100 gradient.setColorAt (0, colorStart);
101 gradient.setColorAt (1, colorStop);
102
103 QPainter painter (this);
104 painter.setPen (Qt::NoPen);
105
106 QBrush brush (gradient);
107
108 painter.setBrush (brush);
109 painter.drawRect (0,
110 0,
111 rect().width (),
112 rect().height ());
113}
114
115void ViewProfileScale::paintSaturation ()
116{
117 paintOneSpectrum (QColor (Qt::white), QColor (Qt::red));
118}
119
120void ViewProfileScale::paintValue ()
121{
122 paintOneSpectrum (QColor (Qt::black), QColor (Qt::red));
123}
124
126{
127 m_rgbBackground = rgbBackground;
128}
129
131{
132 m_colorFilterMode = colorFilterMode;
133 update ();
134}
ColorFilterMode
@ COLOR_FILTER_MODE_FOREGROUND
@ COLOR_FILTER_MODE_VALUE
@ COLOR_FILTER_MODE_INTENSITY
@ COLOR_FILTER_MODE_SATURATION
@ COLOR_FILTER_MODE_HUE
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Definition Logger.cpp:14
ViewProfileScale(int minimumWidth, QWidget *parent=0)
Single constructor.
void setBackgroundColor(QRgb rgbBackground)
Save the background color for foreground calculations.
virtual void paintEvent(QPaintEvent *)
Draw the gradient.
void setColorFilterMode(ColorFilterMode colorFilterMode)
Change the gradient type.
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12