dock/qml/AppItem.qml

132 lines
3.6 KiB
QML
Raw Permalink Normal View History

2021-05-25 04:44:02 -07:00
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: rekols <revenmartin@gmail.com>
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
2021-03-15 20:17:11 -07:00
import QtQuick 2.12
import QtQuick.Controls 2.12
2021-03-16 03:20:04 -07:00
import Cutefish.Dock 1.0
2021-04-09 07:38:15 -07:00
import FishUI 1.0 as FishUI
2021-03-15 20:17:11 -07:00
DockItem {
id: appItem
property var windowCount: model.windowCount
2021-11-08 07:44:15 -08:00
property var dragSource: null
2021-03-15 20:17:11 -07:00
iconName: model.iconName ? model.iconName : "application-x-desktop"
isActive: model.isActive
popupText: model.visibleName
enableActivateDot: windowCount !== 0
2021-05-05 20:24:12 -07:00
draggable: !model.fixed
2021-03-15 20:17:11 -07:00
dragItemIndex: index
2021-04-19 22:43:06 -07:00
onXChanged: {
if (windowCount > 0)
updateGeometry()
}
onYChanged: {
if (windowCount > 0)
updateGeometry()
}
2021-03-15 20:17:11 -07:00
onWindowCountChanged: {
if (windowCount > 0)
updateGeometry()
}
onPositionChanged: updateGeometry()
onPressed: updateGeometry()
2021-03-22 02:10:08 -07:00
onRightClicked: if (model.appId !== "cutefish-launcher") contextMenu.show()
2021-03-15 20:17:11 -07:00
onClicked: {
if (mouse.button === Qt.LeftButton)
appModel.clicked(model.appId)
else if (mouse.button === Qt.MiddleButton)
appModel.openNewInstance(model.appId)
}
2021-03-15 20:17:11 -07:00
dropArea.onEntered: {
2021-11-08 07:44:15 -08:00
appItem.dragSource = drag.source
dropTimer.restart()
}
dropArea.onExited: {
appItem.dragSource = null
dropTimer.stop()
2021-03-15 20:17:11 -07:00
}
dropArea.onDropped: {
appModel.save()
updateGeometry()
}
2021-11-08 07:44:15 -08:00
Timer {
id: dropTimer
interval: 300
onTriggered: {
if (appItem.dragSource)
appModel.move(appItem.dragSource.dragItemIndex,
appItem.dragItemIndex)
else
appModel.raiseWindow(model.appId)
}
}
2021-04-09 07:38:15 -07:00
FishUI.DesktopMenu {
2021-03-15 20:17:11 -07:00
id: contextMenu
MenuItem {
text: qsTr("Open")
visible: windowCount === 0
onTriggered: appModel.openNewInstance(model.appId)
}
MenuItem {
text: model.visibleName
2022-01-16 10:17:59 -08:00
visible: windowCount > 0 && model.visibleName
2021-03-15 20:17:11 -07:00
onTriggered: appModel.openNewInstance(model.appId)
}
MenuItem {
text: model.isPinned ? qsTr("Unpin") : qsTr("Pin")
2021-04-11 03:24:23 -07:00
visible: model.desktopFile !== ""
2021-03-15 20:17:11 -07:00
onTriggered: {
model.isPinned ? appModel.unPin(model.appId) : appModel.pin(model.appId)
}
}
MenuItem {
visible: windowCount !== 0
2021-04-21 11:30:46 -07:00
text: windowCount === 1 ? qsTr("Close window")
: qsTr("Close %1 windows").arg(windowCount)
2021-03-15 20:17:11 -07:00
onTriggered: appModel.closeAllByAppId(model.appId)
}
}
function updateGeometry() {
2021-05-05 20:24:12 -07:00
if (model.fixed)
return
2021-03-15 20:17:11 -07:00
appModel.updateGeometries(model.appId, Qt.rect(appItem.mapToGlobal(0, 0).x,
appItem.mapToGlobal(0, 0).y,
appItem.width, appItem.height))
}
}