完成界面搜索框组件,新增插件搜索接口

This commit is contained in:
hewenfei 2023-02-27 09:29:19 +08:00
parent d80deb9e9f
commit 37992ca49d
9 changed files with 232 additions and 57 deletions

View File

@ -16,7 +16,7 @@
* *
*/ */
import QtQuick 2.0 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
@ -25,80 +25,163 @@ import org.ukui.menu.core 1.0
import org.ukui.menu.utils 1.0 import org.ukui.menu.utils 1.0
Item { Item {
id: appPageHeader id: appPageHeaderRoot
property string title: "" property string title: ""
RowLayout { state: "normal"
anchors.fill: parent states: [
anchors.leftMargin: 16 State {
Text { name: "normal"
Layout.fillWidth: true PropertyChanges { target: searchBar; visible: false }
Layout.fillHeight: true PropertyChanges { target: pluginSelectionBar; visible: true }
verticalAlignment: Qt.AlignVCenter StateChangeScript {
text: appPageHeader.title script: {
} sortMenu.sortMenuModel.reactivateProvider();
}
ListView {
Layout.preferredWidth: childrenRect.width
Layout.preferredHeight: 32
Layout.maximumWidth: 68
Layout.alignment: Qt.AlignVCenter
clip: true
spacing: 4
orientation: ListView.Horizontal
model: appPageHeaderUtils.model(PluginGroup.Button)
delegate: Image {
width: height
height: ListView.view ? ListView.view.height : 0
source: model.icon
} }
},
State {
name: "search"
PropertyChanges { target: searchBar; visible: true }
PropertyChanges { target: pluginSelectionBar; visible: false }
} }
]
Row { Item {
Layout.preferredWidth: childrenRect.width id: searchBar
Layout.preferredHeight: 32 width: parent.width
Layout.rightMargin: 8 height: 30
Layout.alignment: Qt.AlignVCenter RowLayout {
anchors.fill: parent
anchors.leftMargin: 15
anchors.rightMargin: 15
spacing: 10
Image { SearchInputBar {
id: providerIcon id: searchInputBar
width: 32 Layout.fillWidth: true
height: width Layout.fillHeight: true
anchors.verticalCenter: parent.verticalCenter radius: 16
source: "image://appicon/ukui-selected" useStyleTransparent: false
onTextChanged: appPageHeaderUtils.startSearch(text);
}
AppControls2.StyleBackground {
Layout.preferredWidth: parent.height
Layout.preferredHeight: parent.height
radius: height / 2
useStyleTransparent: false
Image {
anchors.centerIn: parent
width: 16; height: 16
source: "image://appicon/edit-clear-symbolic"
}
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
sortMenu.sortMenuModel.autoSwitchProvider(); searchInputBar.clear();
appPageHeaderRoot.state = "normal"
}
}
}
}
}
Item {
id: pluginSelectionBar
width: parent.width
height: parent.height
RowLayout {
anchors.fill: parent
anchors.leftMargin: 16
Text {
Layout.fillWidth: true
Layout.fillHeight: true
verticalAlignment: Qt.AlignVCenter
text: appPageHeaderRoot.title
}
ListView {
Layout.preferredWidth: childrenRect.width
Layout.preferredHeight: 32
Layout.maximumWidth: 68
Layout.alignment: Qt.AlignVCenter
clip: true
spacing: 4
orientation: ListView.Horizontal
model: appPageHeaderUtils.model(PluginGroup.Button)
delegate: AppControls2.StyleBackground {
width: height
height: ListView.view ? ListView.view.height : 0
radius: height / 2
useStyleTransparent: false
Image {
width: parent.height / 2
height: parent.height / 2
anchors.centerIn: parent
source: model.icon
}
MouseArea {
anchors.fill: parent
onClicked: {
appPageHeaderRoot.state = "search"
appPageHeaderUtils.activateProvider(model.id);
}
} }
} }
} }
Image { Row {
id: providerSelector Layout.preferredWidth: childrenRect.width
width: 16 Layout.preferredHeight: 32
height: width Layout.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter Layout.alignment: Qt.AlignVCenter
source: "image://appicon/ukui-down.symbolic"
MouseArea { AppControls2.StyleBackground {
anchors.fill: parent width: 32
onClicked: { height: width
sortMenu.show(); radius: height / 2
useStyleTransparent: false
Image {
id: providerIcon
width: parent.height / 2
height: parent.height / 2
anchors.centerIn: parent
source: "image://appicon/ukui-selected"
}
MouseArea {
anchors.fill: parent
onClicked: {
sortMenu.sortMenuModel.autoSwitchProvider();
}
} }
} }
}
function updateProviderIcon() { Image {
providerIcon.source = sortMenu.sortMenuModel.currentProviderIcon(); id: providerSelector
} width: 16
height: width
anchors.verticalCenter: parent.verticalCenter
source: "image://appicon/ukui-down.symbolic"
Component.onCompleted: { MouseArea {
updateProviderIcon(); anchors.fill: parent
sortMenu.sortMenuModel.currentIndexChanged.connect(updateProviderIcon); onClicked: {
sortMenu.show();
}
}
}
function updateProviderIcon() {
providerIcon.source = sortMenu.sortMenuModel.currentProviderIcon();
}
Component.onCompleted: {
updateProviderIcon();
sortMenu.sortMenuModel.currentIndexChanged.connect(updateProviderIcon);
}
} }
} }
} }

View File

@ -0,0 +1,63 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
*/
import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import AppControls2 1.0 as AppControls2
AppControls2.StyleBackground {
readonly property string text: textInput.text;
function clear() {
textInput.clear();
}
RowLayout {
anchors.fill: parent
anchors.rightMargin: parent.radius
Item {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 2
Layout.maximumWidth: parent.height - 2*Layout.margins
Layout.maximumHeight: parent.height
Layout.alignment: Qt.AlignVCenter
Image {
anchors.centerIn: parent
width:16; height: 16
source: "image://appicon/search-symbolic"
}
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
TextInput {
id: textInput
anchors.fill: parent
selectByMouse: true
selectionColor: "red"
verticalAlignment: TextInput.AlignVCenter
font.pixelSize: 14
}
}
}
}

View File

@ -5,3 +5,4 @@ Sidebar 1.0 Sidebar.qml
NormalUI 1.0 NormalUI.qml NormalUI 1.0 NormalUI.qml
FullScreenUI 1.0 FullScreenUI.qml FullScreenUI 1.0 FullScreenUI.qml
AppPageHeader 1.0 AppPageHeader.qml AppPageHeader 1.0 AppPageHeader.qml
SearchInputBar 1.0 SearchInputBar.qml

View File

@ -11,6 +11,7 @@
<file>AppUI/Sidebar.qml</file> <file>AppUI/Sidebar.qml</file>
<file>AppUI/AppList.qml</file> <file>AppUI/AppList.qml</file>
<file>AppUI/AppPageHeader.qml</file> <file>AppUI/AppPageHeader.qml</file>
<file>AppUI/SearchInputBar.qml</file>
<file>AppControls2/qmldir</file> <file>AppControls2/qmldir</file>
<file>AppControls2/App.qml</file> <file>AppControls2/App.qml</file>
<file>AppControls2/ScrollBar.qml</file> <file>AppControls2/ScrollBar.qml</file>

View File

@ -122,4 +122,14 @@ DataProviderManager::~DataProviderManager()
} }
} }
void DataProviderManager::forceUpdate() const
{
m_providers.value(m_activatedPlugin)->forceUpdate();
}
void DataProviderManager::forceUpdate(QString &key) const
{
m_providers.value(m_activatedPlugin)->forceUpdate(key);
}
} // UkuiMenu } // UkuiMenu

View File

@ -50,6 +50,8 @@ public:
QString activatedProvider() const; QString activatedProvider() const;
void activateProvider(const QString &id); void activateProvider(const QString &id);
QVector<DataEntity> data() const; QVector<DataEntity> data() const;
void forceUpdate() const;
void forceUpdate(QString &key) const;
Q_SIGNALS: Q_SIGNALS:
void pluginChanged(const QString &id, PluginGroup::Group group); void pluginChanged(const QString &id, PluginGroup::Group group);

View File

@ -35,7 +35,8 @@ class PluginGroup
public: public:
enum Group { enum Group {
Button = 0, Button = 0,
SortMenuItem SortMenuItem,
Search,
}; };
Q_ENUM(Group) Q_ENUM(Group)
}; };
@ -62,6 +63,7 @@ public:
* dataChange信号 * dataChange信号
*/ */
virtual void forceUpdate() = 0; virtual void forceUpdate() = 0;
virtual void forceUpdate(QString &key) {};
Q_SIGNALS: Q_SIGNALS:
/** /**

View File

@ -38,6 +38,7 @@ public:
void updateCurrentPId(const QString &providerId); void updateCurrentPId(const QString &providerId);
//自动在各个插件之间切换 //自动在各个插件之间切换
Q_INVOKABLE void reactivateProvider();
Q_INVOKABLE void autoSwitchProvider(); Q_INVOKABLE void autoSwitchProvider();
Q_INVOKABLE QString currentProviderIcon(); Q_INVOKABLE QString currentProviderIcon();
@ -141,6 +142,11 @@ QString ProviderModel::currentProviderIcon()
return data(createIndex(m_currentIndex, 0), Icon).toString(); return data(createIndex(m_currentIndex, 0), Icon).toString();
} }
void ProviderModel::reactivateProvider()
{
DataProviderManager::instance()->activateProvider(m_providers.at(m_currentIndex).id);
}
// ====== AppPageHeaderUtils ====== // ====== AppPageHeaderUtils ======
AppPageHeaderUtils::AppPageHeaderUtils(QObject *parent) : QObject(parent) AppPageHeaderUtils::AppPageHeaderUtils(QObject *parent) : QObject(parent)
{ {
@ -174,6 +180,11 @@ void AppPageHeaderUtils::activateProvider(const QString &name)
DataProviderManager::instance()->activateProvider(name); DataProviderManager::instance()->activateProvider(name);
} }
void AppPageHeaderUtils::startSearch(QString key)
{
DataProviderManager::instance()->forceUpdate(key);
}
} // UkuiMenu } // UkuiMenu
#include "app-page-header-utils.moc" #include "app-page-header-utils.moc"

View File

@ -39,6 +39,8 @@ public:
// 获取不同的model // 获取不同的model
Q_INVOKABLE ProviderModel *model(PluginGroup::Group group); Q_INVOKABLE ProviderModel *model(PluginGroup::Group group);
Q_INVOKABLE void startSearch(QString key);
private Q_SLOTS: private Q_SLOTS:
void onPluginChanged(const QString &id, PluginGroup::Group group); void onPluginChanged(const QString &id, PluginGroup::Group group);