All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RectItem.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _RECT_ITEM_HH_
19 #define _RECT_ITEM_HH_
20 
21 #include <vector>
22 #include "gazebo/gui/qt.h"
24 #include "gazebo/util/system.hh"
25 
26 namespace gazebo
27 {
28  namespace gui
29  {
30  class GrabberHandle;
31  class RotateHandle;
32  class EditorItem;
33 
36 
39  class GAZEBO_VISIBLE RectItem : public EditorItem, public QGraphicsRectItem
40  {
41  Q_OBJECT
42 
44  public: enum ResizeFlags {NONE = 0x00,
45  ITEM_WIDTH = 0x01, ITEM_HEIGHT = 0x02};
46 
48  public: RectItem();
49 
51  public: virtual ~RectItem();
52 
55  public: void SetWidth(int _width);
56 
59  public: void SetHeight(int _height);
60 
63  public: void SetSize(QSize _size);
64 
67  public: double GetWidth() const;
68 
71  public: double GetHeight() const;
72 
75  public: void ShowHandles(bool _show);
76 
79  protected: void UpdateCornerPositions();
80 
83  protected: void DrawBoundingBox(QPainter *_painter);
84 
87  public: virtual void SetPosition(const QPointF &_pos);
88 
92  public: virtual void SetPosition(double _x, double _y);
93 
96  public: virtual void SetRotation(double _angle);
97 
101  public: virtual void SetResizeFlag(unsigned int _flag);
102 
105  public: virtual double GetRotation() const;
106 
107  // Documentation inherited
108  public: virtual QVector3D GetSize() const;
109 
110  // Documentation inherited
111  public: virtual QVector3D GetScenePosition() const;
112 
113  // Documentation inherited
114  public: virtual double GetSceneRotation() const;
115 
118  protected: virtual QRectF boundingRect() const;
119 
123  private: virtual bool RotateEventFilter(RotateHandle *_rotateHandle,
124  QEvent *_event);
125 
129  private: virtual bool GrabberEventFilter(GrabberHandle *_grabber,
130  QEvent *_event);
131 
136  private: virtual void paint(QPainter *_painter,
137  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
138 
141  private: void hoverEnterEvent(QGraphicsSceneHoverEvent *_event);
142 
145  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
146 
149  private: void hoverLeaveEvent(QGraphicsSceneHoverEvent *_event);
150 
153  private: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *_event);
154 
157  private: virtual void mousePressEvent(QGraphicsSceneMouseEvent *_event);
158 
161  private: virtual void mouseReleaseEvent(
162  QGraphicsSceneMouseEvent *_event);
163 
166  private: virtual void mousePressEvent(
167  QGraphicsSceneDragDropEvent *_event);
168 
171  private: virtual void mouseMoveEvent(
172  QGraphicsSceneDragDropEvent *_event);
173 
176  private: virtual void mouseDoubleClickEvent(
177  QGraphicsSceneMouseEvent *_event);
178 
182  private: virtual bool sceneEventFilter(QGraphicsItem *_watched,
183  QEvent *_event);
184 
189  private: QVariant itemChange(GraphicsItemChange _change,
190  const QVariant &_value);
191 
194  private: virtual void contextMenuEvent(
195  QGraphicsSceneContextMenuEvent *_event);
196 
198  private: virtual void SizeChanged();
199 
203  private: void AdjustSize(double _x, double _y);
204 
206  private slots: virtual void OnOpenInspector();
207 
209  private slots: virtual void OnDeleteItem();
210 
212  protected: double width;
213 
215  protected: double height;
216 
218  protected: double drawingWidth;
219 
221  protected: double drawingHeight;
222 
224  protected: double drawingOriginX;
225 
227  protected: double drawingOriginY;
228 
230  protected: QColor borderColor;
231 
233  protected: double rotationAngle;
234 
236  protected: int zValueIdle;
237 
239  protected: QAction *openInspectorAct;
240 
242  protected: QAction *deleteItemAct;
243 
245  private: QPointF mousePressPos;
246 
248  private: int gridSpace;
249 
252  private: std::vector<GrabberHandle *> grabbers;
253 
255  private: RotateHandle *rotateHandle;
256 
259  private: std::vector<Qt::CursorShape> cursors;
260 
262  private: int zValueSelected;
263 
265  private: unsigned int resizeFlag;
266  };
268  }
269 }
270 
271 #endif
QAction * deleteItemAct
Qt action for deleting the item.
Definition: RectItem.hh:242
double drawingHeight
Actual height of rect item drawn in pixels.
Definition: RectItem.hh:221
QColor borderColor
Border color of the rect item.
Definition: RectItem.hh:230
double rotationAngle
Rotation angle of the rect item in degrees.
Definition: RectItem.hh:233
Base class of an item in the editor.
Definition: EditorItem.hh:34
ResizeFlags
Resize flags used to indicate which dimension can be resized.
Definition: RectItem.hh:44
2D rectangle.
Definition: RectItem.hh:39
double drawingOriginX
X origin of the rect item in pixels.
Definition: RectItem.hh:224
double drawingWidth
Actual width of rect item drawn in pixels.
Definition: RectItem.hh:218
Handle for rotating an editor item.
Definition: RotateHandle.hh:33
int zValueIdle
Z ordering of the rect item when idle (unselected.)
Definition: RectItem.hh:236
Definition: GrabberHandle.hh:28
double drawingOriginY
Y origin of the rect item in pixels.
Definition: RectItem.hh:227
double width
Width of rect item in pixels.
Definition: RectItem.hh:212
double height
Height of rect item in pixels.
Definition: RectItem.hh:215
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
QAction * openInspectorAct
Qt action for opening the inspector.
Definition: RectItem.hh:239