1
2 #include <qpainter.h>
3 #include <qtimer.h>
4 #include <qpixmap.h>
5
6 #include <kmenubar.h>
7 #include <kapp.h>
8 #include <kstdaccel.h>
9
10 #include "klongdraw.moc"
11
12
13 KLongDraw::KLongDraw (QWidget *parent, const char *name=0) :
14 QWidget (parent, name)
15 {
16 bneedrecreate=true;
17 qpixmap=0;
18
19 for (int i=0; i<NEllipses; i++)
20 {
21 x[i]=(kapp->random()%1000)/1000.;
22 y[i]=(kapp->random()%1000)/1000.;
23 }
24
25 setBackgroundMode (NoBackground);
26
27 qtimer = new QTimer (this);
28 connect ( qtimer, SIGNAL (timeout()),
29 this, SLOT (slotDrawSome()) );
30 }
31 void
32 KLongDraw::paintEvent (QPaintEvent *)
33 {
34
35 if (bneedrecreate)
36 {
37 if (qpixmap!=0)
38 delete qpixmap;
39 qpixmap = new QPixmap (width(), height());
40
41 QPainter qpainter;
42 qpainter.begin (qpixmap, this);
43 qpainter.fillRect (qpixmap->rect(), white);
44
45 bitBlt (this, 0, 0, qpixmap);
46
47 w = width()/100;
48 h = height()/100;
49
50 bneedrecreate=false;
51 total=0;
52
53 qtimer->start(0);
54 }
55
56 bitBlt (this, 0, 0, qpixmap);
57
58 }
59
60 void
61 KLongDraw::slotDrawSome()
62 {
63
64 QPainter qpainter;
65 qpainter.begin (qpixmap, this);
66
67 qpainter.setBrush (blue);
68
69 int imax = total+100;
70 for (int i=total; i<imax; i++)
71 qpainter.drawEllipse (x[i]*width(), y[i]*height(), w, h);
72 total = imax;
73 //This updates the window periodically with the partially-drawn scene.
74 // While this _does_ indicate progress on the update, you might,
75 // instead, update a progress bar here and only call update()
76 // after the entire scene has been drawn.
77 if (!(total%1000))
78 update();
79
80 if (total>=NEllipses)
81 {
82 qtimer->stop();
83 update();
84 }
85
86
87 }
88 void
89 KLongDraw::resizeEvent (QResizeEvent *)
90 {
91 bneedrecreate = true;
92 }
93 |