presentation/KeyOverlayController.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include "AltHoldDetector.h" | ||
| 3 | #include "KeyOverlayLayout.h" | ||
| 4 | |||
| 5 | #include <QElapsedTimer> | ||
| 6 | #include <QHash> | ||
| 7 | #include <QObject> | ||
| 8 | #include <QPointer> | ||
| 9 | #include <QTimer> | ||
| 10 | #include <QVariantList> | ||
| 11 | #include <QVariantMap> | ||
| 12 | |||
| 13 | class KeyHint; | ||
| 14 | struct CommandSpec; | ||
| 15 | class QKeyEvent; | ||
| 16 | class QQuickItem; | ||
| 17 | class QuickCommandRouter; | ||
| 18 | |||
| 19 | // Sprint 105 S105.8.3/S105.8.5/S105.8.6: the keys overlay of one window. | ||
| 20 | // The router feeds it every key and pointer event first; it runs the | ||
| 21 | // AltHoldDetector, and when the overlay opens it collects the registered | ||
| 22 | // elements (KeyHint), asks the router which key runs each command *now* | ||
| 23 | // (rule 3), assigns Alt letters (KeyTipAssigner) and places everything once | ||
| 24 | // (KeyOverlayLayout). KeyOverlay.qml draws the result. | ||
| 25 | class KeyOverlayController : public QObject { | ||
| 26 | 352 | Q_OBJECT | |
| 27 | Q_PROPERTY(int stage READ stage NOTIFY changed) // 0 hidden, 1 keys, 2 explained | ||
| 28 | Q_PROPERTY(bool holding READ holding NOTIFY holdingChanged) | ||
| 29 | Q_PROPERTY(QVariantList badges READ badges NOTIFY changed) | ||
| 30 | Q_PROPERTY(QVariantList callouts READ callouts NOTIFY changed) | ||
| 31 | Q_PROPERTY(QVariantList spotlights READ spotlights NOTIFY changed) | ||
| 32 | Q_PROPERTY(QVariantMap legend READ legend NOTIFY changed) | ||
| 33 | // D-25: one small card per other pane with keys of its own (the agenda). | ||
| 34 | Q_PROPERTY(QVariantList paneLegends READ paneLegends NOTIFY changed) | ||
| 35 | Q_PROPERTY(QString announcement READ announcement NOTIFY changed) | ||
| 36 | Q_PROPERTY(int revision READ revision NOTIFY changed) | ||
| 37 | Q_PROPERTY(QString pulse READ pulse NOTIFY pulseChanged) // the badge id that just acted | ||
| 38 | // From the design tokens (Runtime.tokens): keycap text size and scale. | ||
| 39 | Q_PROPERTY(qreal fontPixelSize READ fontPixelSize WRITE setFontPixelSize NOTIFY metricsChanged) | ||
| 40 | Q_PROPERTY(qreal textScale READ textScale WRITE setTextScale NOTIFY metricsChanged) | ||
| 41 | // Settings › General › Keyboard (S105.8.7). | ||
| 42 | Q_PROPERTY(bool holdEnabled READ holdEnabled WRITE setHoldEnabled NOTIFY settingsChanged) | ||
| 43 | Q_PROPERTY(int holdDelay READ holdDelay WRITE setHoldDelay NOTIFY settingsChanged) | ||
| 44 | // "after" (a longer hold), "atOnce", "never" (D-17). | ||
| 45 | Q_PROPERTY(QString explanations READ explanations WRITE setExplanations NOTIFY settingsChanged) | ||
| 46 | |||
| 47 | public: | ||
| 48 | explicit KeyOverlayController(QuickCommandRouter *router); | ||
| 49 | |||
| 50 | 1389 | int stage() const { return m_stage; } | |
| 51 | 856 | bool holding() const { return m_holding; } | |
| 52 | 215 | QVariantList badges() const { return m_badges; } | |
| 53 | 145 | QVariantList callouts() const { return m_callouts; } | |
| 54 | 144 | QVariantList spotlights() const { return m_spotlights; } | |
| 55 | 133 | QVariantMap legend() const { return m_legend; } | |
| 56 | 144 | QVariantList paneLegends() const { return m_paneLegends; } | |
| 57 | 72 | QString announcement() const { return m_announcement; } | |
| 58 | ✗ | int revision() const { return m_revision; } | |
| 59 | 207 | QString pulse() const { return m_pulse; } | |
| 60 | 3615 | qreal fontPixelSize() const { return m_fontPixelSize; } | |
| 61 | void setFontPixelSize(qreal size); | ||
| 62 | 831 | qreal textScale() const { return m_textScale; } | |
| 63 | void setTextScale(qreal scale); | ||
| 64 | 21 | bool holdEnabled() const { return m_detector.settings().holdEnabled; } | |
| 65 | void setHoldEnabled(bool enabled); | ||
| 66 | 864 | int holdDelay() const { return m_detector.settings().delayMs; } | |
| 67 | void setHoldDelay(int delay); | ||
| 68 | QString explanations() const; | ||
| 69 | void setExplanations(const QString &mode); | ||
| 70 | |||
| 71 | // Ctrl+? (D-12). | ||
| 72 | Q_INVOKABLE void toggle(); | ||
| 73 | Q_INVOKABLE void hide(); | ||
| 74 | // Tests: the letters shown now, and the element each one presses. | ||
| 75 | Q_INVOKABLE QVariantMap tipLetters() const; | ||
| 76 | |||
| 77 | // Router hooks. True: the event is consumed (a tip letter acted). | ||
| 78 | bool keyPress(QKeyEvent *event); | ||
| 79 | void keyRelease(QKeyEvent *event); | ||
| 80 | void pointerPress(); | ||
| 81 | void windowDeactivated(); | ||
| 82 | void cancel(); | ||
| 83 | |||
| 84 | signals: | ||
| 85 | void changed(); | ||
| 86 | void holdingChanged(); | ||
| 87 | void pulseChanged(); | ||
| 88 | void metricsChanged(); | ||
| 89 | void settingsChanged(); | ||
| 90 | |||
| 91 | private: | ||
| 92 | struct Entry { | ||
| 93 | QPointer<KeyHint> hint; | ||
| 94 | QString id; // stable within one computation | ||
| 95 | QString command; | ||
| 96 | QString text; // keycap text | ||
| 97 | bool alt = false; // an Alt letter | ||
| 98 | QString explanation; | ||
| 99 | QString label; // for the announcement and the legend | ||
| 100 | }; | ||
| 101 | void apply(const AltHoldDetector::Result &result); | ||
| 102 | void compute(int stage); | ||
| 103 | void clear(); | ||
| 104 | void scheduleTick(); | ||
| 105 | void finishAction(); | ||
| 106 | QSizeF badgeSize(const QString &text, bool alt) const; | ||
| 107 | QSizeF calloutSize(const QString &text) const; | ||
| 108 | QVariantMap buildLegend(const QRectF &paneRect, const QSet<QString> &badged, bool typing, int dropped); | ||
| 109 | QVariantMap buildPaneLegend(const QRectF &pane, const KeyHint *hint, const QList<const CommandSpec *> &commands); | ||
| 110 | |||
| 111 | QuickCommandRouter *m_router; | ||
| 112 | AltHoldDetector m_detector; | ||
| 113 | QElapsedTimer m_clock; | ||
| 114 | QTimer m_tick; | ||
| 115 | int m_stage = 0; | ||
| 116 | bool m_holding = false; | ||
| 117 | QVariantList m_badges, m_callouts, m_spotlights; | ||
| 118 | QVariantMap m_legend; | ||
| 119 | QVariantList m_paneLegends; | ||
| 120 | QString m_announcement; | ||
| 121 | QString m_pulse; | ||
| 122 | int m_revision = 0; | ||
| 123 | qreal m_fontPixelSize = 12; | ||
| 124 | qreal m_textScale = 1; | ||
| 125 | QHash<QChar, Entry> m_tips; | ||
| 126 | }; | ||
| 127 |