Kirigami2

toolbarlayoutdelegate.h
1 /*
2  * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5  */
6 
7 #ifndef TOOLBARLAYOUTDELEGATE_H
8 #define TOOLBARLAYOUTDELEGATE_H
9 
10 #include "enums.h"
11 #include <QQmlIncubator>
12 #include <QQuickItem>
13 
14 class ToolBarLayout;
15 
16 /*
17  * A helper subclass of QQmlIncubator that allows us to do some things more
18  * easily.
19  */
20 class ToolBarDelegateIncubator : public QQmlIncubator
21 {
22 public:
23  ToolBarDelegateIncubator(QQmlComponent *component, QQmlContext *context);
24 
25  void setStateCallback(std::function<void(QQuickItem *)> callback);
26  void setCompletedCallback(std::function<void(ToolBarDelegateIncubator *)> callback);
27 
28  void create();
29 
30  bool isFinished();
31 
32 private:
33  void setInitialState(QObject *object) override;
35 
36  QQmlComponent *m_component;
37  QQmlContext *m_context;
38  std::function<void(QQuickItem *)> m_stateCallback;
39  std::function<void(ToolBarDelegateIncubator *)> m_completedCallback;
40  bool m_finished = false;
41 };
42 
43 /*
44  * A helper class to encapsulate some of the delegate functionality used by
45  * ToolBarLayout. Primarily, this hides some of the difference that delegates
46  * are two items instead of one.
47  */
48 class ToolBarLayoutDelegate : public QObject
49 {
50  Q_OBJECT
51 public:
52  ToolBarLayoutDelegate(ToolBarLayout *parent);
53  ~ToolBarLayoutDelegate() override;
54 
55  QObject *action() const;
56  void setAction(QObject *action);
57  void createItems(QQmlComponent *fullComponent, QQmlComponent *iconComponent, std::function<void(QQuickItem *)> callback);
58 
59  bool isReady() const;
60  bool isActionVisible() const;
61  bool isHidden() const;
62  bool isIconOnly() const;
63  bool isKeepVisible() const;
64 
65  bool isVisible() const;
66 
67  void hide();
68  void showIcon();
69  void showFull();
70  void show();
71 
72  void setPosition(qreal x, qreal y);
73  void setHeight(qreal height);
74 
75  qreal width() const;
76  qreal height() const;
77  qreal implicitWidth() const;
78  qreal implicitHeight() const;
79  qreal maxHeight() const;
80  qreal iconWidth() const;
81  qreal fullWidth() const;
82 
83 private:
84  Q_SLOT void actionVisibleChanged();
85  Q_SLOT void displayHintChanged();
86  inline void ensureItemVisibility()
87  {
88  if (m_full) {
89  m_full->setVisible(m_fullVisible);
90  }
91  if (m_icon) {
92  m_icon->setVisible(m_iconVisible);
93  }
94  }
95  void cleanupIncubators();
96 
97  ToolBarLayout *m_parent = nullptr;
98  QObject *m_action = nullptr;
99  QQuickItem *m_full = nullptr;
100  QQuickItem *m_icon = nullptr;
101  ToolBarDelegateIncubator *m_fullIncubator = nullptr;
102  ToolBarDelegateIncubator *m_iconIncubator = nullptr;
103 
104  DisplayHint::DisplayHints m_displayHint = DisplayHint::NoPreference;
105  bool m_ready = false;
106  bool m_actionVisible = true;
107  bool m_fullVisible = false;
108  bool m_iconVisible = false;
109 };
110 
111 #endif // TOOLBARLAYOUTDELEGATE_H
Q_OBJECTQ_OBJECT
Q_SCRIPTABLE CaptureState status()
QAction * create(StandardGameAction id, const QObject *recvr, const char *slot, QObject *parent)
Q_SLOTQ_SLOT
An item that creates delegates for actions and lays them out in a row.
Definition: toolbarlayout.h:46
virtual void setInitialState(QObject *object)
virtual void statusChanged(QQmlIncubator::Status status)
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.