RectItem.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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"
25 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace gui
30  {
31  class GrabberHandle;
32  class RotateHandle;
33  class EditorItem;
34 
37 
41  public EditorItem, public QGraphicsRectItem
42  {
43  Q_OBJECT
44 
46  public: enum ResizeFlags {NONE = 0x00,
47  ITEM_WIDTH = 0x01, ITEM_HEIGHT = 0x02};
48 
50  public: RectItem();
51 
53  public: virtual ~RectItem();
54 
57  public: void SetWidth(int _width);
58 
61  public: void SetHeight(int _height);
62 
65  public: void SetSize(QSize _size);
66 
69  public: double GetWidth() const;
70 
73  public: double GetHeight() const;
74 
77  public: void SetPositionOnWall(double _positionOnWall);
78 
81  public: double GetPositionOnWall() const;
82 
85  public: void SetAngleOnWall(double _angleOnWall);
86 
89  public: double GetAngleOnWall() const;
90 
93  public: void ShowHandles(bool _show);
94 
95  // Documentation inherited
96  public: void SetHighlighted(bool _highlighted);
97 
100  protected: void UpdateCornerPositions();
101 
104  protected: void DrawBoundingBox(QPainter *_painter);
105 
108  public: virtual void SetPosition(const QPointF &_pos);
109 
113  public: virtual void SetPosition(double _x, double _y);
114 
117  public: virtual void SetRotation(double _angle);
118 
122  public: virtual void SetResizeFlag(unsigned int _flag);
123 
126  public: virtual double GetRotation() const;
127 
128  // Documentation inherited
129  public: virtual QVector3D GetSize() const;
130 
131  // Documentation inherited
132  public: virtual QVector3D GetScenePosition() const;
133 
134  // Documentation inherited
135  public: virtual double GetSceneRotation() const;
136 
139  protected: virtual QRectF boundingRect() const;
140 
142  protected: void UpdateMeasures();
143 
147  private: virtual bool RotateEventFilter(RotateHandle *_rotateHandle,
148  QEvent *_event);
149 
153  private: virtual bool GrabberEventFilter(GrabberHandle *_grabber,
154  QEvent *_event);
155 
160  private: virtual void paint(QPainter *_painter,
161  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
162 
165  private: void hoverEnterEvent(QGraphicsSceneHoverEvent *_event);
166 
169  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
170 
173  private: void hoverLeaveEvent(QGraphicsSceneHoverEvent *_event);
174 
177  private: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *_event);
178 
181  private: virtual void mousePressEvent(QGraphicsSceneMouseEvent *_event);
182 
185  private: virtual void mouseReleaseEvent(
186  QGraphicsSceneMouseEvent *_event);
187 
190  private: virtual void mousePressEvent(
191  QGraphicsSceneDragDropEvent *_event);
192 
195  private: virtual void mouseMoveEvent(
196  QGraphicsSceneDragDropEvent *_event);
197 
200  private: virtual void mouseDoubleClickEvent(
201  QGraphicsSceneMouseEvent *_event);
202 
206  private: virtual bool sceneEventFilter(QGraphicsItem *_watched,
207  QEvent *_event);
208 
213  private: QVariant itemChange(GraphicsItemChange _change,
214  const QVariant &_value);
215 
218  private: virtual void contextMenuEvent(
219  QGraphicsSceneContextMenuEvent *_event);
220 
222  private: virtual void SizeChanged();
223 
227  private: void AdjustSize(double _x, double _y);
228 
230  private slots: virtual void OnOpenInspector();
231 
233  private slots: virtual void OnDeleteItem();
234 
236  protected: double width;
237 
239  protected: double height;
240 
242  protected: double drawingWidth;
243 
245  protected: double drawingHeight;
246 
248  protected: double drawingOriginX;
249 
251  protected: double drawingOriginY;
252 
254  protected: QColor borderColor;
255 
257  protected: double rotationAngle;
258 
260  protected: QAction *openInspectorAct;
261 
263  protected: QAction *deleteItemAct;
264 
268  protected: std::vector<MeasureItem *> measures;
269 
271  private: QPointF mousePressPos;
272 
274  private: int gridSpace;
275 
278  private: std::vector<GrabberHandle *> grabbers;
279 
281  private: RotateHandle *rotateHandle;
282 
285  private: std::vector<Qt::CursorShape> cursors;
286 
288  private: unsigned int resizeFlag;
289 
292  private: double positionOnWall;
293 
295  private: double angleOnWall;
296  };
298  }
299 }
300 
301 #endif
QAction * deleteItemAct
Qt action for deleting the item.
Definition: RectItem.hh:263
double drawingHeight
Actual height of rect item drawn in pixels.
Definition: RectItem.hh:245
QColor borderColor
Border color of the rect item.
Definition: RectItem.hh:254
double rotationAngle
Rotation angle of the rect item in degrees.
Definition: RectItem.hh:257
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:46
2D rectangle.
Definition: RectItem.hh:40
double drawingOriginX
X origin of the rect item in pixels.
Definition: RectItem.hh:248
double drawingWidth
Actual width of rect item drawn in pixels.
Definition: RectItem.hh:242
std::vector< MeasureItem * > measures
A vector containing this item's measure items.
Definition: RectItem.hh:268
Handle for rotating an editor item.
Definition: RotateHandle.hh:33
Definition: GrabberHandle.hh:29
#define GZ_GUI_BUILDING_VISIBLE
Definition: system.hh:393
double drawingOriginY
Y origin of the rect item in pixels.
Definition: RectItem.hh:251
double width
Width of rect item in pixels.
Definition: RectItem.hh:236
double height
Height of rect item in pixels.
Definition: RectItem.hh:239
QAction * openInspectorAct
Qt action for opening the inspector.
Definition: RectItem.hh:260