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