• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/RocsCore

  • sources
  • kde-4.12
  • kdeedu
  • rocs
  • RocsCore
  • DataStructures
  • LinkedList
LinkedListPointerItem.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2008-2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2008 Ugo Sangiori <ugorox@gmail.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "LinkedListPointerItem.h"
21 
22 #include "Scene/DataItem.h"
23 #include "Data.h"
24 #include "Pointer.h"
25 #include "DataStructure.h"
26 
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneMouseEvent>
29 #include <QPainterPath>
30 #include <QLine>
31 #include <QPolygonF>
32 #include <QtAlgorithms>
33 #include <KDebug>
34 #include <math.h>
35 #include <boost/math/constants/constants.hpp>
36 
37 LinkedListPointerItem::LinkedListPointerItem(PointerPtr edge, QGraphicsItem *parent)
38  : PointerItem(edge, parent)
39 {
40  setPath(createCurves());
41 }
42 
43 LinkedListPointerItem::~LinkedListPointerItem() {}
44 
45 
46 QPolygonF LinkedListPointerItem::createEndArrow() const
47 {
48  const qreal pi = boost::math::constants::pi<double>();
49 
50  DataPtr to = pointer()->to();
51  QPointF pos1(to->x() - to->width() * 40 - 20, to->y());
52  QPointF pos2(to->x() - to->width() * 40, to->y());
53  QLineF line(pos1, pos2);
54  qreal arrowSize = 10.0;
55  QPointF destArrowP1 = pos2 + QPointF(sin(-pi/3.0) * arrowSize, cos(-pi/3.0) * arrowSize);
56  QPointF destArrowP2 = pos2 + QPointF(sin(-pi + pi/3.0) * arrowSize, cos(-pi + pi/3.0) * arrowSize);
57 
58  return QPolygonF() << pos1 << pos2 << destArrowP2 << destArrowP1 << pos2;
59 }
60 
61 QPolygonF LinkedListPointerItem::createPath(const QPointF &pos1, const QPointF &pos2) const
62 {
63  QPolygonF path;
64  path.append(pos1);
65  if (pos1.x() > pos2.x()) {
66  qreal mid = (pos2.y() + pos1.y()) / 2;
67  path.append(QPointF(pos1.x(), mid));
68  path.append(QPointF(pos2.x(), mid));
69  } else {
70  qreal mid = (pos2.x() + pos1.x()) / 2;
71  path.append(QPointF(mid, pos1.y()));
72  path.append(QPointF(mid, pos2.y()));
73  }
74  path.append(pos2);
75  return path;
76 }
77 
78 QPainterPath LinkedListPointerItem::createCurves()
79 {
80  QPointF Pos1(pointer()->from()->x() + pointer()->to()->width() * 40 + 20, pointer()->from()->y());
81  QPointF Pos2(pointer()->to()->x() - pointer()->to()->width() * 40 - 20, pointer()->to()->y());
82 
83  QPainterPath s;
84  s.moveTo(pointer()->from()->x(), pointer()->from()->y());
85  s.lineTo(Pos1);
86  s.addPolygon(createPath(Pos1, Pos2));
87  s.addPolygon(createEndArrow());
88  return s;
89 
90 }
91 
92 #include "LinkedListPointerItem.moc"
LinkedListPointerItem::~LinkedListPointerItem
virtual ~LinkedListPointerItem()
Definition: LinkedListPointerItem.cpp:43
Data.h
PointerPtr
boost::shared_ptr< Pointer > PointerPtr
Definition: CoreTypes.h:35
DataStructure.h
Pointer.h
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
PointerItem
LinkedListPointerItem::LinkedListPointerItem
LinkedListPointerItem(PointerPtr edge, QGraphicsItem *parent=0)
Default constructor.
Definition: LinkedListPointerItem.cpp:37
LinkedListPointerItem.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal