summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Griebl <rgriebl@trolltech.com>2010-04-21 14:25:36 +0200
committerRobert Griebl <rgriebl@trolltech.com>2010-04-21 14:25:36 +0200
commit8b3714636a5b171917d64bca71e8f5762f526a3e (patch)
treee106333d483551cff5eff03cde2ad100cc6f49ee
parent0a8e69e0b4576dbe65dfe6fa8d4deadc08198f88 (diff)
handle both touch and mouse on the same device
-rw-r--r--touchy/main.cpp2
-rw-r--r--touchy/qscrollareakineticscroller.cpp48
2 files changed, 24 insertions, 26 deletions
diff --git a/touchy/main.cpp b/touchy/main.cpp
index b9b5154..732f67c 100644
--- a/touchy/main.cpp
+++ b/touchy/main.cpp
@@ -19,7 +19,7 @@ int main(int argc, char **argv)
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60) || defined(Q_WS_WINCE)
bool smallScreen = true;
#else
- bool smallScreen = true; // false;
+ bool smallScreen = false;
#endif
QWidget *settings = new SettingsWidget(s, smallScreen);
diff --git a/touchy/qscrollareakineticscroller.cpp b/touchy/qscrollareakineticscroller.cpp
index ad7a137..0a00b4e 100644
--- a/touchy/qscrollareakineticscroller.cpp
+++ b/touchy/qscrollareakineticscroller.cpp
@@ -80,7 +80,7 @@ public:
QAbstractScrollArea *area;
QItemSelection oldSelection; // the selection before the first mouse down
bool ignoreEvents;
- bool isTouchEnabled;
+ bool touchActive;
QPoint lastOvershoot; // don't change the type to QPointF or we might never shoot completely back.
QPointer<QWidget> childWidget; // the widget where the mouse was pressed
QPointF fractionalPosition;
@@ -95,7 +95,7 @@ public:
: q_ptr(0)
, area(0)
, ignoreEvents(false)
- , isTouchEnabled(false)
+ , touchActive(false)
{}
void init()
@@ -166,7 +166,6 @@ void QScrollAreaKineticScroller::setWidget(QAbstractScrollArea *widget)
view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
}
- d->isTouchEnabled = d->area->viewport()->testAttribute(Qt::WA_AcceptTouchEvents);
}
}
@@ -184,32 +183,31 @@ bool QScrollAreaKineticScroller::eventFilter(QObject *o, QEvent *e)
switch (e->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
- if (d->isTouchEnabled) {
- Input type = (e->type() == QEvent::TouchBegin) ? InputPress :
- ((e->type() == QEvent::TouchEnd) ? InputRelease : InputMove);
- QTouchEvent *te = static_cast<QTouchEvent *>(e);
- int idx = (te->deviceType() == QTouchEvent::TouchScreen) ? 0 : 1;
-
- if (te->touchPoints().count() == (idx + 1))
- res = handleInput(type, te->touchPoints().at(idx).pos() - d->lastOvershoot, timestamp);
+ case QEvent::TouchEnd: {
+ Input type = (e->type() == QEvent::TouchBegin) ? InputPress :
+ ((e->type() == QEvent::TouchEnd) ? InputRelease : InputMove);
+ QTouchEvent *te = static_cast<QTouchEvent *>(e);
+ int idx = (te->deviceType() == QTouchEvent::TouchScreen) ? 0 : 1;
+
+ if (te->touchPoints().count() == (idx + 1)) {
+ res = handleInput(type, te->touchPoints().at(idx).pos() - d->lastOvershoot, timestamp);
+ if (type == InputPress)
+ d->touchActive = true;
+ else if (type == InputRelease)
+ d->touchActive = false;
}
break;
-
+ }
case QEvent::Wheel:
-#ifdef Q_WS_MAC
- // the two-finger gesture is mapped to wheel events by default
- res = d->isTouchEnabled;
-#endif
+ // the two-finger gesture on the Mac is mapped to wheel events by default
+ res = d->touchActive;
break;
case QEvent::MouseButtonPress:
- if (!d->isTouchEnabled) {
- // re-install the event filter so that we get the mouse release before all other filters.
- // this is an evil hack, but hard to work around without prioritized event filters.
- d->area->viewport()->removeEventFilter(this);
- d->area->viewport()->installEventFilter(this);
- }
+ // re-install the event filter so that we get the mouse release before all other filters.
+ // this is an evil hack, but hard to work around without prioritized event filters.
+ d->area->viewport()->removeEventFilter(this);
+ d->area->viewport()->installEventFilter(this);
// fall through
case QEvent::MouseButtonDblClick:
@@ -218,7 +216,7 @@ bool QScrollAreaKineticScroller::eventFilter(QObject *o, QEvent *e)
case QEvent::MouseMove:
case QEvent::MouseButtonRelease:
- if (!d->isTouchEnabled) {
+ if (!d->touchActive) {
Input type = (e->type() == QEvent::MouseButtonRelease) ? InputRelease :
((e->type() == QEvent::MouseMove) ? InputMove : InputPress);
QMouseEvent *me = static_cast<QMouseEvent *>(e);
@@ -306,7 +304,7 @@ void QScrollAreaKineticScroller::cancelPress(const QPointF &pressPos)
QPoint pos = pressPos.toPoint();
if (d->childWidget) {
- if (d->isTouchEnabled) {
+ if (d->touchActive) {
//TODO
// TouchUpdate + TouchEnd?
} else {