Keymap: give combos their own tab
Combos move from a chip row under every layer to a Combos tab after the layers. Each result sits on the seam between its two keys, with a dashed line for keys far apart; pointing at a key keeps only its combos bright and spells them out. C opens the tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2a5374936b
commit
806f59d6f8
3 files changed
+175
-61
No files matched your search
+167
-55
@@ -1,5 +1,6 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Shapes
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Ui
|
||||
@@ -20,11 +21,23 @@ Panel {
|
||||
readonly property var layoutKeys: sheet && sheet.layout ? sheet.layout.keys : []
|
||||
readonly property var base: layers.length ? layers[0].keys : []
|
||||
|
||||
// -1 is the overview; otherwise a layer index. Pointing at a tab previews it.
|
||||
// -1 is the overview; otherwise a layer index, and the Combos tab comes
|
||||
// after the last layer. Pointing at a tab previews it.
|
||||
property int view: -1
|
||||
property int preview: -2
|
||||
readonly property int shown: preview > -2 ? preview : view
|
||||
property var highlight: []
|
||||
|
||||
// Combos tab: every combo drawn on the seam between its keys; pointing at a
|
||||
// key keeps only its combos bright.
|
||||
readonly property var allCombos: sheet && sheet.combos ? sheet.combos : []
|
||||
readonly property var layerCombos: sheet && sheet.layerCombos ? sheet.layerCombos : []
|
||||
readonly property bool combosOn: setting("showCombos", true) !== false && (allCombos.length > 0 || layerCombos.length > 0)
|
||||
readonly property int comboTab: layers.length
|
||||
readonly property int lastTab: combosOn ? comboTab : layers.length - 1
|
||||
readonly property bool comboMode: combosOn && shown === comboTab
|
||||
property int comboFocus: -1
|
||||
readonly property var focusCombos: comboFocus < 0 ? [] : allCombos.filter(c => c.keys.indexOf(comboFocus) >= 0)
|
||||
readonly property var highlight: comboMode ? focusCombos.reduce((all, c) => all.concat(c.keys), []) : []
|
||||
|
||||
// Corner of each overview layer (layers 1..4), as in the repo's own drawing.
|
||||
readonly property var places: ["bl", "tr", "tl", "br"]
|
||||
@@ -55,6 +68,8 @@ Panel {
|
||||
// What one key shows in the current view.
|
||||
function cellFor(i) {
|
||||
const b = base[i] || {}
|
||||
if (comboMode)
|
||||
return { t: legend(b), s: "", h: "", kind: "combo", corners: [], tint: -1, holdTint: -1 }
|
||||
const thumb = !!(layoutKeys[i] && layoutKeys[i].thumb)
|
||||
const out = { t: legend(b), s: b.s || "", h: b.h || "", kind: b.type || "", corners: [], tint: -1, holdTint: -1 }
|
||||
if (shown >= 0 && shown < layers.length && shown > 0) {
|
||||
@@ -81,15 +96,15 @@ Panel {
|
||||
}
|
||||
|
||||
readonly property string shownName: shown >= 0 && shown < layers.length ? layers[shown].name : (layers.length ? layers[0].name : "")
|
||||
readonly property var combos: (sheet && sheet.combos ? sheet.combos : []).filter(c => !c.layers.length || c.layers.indexOf(shownName) >= 0)
|
||||
readonly property var layerCombos: sheet && sheet.layerCombos ? sheet.layerCombos : []
|
||||
|
||||
function select(v) {
|
||||
view = Math.max(-1, Math.min(layers.length - 1, v))
|
||||
view = Math.max(-1, Math.min(lastTab, v))
|
||||
preview = -2
|
||||
comboFocus = -1
|
||||
}
|
||||
function showNamed(name) {
|
||||
const i = String(name).toLowerCase() === "overview" ? -1 : layers.findIndex(l => l.name.toLowerCase() === String(name).toLowerCase())
|
||||
const wanted = String(name).toLowerCase()
|
||||
const i = wanted === "overview" ? -1 : wanted === "combos" && combosOn ? comboTab : layers.findIndex(l => l.name.toLowerCase() === wanted)
|
||||
if (i >= -1) select(i)
|
||||
}
|
||||
Connections {
|
||||
@@ -125,7 +140,7 @@ Panel {
|
||||
if (service.wantedView) showNamed(service.wantedView)
|
||||
service.wantedView = ""
|
||||
preview = -2
|
||||
highlight = []
|
||||
comboFocus = -1
|
||||
}
|
||||
}
|
||||
Component.onDestruction: if (opened && service) service.openPanels--
|
||||
@@ -155,14 +170,15 @@ Panel {
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
Keys.onPressed: function(event) {
|
||||
const n = root.layers.length
|
||||
const last = root.lastTab
|
||||
if (event.key === Qt.Key_Escape) root.close()
|
||||
else if (event.key === Qt.Key_Right || event.key === Qt.Key_Tab || event.key === Qt.Key_L)
|
||||
root.select(root.view + 1 >= n ? -1 : root.view + 1)
|
||||
root.select(root.view + 1 > last ? -1 : root.view + 1)
|
||||
else if (event.key === Qt.Key_Left || event.key === Qt.Key_Backtab || event.key === Qt.Key_H)
|
||||
root.select(root.view - 1 < -1 ? n - 1 : root.view - 1)
|
||||
root.select(root.view - 1 < -1 ? last : root.view - 1)
|
||||
else if (event.key === Qt.Key_0 || event.key === Qt.Key_QuoteLeft) root.select(-1)
|
||||
else if (event.key >= Qt.Key_1 && event.key <= Qt.Key_9 && event.key - Qt.Key_1 < n) root.select(event.key - Qt.Key_1)
|
||||
else if (event.key >= Qt.Key_1 && event.key <= Qt.Key_9 && event.key - Qt.Key_1 <= last) root.select(event.key - Qt.Key_1)
|
||||
else if (event.key === Qt.Key_C && root.combosOn) root.select(root.comboTab)
|
||||
else if (event.key === Qt.Key_R && root.service) root.service.refresh(true)
|
||||
else return
|
||||
event.accepted = true
|
||||
@@ -269,13 +285,14 @@ Panel {
|
||||
spacing: Style.spacing.md
|
||||
visible: root.layers.length > 0
|
||||
Repeater {
|
||||
model: root.layers.length + 1
|
||||
model: root.layers.length + 1 + (root.combosOn ? 1 : 0)
|
||||
delegate: Rectangle {
|
||||
id: tab
|
||||
required property int index
|
||||
readonly property int idx: index - 1
|
||||
readonly property bool selected: root.view === idx
|
||||
readonly property color tone: idx < 0 ? Color.accent : root.layerColor(idx)
|
||||
readonly property bool isCombo: idx === root.comboTab
|
||||
readonly property color tone: idx < 0 || isCombo ? Color.accent : root.layerColor(idx)
|
||||
readonly property string place: idx >= 1 && idx <= 4 ? root.places[idx - 1] : idx === 0 ? "c" : ""
|
||||
width: tabRow.implicitWidth + Style.spacing.xxl * 2
|
||||
height: Style.space(30)
|
||||
@@ -292,7 +309,7 @@ Panel {
|
||||
// Mini key: a dot in this layer's corner (centre for the base layer).
|
||||
Rectangle {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: tab.idx >= 0
|
||||
visible: tab.idx >= 0 && !tab.isCombo
|
||||
width: Style.space(13)
|
||||
height: width
|
||||
radius: Style.space(3)
|
||||
@@ -308,6 +325,23 @@ Panel {
|
||||
y: tab.place === "tl" || tab.place === "tr" ? Style.space(2) : tab.place === "bl" || tab.place === "br" ? parent.height - height - Style.space(2) : (parent.height - height) / 2
|
||||
}
|
||||
}
|
||||
// Combos: a little result badge, as drawn on the board.
|
||||
Rectangle {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: tab.isCombo
|
||||
width: Style.space(14)
|
||||
height: width
|
||||
radius: Style.space(4)
|
||||
color: Color.accent
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "+"
|
||||
color: Color.accentText
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.bodySmall
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: tab.idx < 0
|
||||
@@ -318,7 +352,7 @@ Panel {
|
||||
}
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: tab.idx < 0 ? "Overview" : root.layers[tab.idx].name
|
||||
text: tab.idx < 0 ? "Overview" : tab.isCombo ? "Combos" : root.layers[tab.idx] ? root.layers[tab.idx].name : ""
|
||||
color: tab.selected ? Color.foreground : Qt.alpha(Color.foreground, 0.75)
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.body
|
||||
@@ -378,7 +412,8 @@ Panel {
|
||||
required property int index
|
||||
readonly property var pos: root.layoutKeys[index]
|
||||
readonly property var cell: root.cells[index] || ({ t: "", s: "", h: "", kind: "", corners: [], tint: -1, holdTint: -1 })
|
||||
readonly property bool dim: cell.kind === "trans" || cell.kind === "blank"
|
||||
readonly property bool dim: cell.kind === "trans" || cell.kind === "blank" || cell.kind === "combo"
|
||||
readonly property bool inCombo: root.comboMode && root.allCombos.some(c => c.keys.indexOf(index) >= 0)
|
||||
readonly property bool lit: root.highlight.indexOf(index) >= 0
|
||||
readonly property color tone: cell.tint > 0 ? root.layerColor(cell.tint) : Color.foreground
|
||||
readonly property bool toned: cell.tint > 0 && !dim
|
||||
@@ -395,21 +430,23 @@ Panel {
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: key.cell.kind === "held" ? Qt.alpha(key.tone, 0.42)
|
||||
color: key.lit ? Qt.alpha(Color.accent, 0.24)
|
||||
: key.cell.kind === "held" ? Qt.alpha(key.tone, 0.42)
|
||||
: key.toned ? Qt.alpha(key.tone, 0.24)
|
||||
: key.dim ? Qt.alpha(Color.foreground, 0.025) : Qt.alpha(Color.foreground, 0.09)
|
||||
Behavior on color { ColorAnimation { duration: 140 } }
|
||||
}
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: key.cell.kind === "held" ? Qt.alpha(key.tone, 0.28)
|
||||
color: key.lit ? Qt.alpha(Color.accent, 0.12)
|
||||
: key.cell.kind === "held" ? Qt.alpha(key.tone, 0.28)
|
||||
: key.toned ? Qt.alpha(key.tone, 0.13)
|
||||
: key.dim ? Qt.alpha(Color.foreground, 0.015) : Qt.alpha(Color.foreground, 0.045)
|
||||
Behavior on color { ColorAnimation { duration: 140 } }
|
||||
}
|
||||
}
|
||||
border.width: key.lit ? 2 : 1
|
||||
border.color: key.lit ? Color.accent
|
||||
border.width: 1
|
||||
border.color: key.lit ? Qt.alpha(Color.accent, 0.7)
|
||||
: key.toned || key.cell.kind === "held" ? Qt.alpha(key.tone, 0.5)
|
||||
: Qt.alpha(Color.foreground, key.dim ? 0.05 : 0.1)
|
||||
Behavior on border.color { ColorAnimation { duration: 140 } }
|
||||
@@ -442,8 +479,9 @@ Panel {
|
||||
maximumLineCount: 2
|
||||
elide: Text.ElideRight
|
||||
lineHeight: 0.9
|
||||
color: key.lit ? Color.accent
|
||||
color: key.lit ? Color.foreground
|
||||
: key.cell.kind === "held" ? key.tone
|
||||
: key.cell.kind === "combo" ? Qt.alpha(Color.foreground, root.comboFocus >= 0 ? 0.25 : 0.45)
|
||||
: key.dim ? Qt.alpha(Color.foreground, 0.22)
|
||||
: key.toned ? key.tone : Color.foreground
|
||||
font.family: Style.font.family
|
||||
@@ -468,6 +506,16 @@ Panel {
|
||||
font.bold: key.cell.holdTint > 0
|
||||
}
|
||||
|
||||
// Combos tab: pointing at a key keeps only its combos bright.
|
||||
HoverHandler {
|
||||
enabled: key.inCombo
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onHoveredChanged: {
|
||||
if (hovered) root.comboFocus = key.index
|
||||
else if (root.comboFocus === key.index) root.comboFocus = -1
|
||||
}
|
||||
}
|
||||
|
||||
// Overview: the other layers in the corners.
|
||||
Repeater {
|
||||
model: key.cell.corners
|
||||
@@ -489,34 +537,100 @@ Panel {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Combos tab: each result on the seam between its two keys; keys
|
||||
// far apart get a dashed line.
|
||||
Repeater {
|
||||
model: root.comboMode ? root.allCombos : []
|
||||
delegate: Item {
|
||||
id: combo
|
||||
required property var modelData
|
||||
readonly property var pa: root.layoutKeys[modelData.keys[0]] || ({ x: 0, y: 0 })
|
||||
readonly property var pb: root.layoutKeys[modelData.keys[modelData.keys.length - 1]] || ({ x: 0, y: 0 })
|
||||
readonly property real ax: (pa.x + 0.5) * root.unit
|
||||
readonly property real ay: (pa.y + 0.5) * root.unit
|
||||
readonly property real bx: (pb.x + 0.5) * root.unit
|
||||
readonly property real by: (pb.y + 0.5) * root.unit
|
||||
readonly property bool far: Math.hypot(pa.x - pb.x, pa.y - pb.y) > 1.6
|
||||
readonly property real lift: far ? -root.unit * 0.55 : 0
|
||||
readonly property bool on: root.comboFocus < 0 || modelData.keys.indexOf(root.comboFocus) >= 0
|
||||
anchors.fill: parent
|
||||
z: on && root.comboFocus >= 0 ? 3 : 2
|
||||
opacity: on ? 1 : 0.12
|
||||
Behavior on opacity { NumberAnimation { duration: 120 } }
|
||||
|
||||
Shape {
|
||||
anchors.fill: parent
|
||||
visible: combo.far
|
||||
preferredRendererType: Shape.CurveRenderer
|
||||
ShapePath {
|
||||
strokeColor: Qt.alpha(Color.accent, 0.6)
|
||||
strokeWidth: 1.5
|
||||
fillColor: "transparent"
|
||||
strokeStyle: ShapePath.DashLine
|
||||
dashPattern: [3, 3]
|
||||
startX: combo.ax
|
||||
startY: combo.ay
|
||||
PathQuad {
|
||||
controlX: (combo.ax + combo.bx) / 2
|
||||
controlY: (combo.ay + combo.by) / 2 + combo.lift
|
||||
x: combo.bx
|
||||
y: combo.by
|
||||
}
|
||||
}
|
||||
}
|
||||
Repeater {
|
||||
model: combo.far ? [[combo.ax, combo.ay], [combo.bx, combo.by]] : []
|
||||
delegate: Rectangle {
|
||||
required property var modelData
|
||||
width: Math.max(5, Math.round(root.unit * 0.09))
|
||||
height: width
|
||||
radius: width / 2
|
||||
x: modelData[0] - width / 2
|
||||
y: modelData[1] - height / 2
|
||||
color: Color.accent
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
readonly property bool wide: String(combo.modelData.legend).length > 2
|
||||
height: Math.round(root.unit * 0.36)
|
||||
width: Math.max(height, badgeText.implicitWidth + Math.round(root.unit * 0.18))
|
||||
x: (combo.ax + combo.bx) / 2 - width / 2
|
||||
y: (combo.ay + combo.by) / 2 + combo.lift / 2 - height / 2
|
||||
radius: Math.round(height * 0.3)
|
||||
color: combo.far ? Color.background : Color.accent
|
||||
border.width: combo.far ? 1 : 2
|
||||
border.color: combo.far ? Qt.alpha(Color.accent, 0.6) : Qt.rgba(0, 0, 0, 0.35)
|
||||
scale: combo.on && root.comboFocus >= 0 ? 1.15 : 1
|
||||
Behavior on scale { NumberAnimation { duration: 120 } }
|
||||
Text {
|
||||
id: badgeText
|
||||
anchors.centerIn: parent
|
||||
text: combo.modelData.legend || "?"
|
||||
color: combo.far ? Color.accent : Color.accentText
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Math.round(root.unit * (parent.wide ? 0.16 : 0.22))
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combos for the layer on screen, and layers you reach by holding two.
|
||||
Column {
|
||||
// Combos tab: what the key you point at makes, or the layer combos.
|
||||
Item {
|
||||
width: parent.width
|
||||
spacing: Style.spacing.lg
|
||||
visible: root.setting("showCombos", true) !== false && (root.combos.length > 0 || root.layerCombos.length > 0)
|
||||
height: Style.space(28)
|
||||
visible: root.comboMode
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: 1
|
||||
color: Qt.alpha(Color.foreground, 0.07)
|
||||
}
|
||||
Text {
|
||||
text: "COMBOS" + (root.shown > 0 ? " · " + root.shownName.toUpperCase() : "")
|
||||
color: Color.muted
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.caption
|
||||
font.letterSpacing: 1.2
|
||||
font.bold: true
|
||||
}
|
||||
Flow {
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: parent.width
|
||||
spacing: Style.spacing.md
|
||||
|
||||
Repeater {
|
||||
model: root.layerCombos
|
||||
model: root.comboFocus < 0 ? root.layerCombos : []
|
||||
delegate: Rectangle {
|
||||
id: lchip
|
||||
required property var modelData
|
||||
@@ -564,7 +678,6 @@ Panel {
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.select(root.layerIndex(lchip.modelData.layer))
|
||||
}
|
||||
@@ -572,17 +685,16 @@ Panel {
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: root.combos
|
||||
model: root.focusCombos
|
||||
delegate: Rectangle {
|
||||
id: chip
|
||||
required property var modelData
|
||||
width: crow.implicitWidth + Style.spacing.xl * 2
|
||||
height: Style.space(28)
|
||||
radius: Style.space(8)
|
||||
color: chipMouse.containsMouse ? Qt.alpha(Color.accent, 0.14) : Qt.alpha(Color.foreground, 0.04)
|
||||
color: Qt.alpha(Color.accent, 0.1)
|
||||
border.width: 1
|
||||
border.color: chipMouse.containsMouse ? Qt.alpha(Color.accent, 0.5) : Qt.alpha(Color.foreground, 0.08)
|
||||
Behavior on color { ColorAnimation { duration: 100 } }
|
||||
border.color: Qt.alpha(Color.accent, 0.4)
|
||||
Row {
|
||||
id: crow
|
||||
anchors.centerIn: parent
|
||||
@@ -634,31 +746,31 @@ Panel {
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: chip.modelData.legend || "?"
|
||||
color: chipMouse.containsMouse ? Color.accent : Color.foreground
|
||||
color: Color.accent
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.body
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: chipMouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onContainsMouseChanged: {
|
||||
if (containsMouse) root.highlight = chip.modelData.keys
|
||||
else if (root.highlight === chip.modelData.keys) root.highlight = []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: root.comboFocus < 0
|
||||
text: "Point at a key to see only its combos"
|
||||
color: Color.muted
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.bodySmall
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
width: parent.width
|
||||
visible: root.setting("showHints", true) !== false
|
||||
horizontalAlignment: Text.AlignRight
|
||||
text: "Arrow keys or 0–" + Math.min(9, root.layers.length) + " switch layers · R refresh · checks the repo every " + (root.service ? root.service.checkMinutes : 2) + " min"
|
||||
text: "Arrow keys or 0–" + Math.min(9, root.lastTab + 1) + " switch tabs · " + (root.combosOn ? "C combos · " : "") + "R refresh · checks the repo every " + (root.service ? root.service.checkMinutes : 2) + " min"
|
||||
color: Qt.alpha(Color.foreground, 0.32)
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.caption
|
||||
|
||||
Reference in new issue
Block a user