File indexing completed on 2024-04-28 04:41:52
0001 /*************************************************************************** 0002 * Copyright (C) 2017 by Emmanuel Lepage Vallee * 0003 * Author : Emmanuel Lepage Vallee <emmanuel.lepage@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 3 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0017 **************************************************************************/ 0018 #ifndef FLICKABLE_H 0019 #define FLICKABLE_H 0020 0021 #include <QQuickItem> 0022 0023 class FlickablePrivate; 0024 0025 /** 0026 * This file re-implements the flickable view. 0027 * 0028 * It is necessary to avoid a dependency on Qt private APIs in order to 0029 * re-implement higher level views such as the tree view. The upstream code 0030 * could also hardly have been copy/pasted in this project as it depends on 0031 * yet more hidden APIs and the code (along with dependencies) is over an order 0032 * or magnitude larger than this implementation. It would have been a 0033 * maintainability nightmare. 0034 * 0035 * This implementation is API compatible with a small subset of the Flickable 0036 * properties and uses a 200 lines of code inertial state machine instead of 0037 * 1.5k line of vomit code to do the exact same job. 0038 */ 0039 class Q_DECL_EXPORT Flickable : public QQuickItem 0040 { 0041 Q_OBJECT 0042 public: 0043 // Implement some of the QtQuick2.Flickable API 0044 Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged) 0045 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentHeightChanged ) 0046 Q_PROPERTY(bool dragging READ isDragging NOTIFY draggingChanged) 0047 Q_PROPERTY(bool flicking READ isDragging NOTIFY movingChanged) 0048 Q_PROPERTY(bool moving READ isDragging NOTIFY movingChanged) 0049 Q_PROPERTY(bool movingHorizontally READ isDragging NOTIFY movingChanged) 0050 Q_PROPERTY(bool draggingHorizontally READ isDragging NOTIFY draggingChanged) 0051 Q_PROPERTY(bool flickingHorizontally READ isDragging NOTIFY movingChanged) 0052 Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration) 0053 Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) 0054 Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) 0055 0056 /** 0057 * The geometry of the content subset currently displayed be the Flickable. 0058 * 0059 * It is usually {0, contentY, height, width}. 0060 */ 0061 Q_PROPERTY(QRectF viewport READ viewport NOTIFY viewportChanged) 0062 0063 explicit Flickable(QQuickItem* parent = nullptr); 0064 virtual ~Flickable(); 0065 0066 qreal contentY() const; 0067 virtual void setContentY(qreal y); 0068 0069 QRectF viewport() const; 0070 0071 qreal contentHeight() const; 0072 0073 QQuickItem* contentItem(); 0074 0075 bool isDragging() const; 0076 bool isMoving() const; 0077 0078 qreal flickDeceleration() const; 0079 void setFlickDeceleration(qreal v); 0080 0081 bool isInteractive() const; 0082 void setInteractive(bool v); 0083 0084 qreal maximumFlickVelocity() const; 0085 void setMaximumFlickVelocity(qreal v); 0086 0087 QQmlContext* rootContext() const; 0088 0089 Q_SIGNALS: 0090 void contentHeightChanged(qreal height); 0091 void contentYChanged(qreal y); 0092 void percentageChanged(qreal percent); 0093 void draggingChanged(bool dragging); 0094 void movingChanged(bool dragging); 0095 void viewportChanged(const QRectF &view); 0096 0097 protected: 0098 bool event(QEvent *ev) override; 0099 bool childMouseEventFilter(QQuickItem *, QEvent *) override; 0100 void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override; 0101 0102 private: 0103 FlickablePrivate* d_ptr; 0104 Q_DECLARE_PRIVATE(Flickable) 0105 }; 0106 0107 #endif