@@ -0,0 +1,112 @@
2+ * Copyright (C) 2015 Canonical, Ltd.
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.
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.
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/>.
17+#include "FloatingFlickable.h"
19+#include <private/qquickflickable_p.h>
20+#include "DirectionalDragArea.h"
24+FloatingFlickable::FloatingFlickable(QQuickItem *parent)
26+ , m_mousePressed(false)
28+ m_dragArea = new DirectionalDragArea(this);
29+ m_dragArea->setWidth(width());
30+ m_dragArea->setHeight(height());
31+ m_dragArea->setDirection(Direction::Horizontal);
32+ connect(m_dragArea, &DirectionalDragArea::touchXChanged,
33+ this, &FloatingFlickable::onDragAreaTouchXChanged);
34+ connect(m_dragArea, &DirectionalDragArea::draggingChanged,
35+ this, &FloatingFlickable::onDragAreaDraggingChanged);
37+ m_flickable = new QQuickFlickable(this);
38+ m_flickable->setEnabled(false);
39+ m_flickable->setWidth(width());
40+ m_flickable->setHeight(height());
41+ connect(m_flickable, &QQuickFlickable::contentWidthChanged,
42+ this, &FloatingFlickable::contentWidthChanged);
43+ connect(m_flickable, &QQuickFlickable::contentXChanged,
44+ this, &FloatingFlickable::contentXChanged);
46+ connect(this, &QQuickItem::widthChanged, this, &FloatingFlickable::updateChildrenWidth);
47+ connect(this, &QQuickItem::heightChanged, this, &FloatingFlickable::updateChildrenHeight);
50+qreal FloatingFlickable::contentWidth() const
52+ return m_flickable->contentWidth();
55+void FloatingFlickable::setContentWidth(qreal contentWidth)
57+ m_flickable->setContentWidth(contentWidth);
60+qreal FloatingFlickable::contentX() const
62+ return m_flickable->contentX();
65+void FloatingFlickable::setContentX(qreal contentX)
67+ m_flickable->setContentX(contentX);
70+void FloatingFlickable::updateChildrenWidth()
72+ m_dragArea->setWidth(width());
73+ m_flickable->setWidth(width());
76+void FloatingFlickable::updateChildrenHeight()
78+ m_dragArea->setHeight(height());
79+ m_flickable->setHeight(height());
82+void FloatingFlickable::onDragAreaTouchXChanged(qreal /*touchX*/)
84+ if (m_mousePressed) {
85+ QMouseEvent mouseEvent(QEvent::MouseMove,
86+ QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
87+ Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
89+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
94+void FloatingFlickable::onDragAreaDraggingChanged(bool dragging)
96+ if (dragging && !m_mousePressed) {
97+ QMouseEvent mouseEvent(QEvent::MouseButtonPress,
98+ QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
99+ Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
101+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
102+ m_mousePressed = true;
104+ } else if (!dragging && m_mousePressed) {
105+ QMouseEvent mouseEvent(QEvent::MouseButtonRelease,
106+ QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
107+ Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
109+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
110+ m_mousePressed = false;