src/testlib/qtesttouch.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtTest module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    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 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QTESTTOUCH_H
       
    43 #define QTESTTOUCH_H
       
    44 
       
    45 #if 0
       
    46 // inform syncqt
       
    47 #pragma qt_no_master_include
       
    48 #endif
       
    49 
       
    50 #include <QtTest/qtest_global.h>
       
    51 #include <QtTest/qtestassert.h>
       
    52 #include <QtTest/qtestsystem.h>
       
    53 #include <QtTest/qtestspontaneevent.h>
       
    54 
       
    55 #include <QtCore/qmap.h>
       
    56 #include <QtGui/qevent.h>
       
    57 #include <QtGui/qwidget.h>
       
    58 
       
    59 QT_BEGIN_HEADER
       
    60 
       
    61 QT_BEGIN_NAMESPACE
       
    62 
       
    63 QT_MODULE(Test)
       
    64 
       
    65 extern Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window,
       
    66                                                    QTouchEvent::DeviceType deviceType,
       
    67                                                    const QList<QTouchEvent::TouchPoint> &touchPoints);
       
    68 
       
    69 namespace QTest
       
    70 {
       
    71 
       
    72     class QTouchEventSequence
       
    73     {
       
    74     public:
       
    75         ~QTouchEventSequence()
       
    76         {
       
    77             commit();
       
    78             points.clear();
       
    79         }
       
    80         QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = 0)
       
    81         {
       
    82             QTouchEvent::TouchPoint &p = point(touchId);
       
    83             p.setScreenPos(mapToScreen(widget, pt));
       
    84             p.setState(Qt::TouchPointPressed);
       
    85             return *this;
       
    86         }
       
    87         QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = 0)
       
    88         {
       
    89             QTouchEvent::TouchPoint &p = point(touchId);
       
    90             p.setScreenPos(mapToScreen(widget, pt));
       
    91             p.setState(Qt::TouchPointMoved);
       
    92             return *this;
       
    93         }
       
    94         QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = 0)
       
    95         {
       
    96             QTouchEvent::TouchPoint &p = point(touchId);
       
    97             p.setScreenPos(mapToScreen(widget, pt));
       
    98             p.setState(Qt::TouchPointReleased);
       
    99             return *this;
       
   100         }
       
   101         QTouchEventSequence& stationary(int touchId)
       
   102         {
       
   103             QTouchEvent::TouchPoint &p = point(touchId);
       
   104             p.setState(Qt::TouchPointStationary);
       
   105             return *this;
       
   106         }
       
   107 
       
   108     private:
       
   109         QTouchEventSequence(QWidget *widget, QTouchEvent::DeviceType deviceType)
       
   110             : targetWidget(widget), deviceType(deviceType)
       
   111         {
       
   112         }
       
   113         QTouchEventSequence(const QTouchEventSequence &v);
       
   114         void operator=(const QTouchEventSequence&);
       
   115 
       
   116         QTouchEvent::TouchPoint &point(int touchId)
       
   117         {
       
   118             if (!points.contains(touchId))
       
   119                 points[touchId] = QTouchEvent::TouchPoint(touchId);
       
   120             return points[touchId];
       
   121         }
       
   122         QPoint mapToScreen(QWidget *widget, const QPoint &pt)
       
   123         {
       
   124             if (widget)
       
   125                 return widget->mapToGlobal(pt);
       
   126             return targetWidget ? targetWidget->mapToGlobal(pt) : pt;
       
   127         }
       
   128         void commit()
       
   129         {
       
   130             qt_translateRawTouchEvent(targetWidget, deviceType, points.values());
       
   131             targetWidget = 0;
       
   132         }
       
   133 
       
   134         QMap<int, QTouchEvent::TouchPoint> points;
       
   135         QWidget *targetWidget;
       
   136         QTouchEvent::DeviceType deviceType;
       
   137         friend QTouchEventSequence touchEvent(QWidget *, QTouchEvent::DeviceType);
       
   138     };
       
   139 
       
   140     inline
       
   141     QTouchEventSequence touchEvent(QWidget *widget = 0,
       
   142                                    QTouchEvent::DeviceType deviceType = QTouchEvent::TouchScreen)
       
   143     {
       
   144         return QTouchEventSequence(widget, deviceType);
       
   145     }
       
   146 
       
   147 }
       
   148 
       
   149 QT_END_NAMESPACE
       
   150 
       
   151 QT_END_HEADER
       
   152 
       
   153 #endif // QTESTTOUCH_H