Changeset 561 for trunk/demos/pathstroke/pathstroke.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/demos/pathstroke/pathstroke.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 403 403 m_wasAnimated = true; 404 404 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 405 setAttribute(Qt::WA_AcceptTouchEvents); 405 406 } 406 407 … … 511 512 Q_ASSERT(m_points.size() == m_vectors.size()); 512 513 for (int i=0; i<m_points.size(); ++i) { 513 514 if (i == m_activePoint)515 continue;516 517 514 QPointF pos = m_points.at(i); 518 515 QPointF vec = m_vectors.at(i); … … 533 530 void PathStrokeRenderer::mousePressEvent(QMouseEvent *e) 534 531 { 532 if (!m_fingerPointMapping.isEmpty()) 533 return; 535 534 setDescriptionEnabled(false); 536 535 m_activePoint = -1; … … 557 556 void PathStrokeRenderer::mouseMoveEvent(QMouseEvent *e) 558 557 { 558 if (!m_fingerPointMapping.isEmpty()) 559 return; 559 560 // If we've moved more then 25 pixels, assume user is dragging 560 561 if (!m_mouseDrag && QPoint(m_mousePress - e->pos()).manhattanLength() > 25) … … 569 570 void PathStrokeRenderer::mouseReleaseEvent(QMouseEvent *) 570 571 { 572 if (!m_fingerPointMapping.isEmpty()) 573 return; 571 574 m_activePoint = -1; 572 575 setAnimation(m_wasAnimated); … … 587 590 } 588 591 592 bool PathStrokeRenderer::event(QEvent *e) 593 { 594 bool touchBegin = false; 595 switch (e->type()) { 596 case QEvent::TouchBegin: 597 touchBegin = true; 598 case QEvent::TouchUpdate: 599 { 600 const QTouchEvent *const event = static_cast<const QTouchEvent*>(e); 601 const QList<QTouchEvent::TouchPoint> points = event->touchPoints(); 602 foreach (const QTouchEvent::TouchPoint &touchPoint, points) { 603 const int id = touchPoint.id(); 604 switch (touchPoint.state()) { 605 case Qt::TouchPointPressed: 606 { 607 // find the point, move it 608 QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values()); 609 int activePoint = -1; 610 qreal distance = -1; 611 const int pointsCount = m_points.size(); 612 for (int i=0; i<pointsCount; ++i) { 613 if (activePoints.contains(i)) 614 continue; 615 616 qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length(); 617 if ((distance < 0 && d < 12 * m_pointSize) || d < distance) { 618 distance = d; 619 activePoint = i; 620 } 621 } 622 if (activePoint != -1) { 623 m_fingerPointMapping.insert(touchPoint.id(), activePoint); 624 m_points[activePoint] = touchPoint.pos(); 625 } 626 } 627 break; 628 case Qt::TouchPointReleased: 629 { 630 // move the point and release 631 QHash<int,int>::iterator it = m_fingerPointMapping.find(id); 632 m_points[it.value()] = touchPoint.pos(); 633 m_fingerPointMapping.erase(it); 634 } 635 break; 636 case Qt::TouchPointMoved: 637 { 638 // move the point 639 const int pointIdx = m_fingerPointMapping.value(id, -1); 640 if (pointIdx >= 0) 641 m_points[pointIdx] = touchPoint.pos(); 642 } 643 break; 644 default: 645 break; 646 } 647 } 648 if (m_fingerPointMapping.isEmpty()) { 649 e->ignore(); 650 return false; 651 } else { 652 if (touchBegin) { 653 m_wasAnimated = m_timer.isActive(); 654 setAnimation(false); 655 } 656 update(); 657 return true; 658 } 659 } 660 break; 661 case QEvent::TouchEnd: 662 if (m_fingerPointMapping.isEmpty()) { 663 e->ignore(); 664 return false; 665 } 666 m_fingerPointMapping.clear(); 667 setAnimation(m_wasAnimated); 668 return true; 669 break; 670 default: 671 break; 672 } 673 return QWidget::event(e); 674 } 675 589 676 void PathStrokeRenderer::setAnimation(bool animation) 590 677 {
Note:
See TracChangeset
for help on using the changeset viewer.