1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QSPLITTER_P_H
41#define QSPLITTER_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtWidgets/private/qtwidgetsglobal_p.h>
55#include "private/qframe_p.h"
56
57QT_REQUIRE_CONFIG(splitter);
58
59QT_BEGIN_NAMESPACE
60
61static const uint Default = 2;
62
63class QSplitterLayoutStruct
64{
65public:
66 QRect rect;
67 int sizer;
68 uint collapsed : 1;
69 uint collapsible : 2;
70 QWidget *widget;
71 QSplitterHandle *handle;
72
73 QSplitterLayoutStruct() : sizer(-1), collapsed(false), collapsible(Default), widget(nullptr), handle(nullptr) {}
74 ~QSplitterLayoutStruct() { delete handle; }
75 int getWidgetSize(Qt::Orientation orient);
76 int getHandleSize(Qt::Orientation orient);
77 int pick(const QSize &size, Qt::Orientation orient)
78 { return (orient == Qt::Horizontal) ? size.width() : size.height(); }
79};
80
81class QSplitterPrivate : public QFramePrivate
82{
83 Q_DECLARE_PUBLIC(QSplitter)
84public:
85 QSplitterPrivate() :
86#if QT_CONFIG(rubberband)
87 rubberBand(nullptr),
88#endif
89 opaque(true), firstShow(true),
90 childrenCollapsible(true), compatMode(false), handleWidth(-1), blockChildAdd(false), opaqueResizeSet(false) {}
91 ~QSplitterPrivate();
92
93#if QT_CONFIG(rubberband)
94 QPointer<QRubberBand> rubberBand;
95#endif
96 mutable QList<QSplitterLayoutStruct *> list;
97 Qt::Orientation orient;
98 bool opaque : 8;
99 bool firstShow : 8;
100 bool childrenCollapsible : 8;
101 bool compatMode : 8;
102 int handleWidth;
103 bool blockChildAdd;
104 bool opaqueResizeSet;
105
106 inline int pick(const QPoint &pos) const
107 { return orient == Qt::Horizontal ? pos.x() : pos.y(); }
108 inline int pick(const QSize &s) const
109 { return orient == Qt::Horizontal ? s.width() : s.height(); }
110
111 inline int trans(const QPoint &pos) const
112 { return orient == Qt::Vertical ? pos.x() : pos.y(); }
113 inline int trans(const QSize &s) const
114 { return orient == Qt::Vertical ? s.width() : s.height(); }
115
116 void init();
117 void recalc(bool update = false);
118 void doResize();
119 void storeSizes();
120 void getRange(int index, int *, int *, int *, int *) const;
121 void addContribution(int, int *, int *, bool) const;
122 int adjustPos(int, int, int *, int *, int *, int *) const;
123 bool collapsible(QSplitterLayoutStruct *) const;
124 bool collapsible(int index) const
125 { return (index < 0 || index >= list.size()) ? true : collapsible(list.at(i: index)); }
126 QSplitterLayoutStruct *findWidget(QWidget *) const;
127 void insertWidget_helper(int index, QWidget *widget, bool show);
128 QSplitterLayoutStruct *insertWidget(int index, QWidget *);
129 void doMove(bool backwards, int pos, int index, int delta,
130 bool mayCollapse, int *positions, int *widths);
131 void setGeo(QSplitterLayoutStruct *s, int pos, int size, bool allowCollapse);
132 int findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const;
133 void updateHandles();
134 void setSizes_helper(const QList<int> &sizes, bool clampNegativeSize = false);
135 bool shouldShowWidget(const QWidget *w) const;
136
137};
138
139class QSplitterHandlePrivate : public QWidgetPrivate
140{
141 Q_DECLARE_PUBLIC(QSplitterHandle)
142public:
143 QSplitterHandlePrivate() : s(nullptr), orient(Qt::Horizontal), mouseOffset(0), opaq(false), hover(false), pressed(false) {}
144
145 inline int pick(const QPoint &pos) const
146 { return orient == Qt::Horizontal ? pos.x() : pos.y(); }
147
148 QSplitter *s;
149 Qt::Orientation orient;
150 int mouseOffset;
151 bool opaq : 1;
152 bool hover : 1;
153 bool pressed : 1;
154};
155
156QT_END_NAMESPACE
157
158#endif
159

source code of qtbase/src/widgets/widgets/qsplitter_p.h