2023-02-14 09:34:15 +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-05-04 15:09:52 +08:00
|
|
|
|
import QtQuick 2.15
|
2023-02-14 09:34:15 +08:00
|
|
|
|
import QtQml 2.12
|
2023-02-20 17:23:08 +08:00
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
|
import QtQuick.Layouts 1.12
|
2023-02-14 09:34:15 +08:00
|
|
|
|
import AppControls2 1.0 as AppControls2
|
|
|
|
|
import org.ukui.menu.core 1.0
|
|
|
|
|
|
2023-02-20 17:23:08 +08:00
|
|
|
|
Item {
|
2023-05-17 14:03:33 +08:00
|
|
|
|
id: appListRoot
|
2023-02-14 09:34:15 +08:00
|
|
|
|
property string title: ""
|
2023-05-04 15:09:52 +08:00
|
|
|
|
property string idSelect: ""
|
2023-05-23 11:54:17 +08:00
|
|
|
|
property bool folderEditStatus: false
|
2023-12-05 16:22:10 +08:00
|
|
|
|
property int viewContentY: appListView.view.contentY
|
2023-03-31 16:08:10 +08:00
|
|
|
|
signal labelItemClicked()
|
2023-05-23 11:54:17 +08:00
|
|
|
|
signal openFolderPageSignal(string folderId, string folderName)
|
2023-03-06 09:37:06 +08:00
|
|
|
|
function labelSelection(labelId) {
|
2023-08-14 11:15:54 +08:00
|
|
|
|
appListView.view.positionViewAtIndex(appListView.model.getLabelIndex(labelId), ListView.Beginning);
|
|
|
|
|
appListView.view.currentIndex = appListView.model.getLabelIndex(labelId);
|
2023-03-06 09:37:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 17:04:22 +08:00
|
|
|
|
function resetListFocus() {
|
|
|
|
|
appListView.listFocus = true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 16:08:10 +08:00
|
|
|
|
AppListView {
|
|
|
|
|
id: appListView
|
2023-02-20 17:23:08 +08:00
|
|
|
|
anchors.fill: parent
|
2023-04-26 17:04:22 +08:00
|
|
|
|
|
2023-05-23 11:54:17 +08:00
|
|
|
|
// 在listview区域,鼠标进出和移动事件都会清空原有的按键焦点
|
|
|
|
|
// 鼠标不移动,原有的鼠标悬浮三态会保留
|
|
|
|
|
onContainsMouseChanged: clearViewFocus()
|
|
|
|
|
onPositionChanged: clearViewFocus()
|
|
|
|
|
function clearViewFocus() {
|
|
|
|
|
if(!folderEditStatus) {
|
|
|
|
|
appListView.listFocus = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 16:08:10 +08:00
|
|
|
|
model: modelManager.getAppModel()
|
|
|
|
|
delegate: Component {
|
|
|
|
|
Loader {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
id: loaderView
|
2023-04-26 17:04:22 +08:00
|
|
|
|
focus: true
|
2023-05-04 15:09:52 +08:00
|
|
|
|
width: ListView.view ? ListView.view.width : 0
|
|
|
|
|
height: appListView.itemHeight
|
2023-03-31 16:08:10 +08:00
|
|
|
|
property int index: model.index
|
|
|
|
|
property int type: model.type
|
|
|
|
|
property string id: model.id
|
|
|
|
|
property string name: model.name
|
|
|
|
|
property string icon: model.icon
|
2023-06-02 15:44:16 +08:00
|
|
|
|
property string comment: model.comment // label tooltip
|
2023-12-07 10:59:26 +08:00
|
|
|
|
property bool favorite: model.favorite
|
2023-03-31 16:08:10 +08:00
|
|
|
|
sourceComponent: {
|
|
|
|
|
if (type === DataType.Normal) {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
return appItemComponent;
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
|
|
|
|
if (type === DataType.Folder) {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
return folderItemComponent;
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
|
|
|
|
if (type === DataType.Label) {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
return labelItemComponent;
|
2023-02-20 17:23:08 +08:00
|
|
|
|
}
|
2023-02-14 09:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 14:03:33 +08:00
|
|
|
|
|
|
|
|
|
view.onContentYChanged: {
|
|
|
|
|
if (appPageHeaderUtils.currentPluginId() === "all") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var obj = view.itemAt(10, view.contentY);
|
|
|
|
|
if (obj !== null && obj.type === DataType.Label) {
|
|
|
|
|
appListRoot.title = obj.name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-14 09:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
id: appItemComponent
|
|
|
|
|
Item {
|
|
|
|
|
id: appItemBase
|
|
|
|
|
AppControls2.AppItem {
|
|
|
|
|
id: appItem
|
|
|
|
|
focus: true
|
|
|
|
|
width: appListView.view ? appListView.view.width : 0
|
|
|
|
|
height: appListView.itemHeight
|
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
Drag.active: drag.active
|
|
|
|
|
Drag.hotSpot.x: width / 2
|
|
|
|
|
Drag.hotSpot.y: height / 2
|
|
|
|
|
onClicked: {
|
|
|
|
|
if (mouse.button === Qt.RightButton) {
|
2023-05-06 09:20:34 +08:00
|
|
|
|
appListView.model.openMenu(index, MenuInfo.AppList);
|
2023-05-04 15:09:52 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mouse.button === Qt.LeftButton) {
|
|
|
|
|
appManager.launchApp(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
2023-05-04 15:09:52 +08:00
|
|
|
|
onPressAndHold: {
|
|
|
|
|
if (mouse.button === Qt.LeftButton) {
|
|
|
|
|
x = appItem.mapToItem(appListView,0,0).x;
|
|
|
|
|
y = appItem.mapToItem(appListView,0,0).y;
|
|
|
|
|
drag.target = appItem;
|
|
|
|
|
appItem.parent = appListView;
|
|
|
|
|
appItem.isSelect = true;
|
2023-04-17 17:23:08 +08:00
|
|
|
|
}
|
2023-05-04 15:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
onReleased: {
|
|
|
|
|
idSelect = id;
|
|
|
|
|
Drag.drop();
|
|
|
|
|
drag.target = null;
|
|
|
|
|
appItem.parent = appItemBase;
|
|
|
|
|
x = 0;
|
|
|
|
|
y = 0;
|
|
|
|
|
appItem.isSelect = false;
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-26 17:04:22 +08:00
|
|
|
|
Keys.onPressed: {
|
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
|
|
|
|
appManager.launchApp(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
2023-02-14 09:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
id: labelItemComponent
|
2023-03-31 16:08:10 +08:00
|
|
|
|
AppControls2.LabelItem {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
focus: true;
|
2023-03-31 16:08:10 +08:00
|
|
|
|
onClicked: labelItemClicked();
|
2023-08-14 11:15:54 +08:00
|
|
|
|
Keys.onPressed: {
|
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
|
|
|
|
labelItemClicked();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
2023-02-14 09:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component {
|
2023-05-04 15:09:52 +08:00
|
|
|
|
id: folderItemComponent
|
|
|
|
|
DropArea {
|
|
|
|
|
onEntered: {
|
|
|
|
|
folderItem.isSelect = true;
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
2023-05-04 15:09:52 +08:00
|
|
|
|
onExited: {
|
|
|
|
|
folderItem.isSelect = false;
|
2023-04-07 10:00:56 +08:00
|
|
|
|
}
|
2023-05-04 15:09:52 +08:00
|
|
|
|
onDropped: {
|
|
|
|
|
folderItem.isSelect = false;
|
|
|
|
|
if (id !== idSelect) {
|
|
|
|
|
appListView.model.addAppToFolder(idSelect, id);
|
|
|
|
|
}
|
2023-04-07 10:00:56 +08:00
|
|
|
|
}
|
2023-05-04 15:09:52 +08:00
|
|
|
|
AppControls2.FolderItem {
|
|
|
|
|
id: folderItem
|
|
|
|
|
focus: true
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
onClicked: {
|
|
|
|
|
if (mouse.button === Qt.RightButton) {
|
2023-05-06 09:20:34 +08:00
|
|
|
|
appListView.model.openMenu(index, MenuInfo.AppList);
|
2023-05-04 15:09:52 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mouse.button === Qt.LeftButton) {
|
|
|
|
|
openFolderPageSignal(id, name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Keys.onPressed: {
|
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
|
|
|
|
openFolderPageSignal(id, name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
|
appListView.model.renameText.connect(toEditText);
|
|
|
|
|
}
|
|
|
|
|
Component.onDestruction: {
|
|
|
|
|
appListView.model.renameText.disconnect(toEditText);
|
|
|
|
|
}
|
2023-04-07 10:00:56 +08:00
|
|
|
|
|
2023-05-23 11:54:17 +08:00
|
|
|
|
onEditStatusChanged: folderEditStatus = editStatus;
|
2023-05-04 15:09:52 +08:00
|
|
|
|
function toEditText(idOfIndex){
|
|
|
|
|
if (id === idOfIndex) {
|
|
|
|
|
editStatus = true;
|
|
|
|
|
}
|
2023-04-07 10:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-31 16:08:10 +08:00
|
|
|
|
}
|
2023-02-14 09:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|