1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL3$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or later as published by the Free
28 ** Software Foundation and appearing in the file LICENSE.GPL included in
29 ** the packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 2.0 requirements will be
31 ** met: http://www.gnu.org/licenses/gpl-2.0.html.
32 **
33 ** $QT_END_LICENSE$
34 **
35 ****************************************************************************/
36 
37 #ifndef QQUICKSPLITVIEW_P_P_H
38 #define QQUICKSPLITVIEW_P_P_H
39 
40 //
41 //  W A R N I N G
42 //  -------------
43 //
44 // This file is not part of the Qt API.  It exists purely as an
45 // implementation detail.  This header file may change from version to
46 // version without notice, or even be removed.
47 //
48 // We mean it.
49 //
50 
51 #include <QtQuickTemplates2/private/qquickcontainer_p_p.h>
52 
53 QT_BEGIN_NAMESPACE
54 
55 class QQuickSplitView;
56 class QQuickSplitViewAttached;
57 class QQuickSplitHandleAttached;
58 
59 class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSplitViewPrivate : public QQuickContainerPrivate
60 {
61     Q_DECLARE_PUBLIC(QQuickSplitView)
62 
63 public:
64     void updateFillIndex();
65     void layoutResizeSplitItems(qreal &usedWidth, qreal &usedHeight, int &indexBeingResizedDueToDrag);
66     void layoutResizeFillItem(QQuickItem *fillItem, qreal &usedWidth, qreal &usedHeight, int indexBeingResizedDueToDrag);
67     void layoutPositionItems(const QQuickItem *fillItem);
68     void requestLayout();
69     void layout();
70     void createHandles();
71     void createHandleItem(int index);
72     void removeExcessHandles();
73     void destroyHandles();
74     void resizeHandle(QQuickItem *handleItem);
75     void resizeHandles();
76     void updateHandleVisibilities();
77     void updateHoveredHandle(QQuickItem *hoveredItem);
78     void setResizing(bool resizing);
79 
80     bool isHorizontal() const;
81     qreal accumulatedSize(int firstIndex, int lastIndex) const;
82 
83     struct EffectiveSizeData {
84         qreal effectiveMinimumWidth;
85         qreal effectiveMinimumHeight;
86         qreal effectivePreferredWidth;
87         qreal effectivePreferredHeight;
88         qreal effectiveMaximumWidth;
89         qreal effectiveMaximumHeight;
90     };
91 
92     EffectiveSizeData effectiveSizeData(const QQuickItemPrivate *itemPrivate,
93         const QQuickSplitViewAttached *attached) const;
94 
95     int handleIndexForSplitIndex(int splitIndex) const;
96 
97     QQuickItem *getContentItem() override;
98     void handlePress(const QPointF &point) override;
99     void handleMove(const QPointF &point) override;
100     void handleRelease(const QPointF &point) override;
101 
102     void itemVisibilityChanged(QQuickItem *item) override;
103     void itemImplicitWidthChanged(QQuickItem *item) override;
104     void itemImplicitHeightChanged(QQuickItem *item) override;
105 
106     void updatePolish() override;
107 
108     static QQuickSplitViewPrivate *get(QQuickSplitView *splitView);
109 
110     Qt::Orientation m_orientation = Qt::Horizontal;
111     QQmlComponent *m_handle = nullptr;
112     QVector<QQuickItem*> m_handleItems;
113     int m_hoveredHandleIndex = -1;
114     int m_pressedHandleIndex = -1;
115     int m_nextVisibleIndexAfterPressedHandle = -1;
116     QPointF m_pressPos;
117     QPointF m_mousePos;
118     QPointF m_handlePosBeforePress;
119     qreal m_leftOrTopItemSizeBeforePress = 0.0;
120     qreal m_rightOrBottomItemSizeBeforePress = 0.0;
121     int m_fillIndex = -1;
122     bool m_layingOut = false;
123     bool m_ignoreNextLayoutRequest = false;
124     bool m_resizing = false;
125 };
126 
127 class QQuickSplitViewAttachedPrivate : public QObjectPrivate
128 {
129     Q_DECLARE_PUBLIC(QQuickSplitViewAttached)
130 
131 public:
132     QQuickSplitViewAttachedPrivate();
133 
134     void setView(QQuickSplitView *newView);
135     void requestLayoutView();
136 
137     static QQuickSplitViewAttachedPrivate *get(QQuickSplitViewAttached *attached);
138     static const QQuickSplitViewAttachedPrivate *get(const QQuickSplitViewAttached *attached);
139 
140     QQuickItem *m_splitItem = nullptr;
141     QQuickSplitView *m_splitView = nullptr;
142 
143     unsigned m_fillWidth : 1;
144     unsigned m_fillHeight : 1;
145     unsigned m_isFillWidthSet : 1;
146     unsigned m_isFillHeightSet : 1;
147     unsigned m_isMinimumWidthSet : 1;
148     unsigned m_isMinimumHeightSet : 1;
149     unsigned m_isPreferredWidthSet : 1;
150     unsigned m_isPreferredHeightSet : 1;
151     unsigned m_isMaximumWidthSet : 1;
152     unsigned m_isMaximumHeightSet : 1;
153     qreal m_minimumWidth;
154     qreal m_minimumHeight;
155     qreal m_preferredWidth;
156     qreal m_preferredHeight;
157     qreal m_maximumWidth;
158     qreal m_maximumHeight;
159 };
160 
161 class QQuickSplitHandleAttachedPrivate : public QObjectPrivate
162 {
163     Q_DECLARE_PUBLIC(QQuickSplitHandleAttached)
164 
165 public:
166     QQuickSplitHandleAttachedPrivate();
167 
168     void setHovered(bool hovered);
169     void setPressed(bool pressed);
170 
171     static QQuickSplitHandleAttachedPrivate *get(QQuickSplitHandleAttached *attached);
172     static const QQuickSplitHandleAttachedPrivate *get(const QQuickSplitHandleAttached *attached);
173 
174     unsigned m_hovered : 1;
175     unsigned m_pressed : 1;
176 };
177 
178 QT_END_NAMESPACE
179 
180 #endif // QQUICKSPLITVIEW_P_P_H
181