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/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
33 Q_INVOKABLE bool hasIcon(const QJSValue& v) const;
34
35 Q_INVOKABLE static void closePopup(QObject* obj);
36
37 Q_INVOKABLE static QColor transparent(QColor in, float alpha) noexcept;
38 Q_INVOKABLE static QColor hoverColor(QColor in) noexcept;
39 Q_INVOKABLE static QColor pressColor(QColor in) noexcept;
40
41 Q_INVOKABLE static qreal devicePixelRatio(QQuickItem* in);
42
43 Q_INVOKABLE static CornersGroup listCorners(qint32 idx, qint32 count, qint32 radius) noexcept;
44 Q_INVOKABLE static CornersGroup tableCorners(qint32 row, qint32 column, qint32 rows,
45 qint32 columns, qint32 radius) noexcept;
46 Q_INVOKABLE static CornersGroup tableWithHeaderCorners(qint32 row, qint32 column, qint32 rows,
47 qint32 columns, qint32 radius) noexcept;
48
49 Q_INVOKABLE static CornersGroup cornerArray(QVariant in) noexcept;
50 Q_INVOKABLE static CornersGroup corners(qreal in) noexcept;
51 Q_INVOKABLE static CornersGroup corners(qreal, qreal) noexcept;
52 Q_INVOKABLE static CornersGroup corners(qreal tl, qreal tr, qreal bl, qreal br) noexcept;
53
54 QString type_str(const QJSValue&);
55
56 Q_INVOKABLE void print_parents(const QJSValue&);
57
58 Q_INVOKABLE static qreal lightness(QColor color) noexcept;
59
60 Q_INVOKABLE static token::Elevation tokenElevation() noexcept;
61 Q_INVOKABLE static token::Shape tokenShape() noexcept;
62 Q_INVOKABLE static token::State tokenState() noexcept;
63
64 Q_INVOKABLE QObject* createItem(const QJSValue& url_or_comp, const QVariantMap& props,
65 QObject* parent = nullptr);
66
67 Q_INVOKABLE QObject* showPopup(const QJSValue& url_or_comp, const QVariantMap& props,
68 QObject* parent = nullptr, bool open_and_destry = true);
69
70 Q_INVOKABLE static QString paramsString(const QVariantMap& props);
71 Q_INVOKABLE static void setCursor(QQuickItem* item, Qt::CursorShape shape);
72
73 Q_INVOKABLE static double clamp(double t, double low, double high);
74 Q_INVOKABLE static double teleportCurve(double t, double left, double right);
75
76 Q_INVOKABLE static void forceSetImplicitHeight(QQuickItem* item, qreal height);
77 Q_INVOKABLE static void forceSetImplicitWidth(QQuickItem* item, qreal width);
78
79 Q_INVOKABLE static void cellHoveredOn(QQuickItem* item, bool hovered, qint32 row,
80 qint32 column);
81 Q_INVOKABLE static QObject* getParent(QObject* obj);
82 Q_INVOKABLE static bool disconnectAll(QObject* obj, const QString&);
83
84private:
85 Q_SLOT void onPopupClosed();
86
87private:
88 usize m_tracked { 0 };
89};
90
91auto tryCreateComponent(const QVariant& val, QQmlComponent::CompilationMode useAsync,
92 const std::function<QQmlComponent*()>& createComponent) -> QQmlComponent*;
93} // namespace qml_material
94
95namespace qcm
96{
97auto qml_dyn_count() -> std::atomic<i32>&;
98auto createItem(QQmlEngine* engine, const QJSValue& url_or_comp, const QVariantMap& props,
99 QObject* parent) -> QObject*;
100
101} // namespace qcm
Definition Util.qml:5