File indexing completed on 2024-04-28 15:27:41

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 class Units;
0018 }
0019 
0020 class QmlComponentsPool : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     QmlComponentsPool(QQmlEngine *engine);
0026     ~QmlComponentsPool() override;
0027 
0028     QQmlComponent *m_leadingSeparatorComponent = nullptr;
0029     QQmlComponent *m_trailingSeparatorComponent = nullptr;
0030     Kirigami::Units *m_units = nullptr;
0031 
0032 Q_SIGNALS:
0033     void gridUnitChanged();
0034     void longDurationChanged();
0035 
0036 private:
0037     QObject *m_instance = nullptr;
0038 };
0039 
0040 class ContentItem : public QQuickItem
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     ContentItem(ColumnView *parent = nullptr);
0046     ~ContentItem() override;
0047 
0048     void layoutItems();
0049     void layoutPinnedItems();
0050     qreal childWidth(QQuickItem *child);
0051     void updateVisibleItems();
0052     void forgetItem(QQuickItem *item);
0053     QQuickItem *ensureLeadingSeparator(QQuickItem *item);
0054     QQuickItem *ensureTrailingSeparator(QQuickItem *item);
0055 
0056     void setBoundedX(qreal x);
0057     void animateX(qreal x);
0058     void snapToItem();
0059 
0060     inline qreal viewportLeft() const;
0061     inline qreal viewportRight() const;
0062 
0063 protected:
0064     void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override;
0065 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0066     void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
0067 #else
0068     void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
0069 #endif
0070 
0071 private Q_SLOTS:
0072     void syncItemsOrder();
0073     void updateRepeaterModel();
0074 
0075 private:
0076     ColumnView *m_view;
0077     QPropertyAnimation *m_slideAnim;
0078     QList<QQuickItem *> m_items;
0079     QList<QObject *> m_visibleItems;
0080     QPointer<QQuickItem> m_viewAnchorItem;
0081     QHash<QQuickItem *, QQuickItem *> m_leadingSeparators;
0082     QHash<QQuickItem *, QQuickItem *> m_trailingSeparators;
0083     QHash<QObject *, QObject *> m_models;
0084 
0085     qreal m_leftPinnedSpace = 361;
0086     qreal m_rightPinnedSpace = 0;
0087 
0088     qreal m_columnWidth = 0;
0089     qreal m_lastDragDelta = 0;
0090     ColumnView::ColumnResizeMode m_columnResizeMode = ColumnView::FixedColumns;
0091     bool m_shouldAnimate = false;
0092     friend class ColumnView;
0093 };