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 #include <ignition/math/Vector2.hh>
24 #include <ignition/math/Vector3.hh>
25 
26 #include "gazebo/common/Color.hh"
27 
28 #include "gazebo/gui/qt.h"
30 
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace gui
36  {
37  class GrabberHandle;
38  class MeasureItem;
39  class RotateHandle;
40 
41  // Forward declare private data.
42  class RectItemPrivate;
43 
46 
49  class GZ_GUI_VISIBLE RectItem :
50  public EditorItem, public QGraphicsRectItem
51  {
52  Q_OBJECT
53 
55  public: enum ResizeFlags
56  {
58  NONE = 0x00,
59 
61  ITEM_WIDTH = 0x01,
62 
64  ITEM_HEIGHT = 0x02
65  };
66 
68  public: RectItem();
69 
71  public: virtual ~RectItem();
72 
75  public: void SetWidth(const int _width);
76 
79  public: void SetHeight(const int _height);
80 
83  public: void SetSize(const ignition::math::Vector2i &_size);
84 
87  public: double Width() const;
88 
91  public: double Height() const;
92 
95  public: void SetPositionOnWall(const double _positionOnWall);
96 
99  public: double PositionOnWall() const;
100 
103  public: void SetAngleOnWall(const double _angleOnWall);
104 
107  public: double AngleOnWall() const;
108 
111  public: void ShowHandles(const bool _show);
112 
113  // Documentation inherited
114  public: void SetHighlighted(const bool _highlighted);
115 
117  public: void DetachFromParent();
118 
121  protected: void UpdateCornerPositions();
122 
125  protected: void DrawBoundingBox(QPainter *_painter);
126 
129  public: virtual void SetPosition(const ignition::math::Vector2d &_pos);
130 
134  public: virtual void SetPosition(const double _x, const double _y);
135 
138  public: virtual void SetRotation(const double _angle);
139 
143  public: virtual void SetResizeFlag(const unsigned int _flag);
144 
147  public: virtual double Rotation() const;
148 
149  // Documentation inherited
150  public: virtual ignition::math::Vector3d Size() const;
151 
152  // Documentation inherited
153  public: virtual ignition::math::Vector3d ScenePosition() const;
154 
155  // Documentation inherited
156  public: virtual double SceneRotation() const;
157 
160  protected: virtual QRectF boundingRect() const;
161 
163  protected: void UpdateMeasures();
164 
168  private: virtual bool RotateEventFilter(RotateHandle *_rotateHandle,
169  QEvent *_event);
170 
174  private: virtual bool GrabberEventFilter(GrabberHandle *_grabber,
175  QEvent *_event);
176 
181  private: virtual void paint(QPainter *_painter,
182  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
183 
186  private: void hoverEnterEvent(QGraphicsSceneHoverEvent *_event);
187 
190  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
191 
194  private: void hoverLeaveEvent(QGraphicsSceneHoverEvent *_event);
195 
198  private: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *_event);
199 
202  private: virtual void mousePressEvent(QGraphicsSceneMouseEvent *_event);
203 
206  private: virtual void mouseReleaseEvent(
207  QGraphicsSceneMouseEvent *_event);
208 
211  private: virtual void mousePressEvent(
212  QGraphicsSceneDragDropEvent *_event);
213 
216  private: virtual void mouseMoveEvent(
217  QGraphicsSceneDragDropEvent *_event);
218 
221  private: virtual void mouseDoubleClickEvent(
222  QGraphicsSceneMouseEvent *_event);
223 
227  private: virtual bool sceneEventFilter(QGraphicsItem *_watched,
228  QEvent *_event);
229 
234  private: QVariant itemChange(GraphicsItemChange _change,
235  const QVariant &_value);
236 
239  private: virtual void contextMenuEvent(
240  QGraphicsSceneContextMenuEvent *_event);
241 
243  private: virtual void SizeChanged();
244 
248  private: void AdjustSize(const double _x, const double _y);
249 
251  private slots: virtual void OnOpenInspector();
252 
254  private slots: virtual void OnDeleteItem();
255 
257  protected: double width;
258 
260  protected: double height;
261 
263  protected: double drawingWidth;
264 
266  protected: double drawingHeight;
267 
269  protected: double drawingOriginX;
270 
272  protected: double drawingOriginY;
273 
276 
278  protected: double rotationAngle;
279 
281  protected: QAction *openInspectorAct;
282 
284  protected: QAction *deleteItemAct;
285 
289  protected: std::vector<MeasureItem *> measures;
290 
293  private: std::unique_ptr<RectItemPrivate> dataPtr;
294  };
296  }
297 }
298 
299 #endif
ResizeFlags
Resize flags used to indicate which dimension can be resized.
Definition: RectItem.hh:55
Base class of an item in the editor.
Definition: EditorItem.hh:43
double drawingOriginY
Y origin of the rect item in pixels.
Definition: RectItem.hh:272
double height
Height of rect item in pixels.
Definition: RectItem.hh:260
2D rectangle.
Definition: RectItem.hh:49
QAction * openInspectorAct
Qt action for opening the inspector.
Definition: RectItem.hh:281
QAction * deleteItemAct
Qt action for deleting the item.
Definition: RectItem.hh:284
double drawingWidth
Actual width of rect item drawn in pixels.
Definition: RectItem.hh:263
common::Color borderColor
Border color of the rect item.
Definition: RectItem.hh:275
double width
Width of rect item in pixels.
Definition: RectItem.hh:257
double drawingHeight
Actual height of rect item drawn in pixels.
Definition: RectItem.hh:266
Handle for rotating an editor item.
Definition: RotateHandle.hh:40
std::vector< MeasureItem * > measures
A vector containing this item's measure items.
Definition: RectItem.hh:289
Defines a color.
Definition: Color.hh:36
double rotationAngle
Rotation angle of the rect item in degrees.
Definition: RectItem.hh:278
Definition: GrabberHandle.hh:42
double drawingOriginX
X origin of the rect item in pixels.
Definition: RectItem.hh:269