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