From eb1b79fe43a0c8b2e39303b0f0720fdbe92d796c Mon Sep 17 00:00:00 2001 From: qiqi Date: Tue, 23 May 2023 11:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E8=BF=9B=E5=85=A5=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=E6=97=B6=EF=BC=8C=E5=B8=A6=E5=85=A5=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E5=AD=97=E6=AF=8D=EF=BC=9B=E8=A7=A3=E5=86=B3=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E5=92=8C=E6=8C=89=E9=94=AE=E7=84=A6=E7=82=B9?= =?UTF-8?q?=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppControls2/FolderItem.qml | 14 +++++---- qml/AppUI/AppList.qml | 15 +++++++-- qml/AppUI/AppListView.qml | 3 +- qml/AppUI/AppPageHeader.qml | 13 +++++--- qml/AppUI/NormalUI.qml | 8 ++--- qml/AppUI/SearchInputBar.qml | 14 ++++++--- qml/AppUI/Sidebar.qml | 4 +++ qml/extensions/FavoriteExtension.qml | 47 ++++++++++++++++++++++++++-- 8 files changed, 94 insertions(+), 24 deletions(-) diff --git a/qml/AppControls2/FolderItem.qml b/qml/AppControls2/FolderItem.qml index 92c7dc7..dcbb9c7 100644 --- a/qml/AppControls2/FolderItem.qml +++ b/qml/AppControls2/FolderItem.qml @@ -19,6 +19,7 @@ MouseArea { alpha: 0.55 } } + StyleBackground { id: controlBase anchors.fill: parent @@ -84,9 +85,9 @@ MouseArea { selectByMouse: true maximumLength: 14 - onEditingFinished: { - modelManager.getAppModel().renameFolder(id, text); + function editStatusEnd() { control.editStatus = false; + control.focus = true; } function updateTextInputColor() { @@ -94,12 +95,15 @@ MouseArea { selectionColor = themePalette.paletteColor(Palette.Highlight); } + onEditingFinished: { + modelManager.getAppModel().renameFolder(id, text); + textChange.editStatusEnd(); + } Component.onCompleted: { updateTextInputColor(); themePalette.styleColorChanged.connect(updateTextInputColor); forceActiveFocus(); } - Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor); } @@ -120,12 +124,10 @@ MouseArea { onClicked: { textChange.text = name; - control.editStatus = false; + textChange.editStatusEnd(); } } - } - } Loader { diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 2f2882a..2eecaf1 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -27,9 +27,9 @@ Item { id: appListRoot property string title: "" property string idSelect: "" + property bool folderEditStatus: false signal labelItemClicked() - signal openFolderPageSignal(string folderId, string folderName); - + signal openFolderPageSignal(string folderId, string folderName) function labelSelection(labelId) { appListView.view.positionViewAtIndex(appListView.model.getLabelIndex(labelId), ListView.Beginning) } @@ -42,6 +42,16 @@ Item { id: appListView anchors.fill: parent + // 在listview区域,鼠标进出和移动事件都会清空原有的按键焦点 + // 鼠标不移动,原有的鼠标悬浮三态会保留 + onContainsMouseChanged: clearViewFocus() + onPositionChanged: clearViewFocus() + function clearViewFocus() { + if(!folderEditStatus) { + appListView.listFocus = false + } + } + model: modelManager.getAppModel() delegate: Component { Loader { @@ -188,6 +198,7 @@ Item { appListView.model.renameText.disconnect(toEditText); } + onEditStatusChanged: folderEditStatus = editStatus; function toEditText(idOfIndex){ if (id === idOfIndex) { editStatus = true; diff --git a/qml/AppUI/AppListView.qml b/qml/AppUI/AppListView.qml index 05dd6a6..98823c4 100644 --- a/qml/AppUI/AppListView.qml +++ b/qml/AppUI/AppListView.qml @@ -32,7 +32,7 @@ MouseArea { property int itemHeight: 40 hoverEnabled: true clip: true - onContainsMouseChanged: listView.focus = false + AppControls2.StyleBackground { anchors.top: parent.top width: parent.width @@ -57,6 +57,7 @@ MouseArea { highlightMoveDuration: 0 boundsBehavior: Flickable.StopAtBounds ScrollBar.vertical: listViewScrollBar + // 焦点切换后,listView按键导航重新开始 onActiveFocusChanged: currentIndex = 0 onCountChanged: currentIndex = 0 diff --git a/qml/AppUI/AppPageHeader.qml b/qml/AppUI/AppPageHeader.qml index 2c0f149..ea179a8 100644 --- a/qml/AppUI/AppPageHeader.qml +++ b/qml/AppUI/AppPageHeader.qml @@ -26,13 +26,13 @@ import org.ukui.menu.utils 1.0 Item { id: appPageHeaderRoot property string title: "" - required property Item focusToListView + property Item focusToListView property Component content: null clip: true - function changeToSearch() { + function changeToSearch(keyEvent) { if (appPageHeaderRoot.content === null) { - loader.item.state = "search"; + loader.item.changeToSearchState(keyEvent); } } @@ -50,6 +50,11 @@ Item { Item { id: root + function changeToSearchState(keyEvent) { + state = "search"; + searchInputBar.text = keyEvent; + } + state: "normal" states: [ State { @@ -128,7 +133,7 @@ Item { Layout.fillWidth: true Layout.fillHeight: true radius: 16 - keyDownTarget: focusToListView + changeFocusTarget: focusToListView onTextChanged: { if (text === "") { pluginSelectMenu.model.reactivateProvider(); diff --git a/qml/AppUI/NormalUI.qml b/qml/AppUI/NormalUI.qml index 40323c3..a27eced 100644 --- a/qml/AppUI/NormalUI.qml +++ b/qml/AppUI/NormalUI.qml @@ -11,14 +11,14 @@ FocusScope { } function keyPressed(event) { // 任意字符键焦点切换到搜索(0-9 a-z) - if ((0x2f < event.key && event.key < 0x3a )||(0x40 < event.key && event.key < 0x5b)) { + if ((0x2f < event.key && event.key < 0x3a)||(0x40 < event.key && event.key < 0x5b)) { focus = true; - appPage.header.changeToSearch(); + appPage.header.changeToSearch(event.text); // 任意方向键切换至搜索结果 - } else if ( 0x01000011 < event.key && event.key < 0x01000016) { + } else if ((0x01000011 < event.key)&&(event.key < 0x01000016)) { focus = true; - appPage.content.resetFocus(); appPage.content.focus = true; + appPage.content.resetFocus(); } } diff --git a/qml/AppUI/SearchInputBar.qml b/qml/AppUI/SearchInputBar.qml index 74658ef..be9fa96 100644 --- a/qml/AppUI/SearchInputBar.qml +++ b/qml/AppUI/SearchInputBar.qml @@ -23,8 +23,8 @@ import org.ukui.menu.core 1.0 import AppControls2 1.0 as AppControls2 AppControls2.StyleBackground { - property Item keyDownTarget - readonly property string text: textInput.text; + property Item changeFocusTarget + property alias text: textInput.text; alpha: 0.04 useStyleTransparent: false @@ -98,8 +98,14 @@ AppControls2.StyleBackground { font.pointSize: defaultText.font.pointSize focus: parent.visible || mainWindow.isFullScreen - KeyNavigation.down: keyDownTarget - onEditingFinished: KeyNavigation.down = keyDownTarget + activeFocusOnTab: true + function changeFocusToListView() { + if (!mainWindow.isFullScreen) { + changeFocusTarget.focus = true + } + } + onEditingFinished: changeFocusToListView() + Keys.onDownPressed: changeFocusToListView() //字体选中跟随主题高亮 property int textColor: mainWindow.isFullScreen ? Palette.HighlightedText : Palette.Text diff --git a/qml/AppUI/Sidebar.qml b/qml/AppUI/Sidebar.qml index b92edf1..b017a68 100644 --- a/qml/AppUI/Sidebar.qml +++ b/qml/AppUI/Sidebar.qml @@ -99,6 +99,9 @@ Item { onLoaded: { item.send.connect(extensionListView.send); } + Keys.onTabPressed: { + extensionListView.focus = true + } } } @@ -170,6 +173,7 @@ Item { height: ListView.view ? ListView.view.height : 0 activeFocusOnTab: true + KeyNavigation.down: extensionLoader Keys.onPressed: { if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { ListView.view.currentIndex = model.index; diff --git a/qml/extensions/FavoriteExtension.qml b/qml/extensions/FavoriteExtension.qml index 663a841..d1a0669 100644 --- a/qml/extensions/FavoriteExtension.qml +++ b/qml/extensions/FavoriteExtension.qml @@ -53,6 +53,38 @@ UkuiMenuExtension { property int exchangedStartIndex: 0 property int spacing: 4 property int itemHeight: 104 + property int column: Math.floor(width / cellWidth) + + // 按键导航处理(左右键可以循环) + focus: true + onActiveFocusChanged: currentIndex = 0 + onCountChanged: currentIndex = 0 + Keys.onRightPressed: { + if(currentIndex === count - 1) { + currentIndex = 0; + return; + } + currentIndex++; + } + Keys.onLeftPressed: { + if(currentIndex === 0) { + currentIndex = count - 1; + return; + } + currentIndex--; + } + Keys.onDownPressed: { + if(currentIndex > count - 1 - column) { + return; + } + currentIndex = currentIndex + column; + } + Keys.onUpPressed: { + if(currentIndex < column) { + return; + } + currentIndex = currentIndex - column; + } ScrollBar.vertical: AppControls2.ScrollBar { id: scrollBar @@ -73,16 +105,26 @@ UkuiMenuExtension { onEntered: { visualModel.items.move(drag.source.visualIndex, icon.visualIndex) } - Binding { target: icon; property: "visualIndex"; value: visualIndex } + focus: true + Keys.onReturnPressed: { + var data = {"id": model.id}; + send(data); + } + states: State { + when: delegateRoot.activeFocus + PropertyChanges { + target: icon + alpha: 0.6 + } + } AppControls2.StyleBackground { id: icon height: favoriteView.itemHeight; width: height property bool hold: false property int visualIndex: 0 x: 0; y: 0 - radius: 8 useStyleTransparent: false scale: icon.hold ? 1.1 :1.0 @@ -91,7 +133,6 @@ UkuiMenuExtension { Behavior on scale { NumberAnimation { duration: 300; easing.type: Easing.InOutCubic } } - AppControls2.IconLabel { height: icon.height width: icon.width - 14