From 1c86a7a981b76053ca826c703d88e8dde58a2fa4 Mon Sep 17 00:00:00 2001 From: youdiansaodongxi Date: Mon, 4 Dec 2023 10:03:41 +0800 Subject: [PATCH] feat(ukui-menu): Change the style of the classification function button --- qml/AppUI/AppPageHeader.qml | 73 +-------- qml/AppUI/FullScreenHeader.qml | 20 +-- qml/AppUI/PluginSelectButton.qml | 121 ++++++++++++++ qml/AppUI/PluginSelectMenu.qml | 151 ------------------ qml/AppUI/qmldir | 2 +- qml/qml.qrc | 2 +- src/appdata/data-provider-manager.cpp | 7 +- src/appdata/plugin/all-app-data-provider.cpp | 2 +- src/appdata/plugin/app-letter-sort-plugin.cpp | 2 +- src/utils/app-page-header-utils.cpp | 49 ++---- 10 files changed, 150 insertions(+), 279 deletions(-) create mode 100644 qml/AppUI/PluginSelectButton.qml delete mode 100644 qml/AppUI/PluginSelectMenu.qml diff --git a/qml/AppUI/AppPageHeader.qml b/qml/AppUI/AppPageHeader.qml index 38b4f3b..e2c1f00 100644 --- a/qml/AppUI/AppPageHeader.qml +++ b/qml/AppUI/AppPageHeader.qml @@ -30,12 +30,6 @@ Item { property Component content: null clip: true - function changeToSearch(keyEvent) { - if (appPageHeaderRoot.content === null) { - loader.item.changeToSearchState(keyEvent); - } - } - Loader { id: loader anchors.fill: parent @@ -50,65 +44,6 @@ Item { Item { id: root - Item { - id: searchBar - width: parent.width; height: 30 - Component.onCompleted: { - visible = false; - mainWindow.visibleChanged.connect(searchBarHide); - } - Component.onDestruction: mainWindow.visibleChanged.disconnect(searchBarHide); - - function searchBarHide() { - if (!mainWindow.visible) { - root.state = "normal" - } - } - - RowLayout { - anchors.fill: parent - anchors.leftMargin: 15 - anchors.rightMargin: 15 - spacing: 10 - - SearchInputBar { - id: searchInputBar - property string providerId: "" - - Layout.fillWidth: true - Layout.fillHeight: true - radius: 16 - changeFocusTarget: focusToPageContent - onTextChanged: { - if (text === "") { - pluginSelectMenu.model.reactivateProvider(); - } else { - appPageHeaderUtils.activateProvider(providerId); - appPageHeaderUtils.startSearch(text); - } - } - } - - AppControls2.RoundButton { - Layout.preferredWidth: parent.height; Layout.preferredHeight: parent.height - buttonIcon: "image://appicon/edit-clear-symbolic" - activeFocusOnTab: true - - onClicked: { - normalUI.focusToFalse(); - searchInputBar.clear(); - root.state = "normal"; - } - Keys.onPressed: { - if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { - searchInputBar.clear(); - root.state = "normal"; - } - } - } - } - } - Item { id: pluginSelectionBar width: parent.width @@ -125,12 +60,12 @@ Item { font.bold: true } - PluginSelectMenu { - id: pluginSelectMenu - Layout.preferredWidth: childrenRect.width + PluginSelectButton { + id: pluginSelectButton + Layout.preferredWidth: 64 Layout.preferredHeight: 32 Layout.maximumHeight: 32 - Layout.minimumWidth: 32 + Layout.minimumWidth: 64 Layout.rightMargin: 8 Layout.alignment: Qt.AlignVCenter } diff --git a/qml/AppUI/FullScreenHeader.qml b/qml/AppUI/FullScreenHeader.qml index 39ac80f..566f5bc 100644 --- a/qml/AppUI/FullScreenHeader.qml +++ b/qml/AppUI/FullScreenHeader.qml @@ -9,6 +9,15 @@ Item { clip: true property alias searchOpacity: searchInputBar.opacity property alias searchText: searchInputBar.text + + PluginSelectButton { + id: pluginSelectButton + anchors.left: parent.left + anchors.leftMargin: 72 + anchors.verticalCenter: parent.verticalCenter + height: 32; width: 64 + } + SearchInputBar { id: searchInputBar width: 372; height: 36 @@ -18,7 +27,7 @@ Item { onTextChanged: { if (text === "") { - pluginSelectMenu.model.reactivateProvider(); + pluginSelectButton.model.reactivateProvider(); } else { appPageHeaderUtils.model(PluginGroup.Button).reactivateProvider(); appPageHeaderUtils.startSearch(text); @@ -29,15 +38,6 @@ Item { } } - PluginSelectMenu { - id: pluginSelectMenu - anchors.right: parent.right - anchors.rightMargin: 72 // 48+24 - anchors.verticalCenter: parent.verticalCenter - height: 48; width: 72 // 48+16+8 - spacing: 8 - } - AppControls2.StyleBackground { width: 48; height: width radius: 4 diff --git a/qml/AppUI/PluginSelectButton.qml b/qml/AppUI/PluginSelectButton.qml new file mode 100644 index 0000000..bd09a5a --- /dev/null +++ b/qml/AppUI/PluginSelectButton.qml @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2023, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +import QtQuick 2.12 +import QtQuick.Layouts 1.12 +import QtQuick.Controls 2.12 + +import AppControls2 1.0 as AppControls2 +import org.ukui.menu.core 1.0 +import org.ukui.menu.utils 1.0 +import org.ukui.quick.items 1.0 as UkuiItems + +UkuiItems.StyleBackground { + useStyleTransparency: false + paletteRole: UkuiItems.Theme.Text + radius: childrenRect.width / 2 + alpha: 0.06 + + + function resetFocus() { + if(!mainWindow.isFullScreen) { + normalUI.focusToFalse(); + } + } + + RowLayout { + id: pluginSortButtonRoot + property int currentId: 0 + anchors.fill: parent + anchors.topMargin: 2 + anchors.bottomMargin: 2 + anchors.leftMargin: 2 + anchors.rightMargin: 2 + property var model: appPageHeaderUtils.model(PluginGroup.SortMenuItem) + spacing: 4 + + UkuiItems.Button { + id: pluginLetterSortButton + + Layout.fillHeight: true + Layout.fillWidth: true + Layout.maximumWidth: height + activeFocusOnTab: true + ToolTip.delay: 500 + ToolTip.text: qsTr("Letter Sort") + ToolTip.visible: containsMouse + + background.radius: width / 2 + icon.mode: parent.currentId === 0 ? mainWindow.isFullScreen ? UkuiItems.Icon.AutoHighlight : UkuiItems.Icon.Normal : UkuiItems.Icon.Disabled + icon.source: pluginSortButtonRoot.model.getProviderIcon(0); + background.paletteRole: UkuiItems.Theme.Light + background.alpha: parent.currentId === 0 ? 0.7 : 0 + + onClicked: { + resetFocus(); + pluginSortButtonRoot.model.changeProvider(0); + } + Keys.onPressed: { + if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { + pluginSortButtonRoot.model.changeProvider(0); + } + } + } + + UkuiItems.Button { + id: pluginCateGoryButton + + Layout.fillHeight: true + Layout.fillWidth: true + Layout.maximumWidth: height + activeFocusOnTab: true + ToolTip.delay: 500 + ToolTip.text: qsTr("Category") + ToolTip.visible: containsMouse + + background.radius: width / 2 + icon.mode: parent.currentId === 1 ? mainWindow.isFullScreen ? UkuiItems.Icon.AutoHighlight : UkuiItems.Icon.Normal : UkuiItems.Icon.Disabled + icon.source: pluginSortButtonRoot.model.getProviderIcon(1); + background.paletteRole: UkuiItems.Theme.Light + background.alpha: parent.currentId === 1 ? 0.7 : 0 + + onClicked: { + resetFocus(); + pluginSortButtonRoot.model.changeProvider(1); + } + Keys.onPressed: { + if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { + pluginSortButtonRoot.model.changeProvider(1); + } + } + } + + Component.onCompleted: { + updateProviderId(); + pluginSortButtonRoot.model.currentIndexChanged.connect(updateProviderId); + } + + Component.onDestruction: { + pluginSortButtonRoot.model.currentIndexChanged.disconnect(updateProviderId); + } + + function updateProviderId() { + currentId = pluginSortButtonRoot.model.currentProviderId(); + } + } +} diff --git a/qml/AppUI/PluginSelectMenu.qml b/qml/AppUI/PluginSelectMenu.qml deleted file mode 100644 index d6673dd..0000000 --- a/qml/AppUI/PluginSelectMenu.qml +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) 2023, KylinSoft Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -import QtQuick 2.12 -import QtQuick.Layouts 1.12 -import QtQuick.Controls 2.12 - -import AppControls2 1.0 as AppControls2 -import org.ukui.menu.core 1.0 -import org.ukui.menu.utils 1.0 - -RowLayout { - id: pluginSelectMenuRoot - property var model: appPageHeaderUtils.model(PluginGroup.SortMenuItem) - spacing: 2 - function resetFocus() { - if(!mainWindow.isFullScreen) { - normalUI.focusToFalse(); - } - } - - AppControls2.RoundButton { - id: pluginSelectButton - Layout.fillHeight: true - Layout.fillWidth: true - Layout.maximumWidth: height - activeFocusOnTab: true - ToolTip.delay: 500 - ToolTip.text: qsTr("Switch Sort Type") - ToolTip.visible: containsMouse - - highlight: mainWindow.isFullScreen - autoHighLight: !mainWindow.isFullScreen - buttonIcon: "image://appicon/ukui-selected" - onClicked: { - resetFocus(); - pluginSelectMenuRoot.model.autoSwitchProvider(); - } - Keys.onPressed: { - if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { - pluginSelectMenuRoot.model.autoSwitchProvider(); - } - } - } - - MouseArea { - id: sortMenuMouseArea - Layout.alignment: Qt.AlignVCenter - Layout.fillWidth: true - Layout.fillHeight: true - Layout.maximumWidth: 16 - Layout.maximumHeight: 16 - ToolTip.delay: 500 - ToolTip.text: qsTr("Sort Type Options") - ToolTip.visible: containsMouse - hoverEnabled: true - - activeFocusOnTab: true - Keys.onPressed: { - if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { - sortMenuClicked(); - } - } - onClicked: { - resetFocus(); - sortMenuClicked(); - } - function sortMenuClicked() { - if(sortMenuSelector.state === "sortMenuClose") { - sortMenuSelector.state = "sortMenuOpen"; - } - var pressY = sortMenuMouseArea.mapToGlobal(0, 0).y; - var pressX = sortMenuMouseArea.mapToGlobal(0, 0).x; - pluginSelectMenuRoot.model.openMenu(pluginSelectButton.height - y - mouseY + 8, pressX, pressY); - } - - AppControls2.StyleBackground { - anchors.fill: parent - useStyleTransparent: false - paletteRole: Palette.Highlight - alpha: 0 - borderColor: Palette.Highlight - border.width: sortMenuMouseArea.activeFocus ? 2 : 0 - } - - ThemeIcon { - id: sortMenuSelector - anchors.fill: parent - source: "image://appicon/ukui-up-symbolic" - opacity: 0.5 - highLight: mainWindow.isFullScreen - autoHighLight: !mainWindow.isFullScreen - state: "sortMenuClose" - - states: [ - State { - name: "sortMenuOpen" - PropertyChanges { target: sortMenuSelector; rotation: 0 } - }, - State { - name: "sortMenuClose" - PropertyChanges { target: sortMenuSelector; rotation: 180 } - } - ] - transitions: [ - Transition { - to: "sortMenuOpen" - RotationAnimation { duration: 100; direction: RotationAnimation.Counterclockwise} - }, - Transition { - to: "sortMenuClose" - RotationAnimation { duration: 100; direction: RotationAnimation.Clockwise } - } - ] - - Component.onCompleted: { - updateProviderIcon(); - pluginSelectMenuRoot.model.currentIndexChanged.connect(updateProviderIcon); - pluginSelectMenuRoot.model.menuClosed.connect(changeMenuStatus); - } - - Component.onDestruction: { - pluginSelectMenuRoot.model.currentIndexChanged.disconnect(updateProviderIcon); - pluginSelectMenuRoot.model.menuClosed.disconnect(changeMenuStatus); - } - - function updateProviderIcon() { - pluginSelectButton.buttonIcon = pluginSelectMenuRoot.model.currentProviderIcon(); - } - - function changeMenuStatus() { - sortMenuSelector.state = "sortMenuClose"; - } - } - } -} diff --git a/qml/AppUI/qmldir b/qml/AppUI/qmldir index 8d5cdc3..edf547f 100644 --- a/qml/AppUI/qmldir +++ b/qml/AppUI/qmldir @@ -8,7 +8,7 @@ FullScreenUI 1.0 FullScreenUI.qml AppPageHeader 1.0 AppPageHeader.qml AppListView 1.0 AppListView.qml SearchInputBar 1.0 SearchInputBar.qml -PluginSelectMenu 1.0 PluginSelectMenu.qml +PluginSelectButton 1.0 PluginSelectButton.qml FullScreenHeader 1.0 FullScreenHeader.qml FullScreenContent 1.0 FullScreenContent.qml FullScreenFooter 1.0 FullScreenFooter.qml diff --git a/qml/qml.qrc b/qml/qml.qrc index 2522c60..61faa3d 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -29,7 +29,7 @@ AppControls2/FolderIcon.qml AppUI/SelectionPage.qml AppUI/AppPageContent.qml - AppUI/PluginSelectMenu.qml + AppUI/PluginSelectButton.qml AppUI/EditText.qml AppUI/FullScreenFolder.qml AppUI/AppPageSearch.qml diff --git a/src/appdata/data-provider-manager.cpp b/src/appdata/data-provider-manager.cpp index 85dcf74..2e617c3 100644 --- a/src/appdata/data-provider-manager.cpp +++ b/src/appdata/data-provider-manager.cpp @@ -44,10 +44,6 @@ DataProviderManager::DataProviderManager() void DataProviderManager::initProviders() { - auto *allProvider = new AllAppDataProvider; - connect(this, &DataProviderManager::toUpdate, allProvider, &AllAppDataProvider::update); - registerProvider(allProvider); - auto *search = new AppSearchPlugin; connect(this, &DataProviderManager::toUpdate, search, &AppSearchPlugin::update); registerProvider(search); @@ -60,8 +56,7 @@ void DataProviderManager::initProviders() connect(this, &DataProviderManager::toUpdate, sort, &AppLetterSortPlugin::update); registerProvider(sort); - activateProvider(allProvider->id(), false); - allProvider->moveToThread(&m_worker); + activateProvider(sort->id(), false); search->moveToThread(&m_worker); category->moveToThread(&m_worker); sort->moveToThread(&m_worker); diff --git a/src/appdata/plugin/all-app-data-provider.cpp b/src/appdata/plugin/all-app-data-provider.cpp index 3cbaabd..209bbf8 100644 --- a/src/appdata/plugin/all-app-data-provider.cpp +++ b/src/appdata/plugin/all-app-data-provider.cpp @@ -41,7 +41,7 @@ AllAppDataProvider::AllAppDataProvider() : DataProviderPluginIFace() int AllAppDataProvider::index() { - return 0; + return 2; } QString AllAppDataProvider::id() diff --git a/src/appdata/plugin/app-letter-sort-plugin.cpp b/src/appdata/plugin/app-letter-sort-plugin.cpp index c158a25..5612102 100644 --- a/src/appdata/plugin/app-letter-sort-plugin.cpp +++ b/src/appdata/plugin/app-letter-sort-plugin.cpp @@ -33,7 +33,7 @@ AppLetterSortPlugin::AppLetterSortPlugin() int AppLetterSortPlugin::index() { - return 2; + return 0; } QString AppLetterSortPlugin::id() diff --git a/src/utils/app-page-header-utils.cpp b/src/utils/app-page-header-utils.cpp index 6737d9f..1083dc3 100644 --- a/src/utils/app-page-header-utils.cpp +++ b/src/utils/app-page-header-utils.cpp @@ -39,12 +39,11 @@ public: QHash roleNames() const override; void updateCurrentPId(const QString &providerId); - //自动在各个插件之间切换 + //在各个插件之间切换 Q_INVOKABLE void reactivateProvider(); - Q_INVOKABLE void autoSwitchProvider(); - Q_INVOKABLE QString currentProviderIcon(); - - Q_INVOKABLE void openMenu(int offset, int mouseX, int mouseY); + Q_INVOKABLE void changeProvider(int i); + Q_INVOKABLE QString getProviderIcon(int i); + Q_INVOKABLE int currentProviderId(); Q_SIGNALS: void currentIndexChanged(); @@ -137,47 +136,19 @@ int ProviderModel::indexOfProvider(const QString &providerId) return -1; } -void ProviderModel::autoSwitchProvider() +void ProviderModel::changeProvider(int i) { - m_currentIndex = (m_currentIndex + 1) % m_providers.size(); - DataProviderManager::instance()->activateProvider(m_providers.at(m_currentIndex).id); + DataProviderManager::instance()->activateProvider(m_providers.at(i).id); } -QString ProviderModel::currentProviderIcon() +QString ProviderModel::getProviderIcon(int i) { - return data(createIndex(m_currentIndex, 0), Icon).toString(); + return data(createIndex(i, 0), Icon).toString(); } -void ProviderModel::openMenu(int offset, int mouseX, int mouseY) +int ProviderModel::currentProviderId() { - if (m_menu) { - m_menu.data()->close(); - return; - } - - QMenu *menu = new QMenu; - menu->setAttribute(Qt::WA_DeleteOnClose); - - if (m_providers.isEmpty()) { - return; - } - - for (const ProviderInfo &info : m_providers) { - QAction *action = new QAction(info.name, menu); - action->setCheckable(true); - connect(action, &QAction::triggered, menu, [info]() { - DataProviderManager::instance()->activateProvider(info.id); - }); - menu->addAction(action); - } - - menu->actions().at(m_currentIndex)->setChecked(true); - int x = mouseX - menu->sizeHint().width(); - int y = mouseY + offset; - - m_menu = menu; - connect(menu, &QMenu::aboutToHide, this, &ProviderModel::menuClosed); - menu->popup(QPoint(x, y)); + return m_currentIndex; } void ProviderModel::reactivateProvider()