summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-11 14:46:26 +0200
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-11 14:46:26 +0200
commit0218d8f8dc569db9a1290f595a814c3690c1b14b (patch)
treedbc01d884f803e52ab9cae6253cf5e18b6a75b43
parentecc7f07e612bf156afb7fa2dbcbd2288b9b32e79 (diff)
downloadqt4-tools-0218d8f8dc569db9a1290f595a814c3690c1b14b.tar.gz
enable touch events on all views if an item has touch enabled
-rw-r--r--examples/multitouch/knobs/main.cpp1
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp6
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp25
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h2
4 files changed, 26 insertions, 8 deletions
diff --git a/examples/multitouch/knobs/main.cpp b/examples/multitouch/knobs/main.cpp
index 8f78cf9feb..ada57f5c97 100644
--- a/examples/multitouch/knobs/main.cpp
+++ b/examples/multitouch/knobs/main.cpp
@@ -50,7 +50,6 @@ int main(int argc, char **argv)
QGraphicsScene scene;
QGraphicsView view(&scene);
- view.viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
Knob *knob1 = new Knob;
knob1->setPos(-110, 0);
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 97e2ac80bf..1bf73a6194 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -2251,7 +2251,13 @@ bool QGraphicsItem::acceptTouchEvents() const
*/
void QGraphicsItem::setAcceptTouchEvents(bool enabled)
{
+ if (d_ptr->acceptTouchEvents == quint32(enabled))
+ return;
d_ptr->acceptTouchEvents = quint32(enabled);
+ if (d_ptr->acceptTouchEvents && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreTouchEvents) {
+ d_ptr->scene->d_func()->allItemsIgnoreTouchEvents = false;
+ d_ptr->scene->d_func()->enableTouchEventsOnViews();
+ }
}
/*!
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index f881965038..a8abfea1f0 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -360,7 +360,8 @@ QGraphicsScenePrivate::QGraphicsScenePrivate()
painterStateProtection(true),
sortCacheEnabled(false),
updatingSortCache(false),
- style(0)
+ style(0),
+ allItemsIgnoreTouchEvents(true)
{
}
@@ -2888,6 +2889,7 @@ void QGraphicsScene::clear()
d->largestUntransformableItem = QRectF();
d->allItemsIgnoreHoverEvents = true;
d->allItemsUseDefaultCursor = true;
+ d->allItemsIgnoreTouchEvents = true;
}
/*!
@@ -3065,6 +3067,12 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
}
#endif //QT_NO_CURSOR
+ // Enable touch events if the item accepts touch events.
+ if (d->allItemsIgnoreTouchEvents && item->acceptTouchEvents()) {
+ d->allItemsIgnoreTouchEvents = false;
+ d->enableTouchEventsOnViews();
+ }
+
// Update selection lists
if (item->isSelected())
d->selectedItems << item;
@@ -5958,14 +5966,10 @@ void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouch
{
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
for (int i = 0; i < touchPoints.count(); ++i) {
- QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
- touchPoint.setPos(item->d_ptr->genericMapFromScene(touchPoint.scenePos(), touchEvent->widget()));
+ QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
+ touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect());
touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), touchEvent->widget()));
touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), touchEvent->widget()));
-#ifdef Q_CC_GNU
-# warning FIXME
-#endif
- // ### touchPoint.setSize(item->d_ptr->genericMapFromScene(touchPoint.sceneSize(), touchEvent->widget()));
}
touchEvent->setTouchPoints(touchPoints);
}
@@ -6146,6 +6150,13 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
return res;
}
+void QGraphicsScenePrivate::enableTouchEventsOnViews()
+{
+ foreach (QGraphicsView *view, views)
+ view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
+}
+
+
QT_END_NAMESPACE
#include "moc_qgraphicsscene.cpp"
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index 6983d12613..f27bd0329d 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -310,6 +310,8 @@ public:
int findClosestTouchPointId(const QPointF &scenePos);
void touchEventHandler(QTouchEvent *touchEvent);
bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
+ bool allItemsIgnoreTouchEvents;
+ void enableTouchEventsOnViews();
};
QT_END_NAMESPACE