RectItem.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 _GAZEBO_GUI_BUILDING_RECTITEM_HH_
19 #define _GAZEBO_GUI_BUILDING_RECTITEM_HH_
20 
21 #include <memory>
22 #include <vector>
23 
24 #include "gazebo/gui/qt.h"
26 
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace gui
32  {
33  class GrabberHandle;
34  class MeasureItem;
35  class RotateHandle;
36 
37  // Forward declare private data.
38  class RectItemPrivate;
39 
42 
46  public EditorItem, public QGraphicsRectItem
47  {
48  Q_OBJECT
49 
51  public: enum ResizeFlags
52  {
54  NONE = 0x00,
55 
57  ITEM_WIDTH = 0x01,
58 
60  ITEM_HEIGHT = 0x02
61  };
62 
64  public: RectItem();
65 
67  public: virtual ~RectItem();
68 
71  public: void SetWidth(int _width);
72 
75  public: void SetHeight(int _height);
76 
79  public: void SetSize(QSize _size);
80 
83  public: double GetWidth() const;
84 
87  public: double GetHeight() const;
88 
91  public: void SetPositionOnWall(double _positionOnWall);
92 
95  public: double GetPositionOnWall() const;
96 
99  public: void SetAngleOnWall(double _angleOnWall);
100 
103  public: double GetAngleOnWall() const;
104 
107  public: void ShowHandles(bool _show);
108 
109  // Documentation inherited
110  public: void SetHighlighted(bool _highlighted);
111 
113  public: void DetachFromParent();
114 
117  protected: void UpdateCornerPositions();
118 
121  protected: void DrawBoundingBox(QPainter *_painter);
122 
125  public: virtual void SetPosition(const QPointF &_pos);
126 
130  public: virtual void SetPosition(double _x, double _y);
131 
134  public: virtual void SetRotation(double _angle);
135 
139  public: virtual void SetResizeFlag(unsigned int _flag);
140 
143  public: virtual double GetRotation() const;
144 
145  // Documentation inherited
146  public: virtual QVector3D GetSize() const;
147 
148  // Documentation inherited
149  public: virtual QVector3D GetScenePosition() const;
150 
151  // Documentation inherited
152  public: virtual double GetSceneRotation() const;
153 
156  protected: virtual QRectF boundingRect() const;
157 
159  protected: void UpdateMeasures();
160 
164  private: virtual bool RotateEventFilter(RotateHandle *_rotateHandle,
165  QEvent *_event);
166 
170  private: virtual bool GrabberEventFilter(GrabberHandle *_grabber,
171  QEvent *_event);
172 
177  private: virtual void paint(QPainter *_painter,
178  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
179 
182  private: void hoverEnterEvent(QGraphicsSceneHoverEvent *_event);
183 
186  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
187 
190  private: void hoverLeaveEvent(QGraphicsSceneHoverEvent *_event);
191 
194  private: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *_event);
195 
198  private: virtual void mousePressEvent(QGraphicsSceneMouseEvent *_event);
199 
202  private: virtual void mouseReleaseEvent(
203  QGraphicsSceneMouseEvent *_event);
204 
207  private: virtual void mousePressEvent(
208  QGraphicsSceneDragDropEvent *_event);
209 
212  private: virtual void mouseMoveEvent(
213  QGraphicsSceneDragDropEvent *_event);
214 
217  private: virtual void mouseDoubleClickEvent(
218  QGraphicsSceneMouseEvent *_event);
219 
223  private: virtual bool sceneEventFilter(QGraphicsItem *_watched,
224  QEvent *_event);
225 
230  private: QVariant itemChange(GraphicsItemChange _change,
231  const QVariant &_value);
232 
235  private: virtual void contextMenuEvent(
236  QGraphicsSceneContextMenuEvent *_event);
237 
239  private: virtual void SizeChanged();
240 
244  private: void AdjustSize(double _x, double _y);
245 
247  private slots: virtual void OnOpenInspector();
248 
250  private slots: virtual void OnDeleteItem();
251 
253  protected: double width;
254 
256  protected: double height;
257 
259  protected: double drawingWidth;
260 
262  protected: double drawingHeight;
263 
265  protected: double drawingOriginX;
266 
268  protected: double drawingOriginY;
269 
271  protected: QColor borderColor;
272 
274  protected: double rotationAngle;
275 
277  protected: QAction *openInspectorAct;
278 
280  protected: QAction *deleteItemAct;
281 
285  protected: std::vector<MeasureItem *> measures;
286 
289  private: std::unique_ptr<RectItemPrivate> dataPtr;
290  };
292  }
293 }
294 
295 #endif
QAction * deleteItemAct
Qt action for deleting the item.
Definition: RectItem.hh:280
double drawingHeight
Actual height of rect item drawn in pixels.
Definition: RectItem.hh:262
QColor borderColor
Border color of the rect item.
Definition: RectItem.hh:271
double rotationAngle
Rotation angle of the rect item in degrees.
Definition: RectItem.hh:274
Base class of an item in the editor.
Definition: EditorItem.hh:40
ResizeFlags
Resize flags used to indicate which dimension can be resized.
Definition: RectItem.hh:51
#define GZ_GUI_VISIBLE
Definition: system.hh:284
2D rectangle.
Definition: RectItem.hh:45
double drawingOriginX
X origin of the rect item in pixels.
Definition: RectItem.hh:265
double drawingWidth
Actual width of rect item drawn in pixels.
Definition: RectItem.hh:259
std::vector< MeasureItem * > measures
A vector containing this item's measure items.
Definition: RectItem.hh:285
Handle for rotating an editor item.
Definition: RotateHandle.hh:40
Definition: GrabberHandle.hh:42
double drawingOriginY
Y origin of the rect item in pixels.
Definition: RectItem.hh:268
double width
Width of rect item in pixels.
Definition: RectItem.hh:253
double height
Height of rect item in pixels.
Definition: RectItem.hh:256
QAction * openInspectorAct
Qt action for opening the inspector.
Definition: RectItem.hh:277