• 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
DeleteHandAction.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  Copyright 2011 Andreas Cord-Landwehr <cola@uni-paderborn.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "DeleteHandAction.h"
22 
23 #include <KLocale>
24 #include <QGraphicsItem>
25 #include <QGraphicsScene>
26 #include <QKeyEvent>
27 #include "Scene/GraphScene.h"
28 #include "Scene/DataItem.h"
29 #include "Scene/PointerItem.h"
30 #include "DataStructure.h"
31 #include "Data.h"
32 #include "Pointer.h"
33 
34 DeleteHandAction::DeleteHandAction(GraphScene* scene, QObject* parent): AbstractAction(scene, parent)
35 {
36  setText(i18nc("@action:intoolbar", "Delete"));
37  setToolTip(i18nc("@info:tooltip", "Delete items by clicking on them."));
38  setIcon(KIcon("rocsdeletedata"));
39  _name = "rocs-hand-delete";
40 
41  connect(_graphScene, SIGNAL(keyPressed(QKeyEvent*)), this, SLOT(executeKeyRelease(QKeyEvent*)));
42 }
43 
44 bool DeleteHandAction::executePress(QPointF pos)
45 {
46  QGraphicsItem * item = _graphScene->itemAt(pos);
47  if (DataItem *n = qgraphicsitem_cast<DataItem*>(item)) {
48  if (n->isSelected()) {
49  foreach(QGraphicsItem * selectedItem, _graphScene->selectedItems())
50  if (DataItem *dItem = qgraphicsitem_cast<DataItem*>(selectedItem)) {
51  dItem->data()->remove();
52  }
53  } else {
54  n->data()->remove();
55  }
56  return true;
57  } else if (PointerItem *e = qgraphicsitem_cast<PointerItem*>(item)) {
58  e->pointer()->remove();
59  return true;
60  }
61  return false;
62 }
63 
64 bool DeleteHandAction::executeKeyRelease(QKeyEvent* keyEvent)
65 {
66  if (keyEvent->key() == Qt::Key_Delete) {
67  foreach(QGraphicsItem * item, _graphScene->selectedItems()) {
68  if (DataItem *dItem = qgraphicsitem_cast<DataItem*>(item)) {
69  _graphScene->removeItem(item);
70  dItem->deleteLater();
71  dItem->data()->remove();
72  }
73  if (PointerItem *pItem = qgraphicsitem_cast<PointerItem*>(item)) {
74  pItem->pointer()->remove();
75  }
76  }
77  return true;
78  }
79  return false;
80 }
QGraphicsScene::itemAt
QGraphicsItem * itemAt(const QPointF &position) const
QGraphicsScene::selectedItems
QList< QGraphicsItem * > selectedItems() const
DeleteHandAction.h
QGraphicsItem
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
DeleteHandAction::DeleteHandAction
DeleteHandAction(GraphScene *scene, QObject *parent)
Definition: DeleteHandAction.cpp:34
QGraphicsScene::removeItem
void removeItem(QGraphicsItem *item)
GraphScene
Definition: GraphScene.h:38
QObject
AbstractAction::_name
QString _name
Definition: AbstractAction.h:90
DeleteHandAction::executePress
bool executePress(QPointF pos)
Definition: DeleteHandAction.cpp:44
QKeyEvent::key
int key() const
QKeyEvent
QGraphicsItem::data
QVariant data(int key) const
AbstractAction::_graphScene
GraphScene * _graphScene
Definition: AbstractAction.h:88
DataItem
Definition: DataItem.h:38
PointerItem
Graphics item for data connections.
Definition: PointerItem.h:42
DataItem.h
DeleteHandAction::executeKeyRelease
bool executeKeyRelease(QKeyEvent *keyEvent)
Definition: DeleteHandAction.cpp:64
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