QmlMaterial 0.1.0
Loading...
Searching...
No Matches
toolbar_layout_delegate.hpp
1/*
2 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 *
6 * Private header — internal helper for ToolBarLayout. Not installed, not part of public API.
7 */
8
9#pragma once
10
11#include <QQmlIncubator>
12#include <QQuickItem>
13
14#include "qml_material/layout/toolbar_layout.hpp"
15
16namespace qml_material
17{
18
19class ToolBarDelegateIncubator : public QQmlIncubator
20{
21public:
22 ToolBarDelegateIncubator(QQmlComponent *component, QQmlContext *context);
23
24 void setStateCallback(std::function<void(QQuickItem *)> callback);
25 void setCompletedCallback(std::function<void(ToolBarDelegateIncubator *)> callback);
26
27 void create();
28
29 bool isFinished();
30
31private:
32 void setInitialState(QObject *object) override;
33 void statusChanged(QQmlIncubator::Status status) override;
34
35 QQmlComponent *m_component;
36 QQmlContext *m_context;
37 std::function<void(QQuickItem *)> m_stateCallback;
38 std::function<void(ToolBarDelegateIncubator *)> m_completedCallback;
39 bool m_finished = false;
40};
41
42class ToolBarLayoutDelegate : public QObject
43{
44 Q_OBJECT
45public:
46 ToolBarLayoutDelegate(ToolBarLayout *parent);
47 ~ToolBarLayoutDelegate() override;
48
49 QObject *action() const;
50 void setAction(QObject *action);
51 void createItems(QQmlComponent *fullComponent, QQmlComponent *iconComponent, std::function<void(QQuickItem *)> callback);
52
53 bool isReady() const;
54 bool isActionVisible() const;
55 bool isHidden() const;
56 bool isIconOnly() const;
57 bool isKeepVisible() const;
58
59 bool isVisible() const;
60
61 void hide();
62 void showIcon();
63 void showFull();
64 void show();
65
66 void setPosition(qreal x, qreal y);
67 void setHeight(qreal height);
68 void resetHeight();
69
70 qreal width() const;
71 qreal height() const;
72 qreal implicitWidth() const;
73 qreal implicitHeight() const;
74 qreal maxHeight() const;
75 qreal iconWidth() const;
76 qreal fullWidth() const;
77
78private:
79 Q_SLOT void actionVisibleChanged();
80 Q_SLOT void displayHintChanged();
81 inline void ensureItemVisibility()
82 {
83 if (m_full) {
84 m_full->setVisible(m_fullVisible);
85 }
86 if (m_icon) {
87 m_icon->setVisible(m_iconVisible);
88 }
89 }
90 void cleanupIncubators();
91 void triggerRelayout();
92
93 ToolBarLayout *m_parent = nullptr;
94 QObject *m_action = nullptr;
95 QQuickItem *m_full = nullptr;
96 QQuickItem *m_icon = nullptr;
97 ToolBarDelegateIncubator *m_fullIncubator = nullptr;
98 ToolBarDelegateIncubator *m_iconIncubator = nullptr;
99
100 ToolBarLayout::DisplayHints m_displayHint = ToolBarLayout::NoPreference;
101 bool m_ready = false;
102 bool m_actionVisible = true;
103 bool m_fullVisible = false;
104 bool m_iconVisible = false;
105};
106
107} // namespace qml_material