diff --git a/qml/AppUI/AppPageHeader.qml b/qml/AppUI/AppPageHeader.qml
index e00a6f0..15433b2 100644
--- a/qml/AppUI/AppPageHeader.qml
+++ b/qml/AppUI/AppPageHeader.qml
@@ -16,7 +16,7 @@
*
*/
-import QtQuick 2.0
+import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.5
@@ -25,80 +25,163 @@ import org.ukui.menu.core 1.0
import org.ukui.menu.utils 1.0
Item {
- id: appPageHeader
+ id: appPageHeaderRoot
property string title: ""
- RowLayout {
- anchors.fill: parent
- anchors.leftMargin: 16
- Text {
- Layout.fillWidth: true
- Layout.fillHeight: true
- verticalAlignment: Qt.AlignVCenter
- text: appPageHeader.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: Image {
- width: height
- height: ListView.view ? ListView.view.height : 0
- source: model.icon
+ 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 }
}
+ ]
- Row {
- Layout.preferredWidth: childrenRect.width
- Layout.preferredHeight: 32
- Layout.rightMargin: 8
- Layout.alignment: Qt.AlignVCenter
+ Item {
+ id: searchBar
+ width: parent.width
+ height: 30
+ RowLayout {
+ anchors.fill: parent
+ anchors.leftMargin: 15
+ anchors.rightMargin: 15
+ spacing: 10
- Image {
- id: providerIcon
- width: 32
- height: width
- anchors.verticalCenter: parent.verticalCenter
- source: "image://appicon/ukui-selected"
+ 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: {
- 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 {
- id: providerSelector
- width: 16
- height: width
- anchors.verticalCenter: parent.verticalCenter
- source: "image://appicon/ukui-down.symbolic"
+ Row {
+ Layout.preferredWidth: childrenRect.width
+ Layout.preferredHeight: 32
+ Layout.rightMargin: 8
+ Layout.alignment: Qt.AlignVCenter
- MouseArea {
- anchors.fill: parent
- onClicked: {
- sortMenu.show();
+ AppControls2.StyleBackground {
+ width: 32
+ height: width
+ 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() {
- providerIcon.source = sortMenu.sortMenuModel.currentProviderIcon();
- }
+ Image {
+ id: providerSelector
+ width: 16
+ height: width
+ anchors.verticalCenter: parent.verticalCenter
+ source: "image://appicon/ukui-down.symbolic"
- Component.onCompleted: {
- updateProviderIcon();
- sortMenu.sortMenuModel.currentIndexChanged.connect(updateProviderIcon);
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ sortMenu.show();
+ }
+ }
+ }
+
+ function updateProviderIcon() {
+ providerIcon.source = sortMenu.sortMenuModel.currentProviderIcon();
+ }
+
+ Component.onCompleted: {
+ updateProviderIcon();
+ sortMenu.sortMenuModel.currentIndexChanged.connect(updateProviderIcon);
+ }
}
}
}
diff --git a/qml/AppUI/SearchInputBar.qml b/qml/AppUI/SearchInputBar.qml
new file mode 100644
index 0000000..34400f4
--- /dev/null
+++ b/qml/AppUI/SearchInputBar.qml
@@ -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 .
+ *
+ */
+
+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
+ }
+ }
+ }
+}
diff --git a/qml/AppUI/qmldir b/qml/AppUI/qmldir
index 9c5c00f..ab3bfa3 100644
--- a/qml/AppUI/qmldir
+++ b/qml/AppUI/qmldir
@@ -5,3 +5,4 @@ Sidebar 1.0 Sidebar.qml
NormalUI 1.0 NormalUI.qml
FullScreenUI 1.0 FullScreenUI.qml
AppPageHeader 1.0 AppPageHeader.qml
+SearchInputBar 1.0 SearchInputBar.qml
diff --git a/qml/qml.qrc b/qml/qml.qrc
index 56d95ac..6882c96 100644
--- a/qml/qml.qrc
+++ b/qml/qml.qrc
@@ -11,6 +11,7 @@
AppUI/Sidebar.qml
AppUI/AppList.qml
AppUI/AppPageHeader.qml
+ AppUI/SearchInputBar.qml
AppControls2/qmldir
AppControls2/App.qml
AppControls2/ScrollBar.qml
diff --git a/src/appdata/data-provider-manager.cpp b/src/appdata/data-provider-manager.cpp
index 0385691..a121060 100644
--- a/src/appdata/data-provider-manager.cpp
+++ b/src/appdata/data-provider-manager.cpp
@@ -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
diff --git a/src/appdata/data-provider-manager.h b/src/appdata/data-provider-manager.h
index 1892fc0..f0b6de6 100644
--- a/src/appdata/data-provider-manager.h
+++ b/src/appdata/data-provider-manager.h
@@ -50,6 +50,8 @@ public:
QString activatedProvider() const;
void activateProvider(const QString &id);
QVector data() const;
+ void forceUpdate() const;
+ void forceUpdate(QString &key) const;
Q_SIGNALS:
void pluginChanged(const QString &id, PluginGroup::Group group);
diff --git a/src/appdata/data-provider-plugin-iface.h b/src/appdata/data-provider-plugin-iface.h
index c507e72..1a1444c 100644
--- a/src/appdata/data-provider-plugin-iface.h
+++ b/src/appdata/data-provider-plugin-iface.h
@@ -35,7 +35,8 @@ class PluginGroup
public:
enum Group {
Button = 0,
- SortMenuItem
+ SortMenuItem,
+ Search,
};
Q_ENUM(Group)
};
@@ -62,6 +63,7 @@ public:
* 强制刷新数据,刷新完成后发送dataChange信号
*/
virtual void forceUpdate() = 0;
+ virtual void forceUpdate(QString &key) {};
Q_SIGNALS:
/**
diff --git a/src/utils/app-page-header-utils.cpp b/src/utils/app-page-header-utils.cpp
index 5c2a077..f09690d 100644
--- a/src/utils/app-page-header-utils.cpp
+++ b/src/utils/app-page-header-utils.cpp
@@ -38,6 +38,7 @@ public:
void updateCurrentPId(const QString &providerId);
//自动在各个插件之间切换
+ Q_INVOKABLE void reactivateProvider();
Q_INVOKABLE void autoSwitchProvider();
Q_INVOKABLE QString currentProviderIcon();
@@ -141,6 +142,11 @@ QString ProviderModel::currentProviderIcon()
return data(createIndex(m_currentIndex, 0), Icon).toString();
}
+void ProviderModel::reactivateProvider()
+{
+ DataProviderManager::instance()->activateProvider(m_providers.at(m_currentIndex).id);
+}
+
// ====== AppPageHeaderUtils ======
AppPageHeaderUtils::AppPageHeaderUtils(QObject *parent) : QObject(parent)
{
@@ -174,6 +180,11 @@ void AppPageHeaderUtils::activateProvider(const QString &name)
DataProviderManager::instance()->activateProvider(name);
}
+void AppPageHeaderUtils::startSearch(QString key)
+{
+ DataProviderManager::instance()->forceUpdate(key);
+}
+
} // UkuiMenu
#include "app-page-header-utils.moc"
diff --git a/src/utils/app-page-header-utils.h b/src/utils/app-page-header-utils.h
index 0636930..1e51cb8 100644
--- a/src/utils/app-page-header-utils.h
+++ b/src/utils/app-page-header-utils.h
@@ -39,6 +39,8 @@ public:
// 获取不同的model
Q_INVOKABLE ProviderModel *model(PluginGroup::Group group);
+ Q_INVOKABLE void startSearch(QString key);
+
private Q_SLOTS:
void onPluginChanged(const QString &id, PluginGroup::Group group);