2
* Kivio - Visual Modelling and Flowcharting
3
* Copyright (C) 2000-2001 theKompany.com & Dave Marotti
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
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.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
#include "tool_connector.h"
23
#include <kiconloader.h>
24
#include <kstandarddirs.h>
26
#include <kozoomhandler.h>
28
#include "kivio_view.h"
29
#include "kivio_canvas.h"
30
#include "kivio_page.h"
31
#include "kivio_doc.h"
32
#include "kivio_factory.h"
34
#include "kivio_stencil_spawner_set.h"
35
#include "kivio_stencil_spawner.h"
36
#include "kivio_custom_drag_data.h"
37
#include "kivio_layer.h"
38
#include "kivio_point.h"
39
#include "kivio_stencil.h"
40
#include "sml_connector.h"
42
SMLConnector::SMLConnector( KivioView* view )
43
:Tool(view,"SMLConnector")
47
ToolSelectAction* connector = new ToolSelectAction( actionCollection(), "ToolAction" );
48
KAction* m_z1 = new KAction( i18n("Edit Stencil Connector"), "kivio_connector", 0, actionCollection(), "sml_connector" );
49
connector->insert(m_z1);
53
m_pConnectorCursor1 = new QCursor(BarIcon("kivio_connector_cursor1",KivioFactory::global()),2,2);
54
m_pConnectorCursor2 = new QCursor(BarIcon("kivio_connector_cursor2",KivioFactory::global()),2,2);
57
SMLConnector::~SMLConnector()
59
delete m_pConnectorCursor1;
60
delete m_pConnectorCursor2;
67
* @param e The event to be identified and processed
70
void SMLConnector::processEvent( QEvent* e )
74
case QEvent::MouseButtonPress:
75
mousePress( (QMouseEvent*)e );
78
case QEvent::MouseButtonRelease:
79
mouseRelease( (QMouseEvent*)e );
82
case QEvent::MouseMove:
83
mouseMove( (QMouseEvent*)e );
91
void SMLConnector::activate()
93
kdDebug(43000) << "SMLConnector activate" << endl;
94
m_pCanvas->setCursor(*m_pConnectorCursor1);
100
void SMLConnector::deactivate()
109
void SMLConnector::configure()
113
void SMLConnector::connector(QRect)
121
KivioDoc* doc = m_pView->doc();
122
KivioPage* page = m_pCanvas->activePage();
124
if (m_pStencil->w() < 3.0 && m_pStencil->h() < 3.0) {
125
page->unselectAllStencils();
126
page->selectStencil(m_pStencil);
127
page->deleteSelectedStencils();
129
doc->updateView(page);
133
m_pStencil->searchForConnections(page, m_pView->zoomHandler()->unzoomItY(4));
134
doc->updateView(page);
137
void SMLConnector::mousePress( QMouseEvent *e )
139
if(e->button() == RightButton)
141
controller()->activateDefault();
144
if( startRubberBanding( e ) )
146
m_mode = stmDrawRubber;
152
* Tests if we should start rubber banding (always returns true).
154
bool SMLConnector::startRubberBanding( QMouseEvent *e )
156
KivioDoc* doc = m_pView->doc();
157
KivioPage* pPage = m_pCanvas->activePage();
159
startPoint = m_pCanvas->snapToGrid(m_pCanvas->mapFromScreen( e->pos() ));
161
// Create the stencil
162
KivioStencilSpawner* ss = doc->findInternalStencilSpawner("SML Connector");
165
kdDebug(43000) << "SMLTool: Failed to find StencilSpawner!" << endl;
169
startPoint = m_pCanvas->snapToGrid(m_pCanvas->mapFromScreen( e->pos() ));
171
// Create the stencil
172
m_pStencil = (KivioSMLConnector*)ss->newStencil("basic_line");
173
m_pStencil->setTextFont(doc->defaultFont());
175
// Unselect everything, add the stencil to the page, and select it
176
pPage->unselectAllStencils();
177
pPage->addStencil(m_pStencil);
178
pPage->selectStencil(m_pStencil);
180
// Get drag info ready
181
m_pDragData = new KivioCustomDragData();
182
m_pDragData->page = pPage;
183
m_pDragData->x = startPoint.x();
184
m_pDragData->y = startPoint.y();
185
m_pDragData->id = kctCustom + 2;
187
m_pStencil->setStartPoint(startPoint.x() + 10.0f, startPoint.y() + 10.0f);
188
m_pStencil->setEndPoint(startPoint.x(), startPoint.y());
189
m_pStencil->customDrag(m_pDragData);
192
m_pCanvas->repaint();
193
m_pCanvas->setCursor(*m_pConnectorCursor2);
197
void SMLConnector::mouseMove( QMouseEvent * e )
202
continueRubberBanding(e);
210
void SMLConnector::continueRubberBanding( QMouseEvent *e )
212
KoPoint endPoint = m_pCanvas->mapFromScreen( e->pos() );
213
endPoint = m_pCanvas->snapToGrid(endPoint);
215
m_pStencil->setStartPoint(endPoint.x(), endPoint.y());
218
m_pDragData->x = endPoint.x();
219
m_pDragData->y = endPoint.y();
220
m_pDragData->id = kctCustom + 1;
221
m_pStencil->customDrag(m_pDragData);
223
m_pStencil->updateGeometry();
224
m_pCanvas->repaint();
227
void SMLConnector::mouseRelease( QMouseEvent *e )
236
m_pCanvas->setCursor(*m_pConnectorCursor1);
240
void SMLConnector::endRubberBanding(QMouseEvent *)
242
connector(m_pCanvas->rect());
245
#include "tool_connector.moc"