00001
00002
00003
00004
00005
00006
00007 #include "EngaugeAssert.h"
00008 #include "ViewProfileScale.h"
00009 #include <QPainter>
00010
00011 ViewProfileScale::ViewProfileScale(int minimumWidth,
00012 QWidget *parent) :
00013 QLabel (parent),
00014 m_colorFilterMode (COLOR_FILTER_MODE_FOREGROUND)
00015 {
00016 setMinimumWidth(minimumWidth);
00017 }
00018
00019 void ViewProfileScale::paintEvent (QPaintEvent *event)
00020 {
00021 switch (m_colorFilterMode) {
00022 case COLOR_FILTER_MODE_FOREGROUND:
00023 paintForeground ();
00024 break;
00025
00026 case COLOR_FILTER_MODE_HUE:
00027 paintHue ();
00028 break;
00029
00030 case COLOR_FILTER_MODE_INTENSITY:
00031 paintIntensity ();
00032 break;
00033
00034 case COLOR_FILTER_MODE_SATURATION:
00035 paintSaturation ();
00036 break;
00037
00038 case COLOR_FILTER_MODE_VALUE:
00039 paintValue ();
00040 break;
00041
00042 default:
00043 ENGAUGE_ASSERT (false);
00044 }
00045
00046 QLabel::paintEvent (event);
00047 }
00048
00049 void ViewProfileScale::paintForeground ()
00050 {
00051 if (qGray (m_rgbBackground) < 127) {
00052
00053 paintOneSpectrum (QColor (m_rgbBackground), QColor (Qt::white));
00054 } else {
00055
00056 paintOneSpectrum (QColor (m_rgbBackground), QColor (Qt::black));
00057 }
00058 }
00059
00060 void ViewProfileScale::paintHue ()
00061 {
00062
00063
00064
00065 QLinearGradient gradient (QPointF (0.0,
00066 height() / 2.0),
00067 QPointF (width (),
00068 height () / 2.0));
00069 gradient.setColorAt (0.0000, Qt::red);
00070 gradient.setColorAt (0.3333, Qt::green);
00071 gradient.setColorAt (0.6666, Qt::blue);
00072 gradient.setColorAt (1.0000, Qt::red);
00073
00074 QPainter painter (this);
00075 painter.setPen (Qt::NoPen);
00076
00077 QBrush brush (gradient);
00078
00079 painter.setBrush (brush);
00080 painter.drawRect (0,
00081 0,
00082 rect().width (),
00083 rect().height ());
00084 }
00085
00086 void ViewProfileScale::paintIntensity ()
00087 {
00088 paintOneSpectrum (QColor (Qt::black), QColor (Qt::white));
00089 }
00090
00091 void ViewProfileScale::paintOneSpectrum (const QColor &colorStart,
00092 const QColor &colorStop)
00093 {
00094 QLinearGradient gradient (QPointF (0.0,
00095 height() / 2.0),
00096 QPointF (width (),
00097 height () / 2.0));
00098 gradient.setColorAt (0, colorStart);
00099 gradient.setColorAt (1, colorStop);
00100
00101 QPainter painter (this);
00102 painter.setPen (Qt::NoPen);
00103
00104 QBrush brush (gradient);
00105
00106 painter.setBrush (brush);
00107 painter.drawRect (0,
00108 0,
00109 rect().width (),
00110 rect().height ());
00111 }
00112
00113 void ViewProfileScale::paintSaturation ()
00114 {
00115 paintOneSpectrum (QColor (Qt::white), QColor (Qt::red));
00116 }
00117
00118 void ViewProfileScale::paintValue ()
00119 {
00120 paintOneSpectrum (QColor (Qt::black), QColor (Qt::red));
00121 }
00122
00123 void ViewProfileScale::setBackgroundColor (QRgb rgbBackground)
00124 {
00125 m_rgbBackground = rgbBackground;
00126 }
00127
00128 void ViewProfileScale::setColorFilterMode (ColorFilterMode colorFilterMode)
00129 {
00130 m_colorFilterMode = colorFilterMode;
00131 update ();
00132 }