tests/manual/qtabletevent/device_information/tabletwidget.cpp
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 test suite 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 #include "tabletwidget.h"
       
    43 #include <QPainter>
       
    44 #include <QApplication>
       
    45 
       
    46 TabletWidget::TabletWidget()
       
    47 {
       
    48     QPalette newPalette = palette();
       
    49     newPalette.setColor(QPalette::Window, Qt::white);
       
    50     newPalette.setColor(QPalette::WindowText, Qt::black);
       
    51     setPalette(newPalette);
       
    52     qApp->installEventFilter(this);
       
    53     resetAttributes();
       
    54 }
       
    55 
       
    56 bool TabletWidget::eventFilter(QObject *, QEvent *ev)
       
    57 {
       
    58     switch (ev->type()) {
       
    59     case QEvent::TabletEnterProximity:
       
    60     case QEvent::TabletLeaveProximity:
       
    61     case QEvent::TabletMove:
       
    62     case QEvent::TabletPress:
       
    63     case QEvent::TabletRelease:
       
    64         {
       
    65             QTabletEvent *event = static_cast<QTabletEvent*>(ev);
       
    66             mType = event->type();
       
    67             mPos = event->pos();
       
    68             mGPos = event->globalPos();
       
    69             mHiResGlobalPos = event->hiResGlobalPos();
       
    70             mDev = event->device();
       
    71             mPointerType = event->pointerType();
       
    72             mUnique = event->uniqueId();
       
    73             mXT = event->xTilt();
       
    74             mYT = event->yTilt();
       
    75             mZ = event->z();
       
    76             mPress = event->pressure();
       
    77             mTangential = event->tangentialPressure();
       
    78             mRot = event->rotation();
       
    79             if (isVisible())
       
    80                 update();
       
    81             break;
       
    82         }
       
    83     case QEvent::MouseMove:
       
    84         {
       
    85             resetAttributes();
       
    86             QMouseEvent *event = static_cast<QMouseEvent*>(ev);
       
    87             mType = event->type();
       
    88             mPos = event->pos();
       
    89             mGPos = event->globalPos();
       
    90         }
       
    91     default:
       
    92         break;
       
    93     }
       
    94     return false;
       
    95 }
       
    96 
       
    97 void TabletWidget::paintEvent(QPaintEvent *event)
       
    98 {
       
    99     QPainter painter(this);
       
   100 
       
   101     QStringList eventInfo;
       
   102 
       
   103     QString typeString("Event type: ");
       
   104     switch (mType) {
       
   105     case QEvent::TabletEnterProximity:
       
   106         typeString += "QEvent::TabletEnterProximity";
       
   107         break;
       
   108     case QEvent::TabletLeaveProximity:
       
   109         typeString += "QEvent::TabletLeaveProximity";
       
   110         break;
       
   111     case QEvent::TabletMove:
       
   112         typeString += "QEvent::TabletMove";
       
   113         break;
       
   114     case QEvent::TabletPress:
       
   115         typeString += "QEvent::TabletPress";
       
   116         break;
       
   117     case QEvent::TabletRelease:
       
   118         typeString += "QEvent::TabletRelease";
       
   119         break;
       
   120     case QEvent::MouseMove:
       
   121         typeString += "QEvent::MouseMove";
       
   122         break;
       
   123     }
       
   124     eventInfo << typeString;
       
   125 
       
   126     eventInfo << QString("Global position: %1 %2").arg(QString::number(mGPos.x()), QString::number(mGPos.y()));
       
   127     eventInfo << QString("Local position: %1 %2").arg(QString::number(mPos.x()), QString::number(mPos.y()));
       
   128     if (mType == QEvent::TabletEnterProximity || mType == QEvent::TabletLeaveProximity
       
   129         || mType == QEvent::TabletMove || mType == QEvent::TabletPress
       
   130         || mType == QEvent::TabletRelease) {
       
   131 
       
   132         eventInfo << QString("Hight res global position: %1 %2").arg(QString::number(mHiResGlobalPos.x()), QString::number(mHiResGlobalPos.y()));
       
   133 
       
   134         QString pointerType("Pointer type: ");
       
   135         switch (mPointerType) {
       
   136         case QTabletEvent::UnknownPointer:
       
   137             pointerType += "QTabletEvent::UnknownPointer";
       
   138             break;
       
   139         case QTabletEvent::Pen:
       
   140             pointerType += "QTabletEvent::Pen";
       
   141             break;
       
   142         case QTabletEvent::Cursor:
       
   143             pointerType += "QTabletEvent::Cursor";
       
   144             break;
       
   145         case QTabletEvent::Eraser:
       
   146             pointerType += "QTabletEvent::Eraser";
       
   147             break;
       
   148         }
       
   149         eventInfo << pointerType;
       
   150 
       
   151 
       
   152         QString deviceString = "Device type: ";
       
   153         switch (mDev) {
       
   154         case QTabletEvent::NoDevice:
       
   155             deviceString += "QTabletEvent::NoDevice";
       
   156             break;
       
   157         case QTabletEvent::Puck:
       
   158             deviceString += "QTabletEvent::Puck";
       
   159             break;
       
   160         case QTabletEvent::Stylus:
       
   161             deviceString += "QTabletEvent::Stylus";
       
   162             break;
       
   163         case QTabletEvent::Airbrush:
       
   164             deviceString += "QTabletEvent::Airbrush";
       
   165             break;
       
   166         case QTabletEvent::FourDMouse:
       
   167             deviceString += "QTabletEvent::FourDMouse";
       
   168             break;
       
   169         case QTabletEvent::RotationStylus:
       
   170             deviceString += "QTabletEvent::RotationStylus";
       
   171             break;
       
   172         }
       
   173         eventInfo << deviceString;
       
   174 
       
   175         eventInfo << QString("Pressure: %1").arg(QString::number(mPress));
       
   176         eventInfo << QString("Tangential pressure: %1").arg(QString::number(mTangential));
       
   177         eventInfo << QString("Rotation: %1").arg(QString::number(mRot));
       
   178         eventInfo << QString("xTilt: %1").arg(QString::number(mXT));
       
   179         eventInfo << QString("yTilt: %1").arg(QString::number(mYT));
       
   180         eventInfo << QString("z: %1").arg(QString::number(mZ));
       
   181 
       
   182         eventInfo << QString("Unique Id: %1").arg(QString::number(mUnique));
       
   183     }
       
   184 
       
   185     painter.drawText(rect(), eventInfo.join("\n"));
       
   186 }
       
   187 
       
   188 void TabletWidget::tabletEvent(QTabletEvent *event)
       
   189 {
       
   190     event->accept();
       
   191 }
       
   192