on 8.02+15.04.20141216.1-0ubuntu1 help sign in
unity8/libs/UbuntuGestures/DebugHelpers.cpp
95 lines 2.7 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "DebugHelpers.h"
18#include <QTouchEvent>
19#include <QMouseEvent>
21QString touchPointStateToString(Qt::TouchPointState state)
23 switch (state) {
24 case Qt::TouchPointPressed:
25 return QString("pressed");
26 case Qt::TouchPointMoved:
27 return QString("moved");
28 case Qt::TouchPointStationary:
29 return QString("stationary");
30 case Qt::TouchPointReleased:
31 return QString("released");
32 default:
33 return QString("INVALID_STATE");
34 }
37QString touchEventToString(const QTouchEvent *ev)
39 QString message;
41 switch (ev->type()) {
42 case QEvent::TouchBegin:
43 message.append("TouchBegin ");
44 break;
45 case QEvent::TouchUpdate:
46 message.append("TouchUpdate ");
47 break;
48 case QEvent::TouchEnd:
49 message.append("TouchEnd ");
50 break;
51 case QEvent::TouchCancel:
52 message.append("TouchCancel ");
53 break;
54 default:
55 message.append("INVALID_TOUCH_EVENT_TYPE ");
56 }
58 foreach(const QTouchEvent::TouchPoint& touchPoint, ev->touchPoints()) {
59 message.append(
60 QString("(id:%1, state:%2, scenePos:(%3,%4)) ")
61 .arg(touchPoint.id())
62 .arg(touchPointStateToString(touchPoint.state()))
63 .arg(touchPoint.scenePos().x())
64 .arg(touchPoint.scenePos().y())
65 );
66 }
68 return message;
71QString mouseEventToString(const QMouseEvent *ev)
73 QString message;
75 switch (ev->type()) {
76 case QEvent::MouseButtonPress:
77 message.append("MouseButtonPress ");
78 break;
79 case QEvent::MouseButtonRelease:
80 message.append("MouseButtonRelease ");
81 break;
82 case QEvent::MouseButtonDblClick:
83 message.append("MouseButtonDblClick ");
84 break;
85 case QEvent::MouseMove:
86 message.append("MouseMove ");
87 break;
88 default:
89 message.append("INVALID_MOUSE_EVENT_TYPE ");
90 }
92 message.append(QString("pos(%1, %2)").arg(ev->x()).arg(ev->y()));
94 return message;