All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PolylineItem.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 _POLYLINE_ITEM_HH_
19 #define _POLYLINE_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 EditorItem;
32  class LineSegmentItem;
33 
36 
40  : public EditorItem, public QGraphicsPathItem
41  {
47  public: PolylineItem(const QPointF &_start, const QPointF &_end);
48 
50  public: ~PolylineItem();
51 
54  public: void AddPoint(const QPointF &_point);
55 
57  public: void PopEndPoint();
58 
61  public: unsigned int GetVertexCount() const;
62 
65  public: unsigned int GetSegmentCount() const;
66 
70  public: void SetVertexPosition(unsigned int _index,
71  const QPointF &_pos);
72 
76  public: void TranslateVertex(unsigned int _index,
77  const QPointF &_trans);
78 
81  public: LineSegmentItem *GetSegment(unsigned int _index) const;
82 
85  public: void ShowHandles(bool _show);
86 
89  public: void SetThickness(double _thickness);
90 
93  public: void SetPosition(const QPointF &_pos);
94 
97  public: void ClosePath();
98 
101  public: bool IsClosed() const;
102 
105  public: void Update();
106 
108  private: void UpdatePath();
109 
114  private: void UpdatePathAt(unsigned int _index, const QPointF &_pos);
115 
119  private: void AppendToPath(const QPointF &_point);
120 
124  private: bool sceneEventFilter(QGraphicsItem * watched,
125  QEvent *_event);
126 
130  private: virtual bool GrabberEventFilter(GrabberHandle *_grabber,
131  QEvent *_event);
132 
136  private: virtual bool SegmentEventFilter(LineSegmentItem *_item,
137  QEvent *_event);
138 
141  private: void hoverEnterEvent(QGraphicsSceneHoverEvent *_event);
142 
145  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
146 
149  private: void hoverLeaveEvent(QGraphicsSceneHoverEvent *_event);
150 
153  private: void mouseMoveEvent(QGraphicsSceneMouseEvent *_event);
154 
157  private: void mousePressEvent(QGraphicsSceneMouseEvent *_event);
158 
161  private: void mouseReleaseEvent(QGraphicsSceneMouseEvent *_event);
162 
165  private: void mousePressEvent(QGraphicsSceneDragDropEvent *_event);
166 
169  private: void mouseMoveEvent(QGraphicsSceneDragDropEvent *_event);
170 
175  private: QVariant itemChange(GraphicsItemChange _change,
176  const QVariant &_value);
177 
182  private: void paint(QPainter *_painter,
183  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
184 
187  protected: void DrawBoundingBox(QPainter *_painter);
188 
190  protected: std::vector<GrabberHandle *> grabbers;
191 
193  protected: std::vector<LineSegmentItem*> segments;
194 
196  protected: QPointF segmentMouseMove;
197 
199  protected: bool closed;
200 
202  private: QPointF origin;
203 
204  // private: int gridSpace;
205 
207  private: double grabberWidth;
208 
210  private: double grabberHeight;
211 
213  private: double lineThickness;
214  };
216  }
217 }
218 
219 #endif
Base class of an item in the editor.
Definition: EditorItem.hh:34
bool closed
True to indicate that the polyline is closed.
Definition: PolylineItem.hh:199
2D polyline.
Definition: PolylineItem.hh:39
QPointF segmentMouseMove
Keep track of mouse press position for translating segments.
Definition: PolylineItem.hh:196
std::vector< LineSegmentItem * > segments
A list of line segments of the polyline.
Definition: PolylineItem.hh:193
2D line segment.
Definition: LineSegmentItem.hh:35
std::vector< GrabberHandle * > grabbers
A list of grabber handles for this item, one on each vertex.
Definition: PolylineItem.hh:190
Definition: GrabberHandle.hh:28
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48