Kirigami2

sizegroup.h
1 /*
2  * SPDX-FileCopyrightText: 2020 Carson Black <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #pragma once
8 
9 #include <QMap>
10 #include <QObject>
11 #include <QPair>
12 #include <QPointer>
13 #include <QQmlListProperty>
14 #include <QQmlParserStatus>
15 #include <QQuickItem>
16 
17 /**
18  * SizeGroup is a utility object that makes groups of items request the same size.
19  */
20 class SizeGroup : public QObject, public QQmlParserStatus
21 {
22  Q_OBJECT
24 
25 public:
26  enum Mode {
27  None = 0, /// SizeGroup does nothing
28  Width = 1, /// SizeGroup syncs item widths
29  Height = 2, /// SizeGroup syncs item heights
30  Both = 3, /// SizeGroup syncs both item widths and heights
31  };
32  Q_ENUM(Mode)
33  Q_DECLARE_FLAGS(Modes, Mode)
34 
35 private:
36  Mode m_mode = None;
39 
40 public:
41  /**
42  * Which dimensions this SizeGroup should adjust
43  */
44  Q_PROPERTY(Mode mode MEMBER m_mode NOTIFY modeChanged)
45  Q_SIGNAL void modeChanged();
46 
47  /**
48  * Which items this SizeGroup should adjust
49  */
52 
53  void adjustItems(Mode whatChanged);
54  void connectItem(QQuickItem *item);
55 
56  /**
57  * Forces the SizeGroup to relayout items.
58  *
59  * Normally this is never needed as the SizeGroup automatically
60  * relayout items as they're added and their sizes change.
61  */
62  Q_INVOKABLE void relayout();
63 
64  void classBegin() override
65  {
66  }
67  void componentComplete() override;
68 
69 private:
70  static void appendItem(QQmlListProperty<QQuickItem> *prop, QQuickItem *value);
71 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
72  static int itemCount(QQmlListProperty<QQuickItem> *prop);
73  static QQuickItem *itemAt(QQmlListProperty<QQuickItem> *prop, int index);
74 #else
75  static qsizetype itemCount(QQmlListProperty<QQuickItem> *prop);
76  static QQuickItem *itemAt(QQmlListProperty<QQuickItem> *prop, qsizetype index);
77 #endif
78  static void clearItems(QQmlListProperty<QQuickItem> *prop);
79 };
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_INVOKABLE void relayout()
Forces the SizeGroup to relayout items.
Definition: sizegroup.cpp:68
Q_ENUM(...)
@ Height
SizeGroup syncs item widths.
Definition: sizegroup.h:29
SizeGroup is a utility object that makes groups of items request the same size.
Definition: sizegroup.h:20
QQmlListProperty< QQuickItem > items
Which items this SizeGroup should adjust.
Definition: sizegroup.h:50
Q_SIGNALQ_SIGNAL
Q_INVOKABLEQ_INVOKABLE
Q_INTERFACES(...)
@ Both
SizeGroup syncs item heights.
Definition: sizegroup.h:30
Mode mode
Which dimensions this SizeGroup should adjust.
Definition: sizegroup.h:44
@ Width
SizeGroup does nothing.
Definition: sizegroup.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.