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