OpenWalnut  1.5.0dev
WTransferFunctionColorPoint.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WTRANSFERFUNCTIONCOLORPOINT_H
26 #define WTRANSFERFUNCTIONCOLORPOINT_H
27 
28 #include <QGraphicsItem>
29 #include <QGraphicsObject>
30 
31 #include "QMenu"
32 
34 
35 /**
36  * A control point for the color function.
37  *
38  * Internals:
39  * The point has links to its left and right neighbors (double-linked list).
40  */
42 {
43  Q_OBJECT
44 
45 public:
46  /** type of our base class */
48 
49  /**
50  * Default constructor.
51  *
52  * \param parent the parent widget
53  */
54  explicit WTransferFunctionColorPoint( WTransferFunctionWidget* parent = 0x0 );
55 
56  /**
57  * Default destructor
58  */
60 
61  /**
62  * Returns the item left of the this item.
63  *
64  * \returns the item left of us
65  */
67 
68  /**
69  * Returns the item right of this item.
70  *
71  * \returns the item right of us
72  */
74 
75  /**
76  * Set the item left of us.
77  *
78  * \param left the item left of us
79  */
81 
82  /**
83  * Set the item right of us.
84  *
85  * \param right the item right of us
86  */
88 
89  /**
90  * The bounding rectangle used for paint and click events.
91  *
92  * \returns the bounding rectangle
93  */
94  QRectF boundingRect() const;
95 
96  /**
97  * Paint the handle and additional item hints.
98  *
99  * \param painter the painter used
100  * \param option the paint options used
101  * \param widget the widget used for painting
102  */
103  virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget* widget = 0x0 );
104 
105  /** \returns the color of the entry */
106  QColor getColor() const;
107 
108  /**
109  * Drag enter implementation for items that contain a color.
110  *
111  * \param event the event to handle
112  */
113  virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* event );
114 
115  /**
116  * Drop implementation for items that contain a color.
117  *
118  * \param event the event to handle
119  */
120  virtual void dropEvent( QGraphicsSceneDragDropEvent* event );
121 
122  /**
123  * Handler for context menu envents. Currently disabled because it conflicts with other mouse interactions.
124  *
125  * \param event the event to hanlde
126  */
127  void contextMenuEvent( QGraphicsSceneContextMenuEvent* event );
128 
129 public slots:
130  /**
131  * Called by the color dialog every time the user changes the color.
132  *
133  * \param color the new color
134  */
135  void colorSelected( const QColor& color );
136 
137 protected:
138  /**
139  * Helper for item changed.
140  *
141  * \param rectangle a rectangle
142  */
143  void clampToRectangle( const QRectF& rectangle );
144 
145  /**
146  * Helper for item changed.
147  **/
148  void clampToLeftAndRight();
149 
150  /**
151  * Handles change notifications.
152  *
153  * \param change the requrested change
154  * \param value the requested value
155  * \returns the proposed value
156  */
157  QVariant itemChange( GraphicsItemChange change, const QVariant &value );
158 
159  /**
160  * Handles mouse move events.
161  *
162  * \param event the event
163  */
164  void mouseMoveEvent( QGraphicsSceneMouseEvent *event );
165 
166  /**
167  * Handles press move events.
168  *
169  * \param event the event
170  */
171  void mousePressEvent( QGraphicsSceneMouseEvent *event );
172 
173  /**
174  * Handles mouse move events.
175  *
176  * \param event the event
177  */
178  void mouseReleaseEvent( QGraphicsSceneMouseEvent *event );
179 
180  /**
181  * Handles mouse double click events by opening a color selector
182  * if the item is clicked.
183  *
184  * \param event the event
185  */
186  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event );
187 
188  /**
189  * Show the color picker dialog.
190  **/
191  void showColorPicker();
192 
193 private:
194  /** the radius used for paining of the handle */
195  double radius;
196 
197  /** the entry left of this entry */
199 
200  /** the entry to the right of our entry */
202 
203  /** the parent widget */
205 
206  /** the color entry */
207  QColor color;
208 };
209 
210 #endif // WTRANSFERFUNCTIONCOLORPOINT_H
211 
A control point for the color function.
void colorSelected(const QColor &color)
Called by the color dialog every time the user changes the color.
QGraphicsObject BaseClass
type of our base class
WTransferFunctionWidget * _parent
the parent widget
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Handles press move events.
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
Drop implementation for items that contain a color.
void clampToLeftAndRight()
Helper for item changed.
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Handles change notifications.
void setLeft(WTransferFunctionColorPoint *left)
Set the item left of us.
virtual ~WTransferFunctionColorPoint()
Default destructor.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
Handler for context menu envents.
void showColorPicker()
Show the color picker dialog.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0x0)
Paint the handle and additional item hints.
WTransferFunctionColorPoint * right
the entry to the right of our entry
void clampToRectangle(const QRectF &rectangle)
Helper for item changed.
WTransferFunctionColorPoint * getRight() const
Returns the item right of this item.
double radius
the radius used for paining of the handle
void setRight(WTransferFunctionColorPoint *right)
Set the item right of us.
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
Drag enter implementation for items that contain a color.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Handles mouse double click events by opening a color selector if the item is clicked.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Handles mouse move events.
WTransferFunctionColorPoint * getLeft() const
Returns the item left of the this item.
QRectF boundingRect() const
The bounding rectangle used for paint and click events.
WTransferFunctionColorPoint * left
the entry left of this entry
WTransferFunctionColorPoint(WTransferFunctionWidget *parent=0x0)
Default constructor.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Handles mouse move events.
A widget that holds a scene to display and modify the transfer function.