QmlMaterial 0.1.0
Loading...
Searching...
No Matches
token.hpp
1#pragma once
2
3#include <array>
4#include <QtCore/QEasingCurve>
5#include <QtGui/QFont>
6#include <QtQml/QQmlEngine>
7#include <QtQuick/QQuickWindow>
8
9#include "qml_material/core.hpp"
10#include "qml_material/token/type_scale.hpp"
11#include "qml_material/token/split_button.hpp"
12#include "qml_material/token/button.hpp"
13#include "qml_material/token/segmented_button.hpp"
14#include "qml_material/token/badge.hpp"
15#include "qml_material/anim/interpolator.hpp"
16#include "qml_material/enum.hpp"
17Q_MOC_INCLUDE("qml_material/token/icon.hpp")
18
19namespace qml_material::token
20{
21
22class IconToken;
23auto create_icon_token(QObject* parent) -> IconToken*;
24
32 Q_GADGET
33 QML_ANONYMOUS
34
36 Q_PROPERTY(qint32 min_width MEMBER min_width CONSTANT FINAL)
38 Q_PROPERTY(qint32 max_width MEMBER max_width CONSTANT FINAL)
40 Q_PROPERTY(qml_material::Enum::WindowClassType type MEMBER type CONSTANT FINAL)
41
42public:
43 Q_INVOKABLE bool contains(i32 w) const { return w >= min_width && w < max_width; }
44 i32 min_width { 0 };
45 i32 max_width { std::numeric_limits<i32>::max() };
46 Enum::WindowClassType type { Enum::WindowClassType::WindowClassCompact };
47};
48
56 Q_GADGET
57 QML_ANONYMOUS
58
60 Q_PROPERTY(qml_material::token::WindowClassItem compact MEMBER compact CONSTANT FINAL)
62 Q_PROPERTY(qml_material::token::WindowClassItem medium MEMBER medium CONSTANT FINAL)
64 Q_PROPERTY(qml_material::token::WindowClassItem expanded MEMBER expanded CONSTANT FINAL)
66 Q_PROPERTY(qml_material::token::WindowClassItem large MEMBER large CONSTANT FINAL)
68 Q_PROPERTY(qml_material::token::WindowClassItem extra_large MEMBER extra_large CONSTANT FINAL)
69
70public:
71 using Type = Enum::WindowClassType;
72
73 Q_INVOKABLE WindowClassItem select(i32 w) const {
74 std::array wcs { &compact, &medium, &expanded, &large, &extra_large };
75 for (auto& el : wcs) {
76 if (el->contains(w)) return *el;
77 }
78 return compact;
79 }
80 Q_INVOKABLE Enum::WindowClassType select_type(i32 w) const {
81 std::array wcs { &compact, &medium, &expanded, &large, &extra_large };
82 for (auto& el : wcs) {
83 if (el->contains(w)) return el->type;
84 }
85 return compact.type;
86 }
87 WindowClassItem compact { 0, 600, Type::WindowClassCompact };
88 WindowClassItem medium { 600, 840, Type::WindowClassMedium };
89 WindowClassItem expanded { 840, 1200, Type::WindowClassExpanded };
90 WindowClassItem large { 1200, 1600, Type::WindowClassLarge };
91 WindowClassItem extra_large { 1600,
92 std::numeric_limits<i32>::max(),
93 Type::WindowClassExtraLarge };
94};
95
102struct Elevation {
103 Q_GADGET
104 QML_ANONYMOUS
105
107 Q_PROPERTY(qint32 level0 MEMBER level0 CONSTANT FINAL)
109 Q_PROPERTY(qint32 level1 MEMBER level1 CONSTANT FINAL)
111 Q_PROPERTY(qint32 level2 MEMBER level2 CONSTANT FINAL)
113 Q_PROPERTY(qint32 level3 MEMBER level3 CONSTANT FINAL)
115 Q_PROPERTY(qint32 level4 MEMBER level4 CONSTANT FINAL)
117 Q_PROPERTY(qint32 level5 MEMBER level5 CONSTANT FINAL)
118public:
119 i32 level0 { 0 };
120 i32 level1 { 1 };
121 i32 level2 { 3 };
122 i32 level3 { 6 };
123 i32 level4 { 8 };
124 i32 level5 { 12 };
125};
126
131struct Easing {
132 Q_GADGET
133 QML_ANONYMOUS
135 Q_PROPERTY(QEasingCurve emphasized READ emphasized CONSTANT FINAL)
137 Q_PROPERTY(QEasingCurve emphasized_accelerate READ emphasized_accelerate CONSTANT FINAL)
139 Q_PROPERTY(QEasingCurve emphasized_decelerate READ emphasized_decelerate CONSTANT FINAL)
141 Q_PROPERTY(QEasingCurve standard READ standard CONSTANT FINAL)
143 Q_PROPERTY(QEasingCurve standard_accelerate READ standard_accelerate CONSTANT FINAL)
145 Q_PROPERTY(QEasingCurve standard_decelerate READ standard_decelerate CONSTANT FINAL)
147 Q_PROPERTY(QEasingCurve legacy READ legacy CONSTANT FINAL)
149 Q_PROPERTY(QEasingCurve legacy_accelerate READ legacy_accelerate CONSTANT FINAL)
151 Q_PROPERTY(QEasingCurve legacy_decelerate READ legacy_decelerate CONSTANT FINAL)
153 Q_PROPERTY(QEasingCurve linear READ linear CONSTANT FINAL)
154
155public:
156 auto emphasized() const noexcept -> QEasingCurve { return anim::emphasized(); }
157 auto emphasized_accelerate() const noexcept -> QEasingCurve {
158 return anim::emphasized_accelerate();
159 }
160 auto emphasized_decelerate() const noexcept -> QEasingCurve {
161 return anim::emphasized_decelerate();
162 }
163 auto standard() const noexcept -> QEasingCurve { return anim::standard(); }
164 auto standard_accelerate() const noexcept -> QEasingCurve {
165 return anim::standard_accelerate();
166 }
167 auto standard_decelerate() const noexcept -> QEasingCurve {
168 return anim::standard_decelerate();
169 }
170 auto legacy() const noexcept -> QEasingCurve { return anim::legacy(); }
171 auto legacy_accelerate() const noexcept -> QEasingCurve { return anim::legacy_accelerate(); }
172 auto legacy_decelerate() const noexcept -> QEasingCurve { return anim::legacy_decelerate(); }
173 auto linear() const noexcept -> QEasingCurve { return anim::linear(); }
174};
175
180struct Duration {
181 Q_GADGET
182 QML_ANONYMOUS
184 Q_PROPERTY(qreal short1 MEMBER short1 CONSTANT FINAL)
186 Q_PROPERTY(qreal short2 MEMBER short2 CONSTANT FINAL)
188 Q_PROPERTY(qreal short3 MEMBER short3 CONSTANT FINAL)
190 Q_PROPERTY(qreal short4 MEMBER short4 CONSTANT FINAL)
192 Q_PROPERTY(qreal medium1 MEMBER medium1 CONSTANT FINAL)
194 Q_PROPERTY(qreal medium2 MEMBER medium2 CONSTANT FINAL)
196 Q_PROPERTY(qreal medium3 MEMBER medium3 CONSTANT FINAL)
198 Q_PROPERTY(qreal medium4 MEMBER medium4 CONSTANT FINAL)
200 Q_PROPERTY(qreal long1 MEMBER long1 CONSTANT FINAL)
202 Q_PROPERTY(qreal long2 MEMBER long2 CONSTANT FINAL)
204 Q_PROPERTY(qreal long3 MEMBER long3 CONSTANT FINAL)
206 Q_PROPERTY(qreal long4 MEMBER long4 CONSTANT FINAL)
208 Q_PROPERTY(qreal extra_long1 MEMBER extra_long1 CONSTANT FINAL)
210 Q_PROPERTY(qreal extra_long2 MEMBER extra_long2 CONSTANT FINAL)
212 Q_PROPERTY(qreal extra_long3 MEMBER extra_long3 CONSTANT FINAL)
214 Q_PROPERTY(qreal extra_long4 MEMBER extra_long4 CONSTANT FINAL)
215
216public:
217 qreal short1 { 50 };
218 qreal short2 { 100 };
219 qreal short3 { 150 };
220 qreal short4 { 200 };
221 qreal medium1 { 250 };
222 qreal medium2 { 300 };
223 qreal medium3 { 350 };
224 qreal medium4 { 400 };
225 qreal long1 { 450 };
226 qreal long2 { 500 };
227 qreal long3 { 550 };
228 qreal long4 { 600 };
229 qreal extra_long1 { 700 };
230 qreal extra_long2 { 800 };
231 qreal extra_long3 { 900 };
232 qreal extra_long4 { 1000 };
233};
234
242 Q_GADGET
243 QML_ANONYMOUS
245 Q_PROPERTY(qint32 none MEMBER none CONSTANT FINAL)
247 Q_PROPERTY(qint32 extra_small MEMBER extra_small CONSTANT FINAL)
249 Q_PROPERTY(qint32 small MEMBER small CONSTANT FINAL)
251 Q_PROPERTY(qint32 medium MEMBER medium CONSTANT FINAL)
253 Q_PROPERTY(qint32 large MEMBER large CONSTANT FINAL)
255 Q_PROPERTY(qint32 extra_large MEMBER extra_large CONSTANT FINAL)
257 Q_PROPERTY(qint32 full MEMBER full CONSTANT FINAL)
258public:
260 i32 none { 0 };
261 i32 extra_small { 4 };
262 i32 small { 8 };
263 i32 medium { 12 };
264 i32 large { 16 };
265 i32 extra_large { 28 };
266 i32 full { 100 };
267};
268
274struct Shape {
275 Q_GADGET
276 QML_ANONYMOUS
277 Q_PROPERTY(qml_material::token::ShapeCorner corner MEMBER corner CONSTANT FINAL)
278public:
279 ShapeCorner corner;
280};
281
288struct StateItem {
289 Q_GADGET
290 QML_ANONYMOUS
292 Q_PROPERTY(double state_layer_opacity MEMBER state_layer_opacity CONSTANT FINAL)
293public:
294 double state_layer_opacity;
295};
296
303struct State {
304 Q_GADGET
305 QML_ANONYMOUS
307 Q_PROPERTY(qml_material::token::StateItem hover MEMBER hover CONSTANT FINAL)
309 Q_PROPERTY(qml_material::token::StateItem pressed MEMBER pressed CONSTANT FINAL)
311 Q_PROPERTY(qml_material::token::StateItem focus MEMBER focus CONSTANT FINAL)
313 Q_PROPERTY(qml_material::token::StateItem dragged MEMBER dragged CONSTANT FINAL)
314
316 Q_PROPERTY(double disabled_content MEMBER disabled_content CONSTANT FINAL)
318 Q_PROPERTY(double disabled_container MEMBER disabled_container CONSTANT FINAL)
319
320public:
321 StateItem hover { 0.08 };
322 StateItem pressed { 0.1 };
323 StateItem focus { 0.1 };
324 StateItem dragged { 0.16 };
325
326 double disabled_content { 0.38 };
327 double disabled_container { 0.12 };
328};
329
336class Flick : public QObject {
337 Q_OBJECT
338 QML_ANONYMOUS
340 Q_PROPERTY(qint32 pressDelay READ pressDelay NOTIFY pressDelayChanged FINAL)
342 Q_PROPERTY(
343 double flickDeceleration READ flickDeceleration NOTIFY flickDecelerationChanged FINAL)
345 Q_PROPERTY(double maximumFlickVelocity READ maximumFlickVelocity NOTIFY
346 maximumFlickVelocityChanged FINAL)
347public:
348 Flick(QObject* parent = nullptr);
349 ~Flick();
350 auto pressDelay() const -> qint32;
351 auto flickDeceleration() const -> double;
352 auto maximumFlickVelocity() const -> double;
353
354 Q_SIGNAL void pressDelayChanged();
355 Q_SIGNAL void flickDecelerationChanged();
356 Q_SIGNAL void maximumFlickVelocityChanged();
357
358private:
359 qint32 m_press_delay;
360 double m_flick_deceleration;
361 double m_maximum_flickVelocity;
362};
363
370struct Spacing {
371 Q_GADGET
372 QML_ANONYMOUS
374 Q_PROPERTY(qint32 none MEMBER none CONSTANT FINAL)
376 Q_PROPERTY(qint32 extra_small MEMBER extra_small CONSTANT FINAL)
378 Q_PROPERTY(qint32 small MEMBER small CONSTANT FINAL)
380 Q_PROPERTY(qint32 medium_small MEMBER medium_small CONSTANT FINAL)
382 Q_PROPERTY(qint32 medium MEMBER medium CONSTANT FINAL)
384 Q_PROPERTY(qint32 large_medium MEMBER large_medium CONSTANT FINAL)
386 Q_PROPERTY(qint32 large MEMBER large CONSTANT FINAL)
388 Q_PROPERTY(qint32 extra_large MEMBER extra_large CONSTANT FINAL)
389public:
390 i32 none { 0 };
391 i32 extra_small { 4 };
392 i32 small { 8 };
393 i32 medium_small { 12 };
394 i32 medium { 16 };
395 i32 large_medium { 24 };
396 i32 large { 32 };
397 i32 extra_large { 48 };
398};
399
406class Token : public QObject {
407 Q_OBJECT
408 Q_PROPERTY(QQmlListProperty<QObject> datas READ datas FINAL)
409 Q_CLASSINFO("DefaultProperty", "datas")
410 QML_NAMED_ELEMENT(TokenImpl)
411
412 Q_PROPERTY(QString version READ version CONSTANT FINAL)
413 Q_PROPERTY(QString iconFontUrl READ icon_font_url CONSTANT FINAL)
414 Q_PROPERTY(QString iconFill0FontUrl READ icon_fill_0_font_url CONSTANT FINAL)
415 Q_PROPERTY(QString iconFill1FontUrl READ icon_fill_1_font_url CONSTANT FINAL)
416
417
418 Q_PROPERTY(qml_material::token::TypeScale* typescale READ typescale CONSTANT FINAL)
420 Q_PROPERTY(qml_material::token::IconToken* icon READ icon CONSTANT FINAL)
422 Q_PROPERTY(qml_material::token::Flick* flick READ flick CONSTANT FINAL)
424 Q_PROPERTY(qml_material::token::Elevation elevation READ elevation CONSTANT FINAL)
426 Q_PROPERTY(qml_material::token::Duration duration READ duration CONSTANT FINAL)
428 Q_PROPERTY(qml_material::token::Easing easing READ easing CONSTANT FINAL)
430 Q_PROPERTY(qml_material::token::State state READ state CONSTANT FINAL)
432 Q_PROPERTY(qml_material::token::Shape shape READ shape CONSTANT FINAL)
434 Q_PROPERTY(qml_material::token::WindowClass window_class READ window_class CONSTANT FINAL)
436 Q_PROPERTY(qml_material::token::Spacing spacing READ spacing CONSTANT FINAL)
438 Q_PROPERTY(qml_material::token::SplitButtonSize split_button READ split_button CONSTANT FINAL)
440 Q_PROPERTY(qml_material::token::ButtonSize button READ button CONSTANT FINAL)
442 Q_PROPERTY(qml_material::token::SegmentedButtonSize segmented_button READ segmented_button CONSTANT FINAL)
444 Q_PROPERTY(qml_material::token::IconButtonSize icon_button READ icon_button CONSTANT FINAL)
446 Q_PROPERTY(qml_material::token::BadgeSize badge READ badge CONSTANT FINAL)
447 public:
448 Token(QObject* = nullptr);
449 ~Token();
450
451 auto version() const -> QString;
452 auto icon_font_url() const -> QString;
453 auto icon_fill_0_font_url() const -> QString;
454 auto icon_fill_1_font_url() const -> QString;
455
456 auto typescale() const -> TypeScale*;
457 auto icon() const -> IconToken*;
458 auto flick() const -> Flick*;
459 auto elevation() const -> const Elevation&;
460 auto state() const -> const State&;
461 auto shape() const -> const Shape&;
462 auto window_class() const -> const WindowClass&;
463 auto duration() const -> const Duration&;
464 auto easing() const -> const Easing&;
465 auto spacing() const -> const Spacing&;
466 auto split_button() const -> const SplitButtonSize&;
467 auto button() const -> const ButtonSize&;
468 auto segmented_button() const -> const SegmentedButtonSize&;
469 auto icon_button() const -> const IconButtonSize&;
470 auto badge() const -> const BadgeSize&;
471
472 auto datas() -> QQmlListProperty<QObject>;
473
474 Q_INVOKABLE double cal_curve_scale(double dpr) const;
475
476 private:
477 TypeScale* m_typescale;
478 IconToken* m_icon;
479 Flick* m_flick;
480 Duration m_duration;
481 Easing m_easing;
482 Elevation m_elevation;
483 State m_state;
484 Shape m_shape;
485 WindowClass m_win_class;
486 Spacing m_spacing;
487 SplitButtonSize m_split_button;
488 ButtonSize m_button;
489 SegmentedButtonSize m_segmented_button;
490 IconButtonSize m_icon_button;
491 BadgeSize m_badge;
492
493 QList<QObject*> m_datas;
494 };
495
496 } // namespace qml_material::token
Enum.
Definition enum.hpp:13
WindowClassType
Definition enum.hpp:135
Handles flicking behavior and physics parameters.
Definition token.hpp:336
IconToken, full codes.
Definition icon.hpp:15
Main token container for Material Design system.
Definition token.hpp:406
TypeScale.
Definition type_scale.hpp:64
Collection of button size tokens for different size classes.
Definition button.hpp:45
Motion duration.
Definition token.hpp:180
Motion easing.
Definition token.hpp:131
Defines elevation levels for Material Design shadows.
Definition token.hpp:102
Collection of icon button size tokens for different size classes.
Definition button.hpp:144
Collection of segmented button size tokens for different size classes.
Definition segmented_button.hpp:45
Defines corner radius values for shape styling.
Definition token.hpp:241
Container for shape-related styling properties.
Definition token.hpp:274
Defines standard spacing values.
Definition token.hpp:370
Collection of split button size tokens for different size classes.
Definition split_button.hpp:60
Defines opacity values for different UI states.
Definition token.hpp:288
Manages UI element state appearances.
Definition token.hpp:303
Represents a window class category with size constraints.
Definition token.hpp:31
qml_material::Enum::WindowClassType type
Type classification of the window size (compact, medium, expanded etc.)
Definition token.hpp:40
Window classification system based on width ranges.
Definition token.hpp:55