YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
arrow.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
10/****************************************************************************
11**
12** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
13** Contact: http://www.qt-project.org/legal
14**
15** This file is part of the examples of the Qt Toolkit.
16**
17** $QT_BEGIN_LICENSE:BSD$
18** You may use this file under the terms of the BSD license as follows:
19**
20** "Redistribution and use in source and binary forms, with or without
21** modification, are permitted provided that the following conditions are
22** met:
23** * Redistributions of source code must retain the above copyright
24** notice, this list of conditions and the following disclaimer.
25** * Redistributions in binary form must reproduce the above copyright
26** notice, this list of conditions and the following disclaimer in
27** the documentation and/or other materials provided with the
28** distribution.
29** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
30** of its contributors may be used to endorse or promote products derived
31** from this software without specific prior written permission.
32**
33**
34** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
45**
46** $QT_END_LICENSE$
47**
48****************************************************************************/
49
50#ifndef ARROW_H
51#define ARROW_H
52
53#include <QStaticText>
54#include <QGraphicsLineItem>
55#include <QGraphicsProxyWidget>
56#include <QComboBox>
57#include "commons.h"
58#include "itemsignalhandler.h"
59#include "builderitem.h"
60
61
62
63QT_BEGIN_NAMESPACE
64class QGraphicsPolygonItem;
65class QGraphicsLineItem;
66class QGraphicsScene;
67class QRectF;
68class QGraphicsSceneMouseEvent;
69class QPainterPath;
70QT_END_NAMESPACE
71
72class LineHandle;
73class Label : public QGraphicsTextItem
74{
75public:
76 Label(QString label, QGraphicsItem *parent = 0);
78 int type() const override { return UserType + (int)ArrowLabelItemType; }
79 bool hasBeenMoved();
80 void setHasMoved(bool);
81 void currentComboTextChanged(QString text);
82 QString labelText();
83 void setText(QString);
84
85protected:
86 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
87 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
88 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
89 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
90 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
91
92 QPointF computeTopLeftGridPoint(const QPointF &pointP);
93protected:
94 QGraphicsProxyWidget *comboWidget;
95 QString text;
97 bool moved;
99 bool pressed;
101 QPointF offset;
102};
103//class ItemSignalHandler;
104
105class Arrow : public BuilderItem
106{
107public:
108
109 friend class LineHandle;
110 friend class Label;
111
113 int id, Manager *safeManager, bool nestedInApp = false, bool editingMode = false, BuilderItem *parent = 0);
114
115 ~Arrow();
116 int type() const override { return (int)QGraphicsItem::UserType + (int)itemType; }
117
118 QPointF connectionPoint() override;
119 void setConnected(bool);
120 int getId();
121 QString getFrom();
122 QString getTo();
123 void setConnection(const Connection& conn);
124 void setConnectionSelected(bool selected);
125 void updateModel();
126 void updateCarrier(QString carrier);
128
129 QRectF boundingRect() const override;
130 QPainterPath shape() const override;
131 void setColor(const QColor &color) { myColor = color; }
132 BuilderItem *startItem() const { return myStartItem; }
133 BuilderItem *endItem() const { return myEndItem; }
134
135 void addHandle(QPointF clickPos);
136 void updatePosition();
137 QList <LineHandle*> handles();
139 int getHandleIndex(LineHandle *handle);
140 LineHandle *getLineHandle(int index);
141 void updateConnectionFrom(QString from);
142 void updateConnectionTo(QString to);
143 void updateGraphicModel();
144
145protected:
146 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
147 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
148 void mousePressEvent(QGraphicsSceneMouseEvent *e) override;
149 void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
150 void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override;
151 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
152
153
154private:
155 Manager *manager;
156 GraphicModel model;
157 bool externalSelection;
158
159 bool editingMode;
160 bool connected;
161 yarp::manager::Connection connection;
162 BuilderItem *myStartItem;
163 BuilderItem *myEndItem;
164 QColor myColor;
165 QPolygonF arrowHead;
166 Label textLbl;
167 int textWidth;
168 QFont font;
169 //QLineF line;
170 QPolygonF polyline;
171 QPolygonF boundingPolyline;
172 int id;
173
174
175 QPointF startP;
176 QPointF endP;
177
178 QList <LineHandle*> handleList;
179};
180
181
182class LineHandle : public QGraphicsRectItem
183{
184public:
185 LineHandle(QPointF center, Arrow *parent = 0);
187 QPointF handlePoint();
188 int type() const override { return UserType + (int)HandleItemType; }
189
190protected:
191 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
192 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
193 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
194 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
195 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
196 QPointF computeTopLeftGridPoint(const QPointF &pointP);
197private:
198 QPointF center;
199 Arrow *parent;
200 bool pressed;
201 int rectSize;
202 QPointF offset;
203 bool ctrlPressed;
204};
205
206
207
208
209#endif // ARROW_H
Definition arrow.h:106
void updateModel()
Definition arrow.cpp:252
void updateConnectionTo(QString to)
Definition arrow.cpp:191
QPointF connectionPoint() override
Definition arrow.cpp:271
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override
Definition arrow.cpp:435
void setConnectionSelected(bool selected)
Definition arrow.cpp:265
void updateCarrier(QString carrier)
Definition arrow.cpp:156
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override
Definition arrow.cpp:426
void updatePosition()
Definition arrow.cpp:329
int getHandleIndex(LineHandle *handle)
Definition arrow.cpp:509
void addHandle(QPointF clickPos)
Definition arrow.cpp:459
~Arrow()
Definition arrow.cpp:93
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Definition arrow.cpp:492
GraphicModel * getModel()
Definition arrow.cpp:107
QPainterPath shape() const override
Definition arrow.cpp:310
BuilderItem * startItem() const
Definition arrow.h:132
QString getFrom()
Definition arrow.cpp:278
LineHandle * getLineHandle(int index)
Definition arrow.cpp:521
QString getTo()
Definition arrow.cpp:283
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
Definition arrow.cpp:339
void removeHandle(LineHandle *)
Definition arrow.cpp:482
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:447
void updateConnectionFrom(QString from)
Definition arrow.cpp:171
QList< LineHandle * > handles()
Definition arrow.cpp:487
void setColor(const QColor &color)
Definition arrow.h:131
void mousePressEvent(QGraphicsSceneMouseEvent *e) override
Definition arrow.cpp:415
BuilderItem * endItem() const
Definition arrow.h:133
int getId()
Definition arrow.cpp:294
void updateGraphicModel()
Definition arrow.cpp:210
QRectF boundingRect() const override
Definition arrow.cpp:299
void setConnection(const Connection &conn)
Definition arrow.cpp:112
int type() const override
Definition arrow.h:116
void setConnected(bool)
Definition arrow.cpp:288
friend class Arrow
Definition builderitem.h:31
bool nestedInApp
Definition builderitem.h:88
ItemType itemType
Definition builderitem.h:74
Definition arrow.h:74
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Definition arrow.cpp:813
void currentComboTextChanged(QString text)
Definition arrow.cpp:766
bool pressed
Definition arrow.h:99
QString text
Definition arrow.h:95
bool moved
Definition arrow.h:97
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:783
void setText(QString)
Definition arrow.cpp:756
Arrow * parentArrow
Definition arrow.h:100
bool hasMoved
Definition arrow.h:98
void setHasMoved(bool)
Definition arrow.cpp:742
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:789
QPointF computeTopLeftGridPoint(const QPointF &pointP)
Definition arrow.cpp:838
int type() const override
Definition arrow.h:78
QString labelText()
Definition arrow.cpp:752
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:771
bool hasBeenMoved()
Definition arrow.cpp:747
ItemSignalHandler * sigHandler
Definition arrow.h:96
QGraphicsProxyWidget * comboWidget
Definition arrow.h:94
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:803
QPointF offset
Definition arrow.h:101
QPointF computeTopLeftGridPoint(const QPointF &pointP)
Definition arrow.cpp:554
QPointF handlePoint()
Definition arrow.cpp:562
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:588
int type() const override
Definition arrow.h:188
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:604
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Definition arrow.cpp:613
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
Definition arrow.cpp:687
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition arrow.cpp:567
Class Connection.
Definition application.h:56
Class Manager.
Definition manager.h:20
@ HandleItemType
Definition commons.h:17
@ ArrowLabelItemType
Definition commons.h:17