QmlMaterial 0.1.0
Loading...
Searching...
No Matches
icon_spec.hpp
1#pragma once
2
3#include <QColor>
4#include <QFont>
5#include <QObject>
6#include <QPointer>
7#include <QProperty>
8#include <QUrl>
9#include <optional>
10#include <qqmlregistration.h>
11#include "qml_material/export.hpp"
12
13namespace qml_material
14{
15class QML_MATERIAL_API ActionIcon : public QObject {
16 Q_OBJECT
17 QML_ELEMENT
18 QML_UNCREATABLE("Owned by Action")
19 Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged FINAL)
20 Q_PROPERTY(QUrl source READ source WRITE setSource RESET resetSource NOTIFY sourceChanged FINAL)
21 Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged FINAL)
22 Q_PROPERTY(bool cache READ cache WRITE setCache RESET resetCache NOTIFY cacheChanged FINAL)
23 Q_PROPERTY(bool fill READ fill WRITE setFill RESET resetFill NOTIFY fillChanged FINAL)
24 Q_PROPERTY(int weight READ weight WRITE setWeight RESET resetWeight NOTIFY weightChanged FINAL)
25 Q_PROPERTY(int renderType READ renderType WRITE setRenderType RESET resetRenderType NOTIFY
26 renderTypeChanged FINAL)
27 Q_PROPERTY(QUrl resolvedSource READ resolvedSource NOTIFY sourceChanged FINAL)
28 Q_PROPERTY(bool empty READ isEmpty NOTIFY contentChanged BINDABLE bindableEmpty FINAL)
29 Q_PROPERTY(bool image READ isImage NOTIFY contentChanged FINAL)
30public:
31 explicit ActionIcon(QObject* parent = nullptr): QObject(parent) {}
32 QString name() const { return m_name; }
33 void setName(const QString& value);
34 void resetName();
35 Q_SIGNAL void nameChanged();
36 QUrl source() const { return m_source; }
37 void setSource(const QUrl& value);
38 void resetSource();
39 Q_SIGNAL void sourceChanged();
40 QColor color() const { return m_color; }
41 void setColor(const QColor& value);
42 void resetColor();
43 Q_SIGNAL void colorChanged();
44 bool cache() const { return m_cache; }
45 void setCache(bool value);
46 void resetCache();
47 Q_SIGNAL void cacheChanged();
48 bool fill() const { return m_fill; }
49 void setFill(bool value);
50 void resetFill();
51 Q_SIGNAL void fillChanged();
52 int weight() const { return m_weight; }
53 void setWeight(int value);
54 void resetWeight();
55 Q_SIGNAL void weightChanged();
56 int renderType() const { return m_renderType; }
57 void setRenderType(int value);
58 void resetRenderType();
59 Q_SIGNAL void renderTypeChanged();
60 QUrl resolvedSource() const;
61 bool isEmpty() const { return m_empty.value(); }
62 QBindable<bool> bindableEmpty() const { return QBindable<bool>(&m_empty); }
63 bool isImage() const { return ! m_source.isEmpty(); }
64 Q_SIGNAL void contentChanged();
65 Q_SIGNAL void changed();
66
67protected:
68 void setOverride(ActionIcon*);
69
70private:
71 void refresh();
72 const ActionIcon* contentOwner() const;
73 std::optional<QString> m_local_name;
74 std::optional<QUrl> m_local_source;
75 std::optional<QColor> m_local_color;
76 std::optional<bool> m_local_cache;
77 std::optional<bool> m_local_fill;
78 std::optional<int> m_local_weight;
79 std::optional<int> m_local_renderType;
80 QString m_name = QString();
81 QProperty<bool> m_empty { true };
82 QUrl m_source = QUrl();
83 QColor m_color = QColor(Qt::transparent);
84 bool m_cache = true;
85 bool m_fill = false;
86 int m_weight = QFont::Normal;
87 int m_renderType = 2;
88 QUrl m_resolved_source;
89 QPointer<ActionIcon> m_override;
90 QList<QMetaObject::Connection> m_connections;
91};
92
93class QML_MATERIAL_API IconSpec : public ActionIcon {
94 Q_OBJECT
95 QML_ELEMENT
96 Q_PROPERTY(int width READ width WRITE setWidth RESET resetWidth NOTIFY widthChanged FINAL)
97 Q_PROPERTY(int height READ height WRITE setHeight RESET resetHeight NOTIFY heightChanged FINAL)
98public:
99 explicit IconSpec(QObject* parent = nullptr): ActionIcon(parent) {}
100 void setActionIcon(ActionIcon* value) { setOverride(value); }
101 int width() const { return m_width.value_or(0); }
102 int height() const { return m_height.value_or(0); }
103 void setWidth(int);
104 void setHeight(int);
105 void resetWidth();
106 void resetHeight();
107 Q_SIGNAL void widthChanged();
108 Q_SIGNAL void heightChanged();
109
110private:
111 std::optional<int> m_width, m_height;
112};
113} // namespace qml_material