1 | // Copyright (C) 2018 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICKSPLITVIEW_P_P_H |
5 | #define QQUICKSPLITVIEW_P_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtQuickTemplates2/private/qquickcontainer_p_p.h> |
19 | |
20 | QT_BEGIN_NAMESPACE |
21 | |
22 | class QQuickSplitView; |
23 | class QQuickSplitViewAttached; |
24 | class QQuickSplitHandleAttached; |
25 | |
26 | class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSplitViewPrivate : public QQuickContainerPrivate |
27 | { |
28 | Q_DECLARE_PUBLIC(QQuickSplitView) |
29 | |
30 | public: |
31 | void updateFillIndex(); |
32 | void layoutResizeSplitItems(qreal &usedWidth, qreal &usedHeight, int &indexBeingResizedDueToDrag); |
33 | void layoutResizeFillItem(QQuickItem *fillItem, qreal &usedWidth, qreal &usedHeight, int indexBeingResizedDueToDrag); |
34 | void limitAndApplySizes(qreal usedWidth, qreal usedHeight); |
35 | void layoutPositionItems(const QQuickItem *fillItem); |
36 | void requestLayout(); |
37 | void layout(); |
38 | void createHandles(); |
39 | void createHandleItem(int index); |
40 | void removeExcessHandles(); |
41 | void destroyHandles(); |
42 | void resizeHandle(QQuickItem *handleItem); |
43 | void resizeHandles(); |
44 | #if QT_CONFIG(cursor) |
45 | void updateCursorHandle(QQuickItem *handleItem); |
46 | #endif |
47 | void updateHandleVisibilities(); |
48 | void updateHoveredHandle(QQuickItem *hoveredItem); |
49 | void setResizing(bool resizing); |
50 | |
51 | bool isHorizontal() const; |
52 | qreal accumulatedSize(int firstIndex, int lastIndex) const; |
53 | |
54 | struct EffectiveSizeData { |
55 | qreal effectiveMinimumWidth; |
56 | qreal effectiveMinimumHeight; |
57 | qreal effectivePreferredWidth; |
58 | qreal effectivePreferredHeight; |
59 | qreal effectiveMaximumWidth; |
60 | qreal effectiveMaximumHeight; |
61 | }; |
62 | |
63 | // Used during the layout |
64 | struct LayoutData { |
65 | qreal width = 0; |
66 | qreal height = 0; |
67 | bool wasResizedByHandle = false; |
68 | }; |
69 | |
70 | EffectiveSizeData effectiveSizeData(const QQuickItemPrivate *itemPrivate, |
71 | const QQuickSplitViewAttached *attached) const; |
72 | |
73 | int handleIndexForSplitIndex(int splitIndex) const; |
74 | |
75 | QQuickItem *getContentItem() override; |
76 | bool handlePress(const QPointF &point, ulong timestamp) override; |
77 | bool handleMove(const QPointF &point, ulong timestamp) override; |
78 | bool handleRelease(const QPointF &point, ulong timestamp) override; |
79 | |
80 | void itemVisibilityChanged(QQuickItem *item) override; |
81 | void itemImplicitWidthChanged(QQuickItem *item) override; |
82 | void itemImplicitHeightChanged(QQuickItem *item) override; |
83 | |
84 | void updatePolish() override; |
85 | |
86 | static QQuickSplitViewPrivate *get(QQuickSplitView *splitView); |
87 | |
88 | Qt::Orientation m_orientation = Qt::Horizontal; |
89 | QQmlComponent *m_handle = nullptr; |
90 | QList<QQuickItem*> m_handleItems; |
91 | QHash<QQuickItem*, LayoutData> m_layoutData; |
92 | int m_hoveredHandleIndex = -1; |
93 | int m_pressedHandleIndex = -1; |
94 | int m_nextVisibleIndexAfterPressedHandle = -1; |
95 | QPointF m_pressPos; |
96 | QPointF m_mousePos; |
97 | QPointF m_handlePosBeforePress; |
98 | qreal m_leftOrTopItemSizeBeforePress = 0.0; |
99 | qreal m_rightOrBottomItemSizeBeforePress = 0.0; |
100 | int m_fillIndex = -1; |
101 | bool m_layingOut = false; |
102 | bool m_ignoreNextLayoutRequest = false; |
103 | bool m_resizing = false; |
104 | }; |
105 | |
106 | class QQuickSplitViewAttachedPrivate : public QObjectPrivate |
107 | { |
108 | Q_DECLARE_PUBLIC(QQuickSplitViewAttached) |
109 | |
110 | public: |
111 | QQuickSplitViewAttachedPrivate(); |
112 | |
113 | void setView(QQuickSplitView *newView); |
114 | void requestLayoutView(); |
115 | |
116 | static QQuickSplitViewAttachedPrivate *get(QQuickSplitViewAttached *attached); |
117 | static const QQuickSplitViewAttachedPrivate *get(const QQuickSplitViewAttached *attached); |
118 | |
119 | QQuickItem *m_splitItem = nullptr; |
120 | QQuickSplitView *m_splitView = nullptr; |
121 | |
122 | unsigned m_fillWidth : 1; |
123 | unsigned m_fillHeight : 1; |
124 | unsigned m_isFillWidthSet : 1; |
125 | unsigned m_isFillHeightSet : 1; |
126 | unsigned m_isMinimumWidthSet : 1; |
127 | unsigned m_isMinimumHeightSet : 1; |
128 | unsigned m_isPreferredWidthSet : 1; |
129 | unsigned m_isPreferredHeightSet : 1; |
130 | unsigned m_isMaximumWidthSet : 1; |
131 | unsigned m_isMaximumHeightSet : 1; |
132 | qreal m_minimumWidth; |
133 | qreal m_minimumHeight; |
134 | qreal m_preferredWidth; |
135 | qreal m_preferredHeight; |
136 | qreal m_maximumWidth; |
137 | qreal m_maximumHeight; |
138 | }; |
139 | |
140 | class QQuickSplitHandleAttachedPrivate : public QObjectPrivate |
141 | { |
142 | Q_DECLARE_PUBLIC(QQuickSplitHandleAttached) |
143 | |
144 | public: |
145 | QQuickSplitHandleAttachedPrivate(); |
146 | |
147 | void setHovered(bool hovered); |
148 | void setPressed(bool pressed); |
149 | |
150 | static QQuickSplitHandleAttachedPrivate *get(QQuickSplitHandleAttached *attached); |
151 | static const QQuickSplitHandleAttachedPrivate *get(const QQuickSplitHandleAttached *attached); |
152 | |
153 | unsigned m_hovered : 1; |
154 | unsigned m_pressed : 1; |
155 | }; |
156 | |
157 | QT_END_NAMESPACE |
158 | |
159 | #endif // QQUICKSPLITVIEW_P_P_H |
160 | |