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 
40  class GAZEBO_VISIBLE RectItem : public EditorItem, public QGraphicsRectItem
41  {
42  Q_OBJECT
43 
45  public: enum ResizeFlags {NONE = 0x00,
46  ITEM_WIDTH = 0x01, ITEM_HEIGHT = 0x02};
47 
49  public: RectItem();
50 
52  public: virtual ~RectItem();
53 
56  public: void SetWidth(int _width);
57 
60  public: void SetHeight(int _height);
61 
64  public: void SetSize(QSize _size);
65 
68  public: double GetWidth() const;
69 
72  public: double GetHeight() const;
73 
76  public: void SetPositionOnWall(double _positionOnWall);
77 
80  public: double GetPositionOnWall() const;
81 
84  public: void SetAngleOnWall(double _angleOnWall);
85 
88  public: double GetAngleOnWall() const;
89 
92  public: void ShowHandles(bool _show);
93 
94  // Documentation inherited
95  public: void SetHighlighted(bool _highlighted);
96 
99  protected: void UpdateCornerPositions();
100 
103  protected: void DrawBoundingBox(QPainter *_painter);
104 
107  public: virtual void SetPosition(const QPointF &_pos);
108 
112  public: virtual void SetPosition(double _x, double _y);
113 
116  public: virtual void SetRotation(double _angle);
117 
121  public: virtual void SetResizeFlag(unsigned int _flag);
122 
125  public: virtual double GetRotation() const;
126 
127  // Documentation inherited
128  public: virtual QVector3D GetSize() const;
129 
130  // Documentation inherited
131  public: virtual QVector3D GetScenePosition() const;
132 
133  // Documentation inherited
134  public: virtual double GetSceneRotation() const;
135 
138  protected: virtual QRectF boundingRect() const;
139 
141  protected: void UpdateMeasures();
142 
146  private: virtual bool RotateEventFilter(RotateHandle *_rotateHandle,
147  QEvent *_event);
148 
152  private: virtual bool GrabberEventFilter(GrabberHandle *_grabber,
153  QEvent *_event);
154 
159  private: virtual void paint(QPainter *_painter,
160  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
161 
164  private: void hoverEnterEvent(QGraphicsSceneHoverEvent *_event);
165 
168  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
169 
172  private: void hoverLeaveEvent(QGraphicsSceneHoverEvent *_event);
173 
176  private: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *_event);
177 
180  private: virtual void mousePressEvent(QGraphicsSceneMouseEvent *_event);
181 
184  private: virtual void mouseReleaseEvent(
185  QGraphicsSceneMouseEvent *_event);
186 
189  private: virtual void mousePressEvent(
190  QGraphicsSceneDragDropEvent *_event);
191 
194  private: virtual void mouseMoveEvent(
195  QGraphicsSceneDragDropEvent *_event);
196 
199  private: virtual void mouseDoubleClickEvent(
200  QGraphicsSceneMouseEvent *_event);
201 
205  private: virtual bool sceneEventFilter(QGraphicsItem *_watched,
206  QEvent *_event);
207 
212  private: QVariant itemChange(GraphicsItemChange _change,
213  const QVariant &_value);
214 
217  private: virtual void contextMenuEvent(
218  QGraphicsSceneContextMenuEvent *_event);
219 
221  private: virtual void SizeChanged();
222 
226  private: void AdjustSize(double _x, double _y);
227 
229  private slots: virtual void OnOpenInspector();
230 
232  private slots: virtual void OnDeleteItem();
233 
235  protected: double width;
236 
238  protected: double height;
239 
241  protected: double drawingWidth;
242 
244  protected: double drawingHeight;
245 
247  protected: double drawingOriginX;
248 
250  protected: double drawingOriginY;
251 
253  protected: QColor borderColor;
254 
256  protected: double rotationAngle;
257 
259  protected: QAction *openInspectorAct;
260 
262  protected: QAction *deleteItemAct;
263 
267  protected: std::vector<MeasureItem *> measures;
268 
270  private: QPointF mousePressPos;
271 
273  private: int gridSpace;
274 
277  private: std::vector<GrabberHandle *> grabbers;
278 
280  private: RotateHandle *rotateHandle;
281 
284  private: std::vector<Qt::CursorShape> cursors;
285 
287  private: unsigned int resizeFlag;
288 
291  private: double positionOnWall;
292 
294  private: double angleOnWall;
295  };
297  }
298 }
299 
300 #endif
QAction * deleteItemAct
Qt action for deleting the item.
Definition: RectItem.hh:262
double drawingHeight
Actual height of rect item drawn in pixels.
Definition: RectItem.hh:244
QColor borderColor
Border color of the rect item.
Definition: RectItem.hh:253
double rotationAngle
Rotation angle of the rect item in degrees.
Definition: RectItem.hh:256
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:45
2D rectangle.
Definition: RectItem.hh:40
double drawingOriginX
X origin of the rect item in pixels.
Definition: RectItem.hh:247
double drawingWidth
Actual width of rect item drawn in pixels.
Definition: RectItem.hh:241
std::vector< MeasureItem * > measures
A vector containing this item's measure items.
Definition: RectItem.hh:267
Handle for rotating an editor item.
Definition: RotateHandle.hh:33
Definition: GrabberHandle.hh:29
double drawingOriginY
Y origin of the rect item in pixels.
Definition: RectItem.hh:250
double width
Width of rect item in pixels.
Definition: RectItem.hh:235
double height
Height of rect item in pixels.
Definition: RectItem.hh:238
#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:259