4 #include "../../color.h"
5 #include "../../color/ColorBar.h"
6 #include "../../color/ColorTransform.h"
7 #include "../widgets/utils/ColorPickerToolButton.h"
10 #include <QtGui/QPainter>
11 #include <QtGui/qevent.h>
12 #include <QtGui/QColorDialog>
13 #include <QtGui/qmenu.h>
14 #include <QtGui/qaction.h>
15 #include <QtGui/qwidgetaction.h>
18 #include <qwt_color_map.h>
19 #include <qwt_interval.h>
20 #include <qwt_scale_engine.h>
37 this->setColorBarEnabled(
true);
47 setMouseTracking(
true);
85 this->scaleDraw()->enableComponent(QwtScaleDraw::Backbone, flag);
86 this->scaleDraw()->enableComponent(QwtScaleDraw::Ticks, flag);
87 this->scaleDraw()->enableComponent(QwtScaleDraw::Labels, flag);
94 this->setColorBarWidth(m_height);
99 m_interval.setMinValue(min);
100 m_interval.setMaxValue(max);
119 QwtLinearScaleEngine se;
120 this->setScaleDiv(se.divideScale(m_interval.minValue(), m_interval.maxValue(), 8, 5));
125 m_clickPrecision = precision;
130 if(m_colorBar && m_colorBar->getColorMap().size() >= 2)
133 std::map<double, te::color::RGBAColor> map = m_colorBar->getColorMap();
136 QwtLinearColorMap* colormap =
new QwtLinearColorMap(
137 QColor(map[0.].getRed(), map[0.].getGreen(), map[0.].getBlue(), map[0.].getAlpha()),
138 QColor(map[1.].getRed(), map[1.].getGreen(), map[1.].getBlue(), map[1.].getAlpha()));
140 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
142 while(it != m_colorBar->getColorMap().end())
144 double pos = it->first;
146 if(pos != 0. && pos != 1.)
148 QColor c(it->second.getRed(), it->second.getGreen(), it->second.getBlue());
150 colormap->addColorStop(pos, c);
156 this->setColorMap(m_interval, colormap);
158 emit colorBarChanged();
164 if(m_currentPinPos != 0 && m_currentPinPos != 1)
165 m_colorBar->remove(m_currentPinPos);
173 QColor c = m_pinPicker->getColor();
176 m_colorBar->changeColor(m_currentPinPos, rgbaC);
184 QColor c = m_colorBarPicker->getColor();
187 m_colorBar->addColor(rgbaC, m_currentPinPos);
189 m_colorBarMenu->hide();
197 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
199 std::map<double, double> newpos = std::map<double, double>();
201 int numPins = m_colorBar->getColorMap().size();
203 int increment = (int)this->width() / (numPins-1);
206 while(it != m_colorBar->getColorMap().end())
208 if(it->first != 0 && it->first != 1)
210 pinCount == 0 ? pinCount = 2:
true;
211 newpos[it->first] = convert2toolbarPos((pinCount-1)*increment);
217 std::map<double, double>::const_iterator it2 = newpos.begin();
218 while(it2 != newpos.end())
220 m_colorBar->move(it2->first, it2->second);
230 QwtScaleWidget::paintEvent(e);
236 p.setPen(QPen(Qt::black));
238 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
240 while(it != m_colorBar->getColorMap().end())
242 double pos = it->first * this->width();
244 int r = it->second.getRed();
245 int g = it->second.getGreen();
246 int b = it->second.getBlue();
247 int a = it->second.getAlpha();
249 p.drawLine(QPoint(pos, 0 + 2), QPoint(pos, m_height + 2));
250 p.setBrush(QBrush(QColor(r, g, b, a)));
251 p.drawEllipse(QPoint(pos, 0 + 2), 2, 2);
262 double pos = convert2toolbarPos(e->x());
263 double pinPos = getPin(e->x());
265 if(e->button() == Qt::RightButton)
270 m_currentPinPos = pinPos;
274 m_pinMenu->exec(QCursor::pos());
278 m_currentPinPos = pos;
279 m_colorBarMenu->exec(QCursor::pos());
284 if (e->button() == Qt::LeftButton)
286 m_initialXPos = pinPos;
293 if (e->button() == Qt::LeftButton)
301 double currentPos = convert2toolbarPos(e->x());
303 if(getPin(e->x()) != -1)
304 setCursor(Qt::SplitHCursor);
306 setCursor(Qt::PointingHandCursor);
308 if(m_initialXPos > -1)
310 m_colorBar->move(m_initialXPos, currentPos);
312 m_initialXPos = currentPos;
322 double pin = getPin(e->x());
333 c.
getHsl(&hh, &ss, &ll, &a);
342 qc.
getHsl(&h, &s, &l, &a);
354 m_colorBar->changeColor(pin, cor);
364 double width = this->width();
365 double currentPos = (double) pos / width;
367 std::map<double, te::color::RGBAColor>::const_iterator it = m_colorBar->getColorMap().begin();
371 while(it != m_colorBar->getColorMap().end())
373 double colorPos = it->first;
375 if ( colorPos > (currentPos - m_clickPrecision) && colorPos < (currentPos + m_clickPrecision))
377 currentPos = colorPos;
392 double width = this->width();
393 double currentPos = (double) pos / width;
It models the concept of color bar.
te::qt::widgets::ColorPickerToolButton * m_pinPicker
Color picker for pin menu.
QWidgetAction * m_addPinAction
Add Pin Action.
virtual void mouseReleaseEvent(QMouseEvent *e)
It waits a releaseEvent from mouse to do something.
int getRed() const
It returns the red component.
void addPin()
It add a colorbar pin.
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
virtual void paintEvent(QPaintEvent *e)
Inherit of QEvent, receive events to paint e update widgets.
void setClickPrecision(double precision)
It sets the precision of mouse click.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
virtual void mouseMoveEvent(QMouseEvent *e)
It waits a moveEvent from mouse to do something.
double convert2toolbarPos(int pos)
It convert a mouse position to a toolbar position.
double m_initialXPos
Position initial to move color.
void editPin()
It edit a colorbar pin.
void buildColorBar()
It build and paint the colorbar.
ColorBar(QWidget *parent=0)
It initializes a new ColorBar.
virtual void wheelEvent(QWheelEvent *e)
It waits the wheel from mouse to do something.
QAction * m_equalStepAction
Equal Step Pin Action.
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color.
void equalStep()
It changes the pins positions for an equal distribution.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
int getBlue() const
It returns the blue component.
QMenu * m_colorBarMenu
Popup menu for Pin on color bar.
int getGreen() const
It returns the green component.
void setColorBar(te::color::ColorBar *cb)
It sets the color bar.
void setInterval(double min, double max)
It sets the min e max value of colorbar.
void setHeight(int value)
Sets the height of colobar.
void getHsl(int *h, int *s, int *l, int *a=0) const
It gets the h, s, l components of this color.
void setHsl(int h, int s, int l, int a=255)
It sets the h, s, l components of this color.
QMenu * m_pinMenu
Popup menu for Pin on color bar.
te::qt::widgets::ColorPickerToolButton * m_colorBarPicker
Color picker for colorbar menu.
void setScaleEngine()
Sets the transformation and the scale of colorbar values.
int getAlpha() const
It returns the alpha component.
te::color::ColorBar * getColorBar()
It returns the colorbar.
double getPin(int pos)
It returns the pin based on mouse click and the click precision.
QwtInterval m_interval
Color vector.
QWidgetAction * m_editPinAction
Edit Pin Action.
Custom tool button used to pick a color.
void removePin()
It remove a colorbar pin.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
void setScaleVisible(bool flag)
Sets scale of color bar visibility.
QAction * m_removePinAction
Remove Pin Action.
virtual void mousePressEvent(QMouseEvent *e)
It waits a pressEvent from mouse to do something.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
int getRed() const
It returns the red component color value (a value from 0 to 255).
A class to transform RGBA color to HSV, HSL and CMYK.