All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColorBar.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2011 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 "../widgets/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  void setColorBar(te::color::ColorBar* cb);
131 
132  /*!
133  \brief It sets the precision of mouse click.
134 
135  \param double precision of click.
136  */
137 
138  void setClickPrecision(double precision);
139 
140  /*!
141  \brief It returns the colorbar.
142 
143  \return Current color bar.
144  */
145  te::color::ColorBar* getColorBar();
146 
147  //@}
148 
149  protected:
150  /** @name Private methods
151  * Methods used to manange colors and events.
152  */
153  //@{
154 
155  /*!
156  \brief Sets the transformation and the scale of colorbar values.
157  */
158  void setScaleEngine();
159 
160  /*!
161  \brief It build and paint the colorbar.
162  */
163  void buildColorBar();
164 
165  /*!
166  \brief It returns the pin based on mouse click and the click precision
167 
168  \param pos Mouse click X on toolbar
169 
170  \return Pin found or -1, if not found.
171  */
172  double getPin(int pos);
173 
174  /*!
175  \brief It convert a mouse position to a toolbar position
176 
177  \param pos Mouse click X on toolbar
178 
179  \return Toolbar position
180  */
181  double convert2toolbarPos(int pos);
182 
183  /*!
184  \brief Inherit of QEvent, receive events to paint e update widgets.
185 
186  \param QPaintEvent
187  */
188  virtual void paintEvent(QPaintEvent* e);
189 
190  /*!
191  \brief It waits a pressEvent from mouse to do something.
192 
193  \param QMouseEvent
194  \note In this case, it treat the remove colorStops funciontion
195  \note and sets the start position to move stops.
196  */
197  virtual void mousePressEvent(QMouseEvent* e);
198 
199  /*!
200  \brief It waits a releaseEvent from mouse to do something.
201 
202  \param QMouseEvent
203  \note In this case, it treat the finalization of move colorStops.
204  */
205  virtual void mouseReleaseEvent(QMouseEvent* e);
206 
207  /*!
208  \brief It waits a moveEvent from mouse to do something.
209 
210  \param QMouseEvent
211  \note In this case, it treat the moce of colorStops.
212  */
213  virtual void mouseMoveEvent(QMouseEvent* e);
214 
215  /*!
216  \brief It waits the wheel from mouse to do something.
217 
218  \param QWheelEvent
219  \note In this case, it change the color lightness.
220  */
221  virtual void wheelEvent(QWheelEvent* e);
222 
223  //@}
224 
225  protected slots:
226 
227  /*!
228  \brief It add a colorbar pin.
229  */
230  void addPin();
231 
232  /*!
233  \brief It remove a colorbar pin.
234  */
235  void removePin();
236 
237  /*!
238  \brief It edit a colorbar pin.
239  */
240  void editPin();
241 
242  /*!
243  \brief It changes the pins positions for an equal distribution.
244  */
245  void equalStep();
246 
247  signals:
248 
249  void colorBarChanged();
250 
251 
252  protected:
253 
254  te::color::ColorBar* m_colorBar; //!< Color map information
255 
256  QwtInterval m_interval; //!< Color vector.
257 
258  int m_height; //!< Height of colobar.
259 
260  double m_initialXPos; //!< Position initial to move color.
261 
262  double m_clickPrecision; //!< Precision of click to get a color stop.
263 
264  double m_currentPinPos; //!< Value of the current Pin position.
265 
266  QMenu* m_colorBarMenu; //!< Popup menu for Pin on color bar.
267 
268  QMenu* m_pinMenu; //!< Popup menu for Pin on color bar.
269 
270  te::qt::widgets::ColorPickerToolButton* m_colorBarPicker; //!< Color picker for colorbar menu.
271 
272  te::qt::widgets::ColorPickerToolButton* m_pinPicker; //!< Color picker for pin menu.
273 
274  QWidgetAction* m_addPinAction; //!< Add Pin Action
275 
276  QWidgetAction* m_editPinAction; //!< Edit Pin Action
277 
278  QAction* m_removePinAction; //!< Remove Pin Action
279 
280  QAction* m_equalStepAction; //!< Equal Step Pin Action
281 
282  };
283  } // end namespace qwt
284  }
285  } // end namespace qt
286 }
287 #endif // __TERRALIB_QT_QWT_INTERNAL_COLORBAR_H_
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:101
te::qt::widgets::ColorPickerToolButton * m_pinPicker
Color picker for pin menu.
Definition: ColorBar.h:272
QWidgetAction * m_addPinAction
Add Pin Action.
Definition: ColorBar.h:274
It QWidget implementation of color bar.
Definition: ColorBar.h:67
te::color::ColorBar * m_colorBar
Color map information.
Definition: ColorBar.h:254
double m_initialXPos
Position initial to move color.
Definition: ColorBar.h:260
QAction * m_equalStepAction
Equal Step Pin Action.
Definition: ColorBar.h:280
QMenu * m_colorBarMenu
Popup menu for Pin on color bar.
Definition: ColorBar.h:266
double m_clickPrecision
Precision of click to get a color stop.
Definition: ColorBar.h:262
QMenu * m_pinMenu
Popup menu for Pin on color bar.
Definition: ColorBar.h:268
int m_height
Height of colobar.
Definition: ColorBar.h:258
te::qt::widgets::ColorPickerToolButton * m_colorBarPicker
Color picker for colorbar menu.
Definition: ColorBar.h:270
QwtInterval m_interval
Color vector.
Definition: ColorBar.h:256
QWidgetAction * m_editPinAction
Edit Pin Action.
Definition: ColorBar.h:276
Custom tool button used to pick a color.
QAction * m_removePinAction
Remove Pin Action.
Definition: ColorBar.h:278
double m_currentPinPos
Value of the current Pin position.
Definition: ColorBar.h:264