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 ActionIcon* overrideIcon() const { return m_override; }
69 void setOverride(ActionIcon*);
70
71private:
72 void refresh();
73 const ActionIcon* contentOwner() const;
74 std::optional<QString> m_local_name;
75 std::optional<QUrl> m_local_source;
76 std::optional<QColor> m_local_color;
77 std::optional<bool> m_local_cache;
78 std::optional<bool> m_local_fill;
79 std::optional<int> m_local_weight;
80 std::optional<int> m_local_renderType;
81 QString m_name = QString();
82 QProperty<bool> m_empty { true };
83 QUrl m_source = QUrl();
84 QColor m_color = QColor(Qt::transparent);
85 bool m_cache = true;
86 bool m_fill = false;
87 int m_weight = QFont::Normal;
88 int m_renderType = 2;
89 QUrl m_resolved_source;
90 QPointer<ActionIcon> m_override;
91 QList<QMetaObject::Connection> m_connections;
92};
93
94class QML_MATERIAL_API IconSpec : public ActionIcon {
95 Q_OBJECT
96 QML_ELEMENT
97 Q_PROPERTY(qml_material::ActionIcon* actionIcon READ actionIcon WRITE setActionIcon NOTIFY
98 changed FINAL)
99 Q_PROPERTY(int width READ width WRITE setWidth RESET resetWidth NOTIFY widthChanged FINAL)
100 Q_PROPERTY(int height READ height WRITE setHeight RESET resetHeight NOTIFY heightChanged FINAL)
101public:
102 explicit IconSpec(QObject* parent = nullptr): ActionIcon(parent) {}
103 ActionIcon* actionIcon() const { return overrideIcon(); }
104 void setActionIcon(ActionIcon* value) { setOverride(value); }
105 int width() const { return m_width.value_or(0); }
106 int height() const { return m_height.value_or(0); }
107 void setWidth(int);
108 void setHeight(int);
109 void resetWidth();
110 void resetHeight();
111 Q_SIGNAL void widthChanged();
112 Q_SIGNAL void heightChanged();
113
114private:
115 std::optional<int> m_width, m_height;
116};
117} // namespace qml_material