kivio

kivio_stencil.h
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2003 theKompany.com & Dave Marotti,
4 * Peter Simonsson
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program 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 this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20#ifndef KIVIO_STENCIL_H
21#define KIVIO_STENCIL_H
22
23#include <tqfont.h>
24#include <tqcolor.h>
25#include <tqdom.h>
26#include <tqptrlist.h>
27#include <tqbitarray.h>
28#include <KoPoint.h>
29#include <tdeglobalsettings.h>
30#include <KoRect.h>
31#include <koffice_export.h>
32
33#include "kivio_line_style.h"
34
35class KivioCustomDragData;
36class KivioConnectorPoint;
37class KivioConnectorTarget;
38class KivioFillStyle;
39class KivioIntraStencilData;
40class KivioPage;
41class KoPoint;
42class KoRect;
43class KivioStencilSpawner;
44class KivioStencil;
45class KivioStencilIface;
46
47// If a custom draggable is clicked, an ID must be returned in the range of kctCustom to MAXINT
48typedef enum
49{
50 kctNone = 0, // No collision
51 kctBody, // The body of the stencil was clicked
52 kctCustom=500 // A custom draggable portion was clicked.
53} KivioCollisionType;
54
55typedef enum
56{
57 kpX = 0,
58 kpY,
59 kpWidth,
60 kpHeight,
61 kpAspect,
62 kpDeletion
63} KivioProtection;
64#define NUM_PROTECTIONS 6
65
66typedef enum
67{
68 krhpNone=0x0000,
69 krhpNW=0x0001,
70 krhpN=0x0002,
71 krhpNE=0x0004,
72 krhpE=0x0008,
73 krhpSE=0x0010,
74 krhpS=0x0020,
75 krhpSW=0x0040,
76 krhpW=0x0080,
77 krhpC=0x0100
78} KivioResizeHandlePosition;
79
80typedef enum
81{
82 kstNormal = 0,
83 kstConnector,
84 kstGroup,
85 kstText
86} KivioStencilType;
87
88#define KIVIO_RESIZE_HANDLE_POSITION_ALL \
89 ( krhpNW \
90 | krhpN \
91 | krhpNE \
92 | krhpE \
93 | krhpSE \
94 | krhpS \
95 | krhpSW \
96 | krhpW \
97 | krhpC )
98
99#define KIVIO_RESIZE_HANDLE_POSITION_BORDER \
100 ( krhpNW \
101 | krhpN \
102 | krhpNE \
103 | krhpE \
104 | krhpSE \
105 | krhpS \
106 | krhpSW \
107 | krhpW )
108
109#define KIVIO_RESIZE_HANDLE_POSITION_CORNERS \
110 ( krhpNW \
111 | krhpNE \
112 | krhpSE \
113 | krhpSW )
114
115
116
117class KIVIO_EXPORT KivioStencil
118{
119 protected:
120 // Dimensions, size
121 double m_x, m_y, m_w, m_h;
122
123 // Rotation
124 int m_rotation;
125 KoPoint m_pinPoint;
126
127 // The spawner that created this stencil
128 KivioStencilSpawner *m_pSpawner;
129
130 // The protection bits of the stencil
131 TQBitArray *m_pProtection;
132 TQBitArray *m_pCanProtect;
133
134 // The stemcil type
135 KivioStencilType m_type;
136 bool m_connected;
137
138 // Indicates if this stencil is selected
139 bool m_selected;
140
141 // Indicates if the stencil is hidden
142 bool m_hidden;
143
144 protected:
145 void rotatePainter(KivioIntraStencilData *);
146 KoRect calculateBoundingBox();
147
148 public:
149 KivioStencil();
150 virtual ~KivioStencil();
151
152 virtual KivioStencil *duplicate() { return NULL; }
153
154 virtual KivioStencilType type() { return m_type; }
155 virtual void setType(KivioStencilType t) { m_type = t; }
156 virtual bool connected() { return m_connected; }
157 virtual void setConnected(bool c) { m_connected = c; }
158
159 virtual double x() { return m_x; }
160 virtual void setX( double f ) { m_x=f; updateGeometry(); }
161
162 virtual double y() { return m_y; }
163 virtual void setY( double f ) { m_y=f; updateGeometry(); }
164
165 virtual double w() { return m_w; }
166 virtual void setW( double f ) { if( f > 0 ) { m_w=f; updateGeometry(); } }
167
168 virtual double h() { return m_h; }
169 virtual void setH( double f ) { if( f > 0 ) { m_h=f; updateGeometry(); } }
170
171 virtual void move(double xOffset, double yOffset);
172
173 virtual KoRect rect();
174
175 virtual void setPosition( double f1, double f2 ) { m_x=f1; m_y=f2; updateGeometry(); }
176 virtual void setDimensions( double f1, double f2 ) { m_w=f1; m_h=f2; updateGeometry(); }
177
178 virtual TQColor fgColor() { return TQColor(0,0,0); }
179 virtual void setFGColor( TQColor ) { ; }
180
181 virtual void setBGColor( TQColor ) { ; }
182 virtual TQColor bgColor() { return TQColor(0,0,0); }
183 virtual void setFillPattern(int) { ; }
184 virtual int fillPattern() { return 1; }
185
186 virtual KivioFillStyle *fillStyle() { return NULL; }
187 virtual KivioLineStyle lineStyle() { return KivioLineStyle(); }
188 virtual void setLineStyle(KivioLineStyle) { ; }
189
190 virtual void setLineWidth( double ) { ; }
191 virtual double lineWidth() { return 1.0f; }
192
193 virtual void setLinePattern(int) { ; }
194 virtual int linePattern() { return 1; }
195
196 // FOnt stuff
197 virtual TQColor textColor() { return TQColor(0,0,0); }
198 virtual void setTextColor( TQColor ) {;}
199
200 virtual TQFont textFont() { return TDEGlobalSettings::generalFont(); }
201 virtual void setTextFont( const TQFont & ) {;}
202
203 virtual int hTextAlign() { return -1; }
204 virtual int vTextAlign() { return -1; }
205
206 virtual void setHTextAlign(int) { ; }
207 virtual void setVTextAlign(int) { ; }
208
209 virtual void setText( const TQString & ) { ; }
210 virtual TQString text() { return TQString(""); }
211
212 virtual void setRotation(int d);
213 virtual int rotation() { return m_rotation; }
214
215 virtual KivioStencilSpawner *spawner() { return m_pSpawner; }
216 virtual void setSpawner( KivioStencilSpawner *s ) { m_pSpawner=s; }
217
218 virtual void paint( KivioIntraStencilData * );
219 virtual void paintOutline( KivioIntraStencilData * );
220 virtual void paintConnectorTargets( KivioIntraStencilData * );
221 virtual void paintSelectionHandles( KivioIntraStencilData * );
222
223 virtual KivioCollisionType checkForCollision( KoPoint *, double );
224 virtual void customDrag( KivioCustomDragData * );
225
226
227 virtual bool loadXML( const TQDomElement & );
228 virtual TQDomElement saveXML( TQDomDocument & );
229
230 virtual bool isSelected() { return m_selected; }
231 virtual void select() { m_selected = true; }
232 virtual void unselect() { m_selected = false; }
233 virtual void subSelect( const double &, const double & ) { ; }
234
235 virtual TQBitArray *protection() { return m_pProtection; }
236 virtual TQBitArray *canProtect() { return m_pCanProtect; }
237
238 virtual void addToGroup( KivioStencil * );
239 virtual TQPtrList<KivioStencil>* groupList() { return NULL; }
240
241 virtual void updateGeometry();
242 virtual void updateConnectorPoints(KivioConnectorPoint *, double oldX, double oldY);
243
244 // This attempts to connect based on position
245 virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, double );
246
247 // This attempts to connect based on a targetID. This should ***ONLY*** be used
248 // right after a load
249 virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, int );
250
251 virtual KoPoint snapToTarget( const KoPoint& p, double /*thresh*/, bool& hit );
252
253 virtual void searchForConnections( KivioPage * );
254 virtual void searchForConnections( KivioPage *pPage, double threshold );
255
256 virtual int generateIds( int );
257
258 virtual int resizeHandlePositions() { return krhpNone; }
259
264 virtual TQString getTextBoxName(const KoPoint& /*p*/) { return TQString(); }
265
266 virtual void setText(const TQString& /*text*/, const TQString& /*name*/) { ; }
267 virtual TQString text(const TQString& /*name*/) { return TQString(""); }
268
270 virtual bool hasTextBox() const { return false; }
271
272 virtual TQColor textColor(const TQString& /*textBoxName*/) { return TQColor(); }
273 virtual void setTextColor(const TQString& /*textBoxName*/, const TQColor& /*color*/) {}
274
275 virtual TQFont textFont(const TQString& /*textBoxName*/) { return TDEGlobalSettings::generalFont(); }
276 virtual void setTextFont(const TQString& /*textBoxName*/, const TQFont& /*font*/) {}
277
278 virtual int hTextAlign(const TQString& /*textBoxName*/) { return -1; }
279 virtual int vTextAlign(const TQString& /*textBoxName*/) { return -1; }
280
281 virtual void setHTextAlign(const TQString& /*textBoxName*/, int /*align*/) {}
282 virtual void setVTextAlign(const TQString& /*textBoxName*/, int /*align*/) {}
283
284 virtual void setPinPoint(const KoPoint& p) { m_pinPoint = p; }
285 virtual KoPoint pinPoint() const { return m_pinPoint; }
286
287 virtual void addConnectorTarget(const KoPoint&) {}
288 virtual void removeConnectorTarget(const KoPoint&) {}
289
290 virtual bool isInRect(const KoRect& rect);
291
292 virtual void setHidden(bool hide) { m_hidden = hide; }
293 virtual bool hidden() { return m_hidden; }
294
295 virtual void setCustomIDPoint(int, const KoPoint&, KivioPage*) {}
296 virtual KoPoint customIDPoint(int) { return KoPoint(); }
297
298 /****** ARROW HEAD STUFF *******/
299 virtual void setStartAHType( int ) { ; }
300 virtual void setStartAHWidth( double ) { ; }
301 virtual void setStartAHLength( double ) { ; }
302 virtual void setEndAHType( int ) { ; }
303 virtual void setEndAHWidth( double ) { ; }
304 virtual void setEndAHLength( double ) { ; }
305
306 virtual int startAHType() { return 0; }
307 virtual double startAHWidth() { return 0.0f; }
308 virtual double startAHLength() { return 0.0f; }
309 virtual int endAHType() { return 0; }
310 virtual double endAHWidth() { return 0.0f; }
311 virtual double endAHLength() { return 0.0f; }
312
313 private:
314 KivioStencilIface *iface;
315};
316
317#endif