API Documentation
Loading...
Searching...
No Matches
QCustomSplitter.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: QCustomSplitter
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <QStyle>
35#include <QEvent>
36#include <QSplitter>
37namespace NDEVR
38{
39 class NDEVR_WIDGETS_API QCustomSplitter : public QSplitter
40 {
41 Q_OBJECT
42 public:
43 explicit QCustomSplitter(QWidget* parent = nullptr)
44 : QSplitter(parent)
45 , m_is_animating(false)
46 {}
47 explicit QCustomSplitter(Qt::Orientation orientation, QWidget* parent = nullptr)
48 : QSplitter(orientation, parent)
49 , m_is_animating(false)
50 {}
52 {};
53
54 void setAnimating(bool animating)
55 {
56 m_is_animating = animating;
57 if (!m_is_animating)
58 {
59 refreshSizes();
60 }
61 }
63 {
64 sint08 total = 0;
65 for (int i = 0; i < count(); i++)
66 {
67 total += (orientation() == Qt::Orientation::Horizontal) ? widget(i)->sizeHint().width() : widget(i)->sizeHint().height();
68 }
69 int our_size = availableSize();
70 if (our_size == 0 || total == 0)
71 return 1.0;
72 return cast<fltp08>(total) / cast<fltp08>(our_size);
73 }
74 int availableSize() const
75 {
76 int available_size = orientation() == Qt::Orientation::Horizontal ? width() : height();
77 available_size -= count() * style()->pixelMetric(QStyle::PixelMetric::PM_SplitterWidth, nullptr, this);
78 return available_size;
79 }
80 sint04 sizeIfAdded(sint04 preferred_size, sint04 min_size, sint04 current_size) const
81 {
82 preferred_size = getMax(preferred_size, min_size);
83 int available_size = availableSize();
84
85 if (available_size == 0)
86 return preferred_size;
87 if (count() == 1)
88 return available_size;
89 sint08 total = 0;
90 for (int i = 0; i < count(); i++)
91 {
92 total += (orientation() == Qt::Orientation::Horizontal) ? widget(i)->sizeHint().width() : widget(i)->sizeHint().height();
93 }
94 if (total <= 0)
95 return available_size;
96 fltp08 multiple = cast<fltp08>(available_size) / cast<fltp08>(total + preferred_size - current_size);
97 if (preferred_size * multiple < min_size)
98 return min_size;
99 else
100 return cast<sint04>(preferred_size * multiple);
101 }
102 /*void resizeEvent(QResizeEvent* event) override
103 {
104 refreshSizes();
105 QSplitter::resizeEvent(event);
106 }*/
107 QSize minimumSizeHint() const override
108 {
109 return QSize(1, 1);
110 }
111 bool eventFilter(QObject* object, QEvent* event) override
112 {
113 switch (event->type())
114 {
115 case QEvent::LayoutRequest:
116 refreshSizes();
117 break;
118 default:
119 break;
120 }
121 return QSplitter::eventFilter(object, event);
122 }
124 {
125 QList<int> current_sizes;
126 int total_size = 0;
127 for (int i = 0; i < count(); i++)
128 {
129 QWidget* w = widget(i);
130 QSize size_hint = w->sizeHint();
131 int local_size = getMax(1, orientation() == Qt::Orientation::Horizontal ? size_hint.width() : size_hint.height());
132 total_size += local_size;
133 current_sizes.append(local_size);
134 }
135 int our_size = (orientation() == Qt::Orientation::Horizontal) ? width() : height();
136 if (total_size < our_size)
137 {
138 fltp08 size_multiple = cast<fltp08>(our_size) / cast<fltp08>(total_size);
139 //QSize our_size = size();
140 for (int i = 0; i < count(); i++)
141 {
142 current_sizes[i] = cast<int>(size_multiple * current_sizes[i]);
143 /*if (orientation() == Qt::Orientation::Horizontal)
144 our_size.setWidth(current_sizes[i]);
145 else
146 our_size.setHeight(current_sizes[i]);
147 widget(i)->resize(our_size);*/
148 }
149 }
150 setSizes(current_sizes);
151 //repaint();
152 //if(m_is_animating)
153 //update();
154 }
155 void refreshSizes(int offset)
156 {
157 QList<int> current_sizes;
158 int total_size = 0;
159 for (int i = 0; i < count(); i++)
160 {
161 QWidget* w = widget(i);
162 QSize size_hint = w->sizeHint();
163 size_hint = size_hint.expandedTo(w->minimumSize());
164 int local_size = getMax(1, orientation() == Qt::Orientation::Horizontal ? size_hint.width() : size_hint.height());
165 total_size += local_size;
166 current_sizes.append(local_size + offset);
167 }
168 int our_size = availableSize();
169 if (total_size < our_size)
170 {
171 fltp08 size_multiple = cast<fltp08>(our_size) / cast<fltp08>(total_size);
172 for (int i = 0; i < count(); i++)
173 {
174 current_sizes[i] = cast<int>(size_multiple * current_sizes[i]);
175 }
176 }
177 setSizes(current_sizes);
178 //repaint();
179 //if(m_is_animating)
180 //update();
181 }
183 };
184}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:81
Definition QCustomSplitter.h:40
QSize minimumSizeHint() const override
Definition QCustomSplitter.h:107
QCustomSplitter(Qt::Orientation orientation, QWidget *parent=nullptr)
Definition QCustomSplitter.h:47
bool eventFilter(QObject *object, QEvent *event) override
Definition QCustomSplitter.h:111
bool m_is_animating
Definition QCustomSplitter.h:182
sint04 sizeIfAdded(sint04 preferred_size, sint04 min_size, sint04 current_size) const
Definition QCustomSplitter.h:80
void refreshSizes(int offset)
Definition QCustomSplitter.h:155
void refreshSizes()
Definition QCustomSplitter.h:123
int availableSize() const
Definition QCustomSplitter.h:74
QCustomSplitter(QWidget *parent=nullptr)
Definition QCustomSplitter.h:43
void setAnimating(bool animating)
Definition QCustomSplitter.h:54
fltp08 sizeMultiple()
Definition QCustomSplitter.h:62
virtual ~QCustomSplitter()
Definition QCustomSplitter.h:51
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:76
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator.
Definition BaseFunctions.hpp:116
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:86
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181