on ba4ffba help sign in
unity8/plugins/Ubuntu/Gestures/FloatingFlickable.cpp
112 lines 3.6 kB history raw
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 */
17#include "FloatingFlickable.h"
19#include <private/qquickflickable_p.h>
20#include "DirectionalDragArea.h"
22#include <QDebug>
24FloatingFlickable::FloatingFlickable(QQuickItem *parent)
25 : 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);
50qreal FloatingFlickable::contentWidth() const
52 return m_flickable->contentWidth();
55void FloatingFlickable::setContentWidth(qreal contentWidth)
57 m_flickable->setContentWidth(contentWidth);
60qreal FloatingFlickable::contentX() const
62 return m_flickable->contentX();
65void FloatingFlickable::setContentX(qreal contentX)
67 m_flickable->setContentX(contentX);
70void FloatingFlickable::updateChildrenWidth()
72 m_dragArea->setWidth(width());
73 m_flickable->setWidth(width());
76void FloatingFlickable::updateChildrenHeight()
78 m_dragArea->setHeight(height());
79 m_flickable->setHeight(height());
82void 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);
91 }
94void 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;
111 }