• 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
  • Interface
EditorToolbar.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "EditorToolbar.h"
20 
21 #include "Scene/GraphScene.h"
22 
23 #include "Actions/AddConnectionHandAction.h"
24 #include "Actions/AddDataHandAction.h"
25 #include "Actions/DeleteHandAction.h"
26 #include "Actions/ZoomAction.h"
27 #include "Actions/SelectMoveHandAction.h"
28 
29 #include "Document.h"
30 #include "DataType.h"
31 #include "PointerType.h"
32 #include "CoreTypes.h"
33 
34 #include <KIcon>
35 #include <KLocalizedString>
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KMenu>
39 #include <KDebug>
40 
41 EditorToolbar::EditorToolbar(QWidget* parent)
42  : QWidget(parent)
43 {
44 }
45 
46 void EditorToolbar::setup(GraphScene* scene, KActionCollection* collection)
47 {
48  _scene = scene;
49 
50  _selectMoveAction = new SelectMoveHandAction(scene, this);
51  DeleteHandAction* deleteAction = new DeleteHandAction(scene, this);
52  ZoomAction* zoomAction = new ZoomAction(scene, this);
53 
54  connect(_selectMoveAction, SIGNAL(triggered()), _selectMoveAction, SLOT(sendExecuteBit()));
55  connect(deleteAction, SIGNAL(triggered()), deleteAction, SLOT(sendExecuteBit()));
56  connect(zoomAction, SIGNAL(triggered()), zoomAction, SLOT(sendExecuteBit()));
57 
58  _addDataActionMenu = new KActionMenu(KIcon("rocsadddata"), i18nc("@title:menu", "Add Data"), this);
59  _addDataActionMenu->setIconText(i18nc("@action:intoolbar", "Add Data"));
60  _addDataActionMenu->setToolTip(i18nc("@info:tooltip", "Add new data element"));
61  _addDataActionMenu->setDelayed(true);
62  _addDataActionMenu->setCheckable(true);
63 
64  _addPointerActionMenu = new KActionMenu(KIcon("rocsaddedge"), i18nc("@title:menu", "Add Connection"), this);
65  _addPointerActionMenu->setIconText(i18nc("@action:intoolbar", "Add Connection"));
66  _addPointerActionMenu->setToolTip(i18nc("@info:tooltip", "Add a new connection between two data elements of selected type"));
67  _addPointerActionMenu->setDelayed(true);
68  _addPointerActionMenu->setCheckable(true);
69 
70  // add actions to collection and group
71  QActionGroup *g = new QActionGroup(this);
72  g->addAction(collection->addAction("selectmove", _selectMoveAction));
73  g->addAction(collection->addAction("add_node", _addDataActionMenu));
74  g->addAction(collection->addAction("add_edge", _addPointerActionMenu));
75  g->addAction(collection->addAction("delete", deleteAction));
76  g->addAction(collection->addAction("zoom", zoomAction));
77  collection->action("selectmove")->toggle();
78  _scene->setAction(_selectMoveAction);
79 }
80 
81 void EditorToolbar::setActiveDocument(Document* activeDocument)
82 {
83  if (_document != 0) {
84  disconnect(_document);
85  }
86  _document = activeDocument;
87  updateTypeActions();
88 
89  // connect to new document
90  connect(_document, SIGNAL(dataTypeCreated(int)), this, SLOT(updateTypeActions()));
91  connect(_document, SIGNAL(pointerTypeCreated(int)), this, SLOT(updateTypeActions()));
92  connect(_document, SIGNAL(dataTypeRemoved(int)), this, SLOT(updateTypeActions()));
93  connect(_document, SIGNAL(pointerTypeRemoved(int)), this, SLOT(updateTypeActions()));
94 }
95 
96 void EditorToolbar::updateTypeActions()
97 {
98  _addDataActionMenu->menu()->clear();
99  foreach (int identifier, _document->dataTypeList()) {
100  DataTypePtr type = _document->dataType(identifier);
101  AddDataHandAction* addDataAction = new AddDataHandAction(_scene, type, _addDataActionMenu->menu());
102  addDataAction->setCheckable(false);
103 
104  if (identifier == 0) { // set default action to menu
105  connect(_addDataActionMenu, SIGNAL(triggered()), addDataAction, SLOT(sendExecuteBit()));
106  }
107 
108  _addDataActionMenu->menu()->addAction(addDataAction);
109  connect(type.get(), SIGNAL(iconChanged(QString)), addDataAction, SLOT(updateIcon()));
110  connect(addDataAction, SIGNAL(triggered()), addDataAction, SLOT(sendExecuteBit()));
111  }
112 
113  _addPointerActionMenu->menu()->clear();
114  foreach (int identifier, _document->pointerTypeList()) {
115  PointerTypePtr type = _document->pointerType(identifier);
116  AddConnectionHandAction* addPointerAction = new AddConnectionHandAction(_scene, type, _addPointerActionMenu->menu());
117  addPointerAction->setCheckable(false);
118 
119  if (identifier == 0) { // set default action to menu
120  connect(_addPointerActionMenu, SIGNAL(triggered()), addPointerAction, SLOT(sendExecuteBit()));
121  }
122 
123  _addPointerActionMenu->menu()->addAction(addPointerAction);
124  connect(addPointerAction, SIGNAL(triggered()), addPointerAction, SLOT(sendExecuteBit()));
125  }
126 }
QWidget
AddDataHandAction
The 'Add Data' Action This action holds the 'Add Data' icon and tooltips, and when it's executed...
Definition: AddDataHandAction.h:34
QActionGroup
QAction::toggle
void toggle()
AddDataHandAction.h
EditorToolbar::updateTypeActions
void updateTypeActions()
Update action menus for data types and pointer types.
Definition: EditorToolbar.cpp:96
DeleteHandAction.h
QActionGroup::addAction
QAction * addAction(QAction *action)
GraphScene.h
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
DeleteHandAction
Activation this action enables the Delete Mode for the GraphScene.
Definition: DeleteHandAction.h:32
EditorToolbar.h
EditorToolbar::EditorToolbar
EditorToolbar(QWidget *parent)
Default constructor.
Definition: EditorToolbar.cpp:41
GraphScene
Definition: GraphScene.h:38
QString
ZoomAction.h
AddConnectionHandAction.h
EditorToolbar::setup
void setup(GraphScene *scene, KActionCollection *collection)
Setup toolbar actions.
Definition: EditorToolbar.cpp:46
GraphScene::setAction
void setAction(QAction *action)
Definition: GraphScene.cpp:69
ZoomAction
Definition: ZoomAction.h:35
EditorToolbar::setActiveDocument
void setActiveDocument(Document *activeDocument)
Set current active graph document.
Definition: EditorToolbar.cpp:81
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
SelectMoveHandAction
This action holds the 'Move Node' icon and tooltips, and when it's executed, it will move the selecte...
Definition: SelectMoveHandAction.h:38
SelectMoveHandAction.h
AddConnectionHandAction
The 'Add Connection' Action.
Definition: AddConnectionHandAction.h:37
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