SegmentItem.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 #ifndef GAZEBO_GUI_BUILDING_SEGMENTITEM_HH_
18 #define GAZEBO_GUI_BUILDING_SEGMENTITEM_HH_
19 
20 #include <memory>
21 #include <vector>
22 #include <ignition/math/Vector2.hh>
23 #include <ignition/math/Vector3.hh>
24 
25 #include "gazebo/gui/qt.h"
27 
28 #include "gazebo/util/system.hh"
29 
30 namespace gazebo
31 {
32  namespace gui
33  {
34  class GrabberHandle;
35 
36  // Forward declare private data.
37  class SegmentItemPrivate;
38 
41 
44  class GZ_GUI_VISIBLE SegmentItem
45  : public EditorItem, public QGraphicsLineItem
46  {
49  public: SegmentItem(QGraphicsItem *_parent = 0);
50 
52  public: ~SegmentItem();
53 
57  public: void SetLine(const ignition::math::Vector2d &_start,
58  const ignition::math::Vector2d &_end);
59 
62  public: void SetStartPoint(const ignition::math::Vector2d &_start);
63 
66  public: ignition::math::Vector2d StartPoint() const;
67 
70  public: void SetEndPoint(const ignition::math::Vector2d &_end);
71 
74  public: ignition::math::Vector2d EndPoint() const;
75 
78  public: void SetThickness(const double _thickness);
79 
82  public: double Thickness() const;
83 
86  public: double Scale() const;
87 
90  public: void SetScale(const double _scale);
91 
94  public: void SetColor(const common::Color &_color);
95 
98  public: void ShowHandles(const bool _show);
99 
101  public: void SegmentChanged();
102 
103  // Documentation Inherited
104  public: ignition::math::Vector3d Size() const;
105 
106  // Documentation Inherited
107  public: ignition::math::Vector3d ScenePosition() const;
108 
109  // Documentation Inherited
110  public: double SceneRotation() const;
111 
114  public: std::vector<GrabberHandle *>Grabbers() const;
115 
117  protected: virtual void SegmentUpdated();
118 
122  protected: void UpdateLinkedGrabbers(GrabberHandle *_grabber,
123  const ignition::math::Vector2d &_pos);
124 
129  private: bool sceneEventFilter(QGraphicsItem *watched,
130  QEvent *_event);
131 
136  private: bool GrabberEventFilter(GrabberHandle *_grabber,
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 
167  private: void paint(QPainter *_painter,
168  const QStyleOptionGraphicsItem *_option, QWidget *_widget);
169 
171  public: static const double SnapAngle;
172 
174  public: static const double SnapLength;
175 
178  protected: std::vector<GrabberHandle *> grabbers;
179 
182  private: std::unique_ptr<SegmentItemPrivate> dataPtr;
183  };
185  }
186 }
187 
188 #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:171
static const double SnapLength
Length to snap in meters.
Definition: SegmentItem.hh:174
2D line segment.
Definition: SegmentItem.hh:44
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:178