From c8cd2fb80ecd64a9cfbed1caff9855794102b537 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 16 Sep 2021 20:24:07 +0200 Subject: Add Hotkey type for defining and displaying shortcuts --- Sidebar.qml | 108 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 56 deletions(-) (limited to 'Sidebar.qml') diff --git a/Sidebar.qml b/Sidebar.qml index 7f391c7..31eeaac 100644 --- a/Sidebar.qml +++ b/Sidebar.qml @@ -97,67 +97,63 @@ Page { anchors.fill: parent // Description box. - ScrollView { + Rectangle { Layout.fillWidth: true Layout.maximumHeight: 100 - ScrollBar.horizontal.policy: ScrollBar.AlwaysOff + Layout.preferredHeight: description.implicitHeight - padding: 0 + border.color: description.activeFocus ? palette.highlight : palette.dark + color: palette.base + radius: 2 - visible: description.enabled - background: Rectangle { - color: palette.base - border.color: description.activeFocus ? palette.highlight : palette.dark - radius: 2 - } - - TextArea { - id: description + ScrollView { + anchors.fill: parent + ScrollBar.horizontal.policy: ScrollBar.AlwaysOff + padding: 0 - placeholderText: qsTr('Description') - padding: filter.padding - leftPadding: filter.leftPadding - selectByMouse: true - wrapMode: Text.Wrap + TextArea { + id: description - onTextChanged: modified = true - KeyNavigation.priority: KeyNavigation.BeforeItem - KeyNavigation.tab: nextItemInFocusChain() + placeholderText: qsTr('Description') + padding: filter.padding + leftPadding: filter.leftPadding + selectByMouse: true + wrapMode: Text.Wrap - Shortcut { - id: shortcutDescription - sequence: 'Ctrl+D' - onActivated: description.forceActiveFocus() - } - Label { - anchors { right: parent.right; bottom: parent.bottom; margins: 4 } - visible: !parent.activeFocus - text: shortcutDescription.nativeText - font.pixelSize: parent.font.pixelSize * 0.75 - color: 'gray' + onTextChanged: modified = true + KeyNavigation.priority: KeyNavigation.BeforeItem + KeyNavigation.tab: nextItemInFocusChain() } } + + Hotkey { + control: description + sequence: 'Ctrl+D' + anchors { right: parent.right; bottom: parent.bottom; margins: 4 } + font.pixelSize: description.font.pixelSize * 0.75 + } } // Filter box. TextField { id: filter + Layout.fillWidth: true placeholderText: qsTr('Filter') + background: Rectangle { + border.color: parent.activeFocus ? palette.highlight : palette.dark + color: palette.base + radius: 2 + } + onTextChanged: eventFilter.setFilter(text) Keys.onEscapePressed: text = '' - Shortcut { - id: shortcutFilter - sequence: 'Ctrl+F' - onActivated: filter.forceActiveFocus() - } - Label { + Hotkey { + control: filter + sequence: StandardKey.Find anchors { right: parent.right; bottom: parent.bottom; margins: 4 } - visible: !parent.activeFocus - text: shortcutFilter.nativeText font.pixelSize: filter.font.pixelSize * 0.75 - color: 'gray' } } @@ -165,15 +161,15 @@ Page { Frame { Layout.fillWidth: true Layout.fillHeight: true - Layout.rightMargin: -control.padding + Layout.rightMargin: -control.padding // fill to window edge for easier scrolling focusPolicy: Qt.StrongFocus + padding: 1 rightPadding: 0 - background: Rectangle { + border.color: parent.activeFocus ? palette.highlight : palette.dark color: 'transparent' - border.color: events.activeFocus ? palette.highlight : palette.dark radius: 2 } @@ -192,19 +188,18 @@ Page { video.seek(event.time) } Keys.forwardTo: control + } - Shortcut { - id: shortcutEvents - sequence: 'Ctrl+E' - onActivated: events.forceActiveFocus() - } - Label { - anchors { right: parent.right; bottom: parent.bottom; margins: 4 } - visible: !parent.activeFocus - text: shortcutEvents.nativeText - font.pixelSize: filter.font.pixelSize * 0.75 - color: 'gray' + Hotkey { + control: events + sequence: 'Ctrl+E' + anchors { + right: parent.right + top: parent.top + margins: 4 + rightMargin: control.padding + anchors.margins } + font.pixelSize: filter.font.pixelSize * 0.75 } } @@ -215,9 +210,9 @@ Page { Layout.fillWidth: true enabled: video.loaded && !events.editing - // Try passing key to each field input in order. - Keys.enabled: enabled + // Try passing key to each tag button in order. Keys.forwardTo: Array.from({ length: buttons.count }, (_, i) => buttons.itemAt(i)) + Keys.enabled: enabled spacing: 5 @@ -237,6 +232,7 @@ Page { implicitWidth: implicitContentWidth + 2*padding onClicked: { + // Create a new event with this tag and current time. const index = eventList.insert(name, video.time) // Reset filter if new event doesn’t match. var row = eventFilter.mapFromSource(eventList.index(index, 0)).row -- cgit v1.3