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

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,9 +25,72 @@ 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: ""
state: "normal"
states: [
State {
name: "normal"
PropertyChanges { target: searchBar; visible: false }
PropertyChanges { target: pluginSelectionBar; visible: true }
StateChangeScript {
script: {
sortMenu.sortMenuModel.reactivateProvider();
}
}
},
State {
name: "search"
PropertyChanges { target: searchBar; visible: true }
PropertyChanges { target: pluginSelectionBar; visible: false }
}
]
Item {
id: searchBar
width: parent.width
height: 30
RowLayout {
anchors.fill: parent
anchors.leftMargin: 15
anchors.rightMargin: 15
spacing: 10
SearchInputBar {
id: searchInputBar
Layout.fillWidth: true
Layout.fillHeight: true
radius: 16
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 {
anchors.fill: parent
onClicked: {
searchInputBar.clear();
appPageHeaderRoot.state = "normal"
}
}
}
}
}
Item {
id: pluginSelectionBar
width: parent.width
height: parent.height
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: 16 anchors.leftMargin: 16
@ -35,7 +98,7 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter
text: appPageHeader.title text: appPageHeaderRoot.title
} }
ListView { ListView {
@ -49,11 +112,25 @@ Item {
orientation: ListView.Horizontal orientation: ListView.Horizontal
model: appPageHeaderUtils.model(PluginGroup.Button) model: appPageHeaderUtils.model(PluginGroup.Button)
delegate: Image { delegate: AppControls2.StyleBackground {
width: height width: height
height: ListView.view ? ListView.view.height : 0 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 source: model.icon
} }
MouseArea {
anchors.fill: parent
onClicked: {
appPageHeaderRoot.state = "search"
appPageHeaderUtils.activateProvider(model.id);
}
}
}
} }
Row { Row {
@ -62,13 +139,18 @@ Item {
Layout.rightMargin: 8 Layout.rightMargin: 8
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Image { AppControls2.StyleBackground {
id: providerIcon
width: 32 width: 32
height: width height: width
anchors.verticalCenter: parent.verticalCenter radius: height / 2
useStyleTransparent: false
Image {
id: providerIcon
width: parent.height / 2
height: parent.height / 2
anchors.centerIn: parent
source: "image://appicon/ukui-selected" source: "image://appicon/ukui-selected"
}
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
@ -102,6 +184,7 @@ Item {
} }
} }
} }
}
Menu { Menu {
id: sortMenu id: sortMenu

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);