2023-02-14 09:58:57 +08:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-27 09:29:19 +08:00
|
|
|
import QtQuick 2.12
|
2023-02-14 09:58:57 +08:00
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
|
|
|
|
import AppControls2 1.0 as AppControls2
|
|
|
|
import org.ukui.menu.core 1.0
|
|
|
|
import org.ukui.menu.utils 1.0
|
|
|
|
|
|
|
|
Item {
|
2023-02-27 09:29:19 +08:00
|
|
|
id: appPageHeaderRoot
|
2023-02-14 09:58:57 +08:00
|
|
|
property string title: ""
|
|
|
|
|
2023-02-27 09:29:19 +08:00
|
|
|
state: "normal"
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "normal"
|
|
|
|
PropertyChanges { target: searchBar; visible: false }
|
|
|
|
PropertyChanges { target: pluginSelectionBar; visible: true }
|
|
|
|
StateChangeScript {
|
|
|
|
script: {
|
|
|
|
sortMenu.sortMenuModel.reactivateProvider();
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
2023-02-27 09:29:19 +08:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "search"
|
|
|
|
PropertyChanges { target: searchBar; visible: true }
|
|
|
|
PropertyChanges { target: pluginSelectionBar; visible: false }
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
2023-02-27 09:29:19 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
|
2023-02-27 09:29:19 +08:00
|
|
|
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"
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
2023-02-27 09:29:19 +08:00
|
|
|
searchInputBar.clear();
|
|
|
|
appPageHeaderRoot.state = "normal"
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-27 09:29:19 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
|
2023-02-27 09:29:19 +08:00
|
|
|
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
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
|
2023-02-27 09:29:19 +08:00
|
|
|
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);
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-27 09:29:19 +08:00
|
|
|
Row {
|
|
|
|
Layout.preferredWidth: childrenRect.width
|
|
|
|
Layout.preferredHeight: 32
|
|
|
|
Layout.rightMargin: 8
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
|
2023-02-27 09:29:19 +08:00
|
|
|
Image {
|
|
|
|
id: providerSelector
|
|
|
|
width: 16
|
|
|
|
height: width
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
source: "image://appicon/ukui-down.symbolic"
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
sortMenu.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateProviderIcon() {
|
|
|
|
providerIcon.source = sortMenu.sortMenuModel.currentProviderIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
updateProviderIcon();
|
|
|
|
sortMenu.sortMenuModel.currentIndexChanged.connect(updateProviderIcon);
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu {
|
|
|
|
id: sortMenu
|
|
|
|
width: 128
|
2023-02-22 10:23:18 +08:00
|
|
|
height: 120
|
|
|
|
padding: 8
|
2023-02-14 09:58:57 +08:00
|
|
|
clip: true
|
|
|
|
property var sortMenuModel: appPageHeaderUtils.model(PluginGroup.SortMenuItem)
|
|
|
|
|
|
|
|
function show() {
|
|
|
|
popup();
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
providerSelector.source = "image://appicon/ukui-up.symbolic";
|
|
|
|
}
|
|
|
|
|
|
|
|
onClosed: {
|
|
|
|
providerSelector.source = "image://appicon/ukui-down.symbolic";
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO 添加边框阴影
|
|
|
|
background: AppControls2.StyleBackground {
|
|
|
|
paletteRole: Palette.Window
|
|
|
|
useStyleTransparent: false
|
|
|
|
radius: 8
|
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: ListView {
|
|
|
|
clip: true
|
2023-02-22 10:23:18 +08:00
|
|
|
spacing: 4
|
2023-02-14 09:58:57 +08:00
|
|
|
model: sortMenu.sortMenuModel
|
2023-02-22 10:23:18 +08:00
|
|
|
delegate: AppControls2.StyleBackground {
|
2023-02-14 09:58:57 +08:00
|
|
|
width: ListView.view ? ListView.view.width : 0
|
2023-02-22 10:23:18 +08:00
|
|
|
height: 32
|
|
|
|
radius: 4
|
|
|
|
alpha: (model.isChecked || mouseArea.isHoverd) ? 0.2 : 1
|
|
|
|
paletteRole: (model.isChecked || mouseArea.isHoverd) ? Palette.Text : Palette.Window
|
|
|
|
useStyleTransparent: false
|
|
|
|
|
|
|
|
Item {
|
2023-02-14 09:58:57 +08:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 8
|
2023-02-22 10:23:18 +08:00
|
|
|
Image {
|
|
|
|
visible: model.isChecked
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
width: 16
|
|
|
|
height: 16
|
|
|
|
source: "image://appicon/object-select.symbolic"
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
2023-02-22 10:23:18 +08:00
|
|
|
AppControls2.StyleText {
|
|
|
|
x: 24
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
width: parent.width - x
|
|
|
|
height: parent.height
|
|
|
|
text: model.name
|
|
|
|
}
|
|
|
|
}
|
2023-02-14 09:58:57 +08:00
|
|
|
|
2023-02-22 10:23:18 +08:00
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
property bool isHoverd: false
|
|
|
|
onClicked: {
|
|
|
|
if (model.isChecked) {
|
|
|
|
return;
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
2023-02-22 10:23:18 +08:00
|
|
|
appPageHeaderUtils.activateProvider(model.id);
|
|
|
|
}
|
|
|
|
onEntered: {
|
|
|
|
isHoverd = true;
|
|
|
|
}
|
|
|
|
onExited: {
|
|
|
|
isHoverd = false;
|
2023-02-14 09:58:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|