ukui-menu/qml/extensions/FavoriteExtension.qml

117 lines
3.8 KiB
QML
Raw Normal View History

2023-02-22 14:07:53 +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/>.
*
*/
import QtQuick 2.12
import QtQml.Models 2.1
import QtQuick.Controls 2.5
import org.ukui.menu.core 1.0
import org.ukui.menu.extension 1.0
import AppControls2 1.0 as AppControls2
import org.ukui.quick.platform 1.0 as Platform
import org.ukui.quick.items 1.0 as UkuiItems
import AppUI 1.0 as AppUI
2023-02-22 14:07:53 +08:00
UkuiMenuExtension {
MouseArea {
id: viewMouseArea
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
2023-02-22 14:07:53 +08:00
onClicked: {
if (mouse.button === Qt.RightButton) {
menu.open();
} else {
if (mainWindow.editMode) {
mainWindow.editMode = false;
}
folderLoader.isFolderOpened = false;
}
}
UkuiItems.Menu {
id: menu
content: [
UkuiItems.MenuItem {
text: qsTr("Enable editing mode")
onClicked: mainWindow.editMode = true;
},
UkuiItems.MenuItem {
text: qsTr("Remove all favorite apps")
onClicked: extensionData.favoriteAppsModel.clearFavorites();
}
]
}
UkuiItems.StyleBackground {
anchors.top: parent.top
width: parent.width; height: 1
useStyleTransparency: false
alpha: 0.15
paletteRole: Platform.Theme.Text
visible: favoriteView.contentY > 0
z: 1
}
FolderGridView {
id: folderLoader
anchors.fill: parent
isFullScreen: false
folderModel: extensionData.folderModel
Component.onCompleted: favoriteView.openFolderSignal.connect(initFolder)
Component.onDestruction: favoriteView.openFolderSignal.disconnect(initFolder)
}
Item {
2023-02-22 14:07:53 +08:00
anchors.fill: parent
anchors.bottomMargin: 8
2023-02-22 14:07:53 +08:00
anchors.leftMargin: 16
anchors.rightMargin: 16
anchors.topMargin: 8
// 拖动到文件到空白区域 添加到收藏
DropArea {
anchors.fill: parent
onEntered: {
if (drag.source.isFavorite) {
favoriteView.dragTypeIsMerge = false;
} else {
var id = drag.source.id;
extensionData.favoriteAppsModel.addAppToFavorites(id);
}
}
2023-02-22 14:07:53 +08:00
}
FavoriteGridView {
id: favoriteView
width: parent.width
height: (contentHeight > parent.height) ? parent.height : contentHeight
interactive: contentHeight > parent.height
isContentShow: !folderLoader.isFolderOpened
Component.onCompleted: {
favoriteView.viewModel.model = extensionData.favoriteAppsModel
folderLoader.turnPageFinished.connect(contentShowFinished)
}
Component.onDestruction: folderLoader.turnPageFinished.disconnect(contentShowFinished)
}
}
2023-02-22 14:07:53 +08:00
}
}