ColorBar.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/qwt/ColorBar.h
22 
23  \brief The QWidget of color bar.
24 */
25 
26 #ifndef __TERRALIB_QT_QWT_INTERNAL_COLORBAR_H_
27 #define __TERRALIB_QT_QWT_INTERNAL_COLORBAR_H_
28 
29 //QWT
30 
31 #include <qwt_scale_widget.h>
32 
33 //STL
34 #include <map>
35 
36 //TerraLib
37 #include "../Config.h"
38 
39 class QMenu;
40 class QAction;
41 class QWidgetAction;
42 
43 namespace te
44 {
45  namespace color
46  {
47  class ColorBar;
48  }
49 
50  namespace qt
51  {
52  namespace widgets
53  {
54  class ColorPickerToolButton;
55 
56  namespace colorbar
57  {
58  /*!
59  \class ColorBar
60 
61  \brief It QWidget implementation of color bar.
62 
63  It is used to construct color bar.
64 
65  \ingroup widgets
66  */
67  class TEQTWIDGETSEXPORT ColorBar: public QwtScaleWidget
68  {
69 
70  Q_OBJECT
71 
72  public:
73 
74  /** @name Initializer Methods
75  * Methods related to instantiation and destruction.
76  */
77  //@{
78 
79  /*!
80  \brief It initializes a new ColorBar.
81 
82  \param parent
83  */
84 
85  ColorBar(QWidget* parent = 0);
86 
87  /*!
88  \brief Destructor */
89 
90  ~ColorBar();
91 
92  //@}
93 
94  public:
95 
96  /** @name Accessor methods
97  * Methods used to get or set properties.
98  */
99  //@{
100 
101  /*!
102  \brief Sets scale of color bar visibility.
103 
104  \param flag Boolean value to set the scale of color bar visibility.
105 
106  \note TRUE is the defaul behavior.
107  */
108  void setScaleVisible(bool flag);
109 
110  /*!
111  \brief Sets the height of colobar.
112 
113  \param Value of height.
114  */
115  void setHeight(int value);
116 
117  /*!
118  \brief It sets the min e max value of colorbar.
119 
120  \param Minimum value.
121  \param Maximum value.
122  */
123  void setInterval(double min, double max);
124 
125  /*!
126  \brief It sets the color bar.
127 
128  \param te::color::colorBar to paint in the colorbar.
129 
130  \note This class takes the ownership of the colorbar pointer.
131  */
132  void setColorBar(te::color::ColorBar* cb);
133 
134  /*!
135  \brief It sets the precision of mouse click.
136 
137  \param double precision of click.
138  */
139 
140  void setClickPrecision(double precision);
141 
142  /*!
143  \brief It returns the colorbar.
144 
145  \return Current color bar.
146  */
147  te::color::ColorBar* getColorBar();
148 
149  //@}
150 
151  protected:
152  /** @name Private methods
153  * Methods used to manange colors and events.
154  */
155  //@{
156 
157  /*!
158  \brief Sets the transformation and the scale of colorbar values.
159  */
160  void setScaleEngine();
161 
162  /*!
163  \brief It build and paint the colorbar.
164  */
165  void buildColorBar();
166 
167  /*!
168  \brief It returns the pin based on mouse click and the click precision
169 
170  \param pos Mouse click X on toolbar
171 
172  \return Pin found or -1, if not found.
173  */
174  double getPin(int pos);
175 
176  /*!
177  \brief It convert a mouse position to a toolbar position
178 
179  \param pos Mouse click X on toolbar
180 
181  \return Toolbar position
182  */
183  double convert2toolbarPos(int pos);
184 
185  /*!
186  \brief Inherit of QEvent, receive events to paint e update widgets.
187 
188  \param QPaintEvent
189  */
190  virtual void paintEvent(QPaintEvent* e);
191 
192  /*!
193  \brief It waits a pressEvent from mouse to do something.
194 
195  \param QMouseEvent
196  \note In this case, it treat the remove colorStops funciontion
197  \note and sets the start position to move stops.
198  */
199  virtual void mousePressEvent(QMouseEvent* e);
200 
201  /*!
202  \brief It waits a releaseEvent from mouse to do something.
203 
204  \param QMouseEvent
205  \note In this case, it treat the finalization of move colorStops.
206  */
207  virtual void mouseReleaseEvent(QMouseEvent* e);
208 
209  /*!
210  \brief It waits a moveEvent from mouse to do something.
211 
212  \param QMouseEvent
213  \note In this case, it treat the moce of colorStops.
214  */
215  virtual void mouseMoveEvent(QMouseEvent* e);
216 
217  /*!
218  \brief It waits the wheel from mouse to do something.
219 
220  \param QWheelEvent
221  \note In this case, it change the color lightness.
222  */
223  virtual void wheelEvent(QWheelEvent* e);
224 
225  //@}
226 
227  protected slots:
228 
229  /*!
230  \brief It add a colorbar pin.
231  */
232  void addPin();
233 
234  /*!
235  \brief It remove a colorbar pin.
236  */
237  void removePin();
238 
239  /*!
240  \brief It edit a colorbar pin.
241  */
242  void editPin();
243 
244  /*!
245  \brief It changes the pins positions for an equal distribution.
246  */
247  void equalStep();
248 
249  signals:
250 
251  void colorBarChanged();
252 
253 
254  protected:
255 
256  te::color::ColorBar* m_colorBar; //!< Color map information
257 
258  QwtInterval m_interval; //!< Color vector.
259 
260  int m_height; //!< Height of colobar.
261 
262  double m_initialXPos; //!< Position initial to move color.
263 
264  double m_clickPrecision; //!< Precision of click to get a color stop.
265 
266  double m_currentPinPos; //!< Value of the current Pin position.
267 
268  QMenu* m_colorBarMenu; //!< Popup menu for Pin on color bar.
269 
270  QMenu* m_pinMenu; //!< Popup menu for Pin on color bar.
271 
272  te::qt::widgets::ColorPickerToolButton* m_colorBarPicker; //!< Color picker for colorbar menu.
273 
274  te::qt::widgets::ColorPickerToolButton* m_pinPicker; //!< Color picker for pin menu.
275 
276  QWidgetAction* m_addPinAction; //!< Add Pin Action
277 
278  QWidgetAction* m_editPinAction; //!< Edit Pin Action
279 
280  QAction* m_removePinAction; //!< Remove Pin Action
281 
282  QAction* m_equalStepAction; //!< Equal Step Pin Action
283 
284  };
285  } // end namespace qwt
286  }
287  } // end namespace qt
288 }
289 #endif // __TERRALIB_QT_QWT_INTERNAL_COLORBAR_H_
te::color::ColorBar * m_colorBar
Color map information.
Definition: ColorBar.h:256
QMenu * m_pinMenu
Popup menu for Pin on color bar.
Definition: ColorBar.h:270
QWidgetAction * m_addPinAction
Add Pin Action.
Definition: ColorBar.h:276
QAction * m_removePinAction
Remove Pin Action.
Definition: ColorBar.h:280
int m_height
Height of colobar.
Definition: ColorBar.h:260
te::qt::widgets::ColorPickerToolButton * m_colorBarPicker
Color picker for colorbar menu.
Definition: ColorBar.h:272
QwtInterval m_interval
Color vector.
Definition: ColorBar.h:258
Custom tool button used to pick a color.
URI C++ Library.
QMenu * m_colorBarMenu
Popup menu for Pin on color bar.
Definition: ColorBar.h:268
It QWidget implementation of color bar.
Definition: ColorBar.h:67
double m_clickPrecision
Precision of click to get a color stop.
Definition: ColorBar.h:264
te::qt::widgets::ColorPickerToolButton * m_pinPicker
Color picker for pin menu.
Definition: ColorBar.h:274
double m_initialXPos
Position initial to move color.
Definition: ColorBar.h:262
QAction * m_equalStepAction
Equal Step Pin Action.
Definition: ColorBar.h:282
double m_currentPinPos
Value of the current Pin position.
Definition: ColorBar.h:266
It models the concept of color bar.
Definition: ColorBar.h:49
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
QWidgetAction * m_editPinAction
Edit Pin Action.
Definition: ColorBar.h:278