QmlMaterial 0.1.0
Loading...
Searching...
No Matches
qml_util.hpp
1#pragma once
2#include <QObject>
3#include <QQmlEngine>
4#include <QColor>
5#include <QQuickItem>
6#include <QPointer>
7#include <QQuickWindow>
8
9#include "qml_material/util/corner.hpp"
10#include "qml_material/core/enum.hpp"
11#include "qml_material/token/token.hpp"
12#include "qml_material/core.hpp"
13
14namespace qml_material
15{
16
17class Util : public QObject {
18 Q_OBJECT
19 QML_NAMED_ELEMENT(UtilCpp)
20public:
21 Util(QObject* parent = nullptr);
22 ~Util();
23
24 enum Track
25 {
26 TrackCreate = 0,
27 TrackDelete
28 };
29 Q_ENUMS(Track)
30
31 Q_INVOKABLE void track(QVariant, Track);
32
37 Q_INVOKABLE void openUrlExternally(const QString& url);
38 Q_INVOKABLE void openFolderExternally(const QString& url);
39
40 Q_INVOKABLE bool hasIcon(const QJSValue& v) const;
41
42 Q_INVOKABLE static void closePopup(QObject* obj);
43
44 Q_INVOKABLE static QColor transparent(QColor in, float alpha) noexcept;
45 Q_INVOKABLE static QColor hoverColor(QColor in) noexcept;
46 Q_INVOKABLE static QColor pressColor(QColor in) noexcept;
47
48 Q_INVOKABLE static qreal devicePixelRatio(QQuickItem* in);
49
50 Q_INVOKABLE static CornersGroup listCorners(qint32 idx, qint32 count, qint32 radius) noexcept;
51 Q_INVOKABLE static CornersGroup tableCorners(qint32 row, qint32 column, qint32 rows,
52 qint32 columns, qint32 radius) noexcept;
53 Q_INVOKABLE static CornersGroup tableWithHeaderCorners(qint32 row, qint32 column, qint32 rows,
54 qint32 columns, qint32 radius) noexcept;
55
56 Q_INVOKABLE static CornersGroup cornerArray(QVariant in) noexcept;
57 Q_INVOKABLE static CornersGroup corners(qreal in) noexcept;
58 Q_INVOKABLE static CornersGroup corners(qreal, qreal) noexcept;
59 Q_INVOKABLE static CornersGroup corners(qreal tl, qreal tr, qreal bl, qreal br) noexcept;
60
61 QString type_str(const QJSValue&);
62
63 Q_INVOKABLE void print_parents(const QJSValue&);
64
65 Q_INVOKABLE static qreal lightness(QColor color) noexcept;
66
67 Q_INVOKABLE static token::Elevation tokenElevation() noexcept;
68 Q_INVOKABLE static token::Shape tokenShape() noexcept;
69 Q_INVOKABLE static token::State tokenState() noexcept;
70
71 Q_INVOKABLE QObject* createItem(const QJSValue& url_or_comp, const QVariantMap& props,
72 QObject* parent = nullptr);
73
74 Q_INVOKABLE QObject* showPopup(const QJSValue& url_or_comp, const QVariantMap& props,
75 QObject* parent = nullptr, bool open_and_destry = true);
76
77 Q_INVOKABLE static QString paramsString(const QVariantMap& props);
78 Q_INVOKABLE static void setCursor(QQuickItem* item, Qt::CursorShape shape);
79
80 Q_INVOKABLE static double clamp(double t, double low, double high);
81 Q_INVOKABLE static double teleportCurve(double t, double left, double right);
82
83 // Cubic Bezier ease — given a normalized fraction `t` in [0,1] and a curve
84 // (0,0) → (p1x,p1y) → (p2x,p2y) → (1,1), returns the eased y. Matches
85 // Android's pathInterpolator.
86 Q_INVOKABLE static double bezierY(double t, double p1x, double p1y, double p2x,
87 double p2y) noexcept;
88 // Convenience for the M3 indeterminate animation drivers: clamp
89 // `(playtime - delay) / duration` to [0,1] then ease via bezierY.
90 Q_INVOKABLE static double segFrac(double playtime, double delay, double duration, double p1x,
91 double p1y, double p2x, double p2y) noexcept;
92
93 Q_INVOKABLE static QString stateText(bool enabled, bool pressed, bool hovered,
94 bool focused) noexcept;
95
96 Q_INVOKABLE static void forceSetImplicitHeight(QQuickItem* item, qreal height);
97 Q_INVOKABLE static void forceSetImplicitWidth(QQuickItem* item, qreal width);
98
99 Q_INVOKABLE static void cellHoveredOn(QQuickItem* item, bool hovered, qint32 row,
100 qint32 column);
101 Q_INVOKABLE static QObject* getParent(QObject* obj);
102 Q_INVOKABLE static bool disconnectAll(QObject* obj, const QString&);
103
104 Q_INVOKABLE static quint32 poolObjectCount() noexcept;
105 Q_INVOKABLE static qint32 i32Max() noexcept;
106private:
107 Q_SLOT void onPopupClosed();
108
109private:
110 usize m_tracked { 0 };
111};
112
113auto tryCreateComponent(const QVariant& val, QQmlComponent::CompilationMode useAsync,
114 const std::function<QQmlComponent*()>& createComponent) -> QQmlComponent*;
115
119void sysOpenUrl(const QString& url);
120void sysOpenFolder(const QString& url);
121} // namespace qml_material
122
123namespace qcm
124{
125auto qml_dyn_count() -> std::atomic<i32>&;
126auto createItem(QQmlEngine* engine, const QJSValue& url_or_comp, const QVariantMap& props,
127 QObject* parent) -> QObject*;
128
129} // namespace qcm
Definition Util.qml:5