1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
/***************************************************************************
kimearea.h - description
-------------------
begin : Thu Jun 14 2001
copyright : (C) 2001 by Jan Schäfer
email : janschaefer@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef KIMEAREA_H
#define KIMEAREA_H
#include <qrect.h>
#include <qpoint.h>
#include <qptrlist.h>
#include <klocale.h>
#include <qmap.h>
#include "kdeversion.h"
class QPainter;
class QPointArray;
class QListViewItem;
class QBitmap;
typedef QPtrList<QRect> SelectionPointList;
typedef QMap<QString,QString> AttributeMap;
typedef QMapConstIterator<QString,QString> AttributeIterator;
class Area
{
public:
enum ShapeType { None, Rectangle, Circle, Polygon, Default, Selection };
static bool highlightArea;
static bool showAlt;
protected:
QRect _rect;
ShapeType _type;
QString _name;
QString _href;
QString _alt;
QString _target;
AttributeMap _attributes;
bool _isSelected;
bool _finished;
bool _isMoving;
int currentHighlighted;
QListViewItem* _listViewItem;
// Only used for Polygons
QPointArray *_coords;
SelectionPointList *_selectionPoints;
QPixmap *_highlightedPixmap;
void drawHighlighting(QPainter & p);
void drawAlt(QPainter & p);
QString getHTMLAttributes() const;
public:
Area();
virtual ~Area();
virtual Area* clone() const;
// Default implementation; is specified by subclasses
virtual bool contains(const QPoint &) const;
// Default implementation; is specified by subclasses
virtual QString coordsToString() const;
virtual void draw(QPainter &);
virtual QBitmap getMask() const;
virtual QString getHTMLCode() const;
virtual void setHighlightedPixmap( QImage &, QBitmap &);
virtual void moveBy(int, int);
virtual void moveTo(int, int);
virtual void moveSelectionPoint(QRect*, const QPoint &);
virtual QRect* onSelectionPoint(const QPoint &,double zoom) const;
virtual bool removeSelectionPoint(QRect * r);
virtual SelectionPointList* selectionPoints() const { return _selectionPoints; }
virtual QRect rect() const;
virtual QRect selectionRect() const;
virtual void setArea(const Area &);
virtual bool setCoords(const QString &);
/** finished drawing only important for polygon */
virtual void setFinished(bool b) { _finished=b; }
virtual void setRect(const QRect &);
virtual void setMoving(bool b);
virtual bool isMoving() const;
// Default implementation; is specified by subclasses
virtual QString typeString() const { return ""; }
virtual ShapeType type() const;
virtual void updateSelectionPoints() {};
// Only interesting for Polygons
virtual void simplifyCoords() {};
virtual int addCoord(const QPoint &);
virtual void insertCoord(int, const QPoint &);
virtual void removeCoord(int);
virtual void moveCoord(int,const QPoint &);
virtual QPointArray* coords() const;
virtual void highlightSelectionPoint(int);
virtual QString attribute(const QString &) const;
virtual void setAttribute(const QString &, const QString &);
virtual AttributeIterator firstAttribute() const;
virtual AttributeIterator lastAttribute() const;
QPixmap cutOut(const QImage &) ;
void setListViewItem(QListViewItem*);
void deleteListViewItem();
QListViewItem* listViewItem() const;
void setName(const QString &);
QString name() const;
void setSelected(bool b);
bool isSelected() const;
bool finished() const;
uint countSelectionPoints() const;
};
inline QListViewItem* Area::listViewItem() const {
return _listViewItem;
}
inline void Area::setName(const QString & name) {
_name=name;
}
inline QString Area::name() const {
return _name;
}
inline bool Area::isMoving() const {
return _isMoving;
}
inline bool Area::isSelected() const {
return _isSelected;
}
inline bool Area::finished() const {
return _finished;
}
/**
* Represents a Rectangle Area
**/
class RectArea : public Area
{
public:
RectArea();
virtual ~RectArea();
virtual Area* clone() const;
virtual bool contains(const QPoint & p) const;
virtual QString coordsToString() const;
virtual void draw(QPainter & p);
virtual void moveSelectionPoint(QRect* selectionPoint, const QPoint & p);
virtual bool setCoords(const QString & s);
virtual QString typeString() const { return i18n("Rectangle"); }
virtual QBitmap getMask() const;
virtual QString getHTMLCode() const;
virtual void updateSelectionPoints();
};
/**
* Represents a Circle Area
**/
class CircleArea : public Area
{
public:
CircleArea();
virtual ~CircleArea();
virtual Area* clone() const;
virtual bool contains(const QPoint & p) const;
virtual QString coordsToString() const;
virtual void draw(QPainter & p);
virtual void moveSelectionPoint(QRect* selectionPoint, const QPoint & p);
virtual bool setCoords(const QString & s);
virtual void setRect(const QRect & r);
virtual QString typeString() const { return i18n("Circle"); }
virtual QBitmap getMask() const;
virtual QString getHTMLCode() const;
virtual void updateSelectionPoints();
};
/**
* Represents a Rectangle Area
**/
class PolyArea :public Area
{
public:
PolyArea();
virtual ~PolyArea();
virtual Area* clone() const;
virtual bool contains(const QPoint & p) const;
virtual QString coordsToString() const;
virtual void draw(QPainter & p);
virtual void moveSelectionPoint(QRect* selectionPoint, const QPoint & p);
virtual void simplifyCoords();
virtual int addCoord(const QPoint & p);
virtual bool setCoords(const QString & s);
virtual QRect selectionRect() const;
virtual void setFinished(bool b);
virtual QString typeString() const { return i18n("Polygon"); }
virtual QBitmap getMask() const;
virtual QString getHTMLCode() const;
virtual void updateSelectionPoints();
private:
static int distance(const QPoint &p1, const QPoint &p2);
static bool isBetween(const QPoint &p, const QPoint &p1, const QPoint &p2);
};
/**
* Represents the default Area
**/
class DefaultArea :public Area
{
public:
DefaultArea();
virtual ~DefaultArea();
virtual Area* clone() const;
// the default area isn't drawn
virtual void draw(QPainter & p);
virtual QString typeString() const { return i18n("Default"); }
virtual QString getHTMLCode() const;
};
typedef QPtrList<Area> AreaList;
typedef QPtrListIterator<Area> AreaListIterator;
/**
* This class represents a selection of areas
* all operations performed on this class
* will be performed on the selected Areas
* the only actions that can be used is the
* move action
**/
class AreaSelection : public Area {
public :
AreaSelection();
virtual ~AreaSelection();
/**
* New Methods
*/
// Adding automatically selects the area
void add(Area *a);
// Removing automatically deselects the area
void remove(Area *a);
// Removes all areas from the list and deselects them
void reset();
uint count() const;
AreaList getAreaList() const;
AreaListIterator getAreaListIterator() const;
void setAreaList( const AreaList & areas );
bool isEmpty() const;
/**
* Overiden Methods of the Area class
*/
virtual bool contains(const QPoint & p) const;
/**
*
**/
virtual QRect* onSelectionPoint(const QPoint & p, double zoom) const;
/**
* Only if one Area is selected the moveSelectionPoint method
* of that Area will be called
**/
virtual void moveSelectionPoint(QRect* selectionPoint, const QPoint & p);
virtual SelectionPointList* selectionPoints() const;
/**
* All Areas will be moved by dx and dy
**/
virtual void moveBy(int dx, int dy);
/**
* Calls for every selected Area the setArea with the
* corresponding Area in the copy Selection.
* IMPORTANT : works only if the copy Area is an AreaSelection
* and have the same number of Areas
**/
virtual void setArea(const Area & copy);
virtual void setAreaSelection(const AreaSelection & copy);
/**
* If only one Area is selected the setRect method of that Area
* will be called
**/
virtual void setRect(const QRect & r);
virtual QRect rect() const;
virtual QString typeString() const;
virtual ShapeType type() const;
// The selection is only a container
// so it is never drawn
virtual void draw(QPainter & p);
/**
* A deep copy of the Areas
**/
virtual Area* clone() const;
virtual void updateSelectionPoints();
virtual int addCoord(const QPoint & p);
virtual void insertCoord(int pos, const QPoint & p);
virtual void removeCoord(int pos);
virtual bool removeSelectionPoint(QRect * r);
virtual void moveCoord(int pos,const QPoint & p);
virtual QPointArray* coords() const;
virtual void highlightSelectionPoint(int);
virtual QRect selectionRect() const;
virtual QString attribute(const QString & name) const;
virtual void setAttribute(const QString & name, const QString & value);
virtual AttributeIterator firstAttribute() const;
virtual AttributeIterator lastAttribute() const;
virtual void setMoving(bool b);
virtual bool isMoving() const;
bool allAreasWithin(const QRect & r) const;
// makes the cache invalid
void invalidate();
private :
AreaList *_areas;
// The selectionRect and the rect are cached
// so even in const functions they must be changeable
mutable QRect _cachedSelectionRect;
mutable QRect _cachedRect;
mutable bool _selectionCacheValid;
mutable bool _rectCacheValid;
};
inline void AreaSelection::invalidate() {
_selectionCacheValid=false;
_rectCacheValid=false;
}
#endif
|