File indexing completed on 2024-04-21 03:55:59

0001 /*
0002  *  SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include "columnview.h"
0010 
0011 #include <QPointer>
0012 #include <QQuickItem>
0013 
0014 class QPropertyAnimation;
0015 class QQmlComponent;
0016 namespace Kirigami
0017 {
0018 namespace Platform
0019 {
0020 class Units;
0021 }
0022 }
0023 
0024 class QmlComponentsPool : public QObject
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     QmlComponentsPool(QQmlEngine *engine);
0030     ~QmlComponentsPool() override;
0031 
0032     QQmlComponent *m_leadingSeparatorComponent = nullptr;
0033     QQmlComponent *m_trailingSeparatorComponent = nullptr;
0034     Kirigami::Platform::Units *m_units = nullptr;
0035 
0036 Q_SIGNALS:
0037     void gridUnitChanged();
0038     void longDurationChanged();
0039 
0040 private:
0041     QObject *m_instance = nullptr;
0042 };
0043 
0044 class ContentItem : public QQuickItem
0045 {
0046     Q_OBJECT
0047 
0048 public:
0049     ContentItem(ColumnView *parent = nullptr);
0050     ~ContentItem() override;
0051 
0052     void layoutItems();
0053     void layoutPinnedItems();
0054     qreal childWidth(QQuickItem *child);
0055     void updateVisibleItems();
0056     void forgetItem(QQuickItem *item);
0057     QQuickItem *ensureLeadingSeparator(QQuickItem *item);
0058     QQuickItem *ensureTrailingSeparator(QQuickItem *item);
0059 
0060     void setBoundedX(qreal x);
0061     void animateX(qreal x);
0062     void snapToItem();
0063 
0064     void connectHeader(QQuickItem *oldHeader, QQuickItem *newHeader);
0065     void connectFooter(QQuickItem *oldFooter, QQuickItem *newFooter);
0066 
0067     inline qreal viewportLeft() const;
0068     inline qreal viewportRight() const;
0069 
0070 protected:
0071     void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override;
0072     void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
0073 
0074 private Q_SLOTS:
0075     void syncItemsOrder();
0076     void updateRepeaterModel();
0077 
0078 private:
0079     ColumnView *m_view;
0080     QQuickItem *m_globalHeaderParent;
0081     QQuickItem *m_globalFooterParent;
0082     QPropertyAnimation *m_slideAnim;
0083     QList<QQuickItem *> m_items;
0084     QList<QObject *> m_visibleItems;
0085     QPointer<QQuickItem> m_viewAnchorItem;
0086     QHash<QQuickItem *, QQuickItem *> m_leadingSeparators;
0087     QHash<QQuickItem *, QQuickItem *> m_trailingSeparators;
0088     QHash<QObject *, QObject *> m_models;
0089 
0090     qreal m_leftPinnedSpace = 361;
0091     qreal m_rightPinnedSpace = 0;
0092 
0093     qreal m_columnWidth = 0;
0094     qreal m_lastDragDelta = 0;
0095     ColumnView::ColumnResizeMode m_columnResizeMode = ColumnView::FixedColumns;
0096     bool m_shouldAnimate = false;
0097     bool m_creationInProgress = true;
0098     friend class ColumnView;
0099 };