QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskLayoutEngine2D.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_LAYOUT_ENGINE_2D_H
7#define QSK_LAYOUT_ENGINE_2D_H
8
9#include "QskGlobal.h"
10#include "QskLayoutChain.h"
11#include "QskSizePolicy.h"
12
13#include <qnamespace.h>
14#include <memory>
15
17
18class QSK_EXPORT QskLayoutEngine2D
19{
20 public:
22 virtual ~QskLayoutEngine2D();
23
24 virtual int count() const = 0;
25
26 int rowCount() const;
27 int columnCount() const;
28
29 bool setVisualDirection( Qt::LayoutDirection );
30 Qt::LayoutDirection visualDirection() const;
31
32 bool setDefaultAlignment( Qt::Alignment );
33 Qt::Alignment defaultAlignment() const;
34
35 bool setExtraSpacingAt( Qt::Edges edges );
36 Qt::Edges extraSpacingAt() const;
37
38 bool setSpacing( qreal spacing, Qt::Orientations );
39 qreal spacing( Qt::Orientation ) const;
40
41 qreal defaultSpacing( Qt::Orientation ) const;
42
43 void invalidate();
44
45 qreal widthForHeight( qreal height ) const;
46 qreal heightForWidth( qreal width ) const;
47
48 QSizeF sizeHint( Qt::SizeHint, const QSizeF& constraint ) const;
49
50 void setGeometries( const QRectF& );
51
52 protected:
53 QRectF geometryAt( const QskLayoutElement*, const QRect& grid ) const;
54
55 enum
56 {
57 ElementCache = 1 << 0,
58 LayoutCache = 1 << 1
59 };
60
61 void invalidate( int what );
62
63 private:
64 Q_DISABLE_COPY( QskLayoutEngine2D )
65
66 void updateSegments( const QSizeF& ) const;
67
68 virtual void layoutItems() = 0;
69 virtual int effectiveCount( Qt::Orientation ) const = 0;
70
71 virtual void invalidateElementCache() = 0;
72 QskSizePolicy::ConstraintType constraintType() const;
73
74 virtual QskSizePolicy sizePolicyAt( int index ) const = 0;
75
76 void setupChain( Qt::Orientation ) const;
77 void setupChain( Qt::Orientation, const QskLayoutChain::Segments& ) const;
78
79 virtual void setupChain( Qt::Orientation,
80 const QskLayoutChain::Segments&, QskLayoutChain& ) const = 0;
81
82 class PrivateData;
83 std::unique_ptr< PrivateData > m_data;
84};
85
86inline void QskLayoutEngine2D::invalidate()
87{
88 invalidate( ElementCache | LayoutCache );
89}
90
91inline int QskLayoutEngine2D::rowCount() const
92{
93 return effectiveCount( Qt::Vertical );
94}
95
96inline int QskLayoutEngine2D::columnCount() const
97{
98 return effectiveCount( Qt::Horizontal );
99}
100
101#endif