@@ -0,0 +1,112 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+#include "FloatingFlickable.h"
18+
19+#include <private/qquickflickable_p.h>
20+#include "DirectionalDragArea.h"
21+
22+#include <QDebug>
23+
24+FloatingFlickable::FloatingFlickable(QQuickItem *parent)
25+ : QQuickItem(parent)
26+ , m_mousePressed(false)
27+{
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);
36+
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);
45+
46+ connect(this, &QQuickItem::widthChanged, this, &FloatingFlickable::updateChildrenWidth);
47+ connect(this, &QQuickItem::heightChanged, this, &FloatingFlickable::updateChildrenHeight);
48+}
49+
50+qreal FloatingFlickable::contentWidth() const
51+{
52+ return m_flickable->contentWidth();
53+}
54+
55+void FloatingFlickable::setContentWidth(qreal contentWidth)
56+{
57+ m_flickable->setContentWidth(contentWidth);
58+}
59+
60+qreal FloatingFlickable::contentX() const
61+{
62+ return m_flickable->contentX();
63+}
64+
65+void FloatingFlickable::setContentX(qreal contentX)
66+{
67+ m_flickable->setContentX(contentX);
68+}
69+
70+void FloatingFlickable::updateChildrenWidth()
71+{
72+ m_dragArea->setWidth(width());
73+ m_flickable->setWidth(width());
74+}
75+
76+void FloatingFlickable::updateChildrenHeight()
77+{
78+ m_dragArea->setHeight(height());
79+ m_flickable->setHeight(height());
80+}
81+
82+void FloatingFlickable::onDragAreaTouchXChanged(qreal /*touchX*/)
83+{
84+ if (m_mousePressed) {
85+ QMouseEvent mouseEvent(QEvent::MouseMove,
86+ QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
87+ Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
88+
89+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
90+
91+ }
92+}
93+
94+void FloatingFlickable::onDragAreaDraggingChanged(bool dragging)
95+{
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);
100+
101+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
102+ m_mousePressed = true;
103+
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);
108+
109+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
110+ m_mousePressed = false;
111+ }
112+}