|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 FOO 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 <QApplication> |
|
43 #include <QDebug> |
|
44 #include <QMouseEvent> |
|
45 #include <QTabletEvent> |
|
46 #include <QWidget> |
|
47 |
|
48 class EventReportWidget : public QWidget |
|
49 { |
|
50 public: |
|
51 EventReportWidget(); |
|
52 protected: |
|
53 void mouseDoubleClickEvent(QMouseEvent *event) { outputMouseEvent(event); } |
|
54 void mouseMoveEvent(QMouseEvent *event) { outputMouseEvent(event); } |
|
55 void mousePressEvent(QMouseEvent *event) { outputMouseEvent(event); } |
|
56 void mouseReleaseEvent(QMouseEvent *event) { outputMouseEvent(event); } |
|
57 |
|
58 void tabletEvent(QTabletEvent *); |
|
59 |
|
60 private: |
|
61 void outputMouseEvent(QMouseEvent *event); |
|
62 |
|
63 bool m_lastIsMouseMove; |
|
64 bool m_lastIsTabletMove; |
|
65 }; |
|
66 |
|
67 EventReportWidget::EventReportWidget() |
|
68 : m_lastIsMouseMove(false) |
|
69 , m_lastIsTabletMove(false) |
|
70 { } |
|
71 |
|
72 void EventReportWidget::tabletEvent(QTabletEvent *event) |
|
73 { |
|
74 QWidget::tabletEvent(event); |
|
75 |
|
76 QString type; |
|
77 switch (event->type()) { |
|
78 case QEvent::TabletEnterProximity: |
|
79 m_lastIsTabletMove = false; |
|
80 type = QString::fromLatin1("TabletEnterProximity"); |
|
81 break; |
|
82 case QEvent::TabletLeaveProximity: |
|
83 m_lastIsTabletMove = false; |
|
84 type = QString::fromLatin1("TabletLeaveProximity"); |
|
85 break; |
|
86 case QEvent::TabletMove: |
|
87 if (m_lastIsTabletMove) |
|
88 return; |
|
89 |
|
90 m_lastIsTabletMove = true; |
|
91 type = QString::fromLatin1("TabletMove"); |
|
92 break; |
|
93 case QEvent::TabletPress: |
|
94 m_lastIsTabletMove = false; |
|
95 type = QString::fromLatin1("TabletPress"); |
|
96 break; |
|
97 case QEvent::TabletRelease: |
|
98 m_lastIsTabletMove = false; |
|
99 type = QString::fromLatin1("TabletRelease"); |
|
100 break; |
|
101 default: |
|
102 Q_ASSERT(false); |
|
103 break; |
|
104 } |
|
105 |
|
106 qDebug() << "Tablet event, type = " << type |
|
107 << " position = " << event->pos() |
|
108 << " global position = " << event->globalPos(); |
|
109 } |
|
110 |
|
111 void EventReportWidget::outputMouseEvent(QMouseEvent *event) |
|
112 { |
|
113 QString type; |
|
114 switch (event->type()) { |
|
115 case QEvent::MouseButtonDblClick: |
|
116 m_lastIsMouseMove = false; |
|
117 type = QString::fromLatin1("MouseButtonDblClick"); |
|
118 break; |
|
119 case QEvent::MouseButtonPress: |
|
120 m_lastIsMouseMove = false; |
|
121 type = QString::fromLatin1("MouseButtonPress"); |
|
122 break; |
|
123 case QEvent::MouseButtonRelease: |
|
124 m_lastIsMouseMove = false; |
|
125 type = QString::fromLatin1("MouseButtonRelease"); |
|
126 break; |
|
127 case QEvent::MouseMove: |
|
128 if (m_lastIsMouseMove) |
|
129 return; // only show one move to keep things readable |
|
130 |
|
131 m_lastIsMouseMove = true; |
|
132 type = QString::fromLatin1("MouseMove"); |
|
133 break; |
|
134 default: |
|
135 Q_ASSERT(false); |
|
136 break; |
|
137 } |
|
138 |
|
139 qDebug() << "Mouse event, type = " << type |
|
140 << " position = " << event->pos() |
|
141 << " global position = " << event->globalPos(); |
|
142 } |
|
143 |
|
144 int main(int argc, char *argv[]) |
|
145 { |
|
146 QApplication app(argc, argv); |
|
147 EventReportWidget widget; |
|
148 widget.show(); |
|
149 return app.exec(); |
|
150 } |