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 "ViewProfileScale.h"
9#include <QPainter>
10
18
20{
21 switch (m_colorFilterMode) {
23 paintForeground ();
24 break;
25
27 paintHue ();
28 break;
29
31 paintIntensity ();
32 break;
33
35 paintSaturation ();
36 break;
37
39 paintValue ();
40 break;
41
42 default:
43 ENGAUGE_ASSERT (false);
44 }
45
46 QLabel::paintEvent (event);
47}
48
49void ViewProfileScale::paintForeground ()
50{
51 if (qGray (m_rgbBackground) < 127) {
52 // Go from blackish to white
53 paintOneSpectrum (QColor (m_rgbBackground), QColor (Qt::white));
54 } else {
55 // Go from whitish to black
56 paintOneSpectrum (QColor (m_rgbBackground), QColor (Qt::black));
57 }
58}
59
60void ViewProfileScale::paintHue ()
61{
62 // Create two spectrums:
63 // 1) one spectrum from red to green
64 // 2) another from green to blue
66 height() / 2.0),
67 QPointF (width (),
68 height () / 2.0));
69 gradient.setColorAt (0.0000, Qt::red);
70 gradient.setColorAt (0.3333, Qt::green);
71 gradient.setColorAt (0.6666, Qt::blue);
72 gradient.setColorAt (1.0000, Qt::red);
73
74 QPainter painter (this);
75 painter.setPen (Qt::NoPen);
76
77 QBrush brush (gradient);
78
79 painter.setBrush (brush);
80 painter.drawRect (0,
81 0,
82 rect().width (),
83 rect().height ());
84}
85
86void ViewProfileScale::paintIntensity ()
87{
88 paintOneSpectrum (QColor (Qt::black), QColor (Qt::white));
89}
90
91void ViewProfileScale::paintOneSpectrum (const QColor &colorStart,
92 const QColor &colorStop)
93{
95 height() / 2.0),
96 QPointF (width (),
97 height () / 2.0));
98 gradient.setColorAt (0, colorStart);
99 gradient.setColorAt (1, colorStop);
100
101 QPainter painter (this);
102 painter.setPen (Qt::NoPen);
103
104 QBrush brush (gradient);
105
106 painter.setBrush (brush);
107 painter.drawRect (0,
108 0,
109 rect().width (),
110 rect().height ());
111}
112
113void ViewProfileScale::paintSaturation ()
114{
115 paintOneSpectrum (QColor (Qt::white), QColor (Qt::red));
116}
117
118void ViewProfileScale::paintValue ()
119{
120 paintOneSpectrum (QColor (Qt::black), QColor (Qt::red));
121}
122
127
129{
130 m_colorFilterMode = colorFilterMode;
131 update ();
132}
ColorFilterMode
@ COLOR_FILTER_MODE_FOREGROUND
@ COLOR_FILTER_MODE_VALUE
@ COLOR_FILTER_MODE_INTENSITY
@ COLOR_FILTER_MODE_SATURATION
@ COLOR_FILTER_MODE_HUE
const int INNER_RADIUS_MIN
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
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.