QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGridBox.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_GRID_BOX_H
7#define QSK_GRID_BOX_H
8
9#include "QskBox.h"
10
11class QSK_EXPORT QskGridBox : public QskBox
12{
13 Q_OBJECT
14
15 Q_PROPERTY( Qt::Alignment defaultAlignment READ defaultAlignment
16 WRITE setDefaultAlignment NOTIFY defaultAlignmentChanged )
17
18 Q_PROPERTY( bool empty READ isEmpty() )
19 Q_PROPERTY( int elementCount READ elementCount )
20
21 using Inherited = QskBox;
22
23 public:
24 explicit QskGridBox( QQuickItem* parent = nullptr );
25 ~QskGridBox() override;
26
27 Q_INVOKABLE int addItem( QQuickItem*,
28 int row, int column, int rowSpan, int columnSpan );
29
30 Q_INVOKABLE int addItem( QQuickItem*, int row, int column );
31
32 int addItem( QQuickItem*, int row, int column, Qt::Alignment );
33
34 int addItem( QQuickItem*, int row, int column,
35 int rowSpan, int columnSpan, Qt::Alignment );
36
37 Q_INVOKABLE int addSpacer( const QSizeF&,
38 int row, int column, int rowSpan = 1, int columnSpan = 1 );
39
40 int addColumnSpacer( qreal spacing, int column );
41 int addRowSpacer( qreal spacing, int row );
42
43 void removeItem( const QQuickItem* );
44 void removeAt( int index );
45
46 Q_INVOKABLE int rowCount() const;
47 Q_INVOKABLE int columnCount() const;
48
49 int elementCount() const;
50
51 QQuickItem* itemAtIndex( int index ) const;
52 int indexOf( const QQuickItem* ) const;
53
54 bool isEmpty() const;
55
56 Q_INVOKABLE QQuickItem* itemAt( int row, int column ) const;
57 Q_INVOKABLE int indexAt( int row, int column ) const;
58
59 Q_INVOKABLE QRect gridOfIndex( int index ) const;
60 Q_INVOKABLE QRect effectiveGridOfIndex( int index ) const;
61
62 void setDefaultAlignment( Qt::Alignment );
63 Qt::Alignment defaultAlignment() const;
64
65 void setSpacing( Qt::Orientations, qreal spacing );
66 void resetSpacing( Qt::Orientations );
67 qreal spacing( Qt::Orientation ) const;
68
69 void setSpacing( qreal spacing );
70
71 // stretch factors
72 Q_INVOKABLE void setRowStretchFactor( int row, int stretch );
73 Q_INVOKABLE int rowStretchFactor( int row ) const;
74
75 Q_INVOKABLE void setColumnStretchFactor( int column, int stretch );
76 Q_INVOKABLE int columnStretchFactor( int column ) const;
77
78 // row/column size hints
79
80 Q_INVOKABLE void setColumnWidthHint( int column, Qt::SizeHint, qreal width );
81 Q_INVOKABLE qreal columnWidthHint( int column, Qt::SizeHint ) const;
82
83 Q_INVOKABLE void setRowHeightHint( int row, Qt::SizeHint, qreal height );
84 Q_INVOKABLE qreal rowHeightHint( int row, Qt::SizeHint ) const;
85
86 Q_INVOKABLE void setRowFixedHeight( int row, qreal height );
87 Q_INVOKABLE void setColumnFixedWidth( int column, qreal width );
88
89 void dump() const;
90
91 public Q_SLOTS:
92 void invalidate();
93 void clear( bool autoDelete = false );
94
95 Q_SIGNALS:
96 void defaultAlignmentChanged();
97
98 protected:
99 bool event( QEvent* ) override;
101
102 void itemChange( ItemChange, const ItemChangeData& ) override;
103 void updateLayout() override;
104
105 QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
106
107 private:
108 void setItemActive( QQuickItem*, bool );
109
110 class PrivateData;
111 std::unique_ptr< PrivateData > m_data;
112};
113
114inline int QskGridBox::addItem( QQuickItem* item, int row, int column )
115{
116 return addItem( item, row, column, 1, 1 );
117}
118
119inline bool QskGridBox::isEmpty() const
120{
121 return elementCount() <= 0;
122}
123
124inline void QskGridBox::setSpacing( qreal spacing )
125{
126 setSpacing( Qt::Horizontal | Qt::Vertical, spacing );
127}
128
129#endif
void itemChange(ItemChange, const ItemChangeData &) override
virtual void geometryChangeEvent(QskGeometryChangeEvent *)
Definition QskItem.cpp:855