direcs
2012-09-30
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
laserScene.cpp
Go to the documentation of this file.
1
/*************************************************************************
2
* Copyright (C) Markus Knapp *
3
* www.direcs.de *
4
* *
5
* This file is part of direcs. *
6
* *
7
* direcs is free software: you can redistribute it and/or modify it *
8
* under the terms of the GNU General Public License as published *
9
* by the Free Software Foundation, version 3 of the License. *
10
* *
11
* direcs 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 direcs. If not, see <http://www.gnu.org/licenses/>. *
18
* *
19
*************************************************************************/
20
21
#include "
laserScene.h
"
22
23
24
LaserScene::LaserScene
(QObject* parent) : QGraphicsScene(parent)
25
{
26
}
27
28
29
LaserScene::~LaserScene
()
30
{}
31
32
33
void
LaserScene::mousePressEvent
(QGraphicsSceneMouseEvent* mouseEvent)
34
{
35
// only one emit!
36
// no other emits while keep the button pressed!
37
//mouseEvent->accept();
38
//emit robotPositionChanged(mouseEvent);
39
40
//QGraphicsScene::mousePressEvent(mouseEvent);
41
Q_UNUSED(mouseEvent);
42
}
43
44
45
void
LaserScene::mouseMoveEvent
(QGraphicsSceneMouseEvent* mouseEvent)
46
{
47
// dragging !
48
if
(mouseEvent->buttons() & Qt::LeftButton)
49
{
50
// Notify the gui about position update
51
// qDebug("dragging...");
52
emit
robotPositionChanged
(mouseEvent);
53
mouseEvent->accept();
54
}
55
56
QGraphicsScene::mouseMoveEvent
(mouseEvent);
57
}
58
59
void
LaserScene::mouseReleaseEvent
(QGraphicsSceneMouseEvent* mouseEvent)
60
{
61
62
emit
robotPositionChanged
(mouseEvent);
63
64
QGraphicsScene::mouseReleaseEvent
(mouseEvent);
65
}
66
67
68
void
LaserScene::wheelEvent
(QGraphicsSceneWheelEvent* wheelEvent)
69
{
70
//wheelEvent->accept();
71
emit
wheelZoom
(wheelEvent);
72
73
//QGraphicsScene::wheelEvent(wheelEvent);
74
}
75
76
77
void
LaserScene::contextMenuEvent
(QGraphicsSceneContextMenuEvent *event)
78
{
79
/*
80
// Verify whether this event originates from a component or a link
81
ComponentItem* componentItem = dynamic_cast<ComponentItem*>(itemAt(event->scenePos()));
82
ComponentLinkItem* linkItem = dynamic_cast<ComponentLinkItem*>(itemAt(event->scenePos()));
83
84
if(componentItem) {
85
// Create component context menu
86
QMenu componentMenu;
87
QAction* rotateAction = componentMenu.addAction("Rotate 45" + QString(QChar(176)));
88
rotateAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
89
rotateAction->setIcon(QIcon(":/icons/resources/context_rotate.png"));
90
componentMenu.addSeparator();
91
QAction* deleteAction = componentMenu.addAction("Delete");
92
deleteAction->setShortcut(QKeySequence::Delete);
93
deleteAction->setIcon(QIcon(":/icons/resources/context_delete.png"));
94
QAction* selectedAction = componentMenu.exec(event->screenPos());
95
96
if(selectedAction == rotateAction) {
97
// Rotate item (and those others selected) by 45 degrees (CCW)
98
foreach(QGraphicsItem* item, selectedItems()) {
99
// We need this downcast to use our own rotate method
100
if((componentItem = dynamic_cast<ComponentItem*>(item))) {
101
componentItem->rotate(45);
102
}
103
}
104
// Notify others we got modified
105
emit sceneItemModified();
106
}
107
else if(selectedAction == deleteAction) {
108
// Remove/delete component (and those others selected)
109
foreach(QGraphicsItem* item, selectedItems()) {
110
removeItem(item);
111
delete item;
112
}
113
// Notify others we got modified
114
emit sceneItemModified();
115
}
116
}
117
else if(linkItem) {
118
// Create link context menu
119
QMenu linkMenu;
120
QAction* uniLinkAction = linkMenu.addAction("Unidirectional");
121
uniLinkAction->setCheckable(true);
122
QAction* biLinkAction = linkMenu.addAction("Bidirectional");
123
biLinkAction->setCheckable(true);
124
linkMenu.addSeparator();
125
QAction* deleteAction = linkMenu.addAction("Delete");
126
deleteAction->setIcon(QIcon(":/icons/resources/context_delete.png"));
127
deleteAction->setShortcut(QKeySequence::Delete);
128
129
// Configure context menu
130
if(linkItem->Directionality() == Unidirectional) {
131
uniLinkAction->setChecked(true);
132
}
133
else {
134
biLinkAction->setChecked(true);
135
}
136
137
// Show menu and store selected action
138
QAction* selectedAction = linkMenu.exec(event->screenPos());
139
140
// Set new mode (or delete link) and notify others we got modified
141
if(selectedAction == uniLinkAction) {
142
linkItem->setDirectionality (Unidirectional);
143
emit sceneItemModified();
144
}
145
else if(selectedAction == biLinkAction) {
146
linkItem->setDirectionality(Bidirectional);
147
emit sceneItemModified();
148
}
149
else if(selectedAction == deleteAction) {
150
removeItem(linkItem);
151
delete linkItem;
152
emit sceneItemModified();
153
}
154
}
155
156
*/
157
update();
158
event
->accept();
159
}
160
161
162
void
LaserScene::keyPressEvent
(QKeyEvent* keyEvent)
163
{
164
/*
165
if(keyEvent->key() == Qt::Key_R && keyEvent->modifiers() & Qt::ControlModifier) {
166
ComponentItem* componentItem;
167
// Rotate selected items by 45 degrees (CCW)
168
foreach(QGraphicsItem* item, selectedItems()) {
169
// We need this downcast to use our own rotate method
170
if((componentItem = dynamic_cast<ComponentItem*>(item))) {
171
componentItem->rotate(45);
172
}
173
}
174
// Notify others we got modified
175
emit sceneItemModified();
176
177
keyEvent->accept();
178
}
179
else if(keyEvent->matches(QKeySequence::Delete)) {
180
// Remove/delete selected components
181
foreach(QGraphicsItem* item, selectedItems()) {
182
removeItem(item);
183
delete item;
184
}
185
// Notify others we got modified
186
emit sceneItemModified();
187
188
keyEvent->accept();
189
}
190
else {
191
*/
192
QGraphicsScene::keyPressEvent
(keyEvent);
193
//}
194
}
direcs
src
laserScene.cpp
Generated on Sat Feb 2 2013 21:41:01 for direcs by
1.8.1.1