presentation/KeyOverlayCompute.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // KeyOverlayController::compute — collecting the elements of the window and | ||
| 2 | // laying out the overlay (Sprint 105 S105.8.3, overlay.md §4, ux.md §3). | ||
| 3 | #include "KeyOverlayController.h" | ||
| 4 | |||
| 5 | #include "KeyHint.h" | ||
| 6 | #include "KeyTipAssigner.h" | ||
| 7 | #include "QuickCommandRouter.h" | ||
| 8 | #include "app/CommandRegistry.h" | ||
| 9 | |||
| 10 | #include <QCoreApplication> | ||
| 11 | #include <QGuiApplication> | ||
| 12 | #include <QLoggingCategory> | ||
| 13 | #include <QQuickItem> | ||
| 14 | #include <QQuickWindow> | ||
| 15 | #include <QRegularExpression> | ||
| 16 | #include <QSet> | ||
| 17 | #include <algorithm> | ||
| 18 | |||
| 19 | Q_DECLARE_LOGGING_CATEGORY(lcKeyOverlay) | ||
| 20 | |||
| 21 | namespace { | ||
| 22 | constexpr qreal kNarrowWidth = 720; | ||
| 23 | constexpr qreal kLegendWidth = 280; | ||
| 24 | constexpr int kLegendRows = 12; | ||
| 25 | constexpr qreal kHeaderBand = 64; // the window header stays badged in narrow windows | ||
| 26 | |||
| 27 | ✗ | QString tr(const char *text) { return QCoreApplication::translate("KeyOverlay", text); } | |
| 28 | |||
| 29 | 1583 | KeyOverlayLayout::Kind kindOf(const QString &kind) { | |
| 30 |
2/2✓ Branch 4 → 5 taken 128 times.
✓ Branch 4 → 6 taken 1455 times.
|
1583 | if (kind == QLatin1String("chip")) return KeyOverlayLayout::Kind::Chip; |
| 31 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1455 times.
|
1455 | if (kind == QLatin1String("field")) return KeyOverlayLayout::Kind::Field; |
| 32 |
1/2✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1455 times.
|
1455 | if (kind == QLatin1String("pane")) return KeyOverlayLayout::Kind::Pane; |
| 33 |
2/2✓ Branch 16 → 17 taken 149 times.
✓ Branch 16 → 18 taken 1306 times.
|
1455 | if (kind == QLatin1String("row")) return KeyOverlayLayout::Kind::Row; |
| 34 | 1306 | return KeyOverlayLayout::Kind::Button; | |
| 35 | } | ||
| 36 | |||
| 37 | 6682 | bool visibleOnScreen(const QQuickItem *item) { | |
| 38 |
7/8✓ Branch 2 → 3 taken 6682 times.
✗ Branch 2 → 7 not taken.
✓ Branch 4 → 5 taken 1623 times.
✓ Branch 4 → 7 taken 5059 times.
✓ Branch 6 → 7 taken 16 times.
✓ Branch 6 → 8 taken 1607 times.
✓ Branch 9 → 10 taken 5075 times.
✓ Branch 9 → 11 taken 1607 times.
|
6682 | if (!item || !item->isVisible() || !item->isEnabled()) return false; |
| 39 |
2/2✓ Branch 17 → 12 taken 16054 times.
✓ Branch 17 → 18 taken 1607 times.
|
17661 | for (const QQuickItem *ancestor = item; ancestor; ancestor = ancestor->parentItem()) |
| 40 |
1/2✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 16054 times.
|
16054 | if (ancestor->opacity() < 0.01) return false; |
| 41 |
2/4✓ Branch 19 → 20 taken 1607 times.
✗ Branch 19 → 23 not taken.
✓ Branch 21 → 22 taken 1607 times.
✗ Branch 21 → 23 not taken.
|
1607 | return item->width() > 0 && item->height() > 0; |
| 42 | } | ||
| 43 | |||
| 44 | 1588 | QRectF clipRect(const QQuickItem *item) { | |
| 45 | 1588 | QRectF clip; | |
| 46 |
2/2✓ Branch 19 → 4 taken 14303 times.
✓ Branch 19 → 20 taken 1588 times.
|
15891 | for (const QQuickItem *ancestor = item->parentItem(); ancestor; ancestor = ancestor->parentItem()) { |
| 47 |
3/3✓ Branch 4 → 5 taken 14303 times.
✓ Branch 5 → 6 taken 13340 times.
✓ Branch 5 → 7 taken 963 times.
|
14303 | if (!ancestor->clip()) continue; |
| 48 |
3/3✓ Branch 7 → 8 taken 963 times.
✓ Branch 8 → 9 taken 963 times.
✓ Branch 10 → 11 taken 963 times.
|
963 | const QRectF rect = ancestor->mapRectToScene(QRectF(0, 0, ancestor->width(), ancestor->height())); |
| 49 |
2/2✓ Branch 12 → 13 taken 591 times.
✓ Branch 12 → 14 taken 372 times.
|
963 | clip = clip.isNull() ? rect : clip & rect; |
| 50 | } | ||
| 51 | 1588 | return clip; | |
| 52 | } | ||
| 53 | |||
| 54 | 197 | bool isDescendant(const QQuickItem *item, const QQuickItem *ancestor) { | |
| 55 |
2/2✓ Branch 7 → 3 taken 1805 times.
✓ Branch 7 → 8 taken 124 times.
|
1929 | for (const QQuickItem *current = item; current; current = current->parentItem()) |
| 56 |
2/2✓ Branch 3 → 4 taken 73 times.
✓ Branch 3 → 5 taken 1732 times.
|
1805 | if (current == ancestor) return true; |
| 57 | 124 | return false; | |
| 58 | } | ||
| 59 | |||
| 60 | ✗ | bool insidePopup(const QQuickItem *item) { | |
| 61 | ✗ | for (const QQuickItem *current = item; current; current = current->parentItem()) | |
| 62 | ✗ | if (qstrcmp(current->metaObject()->className(), "QQuickPopupItem") == 0) return true; | |
| 63 | ✗ | return false; | |
| 64 | } | ||
| 65 | |||
| 66 | 72 | QQuickItem *modalScope(QQuickWindow *window) { | |
| 67 |
6/12✓ Branch 2 → 3 taken 72 times.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 72 times.
✓ Branch 4 → 5 taken 72 times.
✓ Branch 5 → 6 taken 72 times.
✗ Branch 5 → 7 not taken.
✓ Branch 8 → 9 taken 72 times.
✗ Branch 8 → 10 not taken.
✓ Branch 10 → 11 taken 72 times.
✗ Branch 10 → 12 not taken.
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
|
72 | if (!window || window->property("modalDepth").toInt() <= 0) return nullptr; |
| 68 | ✗ | QQuickItem *overlay = nullptr; | |
| 69 | ✗ | for (QQuickItem *child : window->contentItem()->childItems()) | |
| 70 | ✗ | if (qstrcmp(child->metaObject()->className(), "QQuickOverlay") == 0) overlay = child; | |
| 71 | ✗ | if (!overlay) return nullptr; | |
| 72 | ✗ | QQuickItem *top = nullptr; | |
| 73 | ✗ | for (QQuickItem *child : overlay->childItems()) | |
| 74 | ✗ | if (child->isVisible() && qstrcmp(child->metaObject()->className(), "QQuickPopupItem") == 0 | |
| 75 | ✗ | && (!top || child->z() >= top->z())) | |
| 76 | ✗ | top = child; | |
| 77 | ✗ | return top; | |
| 78 | } | ||
| 79 | |||
| 80 | 566 | QString legendGroup(const QString &id) { | |
| 81 |
4/7✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 15 taken 562 times.
✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 15 not taken.
✓ Branch 9 → 10 taken 4 times.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
|
570 | static const QRegularExpression move(QStringLiteral("(next|previous|page_|\\.first|\\.last|expand|collapse)")); |
| 82 |
3/3✓ Branch 16 → 17 taken 566 times.
✓ Branch 20 → 21 taken 539 times.
✓ Branch 20 → 27 taken 2 times.
|
1107 | if (id.contains(QLatin1String(".goto")) || id == QLatin1String("folder.switch") |
| 83 |
8/8✓ Branch 17 → 18 taken 541 times.
✓ Branch 17 → 27 taken 25 times.
✓ Branch 23 → 24 taken 538 times.
✓ Branch 23 → 27 taken 1 time.
✓ Branch 26 → 27 taken 17 times.
✓ Branch 26 → 28 taken 521 times.
✓ Branch 29 → 30 taken 45 times.
✓ Branch 29 → 35 taken 521 times.
|
1107 | || id == QLatin1String("folder.previous") || id == QLatin1String("calendar.today")) |
| 84 | 45 | return QStringLiteral("goto"); | |
| 85 |
8/8✓ Branch 36 → 37 taken 521 times.
✓ Branch 37 → 38 taken 521 times.
✓ Branch 38 → 39 taken 164 times.
✓ Branch 38 → 42 taken 357 times.
✓ Branch 46 → 47 taken 357 times.
✓ Branch 46 → 48 taken 164 times.
✓ Branch 48 → 49 taken 164 times.
✓ Branch 48 → 50 taken 357 times.
|
1042 | return move.match(id).hasMatch() ? QStringLiteral("move") : QStringLiteral("act"); |
| 86 | } | ||
| 87 | |||
| 88 | 3254 | bool legendKey(const QKeySequence &key) { | |
| 89 |
1/1✓ Branch 2 → 3 taken 3254 times.
|
3254 | const QKeyCombination first = key[0]; |
| 90 |
2/2✓ Branch 8 → 9 taken 1527 times.
✓ Branch 8 → 10 taken 1727 times.
|
3254 | if (first.keyboardModifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) return false; |
| 91 | 1727 | const Qt::Key code = first.key(); | |
| 92 |
4/6✗ Branch 12 → 13 not taken.
✓ Branch 12 → 18 taken 381 times.
✓ Branch 13 → 14 taken 1279 times.
✓ Branch 13 → 18 taken 67 times.
✓ Branch 14 → 15 taken 1279 times.
✗ Branch 14 → 18 not taken.
|
1727 | return !(code >= Qt::Key_F1 && code <= Qt::Key_F35) && code != Qt::Key_Escape && code != Qt::Key_Colon |
| 93 |
6/6✓ Branch 11 → 12 taken 381 times.
✓ Branch 11 → 13 taken 1346 times.
✓ Branch 15 → 16 taken 1212 times.
✓ Branch 15 → 18 taken 67 times.
✓ Branch 16 → 17 taken 1166 times.
✓ Branch 16 → 18 taken 46 times.
|
3454 | && code != Qt::Key_Question && code != Qt::Key_Slash; |
| 94 | } | ||
| 95 | |||
| 96 | 1591 | QVariantMap rectMap(const QRectF &rect) { | |
| 97 | 4773 | return {{QStringLiteral("x"), rect.x()}, {QStringLiteral("y"), rect.y()}, | |
| 98 |
2/4✓ Branch 24 → 25 taken 6364 times.
✓ Branch 24 → 26 taken 1591 times.
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 39 not taken.
|
12728 | {QStringLiteral("width"), rect.width()}, {QStringLiteral("height"), rect.height()}}; |
| 99 | 7955 | } | |
| 100 | |||
| 101 | struct Candidate { | ||
| 102 | KeyHint *hint = nullptr; | ||
| 103 | QRectF rect; | ||
| 104 | QRectF clip; | ||
| 105 | QString command; | ||
| 106 | QString keyText; // fixed key ("" = needs an Alt letter) | ||
| 107 | QString explanation; | ||
| 108 | QString label; | ||
| 109 | int priority = 2; | ||
| 110 | qreal prominence = 0; // dedupes elements of one command | ||
| 111 | }; | ||
| 112 | // The registered elements of `window` that the overlay may annotate now, | ||
| 113 | // with the key that runs each one (rule 3). Also finds the pane holding the | ||
| 114 | // focus (the legend's place and title). | ||
| 115 | 72 | QList<Candidate> collect(QuickCommandRouter *router, QQuickWindow *window, bool narrow, QRectF *paneRect, QString *paneName) { | |
| 116 |
1/1✓ Branch 2 → 3 taken 72 times.
|
72 | const bool typing = router->typingFocus(); |
| 117 |
1/1✓ Branch 3 → 4 taken 72 times.
|
72 | QQuickItem *scope = modalScope(window); |
| 118 |
2/3✓ Branch 4 → 5 taken 72 times.
✗ Branch 4 → 7 not taken.
✓ Branch 5 → 6 taken 72 times.
|
72 | if (!scope) scope = router->exclusiveScope(); // Sprint 107: only the resolver sheet |
| 119 |
1/1✓ Branch 7 → 8 taken 72 times.
|
72 | QQuickItem *focus = window->activeFocusItem(); |
| 120 | 72 | QList<KeyHint *> hints; | |
| 121 |
5/5✓ Branch 8 → 9 taken 72 times.
✓ Branch 9 → 10 taken 72 times.
✓ Branch 10 → 11 taken 72 times.
✓ Branch 75 → 12 taken 21797 times.
✓ Branch 75 → 76 taken 72 times.
|
21869 | for (KeyHint *hint : KeyHint::all()) { |
| 122 | 21797 | QQuickItem *item = hint->item(); | |
| 123 |
11/12✓ Branch 14 → 15 taken 21797 times.
✗ Branch 14 → 21 not taken.
✓ Branch 15 → 16 taken 21797 times.
✓ Branch 16 → 17 taken 13968 times.
✓ Branch 16 → 21 taken 7829 times.
✓ Branch 18 → 19 taken 6682 times.
✓ Branch 18 → 21 taken 7286 times.
✓ Branch 19 → 20 taken 6682 times.
✓ Branch 20 → 21 taken 5075 times.
✓ Branch 20 → 22 taken 1607 times.
✓ Branch 23 → 24 taken 20190 times.
✓ Branch 23 → 25 taken 1607 times.
|
23337 | if (!item || item->window() != window || !hint->enabled() || !visibleOnScreen(item)) continue; |
| 124 |
10/16✓ Branch 25 → 26 taken 25 times.
✓ Branch 25 → 28 taken 1582 times.
✓ Branch 26 → 27 taken 25 times.
✓ Branch 28 → 29 taken 1582 times.
✓ Branch 29 → 30 taken 1582 times.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 34 taken 1582 times.
✗ Branch 31 → 32 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
✓ Branch 36 → 37 taken 1582 times.
✓ Branch 36 → 38 taken 25 times.
✓ Branch 38 → 39 taken 19 times.
✓ Branch 38 → 40 taken 1588 times.
✗ Branch 246 → 247 not taken.
✗ Branch 246 → 248 not taken.
|
1607 | if (scope ? !isDescendant(item, scope) : (window->property("modalDepth").toInt() > 0 && insidePopup(item))) continue; |
| 125 |
1/1✓ Branch 40 → 41 taken 1588 times.
|
1588 | hints.append(hint); |
| 126 |
9/13✓ Branch 43 → 44 taken 172 times.
✓ Branch 43 → 47 taken 1416 times.
✓ Branch 44 → 45 taken 172 times.
✗ Branch 44 → 47 not taken.
✓ Branch 45 → 46 taken 172 times.
✓ Branch 46 → 47 taken 105 times.
✓ Branch 46 → 48 taken 67 times.
✓ Branch 49 → 50 taken 1588 times.
✗ Branch 49 → 51 not taken.
✓ Branch 51 → 52 taken 1521 times.
✓ Branch 51 → 53 taken 67 times.
✗ Branch 250 → 251 not taken.
✗ Branch 250 → 252 not taken.
|
1588 | if (hint->pane().isEmpty() || !focus || !isDescendant(focus, item)) continue; |
| 127 |
3/3✓ Branch 53 → 54 taken 67 times.
✓ Branch 54 → 55 taken 67 times.
✓ Branch 56 → 57 taken 67 times.
|
67 | const QRectF rect = item->mapRectToScene(QRectF(0, 0, item->width(), item->height())); |
| 128 |
2/6✗ Branch 58 → 59 not taken.
✓ Branch 58 → 64 taken 67 times.
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 67 times.
✗ Branch 66 → 71 not taken.
|
67 | if (paneRect->isNull() || rect.width() * rect.height() < paneRect->width() * paneRect->height()) { |
| 129 | 67 | *paneRect = rect; | |
| 130 | 67 | *paneName = hint->pane(); | |
| 131 | } | ||
| 132 | 72 | } | |
| 133 | 72 | QList<Candidate> candidates; | |
| 134 |
2/2✓ Branch 242 → 80 taken 1588 times.
✓ Branch 242 → 243 taken 72 times.
|
1660 | for (KeyHint *hint : std::as_const(hints)) { |
| 135 | 1588 | QQuickItem *item = hint->item(); | |
| 136 |
3/3✓ Branch 82 → 83 taken 1588 times.
✓ Branch 83 → 84 taken 1588 times.
✓ Branch 85 → 86 taken 1588 times.
|
1588 | const QRectF rect = item->mapRectToScene(QRectF(0, 0, item->width(), item->height())); |
| 137 | 1588 | Candidate candidate{hint, rect, clipRect(item), hint->command(), {}, hint->explanation(), hint->effectiveLabel(), | |
| 138 |
2/8✓ Branch 86 → 87 taken 1588 times.
✓ Branch 89 → 90 taken 1588 times.
✗ Branch 260 → 261 not taken.
✗ Branch 260 → 262 not taken.
✗ Branch 263 → 264 not taken.
✗ Branch 263 → 265 not taken.
✗ Branch 266 → 267 not taken.
✗ Branch 266 → 268 not taken.
|
1588 | hint->priority(), rect.width() * rect.height()}; |
| 139 |
2/2✓ Branch 94 → 95 taken 1033 times.
✓ Branch 94 → 146 taken 555 times.
|
1588 | if (!candidate.command.isEmpty()) { |
| 140 |
1/1✓ Branch 95 → 96 taken 1033 times.
|
1033 | const CommandSpec *spec = CommandRegistry::find(candidate.command); |
| 141 |
1/2✗ Branch 96 → 97 not taken.
✓ Branch 96 → 109 taken 1033 times.
|
1033 | if (!spec) { |
| 142 | ✗ | qCWarning(lcKeyOverlay) << "KeyHint names an unknown command" << candidate.command; | |
| 143 | ✗ | continue; | |
| 144 | ✗ | } | |
| 145 |
1/1✓ Branch 109 → 110 taken 1033 times.
|
1033 | const QKeySequence key = router->effectiveKey(candidate.command); |
| 146 |
4/4✓ Branch 110 → 111 taken 1033 times.
✓ Branch 111 → 112 taken 20 times.
✓ Branch 111 → 113 taken 1013 times.
✓ Branch 113 → 114 taken 1013 times.
|
1033 | candidate.keyText = key.isEmpty() ? QString() : CommandRegistry::nativeKeyText(key); |
| 147 |
3/3✓ Branch 117 → 118 taken 958 times.
✓ Branch 117 → 122 taken 75 times.
✓ Branch 118 → 119 taken 958 times.
|
1033 | if (candidate.explanation.isEmpty()) candidate.explanation = CommandRegistry::translatedExplanation(*spec); |
| 148 |
3/3✓ Branch 123 → 124 taken 71 times.
✓ Branch 123 → 128 taken 962 times.
✓ Branch 124 → 125 taken 71 times.
|
1033 | if (candidate.label.isEmpty()) candidate.label = CommandRegistry::translatedDescription(*spec); |
| 149 |
2/2✓ Branch 128 → 129 taken 612 times.
✓ Branch 128 → 130 taken 421 times.
|
1033 | if (candidate.priority <= 0) candidate.priority = spec->frequency; |
| 150 | // A command whose key does not work here and that cannot be | ||
| 151 | // pressed (unavailable) gets nothing. | ||
| 152 |
8/10✓ Branch 130 → 131 taken 1033 times.
✓ Branch 131 → 132 taken 20 times.
✓ Branch 131 → 137 taken 1013 times.
✓ Branch 132 → 133 taken 20 times.
✓ Branch 133 → 134 taken 12 times.
✓ Branch 133 → 137 taken 8 times.
✗ Branch 135 → 136 not taken.
✓ Branch 135 → 137 taken 12 times.
✗ Branch 138 → 139 not taken.
✓ Branch 138 → 140 taken 1033 times.
|
1033 | if (key.isEmpty() && !router->isAvailable(candidate.command) && !hint->tip()) continue; |
| 153 |
2/4✓ Branch 142 → 143 taken 1033 times.
✗ Branch 142 → 145 not taken.
✗ Branch 149 → 150 not taken.
✓ Branch 149 → 163 taken 555 times.
|
1588 | } else if (!hint->keys().isEmpty()) { |
| 154 | ✗ | candidate.keyText = QKeySequence(hint->keys()).toString(QKeySequence::NativeText); | |
| 155 | ✗ | if (candidate.keyText.isEmpty()) candidate.keyText = hint->keys(); | |
| 156 |
2/2✓ Branch 166 → 167 taken 172 times.
✓ Branch 166 → 190 taken 383 times.
|
555 | } else if (!hint->pane().isEmpty()) { |
| 157 | // D-25: the pane's own F-key ("F7 · Mail list"). | ||
| 158 |
2/2✓ Branch 168 → 169 taken 172 times.
✓ Branch 169 → 170 taken 172 times.
|
172 | const QKeySequence key = router->effectiveKey(QuickCommandRouter::paneCommand(hint->paneOrder())); |
| 159 |
6/6✓ Branch 171 → 172 taken 172 times.
✓ Branch 172 → 173 taken 160 times.
✓ Branch 172 → 188 taken 12 times.
✓ Branch 177 → 178 taken 160 times.
✓ Branch 178 → 179 taken 160 times.
✓ Branch 179 → 180 taken 160 times.
|
332 | if (!key.isEmpty()) candidate.keyText = CommandRegistry::nativeKeyText(key) + QStringLiteral(" · ") + hint->pane(); |
| 160 | 172 | } | |
| 161 |
2/2✓ Branch 190 → 191 taken 459 times.
✓ Branch 190 → 192 taken 1129 times.
|
1588 | if (candidate.priority <= 0) candidate.priority = 2; |
| 162 | // While typing, only keys that act in a text field (ux.md §3). | ||
| 163 |
8/10✓ Branch 192 → 193 taken 104 times.
✓ Branch 192 → 200 taken 1484 times.
✓ Branch 194 → 195 taken 76 times.
✓ Branch 194 → 200 taken 28 times.
✓ Branch 196 → 197 taken 12 times.
✓ Branch 196 → 200 taken 64 times.
✗ Branch 198 → 199 not taken.
✓ Branch 198 → 200 taken 12 times.
✗ Branch 201 → 202 not taken.
✓ Branch 201 → 203 taken 1588 times.
|
1588 | if (typing && !candidate.command.isEmpty() && candidate.keyText.isEmpty() && !hint->tip()) continue; |
| 164 |
2/10✗ Branch 203 → 204 not taken.
✓ Branch 203 → 211 taken 1588 times.
✗ Branch 205 → 206 not taken.
✗ Branch 205 → 211 not taken.
✗ Branch 207 → 208 not taken.
✗ Branch 207 → 211 not taken.
✗ Branch 209 → 210 not taken.
✗ Branch 209 → 211 not taken.
✗ Branch 212 → 213 not taken.
✓ Branch 212 → 214 taken 1588 times.
|
1588 | if (narrow && !paneRect->isNull() && !paneRect->intersects(rect) && rect.top() > kHeaderBand) continue; |
| 165 |
2/10✓ Branch 214 → 215 taken 1588 times.
✗ Branch 218 → 219 not taken.
✗ Branch 219 → 220 not taken.
✗ Branch 220 → 221 not taken.
✗ Branch 221 → 222 not taken.
✗ Branch 223 → 224 not taken.
✗ Branch 224 → 225 not taken.
✗ Branch 226 → 227 not taken.
✗ Branch 232 → 216 not taken.
✓ Branch 232 → 233 taken 1588 times.
|
1588 | qCDebug(lcKeyOverlay) << "candidate" << candidate.label << candidate.keyText << rect << "tip" << hint->tip(); |
| 166 |
1/1✓ Branch 233 → 234 taken 1588 times.
|
1588 | candidates.append(candidate); |
| 167 | 1588 | } | |
| 168 | 72 | return candidates; | |
| 169 | 72 | } | |
| 170 | } // namespace | ||
| 171 | |||
| 172 | 72 | void KeyOverlayController::compute(int stage) { | |
| 173 |
1/1✓ Branch 2 → 3 taken 72 times.
|
72 | QQuickWindow *window = m_router->window(); |
| 174 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 72 times.
|
72 | if (!window) return; |
| 175 | 72 | m_tips.clear(); | |
| 176 |
1/1✓ Branch 6 → 7 taken 72 times.
|
72 | const bool typing = m_router->typingFocus(); |
| 177 |
1/1✓ Branch 7 → 8 taken 72 times.
|
72 | QQuickItem *focus = window->activeFocusItem(); |
| 178 |
4/5✓ Branch 8 → 9 taken 72 times.
✗ Branch 8 → 13 not taken.
✓ Branch 9 → 10 taken 72 times.
✓ Branch 10 → 11 taken 72 times.
✓ Branch 12 → 14 taken 72 times.
|
72 | const QRectF focusRect = focus ? focus->mapRectToScene(QRectF(0, 0, focus->width(), focus->height())) : QRectF(); |
| 179 |
2/2✓ Branch 14 → 15 taken 72 times.
✓ Branch 15 → 16 taken 72 times.
|
72 | const QSizeF windowSize(window->width(), window->height()); |
| 180 | 72 | const bool narrow = windowSize.width() < kNarrowWidth; | |
| 181 | 72 | QRectF paneRect; | |
| 182 | 72 | QString paneName; | |
| 183 |
1/1✓ Branch 18 → 19 taken 72 times.
|
72 | QList<Candidate> candidates = collect(m_router, window, narrow, &paneRect, &paneName); |
| 184 | |||
| 185 | // One badge per command: the most prominent element (ux.md §3). | ||
| 186 | 72 | QHash<QString, int> best; | |
| 187 |
2/2✓ Branch 41 → 20 taken 1588 times.
✓ Branch 41 → 42 taken 72 times.
|
1660 | for (int index = 0; index < candidates.size(); ++index) { |
| 188 |
1/1✓ Branch 20 → 21 taken 1588 times.
|
1588 | const QString &command = candidates[index].command; |
| 189 |
7/7✓ Branch 22 → 23 taken 1033 times.
✓ Branch 22 → 26 taken 555 times.
✓ Branch 23 → 24 taken 1033 times.
✓ Branch 25 → 26 taken 20 times.
✓ Branch 25 → 27 taken 1013 times.
✓ Branch 28 → 29 taken 575 times.
✓ Branch 28 → 30 taken 1013 times.
|
1588 | if (command.isEmpty() || candidates[index].keyText.isEmpty()) continue; |
| 190 | 1013 | const int previous = best.value(command, -1); | |
| 191 |
3/9✗ Branch 31 → 32 not taken.
✓ Branch 31 → 35 taken 1013 times.
✗ Branch 32 → 33 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 1013 times.
✗ Branch 37 → 39 not taken.
✓ Branch 38 → 39 taken 1013 times.
|
1013 | if (previous < 0 || candidates[index].prominence > candidates[previous].prominence) best.insert(command, index); |
| 192 | } | ||
| 193 | |||
| 194 | // Alt letters for the elements without a working fixed key (D-11). | ||
| 195 | 72 | QList<KeyTipAssigner::Candidate> tipCandidates; | |
| 196 |
2/2✓ Branch 66 → 43 taken 1588 times.
✓ Branch 66 → 67 taken 72 times.
|
1660 | for (int index = 0; index < candidates.size(); ++index) |
| 197 |
10/11✓ Branch 43 → 44 taken 1588 times.
✓ Branch 45 → 46 taken 415 times.
✓ Branch 45 → 53 taken 1173 times.
✓ Branch 46 → 47 taken 415 times.
✓ Branch 48 → 49 taken 415 times.
✗ Branch 48 → 53 not taken.
✓ Branch 49 → 50 taken 415 times.
✓ Branch 51 → 52 taken 410 times.
✓ Branch 51 → 53 taken 5 times.
✓ Branch 54 → 55 taken 410 times.
✓ Branch 54 → 64 taken 1178 times.
|
1588 | if (candidates[index].keyText.isEmpty() && candidates[index].hint->tip() && !candidates[index].label.isEmpty()) |
| 198 | 410 | tipCandidates.append({QString::number(index), candidates[index].label, candidates[index].priority, | |
| 199 | 410 | candidates[index].rect.topLeft()}); | |
| 200 |
1/1✓ Branch 68 → 69 taken 72 times.
|
72 | const QHash<QString, QChar> letters = KeyTipAssigner::assign(tipCandidates); |
| 201 | |||
| 202 | 72 | QList<KeyOverlayLayout::Entry> entries; | |
| 203 | 72 | QHash<QString, Entry> byId; | |
| 204 |
2/2✓ Branch 140 → 71 taken 1588 times.
✓ Branch 140 → 141 taken 72 times.
|
1660 | for (int index = 0; index < candidates.size(); ++index) { |
| 205 |
1/1✓ Branch 71 → 72 taken 1588 times.
|
1588 | Candidate &candidate = candidates[index]; |
| 206 |
1/1✓ Branch 72 → 73 taken 1588 times.
|
1588 | const QString id = QString::number(index); |
| 207 | 1588 | const bool alt = letters.contains(id); | |
| 208 |
6/6✓ Branch 74 → 75 taken 1178 times.
✓ Branch 74 → 78 taken 410 times.
✓ Branch 76 → 77 taken 5 times.
✓ Branch 76 → 78 taken 1173 times.
✓ Branch 79 → 80 taken 5 times.
✓ Branch 79 → 81 taken 1583 times.
|
1588 | if (!alt && candidate.keyText.isEmpty()) continue; |
| 209 |
6/8✓ Branch 81 → 82 taken 1173 times.
✓ Branch 81 → 87 taken 410 times.
✓ Branch 83 → 84 taken 1013 times.
✓ Branch 83 → 87 taken 160 times.
✗ Branch 85 → 86 not taken.
✓ Branch 85 → 87 taken 1013 times.
✗ Branch 88 → 89 not taken.
✓ Branch 88 → 90 taken 1583 times.
|
1583 | if (!alt && !candidate.command.isEmpty() && best.value(candidate.command, index) != index) continue; |
| 210 |
3/3✓ Branch 90 → 91 taken 410 times.
✓ Branch 90 → 93 taken 1173 times.
✓ Branch 92 → 94 taken 410 times.
|
1583 | const QString text = alt ? QString(letters.value(id)) : candidate.keyText; |
| 211 | 1583 | KeyOverlayLayout::Entry entry; | |
| 212 | 1583 | entry.id = id; | |
| 213 | 1583 | entry.rect = candidate.rect; | |
| 214 | 1583 | entry.clip = candidate.clip; | |
| 215 | 1583 | entry.kind = kindOf(candidate.hint->kind()); | |
| 216 |
2/2✓ Branch 101 → 102 taken 172 times.
✓ Branch 101 → 103 taken 1411 times.
|
1583 | if (!candidate.hint->pane().isEmpty()) entry.kind = KeyOverlayLayout::Kind::Pane; |
| 217 |
1/1✓ Branch 103 → 104 taken 1583 times.
|
1583 | entry.badgeSize = badgeSize(text, alt); |
| 218 |
6/7✓ Branch 104 → 105 taken 1360 times.
✓ Branch 104 → 110 taken 223 times.
✓ Branch 105 → 106 taken 1360 times.
✗ Branch 105 → 110 not taken.
✓ Branch 107 → 108 taken 171 times.
✓ Branch 107 → 110 taken 1189 times.
✓ Branch 108 → 109 taken 171 times.
|
1583 | entry.calloutSize = stage >= 2 && !narrow && !candidate.explanation.isEmpty() ? calloutSize(candidate.explanation) : QSizeF(); |
| 219 | 1583 | entry.priority = candidate.priority; | |
| 220 |
1/1✓ Branch 112 → 113 taken 1583 times.
|
1583 | entry.pane = KeyHint::paneOf(candidate.hint->item()); |
| 221 |
1/1✓ Branch 115 → 116 taken 1583 times.
|
1583 | entries.append(entry); |
| 222 | 1583 | byId.insert(id, {candidate.hint, id, candidate.command, text, alt, candidate.explanation, candidate.label}); | |
| 223 |
3/3✓ Branch 124 → 125 taken 410 times.
✓ Branch 124 → 130 taken 1173 times.
✓ Branch 127 → 128 taken 410 times.
|
1583 | if (alt) m_tips.insert(letters.value(id), byId.value(id)); |
| 224 | 1588 | } | |
| 225 | |||
| 226 | // The legend: corner of the focused pane, or of the window (overlay.md §2). | ||
| 227 | 72 | QSet<QString> badgedCommands; | |
| 228 |
5/5✓ Branch 147 → 148 taken 1033 times.
✓ Branch 147 → 150 taken 550 times.
✓ Branch 148 → 149 taken 1033 times.
✓ Branch 152 → 145 taken 1583 times.
✓ Branch 152 → 153 taken 72 times.
|
1655 | for (const Entry &entry : std::as_const(byId)) if (!entry.command.isEmpty()) badgedCommands.insert(entry.command); |
| 229 |
2/2✓ Branch 154 → 155 taken 5 times.
✓ Branch 154 → 157 taken 67 times.
|
72 | QVariantMap legend = buildLegend(paneRect.isNull() ? QRectF(QPointF(0, 0), windowSize) : paneRect, |
| 230 |
1/1✓ Branch 158 → 159 taken 72 times.
|
144 | badgedCommands, typing, 0); |
| 231 |
7/7✓ Branch 160 → 161 taken 67 times.
✓ Branch 160 → 163 taken 5 times.
✓ Branch 161 → 162 taken 63 times.
✓ Branch 161 → 163 taken 4 times.
✓ Branch 164 → 165 taken 63 times.
✓ Branch 164 → 174 taken 9 times.
✓ Branch 169 → 170 taken 63 times.
|
135 | if (!paneName.isEmpty() && !typing) legend.insert(QStringLiteral("title"), paneName); |
| 232 | |||
| 233 | // D-25: the other panes show their own keys too (the agenda's j/k/Enter | ||
| 234 | // after F9), so one hold shows what every pane can do. | ||
| 235 |
1/1✓ Branch 174 → 175 taken 72 times.
|
72 | m_paneLegends.clear(); |
| 236 | 72 | QList<QRectF> paneCards; | |
| 237 |
3/4✓ Branch 175 → 176 taken 68 times.
✓ Branch 175 → 258 taken 4 times.
✓ Branch 176 → 177 taken 68 times.
✗ Branch 176 → 258 not taken.
|
72 | if (!typing && !narrow) { |
| 238 |
5/5✓ Branch 177 → 178 taken 68 times.
✓ Branch 178 → 179 taken 68 times.
✓ Branch 179 → 180 taken 68 times.
✓ Branch 255 → 181 taken 20561 times.
✓ Branch 255 → 256 taken 68 times.
|
20629 | for (KeyHint *hint : KeyHint::all()) { |
| 239 | 20561 | QQuickItem *item = hint->item(); | |
| 240 |
11/15✓ Branch 184 → 185 taken 20561 times.
✓ Branch 185 → 186 taken 13176 times.
✓ Branch 185 → 196 taken 7385 times.
✓ Branch 188 → 189 taken 579 times.
✓ Branch 188 → 196 taken 12597 times.
✓ Branch 191 → 192 taken 136 times.
✓ Branch 191 → 196 taken 443 times.
✓ Branch 200 → 201 taken 13176 times.
✓ Branch 200 → 202 taken 7385 times.
✓ Branch 202 → 203 taken 20555 times.
✓ Branch 202 → 204 taken 6 times.
✗ Branch 628 → 629 not taken.
✗ Branch 628 → 630 not taken.
✗ Branch 632 → 633 not taken.
✗ Branch 632 → 634 not taken.
|
41122 | if (!item || item->window() != window || hint->pane().isEmpty() || hint->context().isEmpty() |
| 241 |
7/9✓ Branch 183 → 184 taken 20561 times.
✗ Branch 183 → 196 not taken.
✓ Branch 193 → 194 taken 136 times.
✗ Branch 193 → 196 not taken.
✓ Branch 194 → 195 taken 136 times.
✓ Branch 195 → 196 taken 130 times.
✓ Branch 195 → 197 taken 6 times.
✓ Branch 198 → 199 taken 579 times.
✓ Branch 198 → 200 taken 19982 times.
|
41122 | || !hint->enabled() || !item->isVisible()) |
| 242 | 20561 | continue; | |
| 243 |
1/1✓ Branch 205 → 206 taken 6 times.
|
6 | const QList<const CommandSpec *> commands = m_router->paneCommands(hint->context()); |
| 244 |
1/2✓ Branch 208 → 209 taken 6 times.
✗ Branch 208 → 210 not taken.
|
6 | if (commands.isEmpty()) continue; |
| 245 | ✗ | const QRectF pane = item->mapRectToScene(QRectF(0, 0, item->width(), item->height())); | |
| 246 | ✗ | QVariantMap card = buildPaneLegend(pane, hint, commands); | |
| 247 | ✗ | if (card.isEmpty()) continue; | |
| 248 | ✗ | paneCards.append(card.value(QStringLiteral("rect")).toRectF()); | |
| 249 | ✗ | card.insert(QStringLiteral("rect"), rectMap(paneCards.last())); | |
| 250 | ✗ | m_paneLegends.append(card); | |
| 251 | 74 | } | |
| 252 | } | ||
| 253 | |||
| 254 | 72 | KeyOverlayLayout::Input input; | |
| 255 | 72 | input.window = windowSize; | |
| 256 | 72 | input.focus = focusRect; | |
| 257 |
2/2✓ Branch 262 → 263 taken 72 times.
✓ Branch 263 → 264 taken 72 times.
|
144 | input.legend = legend.value(QStringLiteral("rect")).toRectF(); |
| 258 | 72 | input.paneLegends = paneCards; | |
| 259 |
1/1✓ Branch 269 → 270 taken 72 times.
|
72 | input.rtl = QGuiApplication::layoutDirection() == Qt::RightToLeft; |
| 260 |
3/4✓ Branch 270 → 271 taken 63 times.
✓ Branch 270 → 273 taken 9 times.
✓ Branch 271 → 272 taken 63 times.
✗ Branch 271 → 273 not taken.
|
72 | input.explanations = stage >= 2 && !narrow; |
| 261 |
1/1✓ Branch 274 → 275 taken 72 times.
|
72 | const auto result = KeyOverlayLayout::compute(entries, input); |
| 262 | |||
| 263 |
1/1✓ Branch 275 → 276 taken 72 times.
|
72 | m_badges.clear(); |
| 264 |
1/1✓ Branch 276 → 277 taken 72 times.
|
72 | m_callouts.clear(); |
| 265 |
1/1✓ Branch 277 → 278 taken 72 times.
|
72 | m_spotlights.clear(); |
| 266 | 72 | QStringList spoken; | |
| 267 |
2/2✓ Branch 355 → 280 taken 1416 times.
✓ Branch 355 → 356 taken 72 times.
|
1488 | for (const auto &badge : result.badges) { |
| 268 | 1416 | const Entry entry = byId.value(badge.id); | |
| 269 |
1/1✓ Branch 282 → 283 taken 1416 times.
|
1416 | QVariantMap map = rectMap(badge.rect); |
| 270 |
1/1✓ Branch 287 → 288 taken 1416 times.
|
2832 | map.insert(QStringLiteral("id"), badge.id); |
| 271 |
1/1✓ Branch 295 → 296 taken 1416 times.
|
2832 | map.insert(QStringLiteral("text"), entry.text); |
| 272 |
1/1✓ Branch 303 → 304 taken 1416 times.
|
2832 | map.insert(QStringLiteral("alt"), entry.alt); |
| 273 |
1/1✓ Branch 311 → 312 taken 1416 times.
|
2832 | map.insert(QStringLiteral("delay"), badge.delayMs); |
| 274 |
1/1✓ Branch 319 → 320 taken 1416 times.
|
2832 | map.insert(QStringLiteral("command"), entry.command); |
| 275 |
1/1✓ Branch 327 → 328 taken 1416 times.
|
2832 | map.insert(QStringLiteral("label"), entry.label); |
| 276 |
1/1✓ Branch 332 → 333 taken 1416 times.
|
1416 | m_badges.append(map); |
| 277 |
8/10✓ Branch 336 → 337 taken 314 times.
✓ Branch 336 → 340 taken 1102 times.
✓ Branch 341 → 342 taken 1416 times.
✓ Branch 342 → 343 taken 1416 times.
✓ Branch 343 → 344 taken 1416 times.
✓ Branch 344 → 345 taken 1416 times.
✓ Branch 349 → 350 taken 314 times.
✓ Branch 349 → 351 taken 1102 times.
✗ Branch 753 → 754 not taken.
✗ Branch 753 → 755 not taken.
|
1730 | spoken.append((entry.alt ? QStringLiteral("Alt ") : QString()) + entry.text + QLatin1Char(' ') + entry.label); |
| 278 | 1416 | } | |
| 279 |
2/2✓ Branch 446 → 358 taken 26 times.
✓ Branch 446 → 447 taken 72 times.
|
98 | for (const auto &callout : result.callouts) { |
| 280 |
1/1✓ Branch 359 → 360 taken 26 times.
|
26 | QVariantMap map = rectMap(callout.rect); |
| 281 |
1/1✓ Branch 364 → 365 taken 26 times.
|
52 | map.insert(QStringLiteral("id"), callout.id); |
| 282 |
1/1✓ Branch 373 → 374 taken 26 times.
|
52 | map.insert(QStringLiteral("text"), byId.value(callout.id).explanation); |
| 283 |
1/1✓ Branch 382 → 383 taken 26 times.
|
52 | map.insert(QStringLiteral("delay"), callout.delayMs); |
| 284 |
1/1✓ Branch 391 → 392 taken 26 times.
|
52 | map.insert(QStringLiteral("fromX"), callout.from.x()); |
| 285 |
1/1✓ Branch 400 → 401 taken 26 times.
|
52 | map.insert(QStringLiteral("fromY"), callout.from.y()); |
| 286 |
1/1✓ Branch 409 → 410 taken 26 times.
|
52 | map.insert(QStringLiteral("controlX"), callout.control.x()); |
| 287 |
1/1✓ Branch 418 → 419 taken 26 times.
|
52 | map.insert(QStringLiteral("controlY"), callout.control.y()); |
| 288 |
1/1✓ Branch 427 → 428 taken 26 times.
|
52 | map.insert(QStringLiteral("toX"), callout.to.x()); |
| 289 |
1/1✓ Branch 436 → 437 taken 26 times.
|
52 | map.insert(QStringLiteral("toY"), callout.to.y()); |
| 290 |
1/1✓ Branch 441 → 442 taken 26 times.
|
26 | m_callouts.append(map); |
| 291 | 26 | } | |
| 292 |
4/4✓ Branch 450 → 451 taken 77 times.
✓ Branch 452 → 453 taken 77 times.
✓ Branch 457 → 449 taken 77 times.
✓ Branch 457 → 458 taken 72 times.
|
149 | for (const QRectF &rect : result.spotlights) m_spotlights.append(rectMap(rect)); |
| 293 | // Tips that were dropped by the layout cannot be pressed. | ||
| 294 | 72 | QSet<QString> shown; | |
| 295 |
3/3✓ Branch 462 → 463 taken 1416 times.
✓ Branch 465 → 461 taken 1416 times.
✓ Branch 465 → 466 taken 72 times.
|
1488 | for (const auto &badge : result.badges) shown.insert(badge.id); |
| 296 |
6/6✓ Branch 466 → 467 taken 72 times.
✓ Branch 470 → 471 taken 314 times.
✓ Branch 470 → 478 taken 96 times.
✓ Branch 479 → 480 taken 96 times.
✓ Branch 483 → 468 taken 410 times.
✓ Branch 483 → 484 taken 72 times.
|
482 | for (auto it = m_tips.begin(); it != m_tips.end();) it = shown.contains(it.value().id) ? std::next(it) : m_tips.erase(it); |
| 297 | 72 | const int more = result.droppedBadges + int(result.droppedCallouts.size()); | |
| 298 |
3/3✓ Branch 485 → 486 taken 68 times.
✓ Branch 485 → 495 taken 4 times.
✓ Branch 490 → 491 taken 68 times.
|
140 | if (more > 0) legend.insert(QStringLiteral("more"), more); |
| 299 |
4/4✓ Branch 499 → 500 taken 72 times.
✓ Branch 500 → 501 taken 72 times.
✓ Branch 501 → 502 taken 72 times.
✓ Branch 506 → 507 taken 72 times.
|
216 | legend.insert(QStringLiteral("rect"), rectMap(legend.value(QStringLiteral("rect")).toRectF())); |
| 300 | 72 | m_legend = legend; | |
| 301 |
3/3✓ Branch 516 → 517 taken 72 times.
✓ Branch 521 → 522 taken 72 times.
✓ Branch 522 → 523 taken 72 times.
|
144 | m_announcement = tr("Keys shown: %1.").arg(spoken.join(QStringLiteral(", "))); |
| 302 | 72 | m_stage = stage; | |
| 303 | 72 | ++m_revision; | |
| 304 |
2/10✓ Branch 529 → 530 taken 72 times.
✗ Branch 533 → 534 not taken.
✗ Branch 534 → 535 not taken.
✗ Branch 535 → 536 not taken.
✗ Branch 536 → 537 not taken.
✗ Branch 538 → 539 not taken.
✗ Branch 539 → 540 not taken.
✗ Branch 541 → 542 not taken.
✗ Branch 550 → 531 not taken.
✓ Branch 550 → 551 taken 72 times.
|
72 | qCInfo(lcKeyOverlay) << "overlay stage" << stage << "badges" << m_badges.size() << "callouts" << m_callouts.size() |
| 305 | ✗ | << "tips" << m_tips.size() << "dropped" << more; | |
| 306 |
1/1✓ Branch 551 → 552 taken 72 times.
|
72 | emit changed(); |
| 307 | 2475 | } | |
| 308 | |||
| 309 | 72 | QVariantMap KeyOverlayController::buildLegend(const QRectF &focusPane, const QSet<QString> &badged, bool typing, int) { | |
| 310 | // The legend stays inside the focused pane (it must not cover the other | ||
| 311 | // panes' elements); a pane too low for four rows gives it the window. | ||
| 312 | 72 | const qreal line = m_fontPixelSize * 1.9; | |
| 313 | 144 | const auto rowsThatFit = [&](const QRectF &area) { return int((area.height() - 24) / line - 2.4 - 3 * 1.2); }; | |
| 314 |
1/1✓ Branch 2 → 3 taken 72 times.
|
72 | QWindow *window = m_router->window(); |
| 315 |
3/4✓ Branch 3 → 4 taken 72 times.
✗ Branch 3 → 7 not taken.
✓ Branch 4 → 5 taken 72 times.
✓ Branch 5 → 6 taken 72 times.
|
72 | const QRectF windowRect = window ? QRectF(0, 0, window->width(), window->height()) : focusPane; |
| 316 |
2/2✓ Branch 9 → 10 taken 7 times.
✓ Branch 9 → 11 taken 65 times.
|
72 | const QRectF paneRect = rowsThatFit(focusPane) >= 4 ? focusPane : windowRect; |
| 317 |
1/1✓ Branch 13 → 14 taken 72 times.
|
72 | const int maxRows = std::clamp(rowsThatFit(paneRect), 0, kLegendRows); |
| 318 | 72 | QVariantMap legend; | |
| 319 |
5/5✓ Branch 14 → 15 taken 4 times.
✓ Branch 14 → 16 taken 68 times.
✓ Branch 15 → 17 taken 4 times.
✓ Branch 16 → 17 taken 68 times.
✓ Branch 21 → 22 taken 72 times.
|
144 | legend.insert(QStringLiteral("title"), typing ? tr("Typing — the letter keys are off") : m_router->contextTitle()); |
| 320 | 72 | QVariantList groups; | |
| 321 | 72 | int rowCount = 0; | |
| 322 |
2/2✓ Branch 26 → 27 taken 68 times.
✓ Branch 26 → 165 taken 4 times.
|
72 | if (!typing) { |
| 323 |
1/1✓ Branch 30 → 31 taken 68 times.
|
136 | const QList<QPair<QString, QString>> names = {{QStringLiteral("move"), tr("Move")}, |
| 324 |
1/1✓ Branch 35 → 36 taken 68 times.
|
136 | {QStringLiteral("act"), tr("Act")}, |
| 325 |
3/5✓ Branch 40 → 41 taken 68 times.
✓ Branch 44 → 45 taken 204 times.
✓ Branch 44 → 46 taken 68 times.
✗ Branch 226 → 227 not taken.
✗ Branch 226 → 228 not taken.
|
340 | {QStringLiteral("goto"), tr("Go to")}}; |
| 326 | 68 | QHash<QString, QVariantList> rows; | |
| 327 | 68 | QList<const CommandSpec *> available; | |
| 328 |
3/3✓ Branch 55 → 56 taken 68 times.
✓ Branch 86 → 58 taken 13940 times.
✓ Branch 86 → 87 taken 68 times.
|
14008 | for (const CommandSpec &spec : CommandRegistry::specs()) { |
| 329 |
8/9✓ Branch 60 → 61 taken 12983 times.
✓ Branch 60 → 64 taken 957 times.
✓ Branch 61 → 62 taken 12983 times.
✗ Branch 61 → 64 not taken.
✓ Branch 62 → 63 taken 12983 times.
✓ Branch 63 → 64 taken 9727 times.
✓ Branch 63 → 65 taken 3256 times.
✓ Branch 66 → 67 taken 10684 times.
✓ Branch 66 → 68 taken 3256 times.
|
16030 | if (badged.contains(spec.id) || !spec.showInHelp || !m_router->isAvailable(spec.id)) continue; |
| 330 |
1/1✓ Branch 68 → 69 taken 3256 times.
|
3256 | const QKeySequence key = m_router->effectiveKey(spec.id); |
| 331 |
8/8✓ Branch 69 → 70 taken 3256 times.
✓ Branch 70 → 71 taken 3254 times.
✓ Branch 70 → 73 taken 2 times.
✓ Branch 71 → 72 taken 3254 times.
✓ Branch 72 → 73 taken 2088 times.
✓ Branch 72 → 74 taken 1166 times.
✓ Branch 75 → 76 taken 2090 times.
✓ Branch 75 → 77 taken 1166 times.
|
3256 | if (key.isEmpty() || !legendKey(key)) continue; |
| 332 |
1/1✓ Branch 77 → 78 taken 1166 times.
|
1166 | available.append(&spec); |
| 333 | 3256 | } | |
| 334 | // Daily first, then weekly, then rare; registry order inside a class. | ||
| 335 |
3/3✓ Branch 87 → 88 taken 68 times.
✓ Branch 88 → 89 taken 68 times.
✓ Branch 89 → 90 taken 68 times.
|
68 | std::stable_sort(available.begin(), available.end(), |
| 336 | 3627 | [](const CommandSpec *a, const CommandSpec *b) { return a->frequency > b->frequency; }); | |
| 337 |
2/2✓ Branch 127 → 93 taken 590 times.
✓ Branch 127 → 128 taken 44 times.
|
634 | for (const CommandSpec *spec : std::as_const(available)) { |
| 338 |
2/2✓ Branch 94 → 95 taken 24 times.
✓ Branch 94 → 96 taken 566 times.
|
590 | if (rowCount >= maxRows) break; |
| 339 |
3/3✓ Branch 96 → 97 taken 566 times.
✓ Branch 97 → 98 taken 566 times.
✓ Branch 111 → 112 taken 566 times.
|
1132 | rows[legendGroup(spec->id)].append(QVariantMap{ |
| 340 |
2/2✓ Branch 101 → 102 taken 566 times.
✓ Branch 102 → 103 taken 566 times.
|
1132 | {QStringLiteral("key"), CommandRegistry::nativeKeyText(m_router->effectiveKey(spec->id))}, |
| 341 |
3/5✓ Branch 107 → 108 taken 566 times.
✓ Branch 115 → 116 taken 1132 times.
✓ Branch 115 → 117 taken 566 times.
✗ Branch 271 → 272 not taken.
✗ Branch 271 → 273 not taken.
|
2830 | {QStringLiteral("text"), CommandRegistry::translatedDescription(*spec)}}); |
| 342 | 566 | ++rowCount; | |
| 343 | } | ||
| 344 |
2/2✓ Branch 160 → 130 taken 204 times.
✓ Branch 160 → 161 taken 68 times.
|
272 | for (const auto &name : names) |
| 345 |
2/2✓ Branch 134 → 135 taken 137 times.
✓ Branch 134 → 158 taken 67 times.
|
204 | if (!rows.value(name.first).isEmpty()) |
| 346 |
3/5✓ Branch 146 → 147 taken 137 times.
✓ Branch 150 → 151 taken 274 times.
✓ Branch 150 → 152 taken 137 times.
✗ Branch 312 → 313 not taken.
✗ Branch 312 → 314 not taken.
|
685 | groups.append(QVariantMap{{QStringLiteral("name"), name.second}, {QStringLiteral("rows"), rows.value(name.first)}}); |
| 347 | 68 | } | |
| 348 |
1/1✓ Branch 169 → 170 taken 72 times.
|
144 | legend.insert(QStringLiteral("groups"), groups); |
| 349 |
5/5✓ Branch 174 → 175 taken 62 times.
✓ Branch 174 → 176 taken 10 times.
✓ Branch 175 → 177 taken 62 times.
✓ Branch 176 → 177 taken 10 times.
✓ Branch 181 → 182 taken 72 times.
|
144 | legend.insert(QStringLiteral("footer"), m_detector.toggled() ? tr("? all keys · Esc closes") |
| 350 | : tr("Hold for explanations · ? all keys · Esc")); | ||
| 351 | // Height: title, group headings, rows, footer (overlay.md §6). | ||
| 352 | 72 | const qreal width = std::min(kLegendWidth * m_textScale, std::max(160.0, paneRect.width() / 3)); | |
| 353 | 72 | const qreal height = line * (2.4 + groups.size() * 1.2 + rowCount); | |
| 354 | 72 | const QRectF rect(paneRect.right() - width - 12, paneRect.bottom() - height - 12, width, height); | |
| 355 |
3/4✗ Branch 195 → 196 not taken.
✓ Branch 195 → 199 taken 72 times.
✓ Branch 200 → 201 taken 72 times.
✓ Branch 204 → 205 taken 72 times.
|
144 | legend.insert(QStringLiteral("rect"), rect.top() < paneRect.top() ? QRectF(rect.left(), paneRect.top() + 12, width, height) : rect); |
| 356 | 72 | return legend; | |
| 357 | 2453 | } | |
| 358 | |||
| 359 | ✗ | QVariantMap KeyOverlayController::buildPaneLegend(const QRectF &pane, const KeyHint *hint, | |
| 360 | const QList<const CommandSpec *> &commands) { | ||
| 361 | // A small card in the pane's bottom corner: "F9 · Agenda" and the keys | ||
| 362 | // that work there once it has the focus. Only when it fits. | ||
| 363 | ✗ | const qreal line = m_fontPixelSize * 1.9; | |
| 364 | ✗ | const int fit = int((pane.height() - 24) / line - 3.6); | |
| 365 | ✗ | if (fit < 2 || pane.width() < 160) return {}; | |
| 366 | ✗ | QVariantList rows; | |
| 367 | ✗ | for (const CommandSpec *spec : commands) { | |
| 368 | ✗ | if (rows.size() >= std::min(fit, 6)) break; | |
| 369 | ✗ | rows.append(QVariantMap{{QStringLiteral("key"), CommandRegistry::nativeKeyText(spec->defaultKeys.first())}, | |
| 370 | ✗ | {QStringLiteral("text"), CommandRegistry::translatedDescription(*spec)}}); | |
| 371 | } | ||
| 372 | ✗ | const QKeySequence key = m_router->effectiveKey(QuickCommandRouter::paneCommand(hint->paneOrder())); | |
| 373 | ✗ | const QString title = key.isEmpty() ? hint->pane() : CommandRegistry::nativeKeyText(key) + QStringLiteral(" · ") + hint->pane(); | |
| 374 | ✗ | const qreal width = std::min(kLegendWidth * m_textScale, pane.width() - 24); | |
| 375 | ✗ | const qreal height = line * (3.6 + rows.size()); | |
| 376 | ✗ | return {{QStringLiteral("title"), title}, | |
| 377 | ✗ | {QStringLiteral("groups"), QVariantList{QVariantMap{{QStringLiteral("name"), tr("After %1").arg(title.section(QStringLiteral(" · "), 0, 0))}, | |
| 378 | ✗ | {QStringLiteral("rows"), rows}}}}, | |
| 379 | ✗ | {QStringLiteral("footer"), QString()}, | |
| 380 | ✗ | {QStringLiteral("rect"), QRectF(pane.right() - width - 12, pane.bottom() - height - 12, width, height)}}; | |
| 381 | ✗ | } | |
| 382 |