4 #include "../../../color.h"
5 #include "../../../color/ColorBar.h"
6 #include "../../../color/ColorTransform.h"
7 #include "../utils/ColorPickerToolButton.h"
15 #include <QColorDialog>
19 #include <QWidgetAction>
22 #include <qwt_color_map.h>
23 #include <qwt_interval.h>
24 #include <qwt_scale_engine.h>
39 this->setColorBarEnabled(
true);
49 setMouseTracking(
true);
88 this->scaleDraw()->enableComponent(QwtScaleDraw::Backbone, flag);
89 this->scaleDraw()->enableComponent(QwtScaleDraw::Ticks, flag);
90 this->scaleDraw()->enableComponent(QwtScaleDraw::Labels, flag);
97 this->setColorBarWidth(m_height);
102 m_interval.setMinValue(min);
103 m_interval.setMaxValue(max);
124 QwtLinearScaleEngine se;
125 this->setScaleDiv(se.divideScale(m_interval.minValue(), m_interval.maxValue(), 8, 5));
130 m_clickPrecision = precision;
135 if(m_colorBar && m_colorBar->getColorMap().size() >= 2)
138 std::map<double, te::color::RGBAColor> map = m_colorBar->getColorMap();
141 QwtLinearColorMap* colormap =
new QwtLinearColorMap(
142 QColor(map[0.].getRed(), map[0.].getGreen(), map[0.].getBlue(), map[0.].getAlpha()),
143 QColor(map[1.].getRed(), map[1.].getGreen(), map[1.].getBlue(), map[1.].getAlpha()));
145 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
147 while(it != m_colorBar->getColorMap().end())
149 double pos = it->first;
151 if(pos != 0. && pos != 1.)
153 QColor c(it->second.getRed(), it->second.getGreen(), it->second.getBlue());
155 colormap->addColorStop(pos, c);
161 this->setColorMap(m_interval, colormap);
163 emit colorBarChanged();
169 if(m_currentPinPos != 0 && m_currentPinPos != 1)
170 m_colorBar->remove(m_currentPinPos);
178 QColor c = m_pinPicker->getColor();
181 m_colorBar->changeColor(m_currentPinPos, rgbaC);
189 QColor c = m_colorBarPicker->getColor();
192 m_colorBar->addColor(rgbaC, m_currentPinPos);
194 m_colorBarMenu->hide();
202 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
204 std::map<double, double> newpos = std::map<double, double>();
206 int numPins = m_colorBar->getColorMap().size();
208 int increment = (int)this->width() / (numPins-1);
211 while(it != m_colorBar->getColorMap().end())
213 if(it->first != 0 && it->first != 1)
215 pinCount == 0 ? pinCount = 2:
true;
216 newpos[it->first] = convert2toolbarPos((pinCount-1)*increment);
222 std::map<double, double>::const_iterator it2 = newpos.begin();
223 while(it2 != newpos.end())
225 m_colorBar->move(it2->first, it2->second);
235 QwtScaleWidget::paintEvent(e);
241 p.setPen(QPen(Qt::black));
243 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
245 while(it != m_colorBar->getColorMap().end())
247 double pos = it->first * this->width();
249 int r = it->second.getRed();
250 int g = it->second.getGreen();
251 int b = it->second.getBlue();
252 int a = it->second.getAlpha();
254 p.drawLine(QPoint(pos, 0 + 2), QPoint(pos, m_height + 2));
255 p.setBrush(QBrush(QColor(r, g, b, a)));
256 p.drawEllipse(QPoint(pos, 0 + 2), 2, 2);
267 double pos = convert2toolbarPos(e->x());
268 double pinPos = getPin(e->x());
270 if(e->button() == Qt::RightButton)
275 m_currentPinPos = pinPos;
280 QColor c(red, green, blue);
281 m_pinPicker->setColor(c);
282 m_pinMenu->exec(QCursor::pos());
286 m_currentPinPos = pos;
287 m_colorBarMenu->exec(QCursor::pos());
292 if (e->button() == Qt::LeftButton)
294 m_initialXPos = pinPos;
301 if (e->button() == Qt::LeftButton)
309 double currentPos = convert2toolbarPos(e->x());
311 if(getPin(e->x()) != -1)
312 setCursor(Qt::SplitHCursor);
314 setCursor(Qt::PointingHandCursor);
316 if(m_initialXPos > -1)
318 m_colorBar->move(m_initialXPos, currentPos);
320 m_initialXPos = currentPos;
330 double pin = getPin(e->x());
341 c.
getHsl(&hh, &ss, &ll, &a);
350 qc.
getHsl(&h, &s, &l, &a);
362 m_colorBar->changeColor(pin, cor);
372 double width = this->width();
373 double currentPos = (double) pos / width;
375 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
379 while(it != m_colorBar->getColorMap().end())
381 double colorPos = it->first;
383 if ( colorPos > (currentPos - m_clickPrecision) && colorPos < (currentPos + m_clickPrecision))
385 currentPos = colorPos;
400 double width = this->width();
401 double currentPos = (double) pos / width;
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
int getRed() const
It returns the red component color value (a value from 0 to 255).
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
int getGreen() const
It returns the green component color value (a value from 0 to 255).
The concept of color bar.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
It models the concept of color bar.