QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskLinearBox.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_LINEAR_BOX_H
7#define QSK_LINEAR_BOX_H
8
9#include "QskIndexedLayoutBox.h"
10
11class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox
12{
13 Q_OBJECT
14
15 Q_PROPERTY( Qt::Orientation orientation READ orientation
16 WRITE setOrientation NOTIFY orientationChanged FINAL )
17
18 Q_PROPERTY( uint dimension READ dimension
19 WRITE setDimension NOTIFY dimensionChanged FINAL )
20
21 Q_PROPERTY( qreal spacing READ spacing
22 WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL )
23
24 Q_PROPERTY( Qt::Alignment defaultAlignment READ defaultAlignment
25 WRITE setDefaultAlignment NOTIFY defaultAlignmentChanged )
26
27 Q_PROPERTY( Qt::Edges extraSpacingAt READ extraSpacingAt
28 WRITE setExtraSpacingAt NOTIFY extraSpacingAtChanged )
29
30 Q_PROPERTY( int elementCount READ elementCount )
31 Q_PROPERTY( bool empty READ isEmpty() )
32
34
35 public:
36 explicit QskLinearBox( QQuickItem* parent = nullptr );
37 explicit QskLinearBox( Qt::Orientation, QQuickItem* parent = nullptr );
38
39 QskLinearBox( Qt::Orientation, uint dimension, QQuickItem* parent = nullptr );
40 ~QskLinearBox() override;
41
42 bool isEmpty() const;
43 int elementCount() const; // items and spacers
44
45 qreal spacingAtIndex( int index ) const;
46
47 QQuickItem* itemAtIndex( int index ) const;
48 int indexOf( const QQuickItem* ) const;
49
50 void removeItem( const QQuickItem* );
51 void removeAt( int index );
52
53 Qt::Orientation orientation() const;
54 void setOrientation( Qt::Orientation );
55
56 void setDimension( uint );
57 uint dimension() const;
58
59 void setExtraSpacingAt( Qt::Edges );
60 Qt::Edges extraSpacingAt() const;
61
62 void setDefaultAlignment( Qt::Alignment );
63 Qt::Alignment defaultAlignment() const;
64
65 void setSpacing( qreal spacing );
66 void resetSpacing();
67 qreal spacing() const;
68
69 Q_INVOKABLE int addItem( QQuickItem* );
70 int addItem( QQuickItem*, Qt::Alignment );
71
72 Q_INVOKABLE int insertItem( int index, QQuickItem* );
73 int insertItem( int index, QQuickItem*, Qt::Alignment );
74
75 Q_INVOKABLE int addSpacer( qreal spacing, int stretchFactor = 0 );
76 Q_INVOKABLE int insertSpacer( int index, qreal spacing, int stretchFactor = 0 );
77
78 Q_INVOKABLE int addStretch( int stretchFactor = 0 );
79 Q_INVOKABLE int insertStretch( int index, int stretchFactor = 0 );
80
81 Q_INVOKABLE void setStretchFactor( int index, int stretchFactor );
82 Q_INVOKABLE int stretchFactor( int index ) const;
83
84 void setStretchFactor( const QQuickItem*, int stretchFactor );
85 int stretchFactor( const QQuickItem* ) const;
86
87 void dump() const;
88
89 public Q_SLOTS:
90 void transpose();
91 void activate();
92 void invalidate();
93 void clear( bool autoDelete = false );
94
95 Q_SIGNALS:
96 void orientationChanged();
97 void dimensionChanged();
98 void defaultAlignmentChanged();
99 void spacingChanged();
100 void extraSpacingAtChanged();
101
102 protected:
103 bool event( QEvent* ) override;
104 void geometryChangeEvent( QskGeometryChangeEvent* ) override;
105
106 void itemChange( ItemChange, const ItemChangeData& ) override;
107 void updateLayout() override;
108
109 QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
110
111 private:
112 void autoAddItem( QQuickItem* ) override final;
113 void autoRemoveItem( QQuickItem* ) override final;
114
115 void setItemActive( QQuickItem*, bool );
116 void removeItemInternal( int index, bool unparent );
117
118 class PrivateData;
119 std::unique_ptr< PrivateData > m_data;
120};
121
122inline bool QskLinearBox::isEmpty() const
123{
124 return elementCount() <= 0;
125}
126
127#endif
Base class of layouts with index ordered elements.
Layout stringing items in rows and columns.