presentation/DesignTokens.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QObject> | ||
| 4 | #include <QVariantMap> | ||
| 5 | |||
| 6 | #include "SystemMotionPreference.h" | ||
| 7 | |||
| 8 | class DesignTokens final : public QObject { | ||
| 9 | Q_OBJECT | ||
| 10 | Q_PROPERTY(QVariantMap palette READ palette NOTIFY changed) | ||
| 11 | Q_PROPERTY(QVariantMap accents READ accents CONSTANT) | ||
| 12 | // The colours a folder can be given (stored values, theme-independent). | ||
| 13 | Q_PROPERTY(QVariantList folderSwatches READ folderSwatches CONSTANT) | ||
| 14 | Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY changed) | ||
| 15 | Q_PROPERTY(QString accentColor READ accentColor WRITE setAccentColor NOTIFY changed) | ||
| 16 | Q_PROPERTY(double fontScale READ fontScale WRITE setFontScale NOTIFY changed) | ||
| 17 | // B3: the persisted motion preference "system"|"reduced"|"full". | ||
| 18 | // "system" follows the desktop preference (SystemMotionPreference); | ||
| 19 | // reducedMotion reports the resulting effective value. | ||
| 20 | Q_PROPERTY(QString motionPolicy READ motionPolicy WRITE applyMotionPolicy NOTIFY changed) | ||
| 21 | Q_PROPERTY(bool reducedMotion READ reducedMotion WRITE setReducedMotion NOTIFY changed) | ||
| 22 | Q_PROPERTY(int textSize READ textSize NOTIFY changed) | ||
| 23 | Q_PROPERTY(int metadataSize READ metadataSize NOTIFY changed) | ||
| 24 | Q_PROPERTY(int sectionSize READ sectionSize NOTIFY changed) | ||
| 25 | Q_PROPERTY(int headingSize READ headingSize NOTIFY changed) | ||
| 26 | Q_PROPERTY(int titleSize READ titleSize NOTIFY changed) | ||
| 27 | Q_PROPERTY(int rowHeight READ rowHeight NOTIFY changed) | ||
| 28 | Q_PROPERTY(int controlHeight READ controlHeight NOTIFY changed) | ||
| 29 | Q_PROPERTY(int wheelScrollLines READ wheelScrollLines NOTIFY changed) | ||
| 30 | // Sprint 98 (DESIGN.md §3/§11): the monospace stack of the command bar — | ||
| 31 | // the first installed of "JetBrains Mono", "Cascadia Code", else the | ||
| 32 | // system's fixed-width font. | ||
| 33 | Q_PROPERTY(QString monoFamily READ monoFamily CONSTANT) | ||
| 34 | public: | ||
| 35 | explicit DesignTokens(QObject *parent = nullptr); | ||
| 36 | QVariantMap palette() const; | ||
| 37 | // Sprint 108 §4.14: the base palette of one theme ("light", "dark"), | ||
| 38 | // whatever the current theme is — the composer's *Preview* frames. | ||
| 39 | 142 | Q_INVOKABLE QVariantMap paletteFor(const QString &theme) const { | |
| 40 |
5/12✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 142 times.
✓ Branch 12 → 13 taken 142 times.
✓ Branch 13 → 14 taken 142 times.
✓ Branch 17 → 18 taken 142 times.
✗ Branch 17 → 19 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 142 times.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
|
284 | return m_palettes.value(theme == QLatin1String("dark") ? QStringLiteral("dark") : QStringLiteral("light")).toMap(); |
| 41 | } | ||
| 42 |
3/3✓ Branch 3 → 4 taken 72 times.
✓ Branch 4 → 5 taken 72 times.
✓ Branch 5 → 6 taken 72 times.
|
72 | QVariantMap accents() const { return m_palettes.value("accents").toMap(); } |
| 43 |
3/3✓ Branch 3 → 4 taken 1662 times.
✓ Branch 4 → 5 taken 1662 times.
✓ Branch 5 → 6 taken 1662 times.
|
1662 | QVariantList folderSwatches() const { return m_palettes.value("folderSwatches").toList(); } |
| 44 | 741 | QString theme() const { return m_theme; } | |
| 45 | void setTheme(const QString &theme); | ||
| 46 | 9582 | QString accentColor() const { return m_accentColor; } | |
| 47 | void setAccentColor(const QString &color); | ||
| 48 | Q_INVOKABLE bool applyAccentColor(const QString &color); | ||
| 49 | static bool validAccentColor(const QString &color); | ||
| 50 | 474646 | double fontScale() const { return m_scale; } | |
| 51 | void setFontScale(double scale); | ||
| 52 | 739 | QString motionPolicy() const { return m_motionPolicy; } | |
| 53 | // Sets the persisted policy and recomputes the effective value: | ||
| 54 | // "reduced" -> always reduced; "full" -> always full motion; | ||
| 55 | // "system" -> whatever the desktop adapter reports (unknown -> full). | ||
| 56 | Q_INVOKABLE void applyMotionPolicy(const QString &policy); | ||
| 57 | 39561 | bool reducedMotion() const { return m_reducedMotion; } | |
| 58 | void setReducedMotion(bool reduced); | ||
| 59 | // Re-evaluates a "system" policy against the current desktop | ||
| 60 | // preference (the adapter calls this when the desktop reports a | ||
| 61 | // change); explicit policies are unaffected. | ||
| 62 | void refreshMotionFromSystem(); | ||
| 63 | // Controlled environments (tests, preview hosts) pin the motion | ||
| 64 | // source instead of querying the session bus. | ||
| 65 | 4 | void setSystemMotionProbe(SystemMotionPreference::Probe probe) { | |
| 66 | 4 | m_motion.setProbe(std::move(probe)); | |
| 67 | 4 | } | |
| 68 | int textSize() const; | ||
| 69 | int metadataSize() const; | ||
| 70 | int sectionSize() const; | ||
| 71 | int headingSize() const; | ||
| 72 | int titleSize() const; | ||
| 73 | int rowHeight() const; | ||
| 74 | int controlHeight() const; | ||
| 75 | int wheelScrollLines() const; | ||
| 76 | QString monoFamily() const; | ||
| 77 | // Sprint 93 S93.2.3: colors of an event block in a calendar color — | ||
| 78 | // background (tint over surface), hover, bar (the calendar color), | ||
| 79 | // text and secondaryText (both >= 4.5:1 on background and hover, G6). | ||
| 80 | Q_INVOKABLE QVariantMap eventColors(const QString &calendarColor) const; | ||
| 81 | // WCAG contrast ratio of two colors (tests, contrast decisions). | ||
| 82 | static double contrastRatio(const QString &first, const QString &second); | ||
| 83 | signals: | ||
| 84 | void changed(); | ||
| 85 | private: | ||
| 86 | QVariantMap m_palettes; | ||
| 87 | QString m_theme = QStringLiteral("light"); | ||
| 88 | QString m_accentColor; | ||
| 89 | mutable QString m_paletteKey; | ||
| 90 | mutable QVariantMap m_cachedPalette; | ||
| 91 | double m_scale = 1; | ||
| 92 | QString m_motionPolicy = QStringLiteral("system"); | ||
| 93 | bool m_reducedMotion = false; | ||
| 94 | SystemMotionPreference m_motion; | ||
| 95 | }; | ||
| 96 |