comparison demos/deform/pathdeform.d @ 161:849b66609571

a few fixes
author mwarning
date Wed, 17 Jun 2009 22:39:42 +0000
parents 691e68637348
children ab01453c9d56
comparison
equal deleted inserted replaced
160:624b4a58556e 161:849b66609571
36 ** If you are unsure which license is appropriate for your use, please 36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at qt-sales@nokia.com. 37 ** contact the sales department at qt-sales@nokia.com.
38 ** $QT_END_LICENSE$ 38 ** $QT_END_LICENSE$
39 ** 39 **
40 ****************************************************************************/ 40 ****************************************************************************/
41 module pathdeform;
42
41 43
42 import arthurwidgets, 44 import arthurwidgets,
43 qt.gui.QPainterPath, 45 qt.gui.QPainterPath,
44 46
45 qt.gui.QApplication, 47 qt.gui.QApplication,
60 qt.gui.QHBoxLayout, 62 qt.gui.QHBoxLayout,
61 qt.gui.QRadialGradient, 63 qt.gui.QRadialGradient,
62 qt.opengl.QGLFormat, 64 qt.opengl.QGLFormat,
63 tango.math.Math; 65 tango.math.Math;
64 66
67
65 class PathDeformControls : QWidget 68 class PathDeformControls : QWidget
66 { 69 {
67 private PathDeformRenderer m_renderer; 70 private PathDeformRenderer m_renderer;
68 71
69 mixin Signal!("okPressed"); 72 mixin Signal!("okPressed");
322 super.setStyle(style); 325 super.setStyle(style);
323 if (m_controls) 326 if (m_controls)
324 { 327 {
325 m_controls.setStyle(style); 328 m_controls.setStyle(style);
326 329
327 auto widgets = m_controls.findChildren!(QWidget); 330 QWidget[] widgets; // = qFindChildren!(QWidget)(m_controls); //TODO
328 foreach (w; widgets) 331 foreach (w; widgets)
329 w.setStyle(style); 332 w.setStyle(style);
330 } 333 }
331 } 334 }
332 } 335 }
333 336
334 private QRect circle_bounds(QPointF center, qreal radius, qreal compensation) 337 private QRect circle_bounds(QPointF center, qreal radius, qreal compensation)
335 { 338 {
336 return new QRect(qRound(center.x() - radius - compensation), 339 return QRect(qRound(center.x() - radius - compensation),
337 qRound(center.y() - radius - compensation), 340 qRound(center.y() - radius - compensation),
338 qRound((radius + compensation) * 2), 341 qRound((radius + compensation) * 2),
339 qRound((radius + compensation) * 2)); 342 qRound((radius + compensation) * 2));
340 } 343 }
341 344
413 f.setStyleStrategy(QFont.ForceOutline); 416 f.setStyleStrategy(QFont.ForceOutline);
414 f.setPointSize(m_fontSize); 417 f.setPointSize(m_fontSize);
415 f.setStyleHint(QFont.Times); 418 f.setStyleHint(QFont.Times);
416 419
417 m_paths = null; 420 m_paths = null;
418 m_pathBounds = new QRectF(); 421 m_pathBounds = QRectF();
419 422
420 QPointF advance; 423 QPointF advance;
421 424
422 auto path = new QPainterPath; 425 auto path = new QPainterPath;
423 path.addText(advance, f, text); 426 path.addText(advance, f, text);
479 override void timerEvent(QTimerEvent e) 482 override void timerEvent(QTimerEvent e)
480 { 483 {
481 484
482 if (e.timerId == m_repaintTimer.timerId) { 485 if (e.timerId == m_repaintTimer.timerId) {
483 486
484 if ((new QLineF(QPointF(0,0), m_direction)).length > 1) 487 if ((QLineF(QPointF(0,0), m_direction)).length() > 1)
485 m_direction *= 0.995; 488 m_direction *= 0.995;
486 qreal time = m_repaintTracker.restart(); 489 qreal time = m_repaintTracker.restart();
487 490
488 QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize); 491 QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize);
489 492
542 { 545 {
543 setDescriptionEnabled(false); 546 setDescriptionEnabled(false);
544 547
545 m_repaintTimer.stop(); 548 m_repaintTimer.stop();
546 m_offset = QPointF(); 549 m_offset = QPointF();
547 if ((new QLineF(m_pos, QPointF(e.pos))).length <= m_radius) 550 if ((QLineF(m_pos, QPointF(e.pos))).length <= m_radius)
548 m_offset = m_pos - QPointF(e.pos); 551 m_offset = m_pos - QPointF(e.pos);
549 552
550 m_mousePress = e.pos; 553 m_mousePress = QPointF(e.pos);
551 554
552 // If we're not running in small screen mode, always assume we're dragging 555 // If we're not running in small screen mode, always assume we're dragging
553 m_mouseDrag = !m_smallScreen; 556 m_mouseDrag = !m_smallScreen;
554 557
555 mouseMoveEvent(e); 558 mouseMoveEvent(e);
568 571
569 override void mouseMoveEvent(QMouseEvent e) 572 override void mouseMoveEvent(QMouseEvent e)
570 { 573 {
571 auto epos = QPointF(e.pos); 574 auto epos = QPointF(e.pos);
572 575
573 if (!m_mouseDrag && (new QLineF(m_mousePress, QPointF(e.pos))).length() > 25.0) 576 if (!m_mouseDrag && (QLineF(m_mousePress, QPointF(e.pos))).length() > 25.0)
574 m_mouseDrag = true; 577 m_mouseDrag = true;
575 578
576 if (m_mouseDrag) { 579 if (m_mouseDrag) {
577 QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize); 580 QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize);
578 if (e.type() == QEvent.MouseMove) { 581 if (e.type() == QEvent.MouseMove) {
579 QLineF line = new QLineF(m_pos, epos + m_offset); 582 QLineF line = QLineF(m_pos, epos + m_offset);
580 line.setLength(line.length() * .1); 583 line.setLength(line.length() * .1);
581 auto dir = QPointF(line.dx(), line.dy()); 584 auto dir = QPointF(line.dx(), line.dy());
582 m_direction = (m_direction + dir) / 2; 585 m_direction = (m_direction + dir) / 2;
583 } 586 }
584 m_pos = epos + m_offset; 587 m_pos = epos + m_offset;