~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kivio/plugins/kiviosmlconnector/tool_connector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Kivio - Visual Modelling and Flowcharting
 
3
 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
 
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
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of 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, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
18
 */
 
19
#include "tool_connector.h"
 
20
 
 
21
#include <qcursor.h>
 
22
#include <kdebug.h>
 
23
#include <kiconloader.h>
 
24
#include <kstandarddirs.h>
 
25
#include <koPoint.h>
 
26
#include <kozoomhandler.h>
 
27
 
 
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"
 
33
 
 
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"
 
41
 
 
42
SMLConnector::SMLConnector( KivioView* view )
 
43
:Tool(view,"SMLConnector")
 
44
{
 
45
  setSortNum(3);
 
46
 
 
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);
 
50
 
 
51
  m_mode = stmNone;
 
52
 
 
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);
 
55
}
 
56
 
 
57
SMLConnector::~SMLConnector()
 
58
{
 
59
  delete m_pConnectorCursor1;
 
60
  delete m_pConnectorCursor2;
 
61
}
 
62
 
 
63
 
 
64
/**
 
65
 * Event delegation
 
66
 *
 
67
 * @param e The event to be identified and processed
 
68
 *
 
69
 */
 
70
void SMLConnector::processEvent( QEvent* e )
 
71
{
 
72
    switch (e->type())
 
73
    {
 
74
    case QEvent::MouseButtonPress:
 
75
        mousePress( (QMouseEvent*)e );
 
76
        break;
 
77
 
 
78
    case QEvent::MouseButtonRelease:
 
79
        mouseRelease( (QMouseEvent*)e );
 
80
        break;
 
81
 
 
82
    case QEvent::MouseMove:
 
83
        mouseMove( (QMouseEvent*)e );
 
84
        break;
 
85
 
 
86
    default:
 
87
      break;
 
88
    }
 
89
}
 
90
 
 
91
void SMLConnector::activate()
 
92
{
 
93
   kdDebug(43000) << "SMLConnector activate" << endl;
 
94
    m_pCanvas->setCursor(*m_pConnectorCursor1);
 
95
    m_mode = stmNone;
 
96
    m_pStencil = 0;
 
97
    m_pDragData = 0;
 
98
}
 
99
 
 
100
void SMLConnector::deactivate()
 
101
{
 
102
    m_pStencil = 0;
 
103
    if (m_pDragData)
 
104
      delete m_pDragData;
 
105
 
 
106
    m_pDragData = 0;
 
107
}
 
108
 
 
109
void SMLConnector::configure()
 
110
{
 
111
}
 
112
 
 
113
void SMLConnector::connector(QRect)
 
114
{
 
115
    if (!m_pStencil)
 
116
      return;
 
117
 
 
118
    delete m_pDragData;
 
119
    m_pDragData = 0;
 
120
 
 
121
    KivioDoc* doc = m_pView->doc();
 
122
    KivioPage* page = m_pCanvas->activePage();
 
123
 
 
124
    if (m_pStencil->w() < 3.0 && m_pStencil->h() < 3.0) {
 
125
        page->unselectAllStencils();
 
126
        page->selectStencil(m_pStencil);
 
127
        page->deleteSelectedStencils();
 
128
        m_pStencil = 0;
 
129
        doc->updateView(page);
 
130
        return;
 
131
    }
 
132
 
 
133
    m_pStencil->searchForConnections(page, m_pView->zoomHandler()->unzoomItY(4));
 
134
    doc->updateView(page);
 
135
}
 
136
 
 
137
void SMLConnector::mousePress( QMouseEvent *e )
 
138
{
 
139
  if(e->button() == RightButton)
 
140
  {
 
141
    controller()->activateDefault();
 
142
    return;
 
143
  }
 
144
  if( startRubberBanding( e ) )
 
145
  {
 
146
    m_mode = stmDrawRubber;
 
147
  }
 
148
}
 
149
 
 
150
 
 
151
/**
 
152
 * Tests if we should start rubber banding (always returns true).
 
153
 */
 
154
bool SMLConnector::startRubberBanding( QMouseEvent *e )
 
155
{
 
156
  KivioDoc* doc = m_pView->doc();
 
157
  KivioPage* pPage = m_pCanvas->activePage();
 
158
 
 
159
  startPoint = m_pCanvas->snapToGrid(m_pCanvas->mapFromScreen( e->pos() ));
 
160
 
 
161
  // Create the stencil
 
162
    KivioStencilSpawner* ss = doc->findInternalStencilSpawner("SML Connector");
 
163
 
 
164
  if (!ss) {
 
165
    kdDebug(43000) << "SMLTool: Failed to find StencilSpawner!" << endl;
 
166
    return false;
 
167
  }
 
168
 
 
169
  startPoint = m_pCanvas->snapToGrid(m_pCanvas->mapFromScreen( e->pos() ));
 
170
 
 
171
  // Create the stencil
 
172
  m_pStencil = (KivioSMLConnector*)ss->newStencil("basic_line");
 
173
  m_pStencil->setTextFont(doc->defaultFont());
 
174
 
 
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);
 
179
 
 
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;
 
186
 
 
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);
 
190
 
 
191
 
 
192
  m_pCanvas->repaint();
 
193
  m_pCanvas->setCursor(*m_pConnectorCursor2);
 
194
  return true;
 
195
}
 
196
 
 
197
void SMLConnector::mouseMove( QMouseEvent * e )
 
198
{
 
199
    switch( m_mode )
 
200
    {
 
201
        case stmDrawRubber:
 
202
            continueRubberBanding(e);
 
203
            break;
 
204
 
 
205
        default:
 
206
            break;
 
207
    }
 
208
}
 
209
 
 
210
void SMLConnector::continueRubberBanding( QMouseEvent *e )
 
211
{
 
212
    KoPoint endPoint = m_pCanvas->mapFromScreen( e->pos() );
 
213
    endPoint = m_pCanvas->snapToGrid(endPoint);
 
214
 
 
215
    m_pStencil->setStartPoint(endPoint.x(), endPoint.y());
 
216
 
 
217
 
 
218
    m_pDragData->x = endPoint.x();
 
219
    m_pDragData->y = endPoint.y();
 
220
    m_pDragData->id = kctCustom + 1;
 
221
    m_pStencil->customDrag(m_pDragData);
 
222
 
 
223
    m_pStencil->updateGeometry();
 
224
    m_pCanvas->repaint();
 
225
}
 
226
 
 
227
void SMLConnector::mouseRelease( QMouseEvent *e )
 
228
{
 
229
    switch( m_mode )
 
230
    {
 
231
        case stmDrawRubber:
 
232
            endRubberBanding(e);
 
233
            break;
 
234
    }
 
235
 
 
236
    m_pCanvas->setCursor(*m_pConnectorCursor1);
 
237
        m_mode = stmNone;
 
238
}
 
239
 
 
240
void SMLConnector::endRubberBanding(QMouseEvent *)
 
241
{
 
242
    connector(m_pCanvas->rect());
 
243
    m_pStencil = 0;
 
244
}
 
245
#include "tool_connector.moc"