summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomap.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2018-03-22 17:14:58 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-03-23 13:08:48 +0000
commit0af62cbe7ddf6a6ef858daa63b0ab02426d3aad9 (patch)
tree406d1085f4e9b068a1936449cc9a44fcf0ca3c0e /src/location/declarativemaps/qdeclarativegeomap.cpp
parent24b6cee60ec448a8cb4181df7a0bc1bb72027e7b (diff)
downloadqtlocation-0af62cbe7ddf6a6ef858daa63b0ab02426d3aad9.tar.gz
Refactor input handling code
Fix coding style in map gesture area, and move all input handling code in the same section in qdeclarativegeomap.cpp Change-Id: I33ef572cb85ebbb446ee9ff0a1359abbe55c3dfa Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp247
1 files changed, 123 insertions, 124 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 1c0815ca..5d0acede 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -435,59 +435,6 @@ void QDeclarativeGeoMap::componentComplete()
}
/*!
- \internal
-*/
-void QDeclarativeGeoMap::mousePressEvent(QMouseEvent *event)
-{
- if (isInteractive())
- m_gestureArea->handleMousePressEvent(event);
- else
- QQuickItem::mousePressEvent(event);
-}
-
-/*!
- \internal
-*/
-void QDeclarativeGeoMap::mouseMoveEvent(QMouseEvent *event)
-{
- if (isInteractive())
- m_gestureArea->handleMouseMoveEvent(event);
- else
- QQuickItem::mouseMoveEvent(event);
-}
-
-/*!
- \internal
-*/
-void QDeclarativeGeoMap::mouseReleaseEvent(QMouseEvent *event)
-{
- if (isInteractive()) {
- m_gestureArea->handleMouseReleaseEvent(event);
- } else {
- QQuickItem::mouseReleaseEvent(event);
- }
-}
-
-/*!
- \internal
-*/
-void QDeclarativeGeoMap::mouseUngrabEvent()
-{
- if (isInteractive())
- m_gestureArea->handleMouseUngrabEvent();
- else
- QQuickItem::mouseUngrabEvent();
-}
-
-void QDeclarativeGeoMap::touchUngrabEvent()
-{
- if (isInteractive())
- m_gestureArea->handleTouchUngrabEvent();
- else
- QQuickItem::touchUngrabEvent();
-}
-
-/*!
\qmlproperty MapGestureArea QtLocation::Map::gesture
Contains the MapGestureArea created with the Map. This covers pan, flick and pinch gestures.
@@ -1682,33 +1629,6 @@ void QDeclarativeGeoMap::itemChange(ItemChange change, const ItemChangeData &val
QQuickItem::itemChange(change, value);
}
-/*!
- \internal
-*/
-void QDeclarativeGeoMap::touchEvent(QTouchEvent *event)
-{
- if (isInteractive()) {
- m_gestureArea->handleTouchEvent(event);
- } else {
- //ignore event so sythesized event is generated;
- QQuickItem::touchEvent(event);
- }
-}
-
-#if QT_CONFIG(wheelevent)
-/*!
- \internal
-*/
-void QDeclarativeGeoMap::wheelEvent(QWheelEvent *event)
-{
- if (isInteractive())
- m_gestureArea->handleWheelEvent(event);
- else
- QQuickItem::wheelEvent(event);
-
-}
-#endif
-
bool QDeclarativeGeoMap::isInteractive()
{
return (m_gestureArea->enabled() && m_gestureArea->acceptedGestures()) || m_gestureArea->isActive();
@@ -1741,50 +1661,6 @@ void QDeclarativeGeoMap::onAttachedCopyrightNoticeVisibilityChanged()
}
/*!
- \internal
-*/
-bool QDeclarativeGeoMap::childMouseEventFilter(QQuickItem *item, QEvent *event)
-{
- Q_UNUSED(item)
- if (!isVisible() || !isEnabled() || !isInteractive())
- return QQuickItem::childMouseEventFilter(item, event);
-
- switch (event->type()) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseMove:
- case QEvent::MouseButtonRelease:
- return sendMouseEvent(static_cast<QMouseEvent *>(event));
- case QEvent::UngrabMouse: {
- QQuickWindow *win = window();
- if (!win) break;
- if (!win->mouseGrabberItem() ||
- (win->mouseGrabberItem() &&
- win->mouseGrabberItem() != this)) {
- // child lost grab, we could even lost
- // some events if grab already belongs for example
- // in item in diffrent window , clear up states
- mouseUngrabEvent();
- }
- break;
- }
- case QEvent::TouchBegin:
- case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
- case QEvent::TouchCancel:
- if (static_cast<QTouchEvent *>(event)->touchPoints().count() >= 2) {
- // 1 touch point = handle with MouseEvent (event is always synthesized)
- // let the synthesized mouse event grab the mouse,
- // note there is no mouse grabber at this point since
- // touch event comes first (see Qt::AA_SynthesizeMouseForUnhandledTouchEvents)
- return sendTouchEvent(static_cast<QTouchEvent *>(event));
- }
- default:
- break;
- }
- return QQuickItem::childMouseEventFilter(item, event);
-}
-
-/*!
\qmlmethod void QtLocation::Map::addMapItem(MapItem item)
Adds the given \a item to the Map (for example MapQuickItem, MapCircle). If the object
@@ -2359,6 +2235,129 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib
fitViewportToMapItemsRefine(false, onlyVisible);
}
+/*!
+ \internal
+*/
+void QDeclarativeGeoMap::mousePressEvent(QMouseEvent *event)
+{
+ if (isInteractive())
+ m_gestureArea->handleMousePressEvent(event);
+ else
+ QQuickItem::mousePressEvent(event);
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMap::mouseMoveEvent(QMouseEvent *event)
+{
+ if (isInteractive())
+ m_gestureArea->handleMouseMoveEvent(event);
+ else
+ QQuickItem::mouseMoveEvent(event);
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMap::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (isInteractive())
+ m_gestureArea->handleMouseReleaseEvent(event);
+ else
+ QQuickItem::mouseReleaseEvent(event);
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMap::mouseUngrabEvent()
+{
+ if (isInteractive())
+ m_gestureArea->handleMouseUngrabEvent();
+ else
+ QQuickItem::mouseUngrabEvent();
+}
+
+void QDeclarativeGeoMap::touchUngrabEvent()
+{
+ if (isInteractive())
+ m_gestureArea->handleTouchUngrabEvent();
+ else
+ QQuickItem::touchUngrabEvent();
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMap::touchEvent(QTouchEvent *event)
+{
+ if (isInteractive()) {
+ m_gestureArea->handleTouchEvent(event);
+ } else {
+ //ignore event so sythesized event is generated;
+ QQuickItem::touchEvent(event);
+ }
+}
+
+#if QT_CONFIG(wheelevent)
+/*!
+ \internal
+*/
+void QDeclarativeGeoMap::wheelEvent(QWheelEvent *event)
+{
+ if (isInteractive())
+ m_gestureArea->handleWheelEvent(event);
+ else
+ QQuickItem::wheelEvent(event);
+
+}
+#endif
+
+/*!
+ \internal
+*/
+bool QDeclarativeGeoMap::childMouseEventFilter(QQuickItem *item, QEvent *event)
+{
+ Q_UNUSED(item)
+ if (!isVisible() || !isEnabled() || !isInteractive())
+ return QQuickItem::childMouseEventFilter(item, event);
+
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseMove:
+ case QEvent::MouseButtonRelease:
+ return sendMouseEvent(static_cast<QMouseEvent *>(event));
+ case QEvent::UngrabMouse: {
+ QQuickWindow *win = window();
+ if (!win) break;
+ if (!win->mouseGrabberItem() ||
+ (win->mouseGrabberItem() &&
+ win->mouseGrabberItem() != this)) {
+ // child lost grab, we could even lost
+ // some events if grab already belongs for example
+ // in item in diffrent window , clear up states
+ mouseUngrabEvent();
+ }
+ break;
+ }
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ case QEvent::TouchCancel:
+ if (static_cast<QTouchEvent *>(event)->touchPoints().count() >= 2) {
+ // 1 touch point = handle with MouseEvent (event is always synthesized)
+ // let the synthesized mouse event grab the mouse,
+ // note there is no mouse grabber at this point since
+ // touch event comes first (see Qt::AA_SynthesizeMouseForUnhandledTouchEvents)
+ return sendTouchEvent(static_cast<QTouchEvent *>(event));
+ }
+ default:
+ break;
+ }
+ return QQuickItem::childMouseEventFilter(item, event);
+}
+
bool QDeclarativeGeoMap::sendMouseEvent(QMouseEvent *event)
{
QPointF localPos = mapFromScene(event->windowPos());