SegmentItem.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-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_SEGMENTITEM_HH_
19 #define _GAZEBO_GUI_BUILDING_SEGMENTITEM_HH_
20 
21 #include <memory>
22 #include <vector>
23 #include <ignition/math/Vector2.hh>
24 #include <ignition/math/Vector3.hh>
25 
26 #include "gazebo/gui/qt.h"
28 
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace gui
34  {
35  class GrabberHandle;
36 
37  // Forward declare private data.
38  class SegmentItemPrivate;
39 
42 
45  class GZ_GUI_VISIBLE SegmentItem
46  : public EditorItem, public QGraphicsLineItem
47  {
50  public: SegmentItem(QGraphicsItem *_parent = 0);
51 
53  public: ~SegmentItem();
54 
58  public: void SetLine(const ignition::math::Vector2d &_start,
59  const ignition::math::Vector2d &_end);
60 
63  public: void SetStartPoint(const ignition::math::Vector2d &_start);
64 
67  public: ignition::math::Vector2d StartPoint() const;
68 
71  public: void SetEndPoint(const ignition::math::Vector2d &_end);
72 
75  public: ignition::math::Vector2d EndPoint() const;
76 
79  public: void SetThickness(const double _thickness);
80 
83  public: double Thickness() const;
84 
87  public: double Scale() const;
88 
91  public: void SetScale(const double _scale);
92 
95  public: void SetColor(const common::Color &_color);
96 
99  public: void ShowHandles(const bool _show);
100 
102  public: void SegmentChanged();
103 
104  // Documentation Inherited
105  public: ignition::math::Vector3d Size() const;
106 
107  // Documentation Inherited
108  public: ignition::math::Vector3d ScenePosition() const;
109 
110  // Documentation Inherited
111  public: double SceneRotation() const;
112 
115  public: std::vector<GrabberHandle *>Grabbers() const;
116 
118  protected: virtual void SegmentUpdated();
119 
123  protected: void UpdateLinkedGrabbers(GrabberHandle *_grabber,
124  const ignition::math::Vector2d &_pos);
125 
130  private: bool sceneEventFilter(QGraphicsItem *watched,
131  QEvent *_event);
132 
137  private: bool GrabberEventFilter(GrabberHandle *_grabber,
138  QEvent *_event);
139 
142  private: void hoverEnterEvent(QGraphicsSceneHoverEvent *_event);
143 
146  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
147 
150  private: void hoverLeaveEvent(QGraphicsSceneHoverEvent *_event);
151 
154  private: void mouseMoveEvent(QGraphicsSceneMouseEvent *_event);
155 
158  private: void mousePressEvent(QGraphicsSceneMouseEvent *_event);
159 
162  private: void mouseReleaseEvent(QGraphicsSceneMouseEvent *_event);
163 
168  private: void paint(QPainter *_painter,
169  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
170 
172  public: static const double SnapAngle;
173 
175  public: static const double SnapLength;
176 
179  protected: std::vector<GrabberHandle *> grabbers;
180 
183  private: std::unique_ptr<SegmentItemPrivate> dataPtr;
184  };
186  }
187 }
188 
189 #endif
Base class of an item in the editor.
Definition: EditorItem.hh:43
static const double SnapAngle
Angle to snap in degrees.
Definition: SegmentItem.hh:172
static const double SnapLength
Length to snap in meters.
Definition: SegmentItem.hh:175
2D line segment.
Definition: SegmentItem.hh:45
Defines a color.
Definition: Color.hh:36
Definition: GrabberHandle.hh:42
std::vector< GrabberHandle * > grabbers
A list of grabber handles for this item.
Definition: SegmentItem.hh:179