1 /*
2  *  SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
3  *
4  *  SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #pragma once
8 
9 #include "columnview.h"
10 
11 #include <QPointer>
12 #include <QQuickItem>
13 
14 class QPropertyAnimation;
15 class QQmlComponent;
16 namespace Kirigami {
17 class Units;
18 }
19 
20 class QmlComponentsPool : public QObject
21 {
22     Q_OBJECT
23 
24 public:
25     QmlComponentsPool(QQmlEngine *engine);
26     ~QmlComponentsPool() override;
27 
28     QQmlComponent *m_separatorComponent = nullptr;
29     QQmlComponent *m_rightSeparatorComponent = nullptr;
30     Kirigami::Units *m_units = nullptr;
31 
32 Q_SIGNALS:
33     void gridUnitChanged();
34     void longDurationChanged();
35 
36 private:
37     QObject *m_instance = nullptr;
38 };
39 
40 class ContentItem : public QQuickItem
41 {
42     Q_OBJECT
43 
44 public:
45     ContentItem(ColumnView *parent = nullptr);
46     ~ContentItem() override;
47 
48     void layoutItems();
49     void layoutPinnedItems();
50     qreal childWidth(QQuickItem *child);
51     void updateVisibleItems();
52     void forgetItem(QQuickItem *item);
53     QQuickItem *ensureSeparator(QQuickItem *item);
54     QQuickItem *ensureRightSeparator(QQuickItem *item);
55 
56     void setBoundedX(qreal x);
57     void animateX(qreal x);
58     void snapToItem();
59 
60     inline qreal viewportLeft() const;
61     inline qreal viewportRight() const;
62 
63 protected:
64     void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override;
65     void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
66 
67 private Q_SLOTS:
68     void syncItemsOrder();
69     void updateRepeaterModel();
70 
71 private:
72     ColumnView *m_view;
73     QPropertyAnimation *m_slideAnim;
74     QList<QQuickItem *> m_items;
75     QList<QObject *> m_visibleItems;
76     QPointer<QQuickItem> m_viewAnchorItem;
77     QHash<QQuickItem *, QQuickItem *> m_separators;
78     QHash<QQuickItem *, QQuickItem *> m_rightSeparators;
79     QHash<QObject *, QObject *> m_models;
80 
81     qreal m_leftPinnedSpace = 361;
82     qreal m_rightPinnedSpace = 0;
83 
84     qreal m_columnWidth = 0;
85     qreal m_lastDragDelta = 0;
86     ColumnView::ColumnResizeMode m_columnResizeMode = ColumnView::FixedColumns;
87     bool m_shouldAnimate = false;
88     friend class ColumnView;
89 };
90