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/core/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
305struct FocusRing {
306 Q_GADGET
307 QML_ANONYMOUS
308 Q_PROPERTY(qreal outer_stroke_width MEMBER outer_stroke_width CONSTANT FINAL)
309 Q_PROPERTY(qreal inner_stroke_width MEMBER inner_stroke_width CONSTANT FINAL)
310 Q_PROPERTY(qreal inner_stroke_inset MEMBER inner_stroke_inset CONSTANT FINAL)
311 Q_PROPERTY(qreal outer_offset MEMBER outer_offset CONSTANT FINAL)
312public:
313 qreal outer_stroke_width { 2 };
314 qreal inner_stroke_width { 3 };
315 qreal inner_stroke_inset { 1 };
316 qreal outer_offset { 2 };
317};
318
325struct State {
326 Q_GADGET
327 QML_ANONYMOUS
329 Q_PROPERTY(qml_material::token::StateItem hover MEMBER hover CONSTANT FINAL)
331 Q_PROPERTY(qml_material::token::StateItem pressed MEMBER pressed CONSTANT FINAL)
333 Q_PROPERTY(qml_material::token::StateItem focus MEMBER focus CONSTANT FINAL)
335 Q_PROPERTY(qml_material::token::StateItem dragged MEMBER dragged CONSTANT FINAL)
336
338 Q_PROPERTY(qml_material::token::FocusRing focus_ring MEMBER focus_ring CONSTANT FINAL)
339
341 Q_PROPERTY(double disabled_content MEMBER disabled_content CONSTANT FINAL)
343 Q_PROPERTY(double disabled_container MEMBER disabled_container CONSTANT FINAL)
344
345public:
346 StateItem hover { 0.08 };
347 StateItem pressed { 0.1 };
348 StateItem focus { 0.1 };
349 StateItem dragged { 0.16 };
350
351 FocusRing focus_ring;
352
353 double disabled_content { 0.38 };
354 double disabled_container { 0.12 };
355};
356
363class Flick : public QObject {
364 Q_OBJECT
365 QML_ANONYMOUS
367 Q_PROPERTY(qint32 pressDelay READ pressDelay NOTIFY pressDelayChanged FINAL)
369 Q_PROPERTY(
370 double flickDeceleration READ flickDeceleration NOTIFY flickDecelerationChanged FINAL)
372 Q_PROPERTY(double maximumFlickVelocity READ maximumFlickVelocity NOTIFY
373 maximumFlickVelocityChanged FINAL)
374public:
375 Flick(QObject* parent = nullptr);
376 ~Flick();
377 auto pressDelay() const -> qint32;
378 auto flickDeceleration() const -> double;
379 auto maximumFlickVelocity() const -> double;
380
381 Q_SIGNAL void pressDelayChanged();
382 Q_SIGNAL void flickDecelerationChanged();
383 Q_SIGNAL void maximumFlickVelocityChanged();
384
385private:
386 qint32 m_press_delay;
387 double m_flick_deceleration;
388 double m_maximum_flickVelocity;
389};
390
397struct Spacing {
398 Q_GADGET
399 QML_ANONYMOUS
401 Q_PROPERTY(qint32 none MEMBER none CONSTANT FINAL)
403 Q_PROPERTY(qint32 extra_small MEMBER extra_small CONSTANT FINAL)
405 Q_PROPERTY(qint32 small MEMBER small CONSTANT FINAL)
407 Q_PROPERTY(qint32 medium_small MEMBER medium_small CONSTANT FINAL)
409 Q_PROPERTY(qint32 medium MEMBER medium CONSTANT FINAL)
411 Q_PROPERTY(qint32 large_medium MEMBER large_medium CONSTANT FINAL)
413 Q_PROPERTY(qint32 large MEMBER large CONSTANT FINAL)
415 Q_PROPERTY(qint32 extra_large MEMBER extra_large CONSTANT FINAL)
416public:
417 i32 none { 0 };
418 i32 extra_small { 4 };
419 i32 small { 8 };
420 i32 medium_small { 12 };
421 i32 medium { 16 };
422 i32 large_medium { 24 };
423 i32 large { 32 };
424 i32 extra_large { 48 };
425};
426
433class Token : public QObject {
434 Q_OBJECT
435 Q_PROPERTY(QQmlListProperty<QObject> datas READ datas FINAL)
436 Q_CLASSINFO("DefaultProperty", "datas")
437 QML_NAMED_ELEMENT(TokenImpl)
438
439 Q_PROPERTY(QString version READ version CONSTANT FINAL)
440 Q_PROPERTY(QString iconFontUrl READ icon_font_url CONSTANT FINAL)
441 Q_PROPERTY(QString iconFill0FontUrl READ icon_fill_0_font_url CONSTANT FINAL)
442 Q_PROPERTY(QString iconFill1FontUrl READ icon_fill_1_font_url CONSTANT FINAL)
443
444
445 Q_PROPERTY(qml_material::token::TypeScale* typescale READ typescale CONSTANT FINAL)
447 Q_PROPERTY(qml_material::token::IconToken* icon READ icon CONSTANT FINAL)
449 Q_PROPERTY(qml_material::token::Flick* flick READ flick CONSTANT FINAL)
451 Q_PROPERTY(qml_material::token::Elevation elevation READ elevation CONSTANT FINAL)
453 Q_PROPERTY(qml_material::token::Duration duration READ duration CONSTANT FINAL)
455 Q_PROPERTY(qml_material::token::Easing easing READ easing CONSTANT FINAL)
457 Q_PROPERTY(qml_material::token::State state READ state CONSTANT FINAL)
459 Q_PROPERTY(qml_material::token::Shape shape READ shape CONSTANT FINAL)
461 Q_PROPERTY(qml_material::token::WindowClass window_class READ window_class CONSTANT FINAL)
463 Q_PROPERTY(qml_material::token::Spacing spacing READ spacing CONSTANT FINAL)
465 Q_PROPERTY(qml_material::token::SplitButtonSize split_button READ split_button CONSTANT FINAL)
467 Q_PROPERTY(qml_material::token::ButtonSize button READ button CONSTANT FINAL)
469 Q_PROPERTY(qml_material::token::SegmentedButtonSize segmented_button READ segmented_button CONSTANT FINAL)
471 Q_PROPERTY(qml_material::token::IconButtonSize icon_button READ icon_button CONSTANT FINAL)
473 Q_PROPERTY(qml_material::token::BadgeSize badge READ badge CONSTANT FINAL)
474 public:
475 Token(QObject* = nullptr);
476 ~Token();
477
478 auto version() const -> QString;
479 auto icon_font_url() const -> QString;
480 auto icon_fill_0_font_url() const -> QString;
481 auto icon_fill_1_font_url() const -> QString;
482
483 auto typescale() const -> TypeScale*;
484 auto icon() const -> IconToken*;
485 auto flick() const -> Flick*;
486 auto elevation() const -> const Elevation&;
487 auto state() const -> const State&;
488 auto shape() const -> const Shape&;
489 auto window_class() const -> const WindowClass&;
490 auto duration() const -> const Duration&;
491 auto easing() const -> const Easing&;
492 auto spacing() const -> const Spacing&;
493 auto split_button() const -> const SplitButtonSize&;
494 auto button() const -> const ButtonSize&;
495 auto segmented_button() const -> const SegmentedButtonSize&;
496 auto icon_button() const -> const IconButtonSize&;
497 auto badge() const -> const BadgeSize&;
498
499 auto datas() -> QQmlListProperty<QObject>;
500
501 Q_INVOKABLE double cal_curve_scale(double dpr) const;
502
503 private:
504 TypeScale* m_typescale;
505 IconToken* m_icon;
506 Flick* m_flick;
507 Duration m_duration;
508 Easing m_easing;
509 Elevation m_elevation;
510 State m_state;
511 Shape m_shape;
512 WindowClass m_win_class;
513 Spacing m_spacing;
514 SplitButtonSize m_split_button;
515 ButtonSize m_button;
516 SegmentedButtonSize m_segmented_button;
517 IconButtonSize m_icon_button;
518 BadgeSize m_badge;
519
520 QList<QObject*> m_datas;
521 };
522
523 } // namespace qml_material::token
Enum.
Definition enum.hpp:13
WindowClassType
Definition enum.hpp:135
Handles flicking behavior and physics parameters.
Definition token.hpp:363
IconToken, full codes.
Definition icon.hpp:15
Main token container for Material Design system.
Definition token.hpp:433
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
Geometry tokens for the M3 keyboard focus ring.
Definition token.hpp:305
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:397
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:325
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