Unity 8
FloatingFlickable.h
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 #ifndef FLOATING_FLICKABLE_H
18 #define FLOATING_FLICKABLE_H
19 
20 #include <QQuickItem>
21 #include "UbuntuGesturesQmlGlobal.h"
22 #include "Direction.h"
23 
24 class DirectionalDragArea;
25 class QQuickFlickable;
26 
27 /*
28  A Flickable that can be put in front of the item to be flicked and
29  still have the item-to-be-flicked receive input events that are not flicks.
30 
31  Ie, it's a Flickable that, input-wise, is transparent to non-flick gestures.
32 
33  With a regular Flickable you would have to make the item-to-be-flicked a child
34  of Flicakble to achieve the same result. FloatingFlickable has no such requirement
35  or limitation.
36  */
37 class UBUNTUGESTURESQML_EXPORT FloatingFlickable : public QQuickItem {
38  Q_OBJECT
39 
40  Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
41  Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
42  Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged)
43  Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged)
44 
45  Q_PROPERTY(Direction::Type direction READ direction WRITE setDirection NOTIFY directionChanged)
46 
47 Q_SIGNALS:
48  void contentWidthChanged();
49  void contentHeightChanged();
50  void contentXChanged();
51  void contentYChanged();
52  void directionChanged();
53 
54 public:
55  FloatingFlickable(QQuickItem *parent = nullptr);
56 
57  qreal contentWidth() const;
58  void setContentWidth(qreal contentWidth);
59 
60  qreal contentHeight() const;
61  void setContentHeight(qreal contentHeight);
62 
63  qreal contentX() const;
64  void setContentX(qreal contentX);
65 
66  qreal contentY() const;
67  void setContentY(qreal contentY);
68 
69  Direction::Type direction() const;
70  void setDirection(Direction::Type);
71 
72 private Q_SLOTS:
73  void updateChildrenWidth();
74  void updateChildrenHeight();
75  void onDragAreaTouchPosChanged(qreal);
76  void onDragAreaDraggingChanged(bool value);
77 
78 private:
79  DirectionalDragArea *m_dragArea;
80  QQuickFlickable *m_flickable;
81  bool m_mousePressed;
82 
83  friend class tst_FloatingFlickable;
84 };
85 
86 #endif // FLOATING_FLICKABLE_H