@@ -43,6 +43,42 @@ void QtCanvas::animate()
4343 update ();
4444}
4545
46+ static QRectF getRect (DrawMode mode, float a, float b, float c, float d)
47+ {
48+ QRectF bbox;
49+ switch (mode)
50+ {
51+ case RADIUS:
52+ {
53+ float x = a - c;
54+ float y = b - d;
55+ bbox.setRect (x, y, 2 * c, 2 * d);
56+ break ;
57+ }
58+ case CENTER:
59+ {
60+ float x = a - 0.5 * c;
61+ float y = b - 0.5 * d;
62+ bbox.setRect (x, y, c, d);
63+ break ;
64+ }
65+ case CORNER:
66+ {
67+ bbox.setRect (a, b, c, d);
68+ break ;
69+ }
70+ case CORNERS:
71+ {
72+ QPointF tl (a, b);
73+ QPointF br (c, d);
74+ bbox.setTopLeft (tl);
75+ bbox.setBottomRight (br);
76+ break ;
77+ }
78+ }
79+ return bbox;
80+ }
81+
4682void QtCanvas::paint (QPainter *painter, QPaintEvent *event)
4783{
4884 for (std::list<PElement *>::const_iterator it = draw_queue.cbegin ();
@@ -158,36 +194,46 @@ void QtCanvas::paint(QPainter *painter, QPaintEvent *event)
158194 case PElement::Rect:
159195 {
160196 PRect *r = (PRect *) e;
161- switch (style.rect_mode )
162- {
163- case RADIUS:
164- {
165- float x = r->a () - r->c ();
166- float y = r->b () - r->d ();
167- painter->drawRect (x, y, 2 * r->c (), 2 * r->d ());
168- break ;
169- }
170- case CENTER:
171- {
172- float x = r->a () - 0.5 * r->c ();
173- float y = r->b () - 0.5 * r->d ();
174- painter->drawRect (x, y, r->c (), r->d ());
175- break ;
176- }
177- case CORNER:
178- {
179- painter->drawRect (r->a (), r->b (), r->c (), r->d ());
180- break ;
181- }
182- case CORNERS:
183- {
184- QPointF tl (r->a (), r->b ());
185- QPointF br (r->c (), r->d ());
186- QRectF bbox (tl, br);
187- painter->drawRect (bbox);
188- break ;
189- }
190- }
197+ QRectF bbox = getRect (style.rect_mode , r->a (), r->b (), r->c (), r->d ());
198+ painter->drawRect (bbox);
199+ break ;
200+ }
201+ case PElement::RoundedRect:
202+ {
203+ PRoundedRect *r = (PRoundedRect *)e;
204+ QRectF bbox = getRect (style.rect_mode , r->a (), r->b (), r->c (), r->d ());
205+ painter->drawRoundedRect (bbox, r->r (), r->r ());
206+ break ;
207+ }
208+ case PElement::RoundedRectC4:
209+ {
210+ PRoundedRectC4 *r = (PRoundedRectC4 *)e;
211+ QRectF bbox = getRect (style.rect_mode , r->a (), r->b (), r->c (), r->d ());
212+ QPainterPath path;
213+ float x = bbox.x ();
214+ float y = bbox.y ();
215+ float w = bbox.width ();
216+ float h = bbox.height ();
217+ float hw = 0.5 * w;
218+ float hh = 0.5 * h;
219+ path.setFillRule (Qt::WindingFill);
220+ path.addRoundedRect (x, y , hw, hh, r->tl (), r->tl ());
221+ path.addRoundedRect (x + hw, y , hw, hh, r->tr (), r->tr ());
222+ path.addRoundedRect (x + hw, y + hw, hw, hh, r->br (), r->br ());
223+ path.addRoundedRect (x, y + hw, hw, hh, r->bl (), r->bl ());
224+ path.addRect (x + hw - r->tl (), y, r->tl (), r->tl ());
225+ path.addRect (x, y + hh - r->tl (), r->tl (), r->tl ());
226+ path.addRect (x + hw - r->tl (), y + hh - r->tl (), r->tl (), r->tl ());
227+ path.addRect (x + hw, y, r->tr (), r->tr ());
228+ path.addRect (x + hw, y + hh - r->tr (), r->tr (), r->tr ());
229+ path.addRect (x + w - r->tr (), y + hh - r->tr (), r->tr (), r->tr ());
230+ path.addRect (x + hw, y + hh, r->br (), r->br ());
231+ path.addRect (x + h - r->br (), y + hh, r->br (), r->br ());
232+ path.addRect (x + hw, y + h - r->br (), r->br (), r->br ());
233+ path.addRect (x, y + hh, r->bl (), r->bl ());
234+ path.addRect (x + hw - r->bl (), y + hh, r->bl (), r->bl ());
235+ path.addRect (x + hw - r->bl (), y + h - r->bl (), r->bl (), r->bl ());
236+ painter->drawPath (path.simplified ());
191237 break ;
192238 }
193239 case PElement::Triangle:
0 commit comments