QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskLayoutChain.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_LAYOUT_CHAIN_H
7#define QSK_LAYOUT_CHAIN_H
8
9#include <QskLayoutMetrics.h>
10#include <qrect.h>
11#include <qvector.h>
12
13class QDebug;
14
16{
17 public:
18 class Segment
19 {
20 public:
21 inline qreal end() const { return start + length; }
22
23 qreal start = 0.0;
24 qreal length = 0.0;
25 };
26
27 typedef QVector< Segment > Segments;
28
30 {
31 public:
32 inline qreal metric( int which ) const
33 {
34 return metrics.metric( which );
35 }
36
37 inline void setMetric( int which, qreal size )
38 {
39 metrics.setMetric( which, size );
40 }
41
42 int stretch = 0;
43 bool canGrow = false;
44 bool isShrunk = false;
45 bool isValid = false;
46
47 QskLayoutMetrics metrics;
48 };
49
50 enum FillMode
51 {
52 Leading = 1 << 0,
53 Trailing = 1 << 1
54 };
55
58
59 void invalidate();
60
61 void reset( int count, qreal constraint );
62 void expandCell( int index, const CellData& );
63 void expandCells( int start, int end, const CellData& );
64 void shrinkCell( int index, const CellData& );
65 void finish();
66
67 const CellData& cell( int index ) const { return m_cells[ index ]; }
68
69 bool setSpacing( qreal spacing );
70 qreal spacing() const { return m_spacing; }
71
72 void setFillMode( int mode ) { m_fillMode = mode; }
73 int fillMode() const { return m_fillMode; }
74
75 Segments segments( qreal size ) const;
76 QskLayoutMetrics boundingMetrics() const { return m_boundingMetrics; }
77
78 inline qreal constraint() const { return m_constraint; }
79 inline int count() const { return m_cells.size(); }
80
81 private:
82 Segments distributed( int which, qreal offset, qreal extra ) const;
83 Segments minimumExpanded( qreal size ) const;
84 Segments preferredStretched( qreal size ) const;
85
86 QskLayoutMetrics m_boundingMetrics;
87 qreal m_constraint = -2.0;
88
89 qreal m_spacing = 0;
90 int m_fillMode = 0;
91
92 int m_sumStretches = 0;
93 int m_validCells = 0;
94
95 QVector< CellData > m_cells;
96};
97
98#ifndef QT_NO_DEBUG_STREAM
99
100QDebug operator<<( QDebug, const QskLayoutChain::Segment& );
101QDebug operator<<( QDebug, const QskLayoutChain::CellData& );
102
103#endif
104
105Q_DECLARE_TYPEINFO( QskLayoutChain::Segment, Q_MOVABLE_TYPE );
106Q_DECLARE_TYPEINFO( QskLayoutChain::CellData, Q_MOVABLE_TYPE );
107
108#endif