1// Copyright (C) 2016 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 QSPLITTER_P_H
5#define QSPLITTER_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 <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "private/qframe_p.h"
20
21QT_REQUIRE_CONFIG(splitter);
22
23QT_BEGIN_NAMESPACE
24
25static const uint Default = 2;
26
27class QSplitterLayoutStruct
28{
29public:
30 QRect rect;
31 int sizer;
32 uint collapsed : 1;
33 uint collapsible : 2;
34 QWidget *widget;
35 QSplitterHandle *handle;
36
37 QSplitterLayoutStruct() : sizer(-1), collapsed(false), collapsible(Default), widget(nullptr), handle(nullptr) {}
38 ~QSplitterLayoutStruct() { delete handle; }
39 int getWidgetSize(Qt::Orientation orient);
40 int getHandleSize(Qt::Orientation orient);
41 int pick(const QSize &size, Qt::Orientation orient)
42 { return (orient == Qt::Horizontal) ? size.width() : size.height(); }
43};
44
45class QSplitterPrivate : public QFramePrivate
46{
47 Q_DECLARE_PUBLIC(QSplitter)
48public:
49 QSplitterPrivate() :
50#if QT_CONFIG(rubberband)
51 rubberBand(nullptr),
52#endif
53 opaque(true), firstShow(true),
54 childrenCollapsible(true), compatMode(false), handleWidth(-1), blockChildAdd(false), opaqueResizeSet(false) {}
55 ~QSplitterPrivate();
56
57#if QT_CONFIG(rubberband)
58 QPointer<QRubberBand> rubberBand;
59#endif
60 mutable QList<QSplitterLayoutStruct *> list;
61 Qt::Orientation orient;
62 bool opaque : 8;
63 bool firstShow : 8;
64 bool childrenCollapsible : 8;
65 bool compatMode : 8;
66 int handleWidth;
67 bool blockChildAdd;
68 bool opaqueResizeSet;
69
70 inline int pick(const QPoint &pos) const
71 { return orient == Qt::Horizontal ? pos.x() : pos.y(); }
72 inline int pick(const QSize &s) const
73 { return orient == Qt::Horizontal ? s.width() : s.height(); }
74
75 inline int trans(const QPoint &pos) const
76 { return orient == Qt::Vertical ? pos.x() : pos.y(); }
77 inline int trans(const QSize &s) const
78 { return orient == Qt::Vertical ? s.width() : s.height(); }
79
80 void init();
81 void recalc(bool update = false);
82 void doResize();
83 void storeSizes();
84 void getRange(int index, int *, int *, int *, int *) const;
85 void addContribution(int, int *, int *, bool) const;
86 int adjustPos(int, int, int *, int *, int *, int *) const;
87 bool collapsible(QSplitterLayoutStruct *) const;
88 bool collapsible(int index) const
89 { return (index < 0 || index >= list.size()) ? true : collapsible(list.at(i: index)); }
90 QSplitterLayoutStruct *findWidget(QWidget *) const;
91 void insertWidget_helper(int index, QWidget *widget, bool show);
92 QSplitterLayoutStruct *insertWidget(int index, QWidget *);
93 void doMove(bool backwards, int pos, int index, int delta,
94 bool mayCollapse, int *positions, int *widths);
95 void setGeo(QSplitterLayoutStruct *s, int pos, int size, bool allowCollapse);
96 int findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const;
97 void updateHandles();
98 void setSizes_helper(const QList<int> &sizes, bool clampNegativeSize = false);
99 bool shouldShowWidget(const QWidget *w) const;
100
101};
102
103class QSplitterHandlePrivate : public QWidgetPrivate
104{
105 Q_DECLARE_PUBLIC(QSplitterHandle)
106public:
107 QSplitterHandlePrivate() : s(nullptr), orient(Qt::Horizontal), mouseOffset(0), opaq(false), hover(false), pressed(false) {}
108
109 inline int pick(const QPoint &pos) const
110 { return orient == Qt::Horizontal ? pos.x() : pos.y(); }
111
112 QSplitter *s;
113 Qt::Orientation orient;
114 int mouseOffset;
115 bool opaq : 1;
116 bool hover : 1;
117 bool pressed : 1;
118};
119
120QT_END_NAMESPACE
121
122#endif
123

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