Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/demos/pathstroke/pathstroke.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the demonstration applications of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    403403    m_wasAnimated = true;
    404404    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     405    setAttribute(Qt::WA_AcceptTouchEvents);
    405406}
    406407
     
    511512    Q_ASSERT(m_points.size() == m_vectors.size());
    512513    for (int i=0; i<m_points.size(); ++i) {
    513 
    514         if (i == m_activePoint)
    515             continue;
    516 
    517514        QPointF pos = m_points.at(i);
    518515        QPointF vec = m_vectors.at(i);
     
    533530void PathStrokeRenderer::mousePressEvent(QMouseEvent *e)
    534531{
     532    if (!m_fingerPointMapping.isEmpty())
     533        return;
    535534    setDescriptionEnabled(false);
    536535    m_activePoint = -1;
     
    557556void PathStrokeRenderer::mouseMoveEvent(QMouseEvent *e)
    558557{
     558    if (!m_fingerPointMapping.isEmpty())
     559        return;
    559560    // If we've moved more then 25 pixels, assume user is dragging
    560561    if (!m_mouseDrag && QPoint(m_mousePress - e->pos()).manhattanLength() > 25)
     
    569570void PathStrokeRenderer::mouseReleaseEvent(QMouseEvent *)
    570571{
     572    if (!m_fingerPointMapping.isEmpty())
     573        return;
    571574    m_activePoint = -1;
    572575    setAnimation(m_wasAnimated);
     
    587590}
    588591
     592bool 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
    589676void PathStrokeRenderer::setAnimation(bool animation)
    590677{
Note: See TracChangeset for help on using the changeset viewer.