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

rocs/VisualEditor

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • VisualEditor
  • Actions
AddConnectionHandAction.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2008 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 "AddConnectionHandAction.h"
21 #include "Scene/GraphScene.h"
22 #include "Scene/DataItem.h"
23 #include "Scene/PointerItem.h"
24 
25 #include "DataStructure.h"
26 #include "Data.h"
27 #include "Pointer.h"
28 #include <PointerType.h>
29 
30 #include <KLocale>
31 #include <KDebug>
32 #include <DocumentManager.h>
33 #include <Document.h>
34 
35 AddConnectionHandAction::AddConnectionHandAction(GraphScene *scene, QObject *parent)
36  : AbstractAction(scene, parent),
37  _pointerType(PointerTypePtr())
38 {
39  setText(i18nc("@action:intoolbar", "Add Edge"));
40  setToolTip(i18nc("@info:tooltip", "Creates a new edge between 2 nodes"));
41  setIcon(KIcon("rocsaddedge"));
42 
43  _from = 0;
44  _to = 0;
45  _tmpLine = 0;
46  _working = false;
47  _name = "rocs-hand-add-edge";
48 }
49 
50 AddConnectionHandAction::AddConnectionHandAction(GraphScene *scene, PointerTypePtr pointerType, QObject *parent)
51  : AbstractAction(scene, parent),
52  _pointerType(pointerType)
53 {
54  setText(i18nc("@action:intoolbar", "Add %1", pointerType->name()));
55  setToolTip(i18nc("@info:tooltip", "Creates a new edge between 2 nodes"));
56  setIcon(KIcon("rocsaddedge"));
57 
58  _from = 0;
59  _to = 0;
60  _tmpLine = 0;
61  _working = false;
62  _name = "rocs-hand-add-edge";
63 }
64 
65 AddConnectionHandAction::~AddConnectionHandAction()
66 {
67 }
68 
69 bool AddConnectionHandAction::executePress(QPointF pos)
70 {
71  if (_working) {
72  return false;
73  }
74  if (! DocumentManager::self().activeDocument()->activeDataStructure()
75  || DocumentManager::self().activeDocument()->activeDataStructure()->readOnly()) {
76  return false;
77  }
78 
79  if ((_from = qgraphicsitem_cast<DataItem*>(_graphScene->itemAt(pos)))) {
80  _working = true;
81  _startPos = QPointF(_from->data()->x(), _from->data()->y());
82  //FIXME workaround for rooted tree creation
83  _from->data()->setProperty("ClickPosition", QVariant::fromValue<QPointF>(_from->mapFromScene(pos)));
84  return true;
85  }
86 
87  return false;
88 }
89 
90 bool AddConnectionHandAction::executeMove(QPointF pos)
91 {
92  if (!DocumentManager::self().activeDocument()->activeDataStructure()
93  || !_from) {
94  return false;
95  }
96 
97  if (!_tmpLine) {
98  _tmpLine = new QGraphicsLineItem();
99  _graphScene->addItem(_tmpLine);
100  }
101 
102  _tmpLine->setLine(_startPos.x(), _startPos.y(), pos.x(), pos.y());
103  return true;
104 }
105 
106 bool AddConnectionHandAction::executeRelease(QPointF pos)
107 {
108  DataStructurePtr activeDataStructure = DocumentManager::self().activeDocument()->activeDataStructure();
109 
110  if (!_working || !activeDataStructure) {
111  return false;
112  }
113 
114  delete _tmpLine;
115  _tmpLine = 0;
116 
117  // if no dataType set, we use default data type
118  int pointerTypeIdentifier = 0;
119  if (_pointerType) {
120  pointerTypeIdentifier = _pointerType->identifier();
121  }
122 
123  if ((_to = qgraphicsitem_cast<DataItem*>(_graphScene->itemAt(pos)))) {
124  //FIXME workaround for rooted tree creation
125  _to->data()->setProperty("ClickPosition", _to->mapFromScene(pos));
126  activeDataStructure->createPointer(_from->data(), _to->data(), pointerTypeIdentifier);
127  _to->data()->setProperty("ClickPosition", QVariant());
128  }
129  _to = 0;
130  _from->data()->setProperty("ClickPosition", QVariant());
131  _from = 0;
132  _working = false;
133  return true;
134 }
QGraphicsScene::itemAt
QGraphicsItem * itemAt(const QPointF &position) const
DataItem::data
DataPtr data() const
Definition: DataItem.cpp:102
GraphScene.h
AbstractAction
the base class for custom actions. This class provides the basic functionality for all custom actions...
Definition: AbstractAction.h:36
QPointF
PointerItem.h
AddConnectionHandAction::~AddConnectionHandAction
~AddConnectionHandAction()
Definition: AddConnectionHandAction.cpp:65
QPointF::x
qreal x() const
QPointF::y
qreal y() const
GraphScene
Definition: GraphScene.h:38
QObject
AbstractAction::_name
QString _name
Definition: AbstractAction.h:90
QGraphicsLineItem
QGraphicsLineItem::setLine
void setLine(const QLineF &line)
QGraphicsItem::mapFromScene
QPointF mapFromScene(const QPointF &point) const
AddConnectionHandAction.h
AddConnectionHandAction::executeMove
bool executeMove(QPointF pos)
Definition: AddConnectionHandAction.cpp:90
AbstractAction::_graphScene
GraphScene * _graphScene
Definition: AbstractAction.h:88
DataItem.h
AddConnectionHandAction::executePress
bool executePress(QPointF pos)
Definition: AddConnectionHandAction.cpp:69
QGraphicsScene::addItem
void addItem(QGraphicsItem *item)
AddConnectionHandAction::AddConnectionHandAction
AddConnectionHandAction(GraphScene *scene, QObject *parent=0)
Default constructor Creates add-edge action that adds data elements of default.
Definition: AddConnectionHandAction.cpp:35
AddConnectionHandAction::executeRelease
bool executeRelease(QPointF pos)
Definition: AddConnectionHandAction.cpp:106
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/VisualEditor

Skip menu "rocs/VisualEditor"
  • Main Page
  • 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
  • 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