~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/canvas/q3canvas.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef Q3CANVAS_H
 
30
#define Q3CANVAS_H
 
31
 
 
32
#include "Qt3Support/q3scrollview.h"
 
33
#include "QtGui/qpixmap.h"
 
34
#include "Qt3Support/q3ptrlist.h"
 
35
#include "QtGui/qbrush.h"
 
36
#include "QtGui/qpen.h"
 
37
#include "Qt3Support/q3valuelist.h"
 
38
#include "Qt3Support/q3pointarray.h"
 
39
 
 
40
class Q3CanvasSprite;
 
41
class Q3CanvasPolygonalItem;
 
42
class Q3CanvasRectangle;
 
43
class Q3CanvasPolygon;
 
44
class Q3CanvasEllipse;
 
45
class Q3CanvasText;
 
46
class Q3CanvasLine;
 
47
class Q3CanvasChunk;
 
48
class Q3Canvas;
 
49
class Q3CanvasItem;
 
50
class Q3CanvasView;
 
51
class Q3CanvasPixmap;
 
52
 
 
53
class Q_COMPAT_EXPORT Q3CanvasItemList : public Q3ValueList<Q3CanvasItem*> {
 
54
public:
 
55
    void sort();
 
56
    void drawUnique(QPainter& painter);
 
57
    Q3CanvasItemList operator+(const Q3CanvasItemList &l) const;
 
58
};
 
59
 
 
60
 
 
61
class Q3CanvasItemExtra;
 
62
 
 
63
class Q_COMPAT_EXPORT Q3CanvasItem
 
64
{
 
65
public:
 
66
    Q3CanvasItem(Q3Canvas* canvas);
 
67
    virtual ~Q3CanvasItem();
 
68
 
 
69
    double x() const
 
70
        { return myx; }
 
71
    double y() const
 
72
        { return myy; }
 
73
    double z() const
 
74
        { return myz; } // (depth)
 
75
 
 
76
    virtual void moveBy(double dx, double dy);
 
77
    void move(double x, double y);
 
78
    void setX(double a) { move(a,y()); }
 
79
    void setY(double a) { move(x(),a); }
 
80
    void setZ(double a) { myz=a; changeChunks(); }
 
81
 
 
82
    bool animated() const;
 
83
    virtual void setAnimated(bool y);
 
84
    virtual void setVelocity(double vx, double vy);
 
85
    void setXVelocity(double vx) { setVelocity(vx,yVelocity()); }
 
86
    void setYVelocity(double vy) { setVelocity(xVelocity(),vy); }
 
87
    double xVelocity() const;
 
88
    double yVelocity() const;
 
89
    virtual void advance(int stage);
 
90
 
 
91
    virtual bool collidesWith(const Q3CanvasItem*) const=0;
 
92
 
 
93
    Q3CanvasItemList collisions(bool exact /* NO DEFAULT */) const;
 
94
 
 
95
    virtual void setCanvas(Q3Canvas*);
 
96
 
 
97
    virtual void draw(QPainter&)=0;
 
98
 
 
99
    void show();
 
100
    void hide();
 
101
 
 
102
    virtual void setVisible(bool yes);
 
103
    bool isVisible() const
 
104
        { return (bool)vis; }
 
105
    virtual void setSelected(bool yes);
 
106
    bool isSelected() const
 
107
        { return (bool)sel; }
 
108
    virtual void setEnabled(bool yes);
 
109
    bool isEnabled() const
 
110
        { return (bool)ena; }
 
111
    virtual void setActive(bool yes);
 
112
    bool isActive() const
 
113
        { return (bool)act; }
 
114
    bool visible() const
 
115
        { return (bool)vis; }
 
116
    bool selected() const
 
117
        { return (bool)sel; }
 
118
    bool enabled() const
 
119
        { return (bool)ena; }
 
120
    bool active() const
 
121
        { return (bool)act; }
 
122
 
 
123
    enum RttiValues {
 
124
        Rtti_Item = 0,
 
125
        Rtti_Sprite = 1,
 
126
        Rtti_PolygonalItem = 2,
 
127
        Rtti_Text = 3,
 
128
        Rtti_Polygon = 4,
 
129
        Rtti_Rectangle = 5,
 
130
        Rtti_Ellipse = 6,
 
131
        Rtti_Line = 7,
 
132
        Rtti_Spline = 8
 
133
    };
 
134
 
 
135
    virtual int rtti() const;
 
136
    static int RTTI;
 
137
 
 
138
    virtual QRect boundingRect() const=0;
 
139
    virtual QRect boundingRectAdvanced() const;
 
140
 
 
141
    Q3Canvas* canvas() const
 
142
        { return cnv; }
 
143
 
 
144
protected:
 
145
    void update() { changeChunks(); }
 
146
 
 
147
private:
 
148
    // For friendly subclasses...
 
149
 
 
150
    friend class Q3CanvasPolygonalItem;
 
151
    friend class Q3CanvasSprite;
 
152
    friend class Q3CanvasRectangle;
 
153
    friend class Q3CanvasPolygon;
 
154
    friend class Q3CanvasEllipse;
 
155
    friend class Q3CanvasText;
 
156
    friend class Q3CanvasLine;
 
157
 
 
158
    virtual Q3PointArray chunks() const;
 
159
    virtual void addToChunks();
 
160
    virtual void removeFromChunks();
 
161
    virtual void changeChunks();
 
162
    virtual bool collidesWith(const Q3CanvasSprite*,
 
163
                               const Q3CanvasPolygonalItem*,
 
164
                               const Q3CanvasRectangle*,
 
165
                               const Q3CanvasEllipse*,
 
166
                               const Q3CanvasText*) const = 0;
 
167
    // End of friend stuff
 
168
 
 
169
    Q3Canvas* cnv;
 
170
    static Q3Canvas* current_canvas;
 
171
    double myx,myy,myz;
 
172
    Q3CanvasItemExtra *ext;
 
173
    Q3CanvasItemExtra& extra();
 
174
    uint ani:1;
 
175
    uint vis:1;
 
176
    uint val:1;
 
177
    uint sel:1;
 
178
    uint ena:1;
 
179
    uint act:1;
 
180
};
 
181
 
 
182
 
 
183
class Q3CanvasData;
 
184
 
 
185
class Q_COMPAT_EXPORT Q3Canvas : public QObject
 
186
{
 
187
    Q_OBJECT
 
188
public:
 
189
    Q3Canvas(QObject* parent = 0, const char* name = 0);
 
190
    Q3Canvas(int w, int h);
 
191
    Q3Canvas(QPixmap p, int h, int v, int tilewidth, int tileheight);
 
192
 
 
193
    virtual ~Q3Canvas();
 
194
 
 
195
    virtual void setTiles(QPixmap tiles, int h, int v,
 
196
                           int tilewidth, int tileheight);
 
197
    virtual void setBackgroundPixmap(const QPixmap& p);
 
198
    QPixmap backgroundPixmap() const;
 
199
 
 
200
    virtual void setBackgroundColor(const QColor& c);
 
201
    QColor backgroundColor() const;
 
202
 
 
203
    virtual void setTile(int x, int y, int tilenum);
 
204
    int tile(int x, int y) const
 
205
        { return grid[x+y*htiles]; }
 
206
 
 
207
    int tilesHorizontally() const
 
208
        { return htiles; }
 
209
    int tilesVertically() const
 
210
        { return vtiles; }
 
211
 
 
212
    int tileWidth() const
 
213
        { return tilew; }
 
214
    int tileHeight() const
 
215
        { return tileh; }
 
216
 
 
217
    virtual void resize(int width, int height);
 
218
    int width() const
 
219
        { return awidth; }
 
220
    int height() const
 
221
        { return aheight; }
 
222
    QSize size() const
 
223
        { return QSize(awidth,aheight); }
 
224
    QRect rect() const
 
225
        { return QRect(0, 0, awidth, aheight); }
 
226
    bool onCanvas(int x, int y) const
 
227
        { return x>=0 && y>=0 && x<awidth && y<aheight; }
 
228
    bool onCanvas(const QPoint& p) const
 
229
        { return onCanvas(p.x(),p.y()); }
 
230
    bool validChunk(int x, int y) const
 
231
        { return x>=0 && y>=0 && x<chwidth && y<chheight; }
 
232
    bool validChunk(const QPoint& p) const
 
233
        { return validChunk(p.x(),p.y()); }
 
234
 
 
235
    int chunkSize() const
 
236
        { return chunksize; }
 
237
    virtual void retune(int chunksize, int maxclusters=100);
 
238
 
 
239
    bool sameChunk(int x1, int y1, int x2, int y2) const
 
240
        { return x1/chunksize==x2/chunksize && y1/chunksize==y2/chunksize; }
 
241
    virtual void setChangedChunk(int i, int j);
 
242
    virtual void setChangedChunkContaining(int x, int y);
 
243
    virtual void setAllChanged();
 
244
    virtual void setChanged(const QRect& area);
 
245
    virtual void setUnchanged(const QRect& area);
 
246
 
 
247
    // These call setChangedChunk.
 
248
    void addItemToChunk(Q3CanvasItem*, int i, int j);
 
249
    void removeItemFromChunk(Q3CanvasItem*, int i, int j);
 
250
    void addItemToChunkContaining(Q3CanvasItem*, int x, int y);
 
251
    void removeItemFromChunkContaining(Q3CanvasItem*, int x, int y);
 
252
 
 
253
    Q3CanvasItemList allItems();
 
254
    Q3CanvasItemList collisions(const QPoint&) const;
 
255
    Q3CanvasItemList collisions(const QRect&) const;
 
256
    Q3CanvasItemList collisions(const Q3PointArray& pa, const Q3CanvasItem* item,
 
257
                                bool exact) const;
 
258
 
 
259
    void drawArea(const QRect&, QPainter* p, bool double_buffer=false);
 
260
 
 
261
    // These are for Q3CanvasView to call
 
262
    virtual void addView(Q3CanvasView*);
 
263
    virtual void removeView(Q3CanvasView*);
 
264
    void drawCanvasArea(const QRect&, QPainter* p=0, bool double_buffer=true);
 
265
    void drawViewArea(Q3CanvasView* view, QPainter* p, const QRect& r, bool dbuf);
 
266
 
 
267
    // These are for Q3CanvasItem to call
 
268
    virtual void addItem(Q3CanvasItem*);
 
269
    virtual void addAnimation(Q3CanvasItem*);
 
270
    virtual void removeItem(Q3CanvasItem*);
 
271
    virtual void removeAnimation(Q3CanvasItem*);
 
272
 
 
273
    virtual void setAdvancePeriod(int ms);
 
274
    virtual void setUpdatePeriod(int ms);
 
275
 
 
276
    virtual void setDoubleBuffering(bool y);
 
277
 
 
278
signals:
 
279
    void resized();
 
280
 
 
281
public slots:
 
282
    virtual void advance();
 
283
    virtual void update();
 
284
 
 
285
protected:
 
286
    virtual void drawBackground(QPainter&, const QRect& area);
 
287
    virtual void drawForeground(QPainter&, const QRect& area);
 
288
 
 
289
private:
 
290
    void init(int w, int h, int chunksze=16, int maxclust=100);
 
291
 
 
292
    Q3CanvasChunk& chunk(int i, int j) const;
 
293
    Q3CanvasChunk& chunkContaining(int x, int y) const;
 
294
 
 
295
    QRect changeBounds(const QRect& inarea);
 
296
 
 
297
    void ensureOffScrSize(int osw, int osh);
 
298
    QPixmap offscr;
 
299
    int awidth,aheight;
 
300
    int chunksize;
 
301
    int maxclusters;
 
302
    int chwidth,chheight;
 
303
    Q3CanvasChunk* chunks;
 
304
 
 
305
    Q3CanvasData* d;
 
306
 
 
307
    void initTiles(QPixmap p, int h, int v, int tilewidth, int tileheight);
 
308
    ushort *grid;
 
309
    ushort htiles;
 
310
    ushort vtiles;
 
311
    ushort tilew;
 
312
    ushort tileh;
 
313
    bool oneone;
 
314
    QPixmap pm;
 
315
    QTimer* update_timer;
 
316
    QColor bgcolor;
 
317
    bool debug_redraw_areas;
 
318
    bool dblbuf;
 
319
 
 
320
    friend void qt_unview(Q3Canvas* c);
 
321
 
 
322
    Q_DISABLE_COPY(Q3Canvas)
 
323
};
 
324
 
 
325
class Q3CanvasViewData;
 
326
 
 
327
class Q_COMPAT_EXPORT Q3CanvasView : public Q3ScrollView
 
328
{
 
329
    Q_OBJECT
 
330
public:
 
331
 
 
332
    Q3CanvasView(QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
 
333
    Q3CanvasView(Q3Canvas* viewing, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
 
334
    ~Q3CanvasView();
 
335
 
 
336
    Q3Canvas* canvas() const
 
337
        { return viewing; }
 
338
    void setCanvas(Q3Canvas* v);
 
339
 
 
340
    const QMatrix &worldMatrix() const;
 
341
    const QMatrix &inverseWorldMatrix() const;
 
342
    bool setWorldMatrix(const QMatrix &);
 
343
 
 
344
protected:
 
345
    void drawContents(QPainter *p, int cx, int cy, int cw, int ch);
 
346
    QSize sizeHint() const;
 
347
 
 
348
private:
 
349
    friend class Q3Canvas;
 
350
    void drawContents(QPainter*);
 
351
    Q3Canvas* viewing;
 
352
    Q3CanvasViewData* d;
 
353
    friend void qt_unview(Q3Canvas* c);
 
354
 
 
355
private slots:
 
356
    void updateContentsSize();
 
357
 
 
358
private:
 
359
    Q_DISABLE_COPY(Q3CanvasView)
 
360
};
 
361
 
 
362
 
 
363
class Q_COMPAT_EXPORT Q3CanvasPixmap : public QPixmap
 
364
{
 
365
public:
 
366
#ifndef QT_NO_IMAGEIO
 
367
    Q3CanvasPixmap(const QString& datafilename);
 
368
#endif
 
369
    Q3CanvasPixmap(const QImage& image);
 
370
    Q3CanvasPixmap(const QPixmap&, const QPoint& hotspot);
 
371
    ~Q3CanvasPixmap();
 
372
 
 
373
    int offsetX() const
 
374
        { return hotx; }
 
375
    int offsetY() const
 
376
        { return hoty; }
 
377
    void setOffset(int x, int y) { hotx = x; hoty = y; }
 
378
 
 
379
private:
 
380
    Q_DISABLE_COPY(Q3CanvasPixmap)
 
381
 
 
382
    void init(const QImage&);
 
383
    void init(const QPixmap& pixmap, int hx, int hy);
 
384
 
 
385
    friend class Q3CanvasSprite;
 
386
    friend class Q3CanvasPixmapArray;
 
387
    friend bool qt_testCollision(const Q3CanvasSprite* s1, const Q3CanvasSprite* s2);
 
388
 
 
389
    int hotx,hoty;
 
390
 
 
391
    QImage* collision_mask;
 
392
};
 
393
 
 
394
 
 
395
class Q_COMPAT_EXPORT Q3CanvasPixmapArray
 
396
{
 
397
public:
 
398
    Q3CanvasPixmapArray();
 
399
#ifndef QT_NO_IMAGEIO
 
400
    Q3CanvasPixmapArray(const QString& datafilenamepattern, int framecount=0);
 
401
#endif
 
402
    // this form is deprecated
 
403
    Q3CanvasPixmapArray(Q3PtrList<QPixmap>, Q3PtrList<QPoint> hotspots);
 
404
 
 
405
    Q3CanvasPixmapArray(Q3ValueList<QPixmap>, Q3PointArray hotspots = Q3PointArray());
 
406
    ~Q3CanvasPixmapArray();
 
407
 
 
408
#ifndef QT_NO_IMAGEIO
 
409
    bool readPixmaps(const QString& datafilenamepattern, int framecount=0);
 
410
    bool readCollisionMasks(const QString& filenamepattern);
 
411
#endif
 
412
 
 
413
    // deprecated
 
414
    bool operator!(); // Failure check.
 
415
    bool isValid() const;
 
416
 
 
417
    Q3CanvasPixmap* image(int i) const
 
418
        { return img ? img[i] : 0; }
 
419
    void setImage(int i, Q3CanvasPixmap* p);
 
420
    uint count() const
 
421
        { return (uint)framecount; }
 
422
 
 
423
private:
 
424
    Q_DISABLE_COPY(Q3CanvasPixmapArray)
 
425
 
 
426
#ifndef QT_NO_IMAGEIO
 
427
    bool readPixmaps(const QString& datafilenamepattern, int framecount, bool maskonly);
 
428
#endif
 
429
 
 
430
    void reset();
 
431
    int framecount;
 
432
    Q3CanvasPixmap** img;
 
433
};
 
434
 
 
435
 
 
436
class Q_COMPAT_EXPORT Q3CanvasSprite : public Q3CanvasItem
 
437
{
 
438
public:
 
439
    Q3CanvasSprite(Q3CanvasPixmapArray* array, Q3Canvas* canvas);
 
440
 
 
441
    void setSequence(Q3CanvasPixmapArray* seq);
 
442
 
 
443
    virtual ~Q3CanvasSprite();
 
444
 
 
445
    void move(double x, double y);
 
446
    virtual void move(double x, double y, int frame);
 
447
    void setFrame(int);
 
448
    enum FrameAnimationType { Cycle, Oscillate };
 
449
    virtual void setFrameAnimation(FrameAnimationType=Cycle, int step=1, int state=0);
 
450
    int frame() const
 
451
        { return frm; }
 
452
    int frameCount() const
 
453
        { return images->count(); }
 
454
 
 
455
    int rtti() const;
 
456
    static int RTTI;
 
457
 
 
458
    bool collidesWith(const Q3CanvasItem*) const;
 
459
 
 
460
    QRect boundingRect() const;
 
461
 
 
462
    // is there a reason for these to be protected? Lars
 
463
//protected:
 
464
 
 
465
    int width() const;
 
466
    int height() const;
 
467
 
 
468
    int leftEdge() const;
 
469
    int topEdge() const;
 
470
    int rightEdge() const;
 
471
    int bottomEdge() const;
 
472
 
 
473
    int leftEdge(int nx) const;
 
474
    int topEdge(int ny) const;
 
475
    int rightEdge(int nx) const;
 
476
    int bottomEdge(int ny) const;
 
477
    Q3CanvasPixmap* image() const
 
478
        { return images->image(frm); }
 
479
    virtual Q3CanvasPixmap* imageAdvanced() const;
 
480
    Q3CanvasPixmap* image(int f) const
 
481
        { return images->image(f); }
 
482
    virtual void advance(int stage);
 
483
 
 
484
public:
 
485
    void draw(QPainter& painter);
 
486
 
 
487
private:
 
488
    Q_DISABLE_COPY(Q3CanvasSprite)
 
489
 
 
490
    void addToChunks();
 
491
    void removeFromChunks();
 
492
    void changeChunks();
 
493
 
 
494
    int frm;
 
495
    ushort anim_val;
 
496
    uint anim_state:2;
 
497
    uint anim_type:14;
 
498
    bool collidesWith(const Q3CanvasSprite*,
 
499
                       const Q3CanvasPolygonalItem*,
 
500
                       const Q3CanvasRectangle*,
 
501
                       const Q3CanvasEllipse*,
 
502
                       const Q3CanvasText*) const;
 
503
 
 
504
    friend bool qt_testCollision(const Q3CanvasSprite* s1,
 
505
                                  const Q3CanvasSprite* s2);
 
506
 
 
507
    Q3CanvasPixmapArray* images;
 
508
};
 
509
 
 
510
class QPolygonalProcessor;
 
511
 
 
512
class Q_COMPAT_EXPORT Q3CanvasPolygonalItem : public Q3CanvasItem
 
513
{
 
514
public:
 
515
    Q3CanvasPolygonalItem(Q3Canvas* canvas);
 
516
    virtual ~Q3CanvasPolygonalItem();
 
517
 
 
518
    bool collidesWith(const Q3CanvasItem*) const;
 
519
 
 
520
    virtual void setPen(QPen p);
 
521
    virtual void setBrush(QBrush b);
 
522
 
 
523
    QPen pen() const
 
524
        { return pn; }
 
525
    QBrush brush() const
 
526
        { return br; }
 
527
 
 
528
    virtual Q3PointArray areaPoints() const=0;
 
529
    virtual Q3PointArray areaPointsAdvanced() const;
 
530
    QRect boundingRect() const;
 
531
 
 
532
    int rtti() const;
 
533
    static int RTTI;
 
534
 
 
535
protected:
 
536
    void draw(QPainter &);
 
537
    virtual void drawShape(QPainter &) = 0;
 
538
 
 
539
    bool winding() const;
 
540
    void setWinding(bool);
 
541
 
 
542
    void invalidate();
 
543
    bool isValid() const
 
544
        { return (bool)val; }
 
545
 
 
546
private:
 
547
    void scanPolygon(const Q3PointArray& pa, int winding,
 
548
                      QPolygonalProcessor& process) const;
 
549
    Q3PointArray chunks() const;
 
550
 
 
551
    bool collidesWith(const Q3CanvasSprite*,
 
552
                       const Q3CanvasPolygonalItem*,
 
553
                       const Q3CanvasRectangle*,
 
554
                       const Q3CanvasEllipse*,
 
555
                       const Q3CanvasText*) const;
 
556
 
 
557
    QBrush br;
 
558
    QPen pn;
 
559
    uint wind:1;
 
560
};
 
561
 
 
562
 
 
563
class Q_COMPAT_EXPORT Q3CanvasRectangle : public Q3CanvasPolygonalItem
 
564
{
 
565
public:
 
566
    Q3CanvasRectangle(Q3Canvas* canvas);
 
567
    Q3CanvasRectangle(const QRect&, Q3Canvas* canvas);
 
568
    Q3CanvasRectangle(int x, int y, int width, int height, Q3Canvas* canvas);
 
569
 
 
570
    ~Q3CanvasRectangle();
 
571
 
 
572
    int width() const;
 
573
    int height() const;
 
574
    void setSize(int w, int h);
 
575
    QSize size() const
 
576
        { return QSize(w,h); }
 
577
    Q3PointArray areaPoints() const;
 
578
    QRect rect() const
 
579
        { return QRect(int(x()),int(y()),w,h); }
 
580
 
 
581
    bool collidesWith(const Q3CanvasItem*) const;
 
582
 
 
583
    int rtti() const;
 
584
    static int RTTI;
 
585
 
 
586
protected:
 
587
    void drawShape(QPainter &);
 
588
    Q3PointArray chunks() const;
 
589
 
 
590
private:
 
591
    bool collidesWith(  const Q3CanvasSprite*,
 
592
                         const Q3CanvasPolygonalItem*,
 
593
                         const Q3CanvasRectangle*,
 
594
                         const Q3CanvasEllipse*,
 
595
                         const Q3CanvasText*) const;
 
596
 
 
597
    int w, h;
 
598
};
 
599
 
 
600
 
 
601
class Q_COMPAT_EXPORT Q3CanvasPolygon : public Q3CanvasPolygonalItem
 
602
{
 
603
public:
 
604
    Q3CanvasPolygon(Q3Canvas* canvas);
 
605
    ~Q3CanvasPolygon();
 
606
    void setPoints(Q3PointArray);
 
607
    Q3PointArray points() const;
 
608
    void moveBy(double dx, double dy);
 
609
 
 
610
    Q3PointArray areaPoints() const;
 
611
 
 
612
    int rtti() const;
 
613
    static int RTTI;
 
614
 
 
615
protected:
 
616
    void drawShape(QPainter &);
 
617
    Q3PointArray poly;
 
618
};
 
619
 
 
620
 
 
621
class Q_COMPAT_EXPORT Q3CanvasSpline : public Q3CanvasPolygon
 
622
{
 
623
public:
 
624
    Q3CanvasSpline(Q3Canvas* canvas);
 
625
    ~Q3CanvasSpline();
 
626
 
 
627
    void setControlPoints(Q3PointArray, bool closed=true);
 
628
    Q3PointArray controlPoints() const;
 
629
    bool closed() const;
 
630
 
 
631
    int rtti() const;
 
632
    static int RTTI;
 
633
 
 
634
private:
 
635
    void recalcPoly();
 
636
    Q3PointArray bez;
 
637
    bool cl;
 
638
};
 
639
 
 
640
 
 
641
class Q_COMPAT_EXPORT Q3CanvasLine : public Q3CanvasPolygonalItem
 
642
{
 
643
public:
 
644
    Q3CanvasLine(Q3Canvas* canvas);
 
645
    ~Q3CanvasLine();
 
646
    void setPoints(int x1, int y1, int x2, int y2);
 
647
 
 
648
    QPoint startPoint() const
 
649
        { return QPoint(x1,y1); }
 
650
    QPoint endPoint() const
 
651
        { return QPoint(x2,y2); }
 
652
 
 
653
    int rtti() const;
 
654
    static int RTTI;
 
655
 
 
656
    void setPen(QPen p);
 
657
    void moveBy(double dx, double dy);
 
658
 
 
659
protected:
 
660
    void drawShape(QPainter &);
 
661
    Q3PointArray areaPoints() const;
 
662
 
 
663
private:
 
664
    int x1,y1,x2,y2;
 
665
};
 
666
 
 
667
 
 
668
class Q_COMPAT_EXPORT Q3CanvasEllipse : public Q3CanvasPolygonalItem
 
669
{
 
670
 
 
671
public:
 
672
    Q3CanvasEllipse(Q3Canvas* canvas);
 
673
    Q3CanvasEllipse(int width, int height, Q3Canvas* canvas);
 
674
    Q3CanvasEllipse(int width, int height, int startangle, int angle,
 
675
                    Q3Canvas* canvas);
 
676
 
 
677
    ~Q3CanvasEllipse();
 
678
 
 
679
    int width() const;
 
680
    int height() const;
 
681
    void setSize(int w, int h);
 
682
    void setAngles(int start, int length);
 
683
    int angleStart() const
 
684
        { return a1; }
 
685
    int angleLength() const
 
686
        { return a2; }
 
687
    Q3PointArray areaPoints() const;
 
688
 
 
689
    bool collidesWith(const Q3CanvasItem*) const;
 
690
 
 
691
    int rtti() const;
 
692
    static int RTTI;
 
693
 
 
694
protected:
 
695
    void drawShape(QPainter &);
 
696
 
 
697
private:
 
698
    bool collidesWith(const Q3CanvasSprite*,
 
699
                       const Q3CanvasPolygonalItem*,
 
700
                       const Q3CanvasRectangle*,
 
701
                       const Q3CanvasEllipse*,
 
702
                       const Q3CanvasText*) const;
 
703
    int w, h;
 
704
    int a1, a2;
 
705
};
 
706
 
 
707
 
 
708
class Q3CanvasTextExtra;
 
709
 
 
710
class Q_COMPAT_EXPORT Q3CanvasText : public Q3CanvasItem
 
711
{
 
712
public:
 
713
    Q3CanvasText(Q3Canvas* canvas);
 
714
    Q3CanvasText(const QString&, Q3Canvas* canvas);
 
715
    Q3CanvasText(const QString&, QFont, Q3Canvas* canvas);
 
716
 
 
717
    virtual ~Q3CanvasText();
 
718
 
 
719
    void setText(const QString&);
 
720
    void setFont(const QFont&);
 
721
    void setColor(const QColor&);
 
722
    QString text() const;
 
723
    QFont font() const;
 
724
    QColor color() const;
 
725
 
 
726
    void moveBy(double dx, double dy);
 
727
 
 
728
    int textFlags() const
 
729
        { return flags; }
 
730
    void setTextFlags(int);
 
731
 
 
732
    QRect boundingRect() const;
 
733
 
 
734
    bool collidesWith(const Q3CanvasItem*) const;
 
735
 
 
736
    int rtti() const;
 
737
    static int RTTI;
 
738
 
 
739
protected:
 
740
    virtual void draw(QPainter&);
 
741
 
 
742
private:
 
743
    Q_DISABLE_COPY(Q3CanvasText)
 
744
 
 
745
    void addToChunks();
 
746
    void removeFromChunks();
 
747
    void changeChunks();
 
748
 
 
749
    void setRect();
 
750
    QRect brect;
 
751
    QString txt;
 
752
    int flags;
 
753
    QFont fnt;
 
754
    QColor col;
 
755
    Q3CanvasTextExtra* extra;
 
756
 
 
757
    bool collidesWith(const Q3CanvasSprite*,
 
758
                      const Q3CanvasPolygonalItem*,
 
759
                      const Q3CanvasRectangle*,
 
760
                      const Q3CanvasEllipse*,
 
761
                      const Q3CanvasText*) const;
 
762
};
 
763
 
 
764
#endif // Q3CANVAS_H