kivio_stencil.cpp
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_custom_drag_data.h"
20#include "kivio_fill_style.h"
21#include "kivio_intra_stencil_data.h"
22#include "kivio_painter.h"
23#include "kivio_stencil.h"
24
25#include <KoZoomHandler.h>
26#include <KoRect.h>
27#include <KIvioStencilIface.h>
28
29KivioStencil::KivioStencil()
30 : m_pSpawner(NULL),
31 m_pProtection(NULL),
32 m_pCanProtect(NULL)
33{
34 m_x = m_y = 0.0f;
35 m_w = m_h = 72.0f;
36
37 m_rotation = 0;
38
39 m_hidden = false;
40
41 m_selected = false;
42
43 m_pProtection = new TQBitArray(NUM_PROTECTIONS);
44 m_pCanProtect = new TQBitArray(NUM_PROTECTIONS);
45
46 for( int i = 0; i < NUM_PROTECTIONS; i++ )
47 {
48 m_pProtection->clearBit(i);
49 m_pCanProtect->setBit(i);
50 }
51
52 m_type = kstNormal;
53 m_connected = false;
54
55 iface = new KivioStencilIface(this);
56}
57
58KivioStencil::~KivioStencil()
59{
60 kdDebug(43000)<<" KivioStencil::~KivioStencil() !"<<this<<endl;
61 delete m_pProtection;
62 m_pProtection = NULL;
63 delete m_pCanProtect;
64 m_pCanProtect = NULL;
65
66
67 m_pSpawner = NULL;
68}
69
70KoRect KivioStencil::rect()
71{
72 return KoRect( m_x, m_y, m_w, m_h );
73}
74
75
76bool KivioStencil::loadXML( const TQDomElement & )
77{
78 return false;
79}
80
81TQDomElement KivioStencil::saveXML( TQDomDocument &doc )
82{
83 return doc.createElement("");
84}
85
86void KivioStencil::paint( KivioIntraStencilData */*pData*/ )
87{
88}
89
90/*
91 * Paints the outline of the stencil, no filling is done.
92 */
93void KivioStencil::paintOutline( KivioIntraStencilData * )
94{
95}
96
97void KivioStencil::paintConnectorTargets( KivioIntraStencilData * )
98{
99}
100
101void KivioStencil::paintSelectionHandles( KivioIntraStencilData *pData )
102{
103 int newX, newY, newW, newH;
104
105 // Handle Width
106 //const double HW = 6.0f;
107 //const double HWP1 = HW+1.0f;
108
109 // Handle Width Over 2
110 //const double HWo2 = HW/2.0f;
111
112 KoZoomHandler* zoomHandler = pData->zoomHandler;
113
114 KivioPainter *painter = pData->painter;
115
116 newX = zoomHandler->zoomItX(m_x - tqRound(lineWidth() / 2));
117 newY = zoomHandler->zoomItY(m_y - tqRound(lineWidth() / 2));
118 newW = zoomHandler->zoomItX(m_w + lineWidth() + 1);
119 newH = zoomHandler->zoomItY(m_h + lineWidth() + 1);
120
121 painter->saveState();
122 painter->setTranslation(newX, newY);
123 rotatePainter(pData); // Rotate the painter if needed
124
125 painter->drawSelectionBox(TQRect(0, 0, newW, newH));
126
127 // top left, top right, bottom left, bottom right
128 if( m_pProtection->at( kpWidth ) ||
129 m_pProtection->at( kpHeight ) )
130 {
131 painter->drawHandle( 0, 0, KivioPainter::cpfLock );
132 painter->drawHandle( newW, 0, KivioPainter::cpfLock );
133 painter->drawHandle( 0, newH, KivioPainter::cpfLock );
134 painter->drawHandle( newW, newH, KivioPainter::cpfLock );
135 }
136 else
137 {
138 painter->drawHandle( 0, 0, 0 );
139 painter->drawHandle( newW, 0, 0 );
140 painter->drawHandle( 0, newH, 0 );
141 painter->drawHandle( newW, newH, 0 );
142 }
143
144 // Top/bottom
145 if( m_pProtection->at( kpHeight ) ||
146 m_pProtection->at( kpAspect ) )
147 {
148 painter->drawHandle( newW / 2, 0, KivioPainter::cpfLock );
149 painter->drawHandle( newW / 2, newH, KivioPainter::cpfLock );
150 }
151 else
152 {
153 painter->drawHandle( newW / 2, 0, 0 );
154 painter->drawHandle( newW / 2, newH, 0 );
155 }
156
157 // left, right
158 if( m_pProtection->at( kpWidth ) ||
159 m_pProtection->at( kpAspect ) )
160 {
161 painter->drawHandle( 0, newH / 2, KivioPainter::cpfLock );
162 painter->drawHandle( newW, newH / 2, KivioPainter::cpfLock );
163 }
164 else
165 {
166 painter->drawHandle( 0, newH / 2, 0 );
167 painter->drawHandle( newW, newH / 2, 0 );
168 }
169 painter->restoreState();
170}
171
172KivioCollisionType KivioStencil::checkForCollision( KoPoint *, double )
173{
174 return kctNone;
175}
176
177void KivioStencil::addToGroup( KivioStencil */*pStencil*/ )
178{
179
180}
181
182void KivioStencil::customDrag( KivioCustomDragData * )
183{
184}
185
186void KivioStencil::updateGeometry()
187{
188}
189
190KivioConnectorTarget *KivioStencil::connectToTarget( KivioConnectorPoint *, double )
191{
192 return NULL;
193}
194
195KivioConnectorTarget *KivioStencil::connectToTarget( KivioConnectorPoint *, int )
196{
197 return NULL;
198}
199
200KoPoint KivioStencil::snapToTarget( const KoPoint& p, double /*thresh*/, bool& hit )
201{
202 KoPoint retVal = p;
203 hit = false;
204 return retVal;
205}
206
207int KivioStencil::generateIds(int nextAvailable)
208{
209 return nextAvailable;
210}
211
212void KivioStencil::searchForConnections( KivioPage * )
213{
214}
215
216void KivioStencil::searchForConnections( KivioPage *, double )
217{
218}
219
220void KivioStencil::updateConnectorPoints(KivioConnectorPoint *, double, double)
221{
222 // Default to just calling updateGeometry
223 updateGeometry();
224}
225
226void KivioStencil::rotatePainter(KivioIntraStencilData *pData)
227{
228 if(m_rotation != 0) {
229 TQWMatrix m;
230 m.translate(pData->zoomHandler->zoomItX(m_pinPoint.x()), pData->zoomHandler->zoomItY(m_pinPoint.y()));
231 m.rotate(m_rotation);
232 m.translate(pData->zoomHandler->zoomItX(-m_pinPoint.x()), pData->zoomHandler->zoomItY(-m_pinPoint.y()));
233 pData->painter->setWorldMatrix(m, true);
234 }
235}
236
237KoRect KivioStencil::calculateBoundingBox()
238{
239 KoRect r;
240 return r;
241}
242
243void KivioStencil::setRotation(int d)
244{
245 m_rotation = d;
246 m_pinPoint.setCoords(m_w / 2.0, m_h / 2.0);
247 updateGeometry();
248}
249
250void KivioStencil::move(double xOffset, double yOffset)
251{
252 setX(x() + xOffset);
253 setY(y() + yOffset);
254}
255
256bool KivioStencil::isInRect(const KoRect& rect)
257{
258 bool retVal;
259 retVal = rect.contains(m_x, m_y);
260 retVal = retVal && rect.contains(m_x + m_w, m_y + m_h);
261
262 return retVal;
263}