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 {
20public:
21 ToolBarDelegateIncubator(QQmlComponent* component, QQmlContext* context);
22
23 void setStateCallback(std::function<void(QQuickItem*)> callback);
24 void setCompletedCallback(std::function<void(ToolBarDelegateIncubator*)> callback);
25
26 void create();
27
28 bool isFinished();
29
30private:
31 void setInitialState(QObject* object) override;
32 void statusChanged(QQmlIncubator::Status status) override;
33
34 QQmlComponent* m_component;
35 QQmlContext* m_context;
36 std::function<void(QQuickItem*)> m_stateCallback;
37 std::function<void(ToolBarDelegateIncubator*)> m_completedCallback;
38 bool m_finished = false;
39};
40
41class ToolBarLayoutDelegate : public QObject {
42 Q_OBJECT
43public:
44 ToolBarLayoutDelegate(ToolBarLayout* parent);
45 ~ToolBarLayoutDelegate() override;
46
47 Action* action() const;
48 void setAction(Action* action);
49 void createItems(QQmlComponent* fullComponent, QQmlComponent* iconComponent,
50 std::function<void(QQuickItem*)> callback);
51
52 bool isReady() const;
53 bool isActionVisible() const;
54 bool isHidden() const;
55 bool isIconOnly() const;
56 bool isKeepVisible() const;
57
58 bool isVisible() const;
59
60 void hide();
61 void showIcon();
62 void showFull();
63 void show();
64
65 void setPosition(qreal x, qreal y);
66 void setHeight(qreal height);
67 void resetHeight();
68
69 qreal width() const;
70 qreal height() const;
71 qreal implicitWidth() const;
72 qreal implicitHeight() const;
73 qreal maxHeight() const;
74 qreal iconWidth() const;
75 qreal fullWidth() const;
76
77private:
78 Q_SLOT void actionVisibleChanged();
79 Q_SLOT void displayHintChanged();
80 inline void ensureItemVisibility() {
81 if (m_full) {
82 m_full->setVisible(m_fullVisible);
83 }
84 if (m_icon) {
85 m_icon->setVisible(m_iconVisible);
86 }
87 }
88 void cleanupIncubators();
89 void triggerRelayout();
90
91 ToolBarLayout* m_parent = nullptr;
92 Action* m_action = nullptr;
93 QQuickItem* m_full = nullptr;
94 QQuickItem* m_icon = nullptr;
95 ToolBarDelegateIncubator* m_fullIncubator = nullptr;
96 ToolBarDelegateIncubator* m_iconIncubator = nullptr;
97
98 ToolBarLayout::DisplayHints m_displayHint = ToolBarLayout::NoPreference;
99 bool m_ready = false;
100 bool m_actionVisible = true;
101 bool m_fullVisible = false;
102 bool m_iconVisible = false;
103};
104
105} // namespace qml_material