File indexing completed on 2024-04-28 04:41:48
0001 /*************************************************************************** 0002 * Copyright (C) 2018 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 KQUICKITEMVIEWS_VIEWPORTADAPTER_H 0019 #define KQUICKITEMVIEWS_VIEWPORTADAPTER_H 0020 0021 // Qt 0022 #include <QtCore/QObject> 0023 #include <QtCore/QRectF> 0024 0025 // KQuickItemViews 0026 class ViewportAdapterPrivate; 0027 class Viewport; 0028 class AbstractItemAdapter; 0029 0030 //WARNING on hold for now, nothing is implemented properly 0031 0032 /** 0033 * Define which QModelIndex get to be loaded at any given time and keep track 0034 * of the view size. 0035 */ 0036 class Q_DECL_EXPORT ViewportAdapter : public QObject 0037 { 0038 Q_OBJECT 0039 public: 0040 0041 /** 0042 * The empty area that can be used by the footer widget. 0043 * 0044 * This is only relevant for footer widget that use `anchors.fill` for 0045 * their size instead of using their implicit size to resize the area. 0046 */ 0047 Q_PROPERTY(QRectF availableFooterArea READ availableFooterArea NOTIFY footerChanged) 0048 0049 0050 /** 0051 * The empty area that can be used by the header widget. 0052 * 0053 * This is only relevant for header widget that use `anchors.fill` for 0054 * their size instead of using their implicit size to resize the area. 0055 */ 0056 Q_PROPERTY(QRectF availableHeaderArea READ availableHeaderArea NOTIFY headerChanged) 0057 0058 /** 0059 * Define how the viewport should move when new elements are inserted. 0060 * 0061 * When anchored, the anchor should be preserved even when elements are 0062 * inserted above and below the viewport in ways that would normally move 0063 * the viewport. 0064 */ 0065 Q_PROPERTY(Qt::Edges anchoredEdges READ anchoredEdges NOTIFY anchorsChanged) 0066 0067 Q_PROPERTY(bool totalSizeKnown READ isTotalSizeKnown NOTIFY totalSizeChanged) 0068 0069 Q_PROPERTY(QSizeF totalSize READ totalSize NOTIFY totalSizeChanged) 0070 0071 Q_INVOKABLE explicit ViewportAdapter(Viewport *parent); 0072 0073 virtual ~ViewportAdapter(); 0074 0075 virtual bool isTotalSizeKnown() const; 0076 0077 virtual QRectF availableFooterArea() const; 0078 virtual QRectF availableHeaderArea() const; 0079 virtual Qt::Edges anchoredEdges() const; 0080 virtual QSizeF totalSize() const; 0081 0082 /** 0083 * Get the size hints for an AbstractItemAdapter. 0084 * 0085 * The implementation should take into account the GeometryAdapter size 0086 * hints and apply its own containts to them. For example a ListView entry 0087 * takes the full width and a TableView might resize the column based on 0088 * the content size. 0089 * 0090 * @see GeometryAdapter::sizeHint 0091 */ 0092 Q_INVOKABLE virtual QSizeF sizeHint(const QModelIndex &index, AbstractItemAdapter *adapter) const; 0093 0094 /** 0095 * Get the position hints for an AbstractItemAdapter. 0096 * 0097 * @see GeometryAdapter::positionHint 0098 */ 0099 Q_INVOKABLE virtual QPointF positionHint(const QModelIndex &index, AbstractItemAdapter *adapter) const; 0100 0101 protected: 0102 0103 /** 0104 * Called when the viewport is resized. 0105 */ 0106 virtual void onResize(const QRectF& newSize, const QRectF& oldSize); 0107 0108 /** 0109 * Called when 0110 */ 0111 virtual void onEnterViewport(AbstractItemAdapter *item); 0112 0113 virtual void onLeaveViewport(AbstractItemAdapter *item); 0114 0115 Q_SIGNALS: 0116 void totalSizeChanged(); 0117 void anchorsChanged(); 0118 void headerChanged(); 0119 void footerChanged(); 0120 0121 private: 0122 ViewportAdapterPrivate *d_ptr; 0123 }; 0124 0125 #endif