ukui-menu/qml/AppUI/AppList.qml

188 lines
6.2 KiB
QML

/*
* 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.15
import QtQml 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0
Item {
property string title: ""
property string idSelect: ""
signal labelItemClicked()
signal openFolderPageSignal(string folderId, string folderName);
function labelSelection(labelId) {
appListView.view.positionViewAtIndex(appListView.model.getLabelIndex(labelId), ListView.Beginning)
}
function resetListFocus() {
appListView.listFocus = true;
}
AppListView {
id: appListView
anchors.fill: parent
model: modelManager.getAppModel()
delegate: Component {
Loader {
id: loaderView
focus: true
width: ListView.view ? ListView.view.width : 0
height: appListView.itemHeight
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
property int toTop: model.top
property bool recentInstall: model.recentInstall
sourceComponent: {
if (type === DataType.Normal) {
return appItemComponent;
}
if (type === DataType.Folder) {
return folderItemComponent;
}
if (type === DataType.Label) {
return labelItemComponent;
}
}
}
}
}
Component {
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) {
appListView.model.openMenu(index);
return;
}
if (mouse.button === Qt.LeftButton) {
appManager.launchApp(id);
if (recentInstall) {
appManager.appLaunched(id);
}
return;
}
}
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;
}
}
onReleased: {
idSelect = id;
Drag.drop();
drag.target = null;
appItem.parent = appItemBase;
x = 0;
y = 0;
appItem.isSelect = false;
}
}
Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
appManager.launchApp(id);
if (recentInstall) {
appManager.appLaunched(id);
}
}
}
}
}
Component {
id: labelItemComponent
AppControls2.LabelItem {
focus: true;
onClicked: labelItemClicked();
}
}
Component {
id: folderItemComponent
DropArea {
onEntered: {
folderItem.isSelect = true;
}
onExited: {
folderItem.isSelect = false;
}
onDropped: {
folderItem.isSelect = false;
if (id !== idSelect) {
appListView.model.addAppToFolder(idSelect, id);
}
}
AppControls2.FolderItem {
id: folderItem
focus: true
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button === Qt.RightButton) {
appListView.model.openMenu(index);
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);
}
function toEditText(idOfIndex){
if (id === idOfIndex) {
editStatus = true;
}
}
}
}
}
}