dock/qml/DockItem.qml

184 lines
5.5 KiB
QML
Raw Normal View History

2021-03-15 20:17:11 -07:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.0
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
Item {
id: control
property bool isLeft: Settings.direction === DockSettings.Left
2021-03-24 09:14:48 -07:00
property bool isRight: Settings.direction === DockSettings.Right
property bool isBottom: Settings.direction === DockSettings.Bottom
2021-03-15 20:17:11 -07:00
2021-03-24 09:14:48 -07:00
property var iconSize: root.isHorizontal ? control.height * iconSizeRatio
: control.width * iconSizeRatio
2021-03-15 20:17:11 -07:00
property bool draggable: false
property int dragItemIndex
property alias icon: icon
property alias mouseArea: iconArea
property alias dropArea: iconDropArea
property bool enableActivateDot: true
property bool isActive: false
property var popupText
property double iconSizeRatio: 0.8
property var iconName
property bool dragStarted: false
signal positionChanged()
signal released()
signal pressed(var mouse)
signal pressAndHold(var mouse)
signal clicked(var mouse)
signal rightClicked(var mouse)
signal doubleClicked(var mouse)
Drag.active: mouseArea.drag.active && control.draggable
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.MoveAction
Drag.hotSpot.x: icon.width / 2
Drag.hotSpot.y: icon.height / 2
Drag.onDragStarted: {
dragStarted = true
}
Drag.onDragFinished: {
dragStarted = false
}
2021-04-09 07:38:15 -07:00
FishUI.IconItem {
2021-03-15 20:17:11 -07:00
id: icon
anchors.centerIn: parent
2021-03-17 06:33:06 -07:00
width: control.iconSize
height: control.iconSize
source: iconName
2021-03-15 20:17:11 -07:00
visible: !dragStarted
ColorOverlay {
id: iconColorize
anchors.fill: icon
source: icon
color: "#000000"
opacity: iconArea.pressed && !mouseArea.drag.active ? 0.5 : 0
}
}
DropArea {
id: iconDropArea
anchors.fill: icon
enabled: draggable
}
MouseArea {
id: iconArea
anchors.fill: icon
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
drag.axis: Drag.XAndYAxis
onClicked: {
if (mouse.button === Qt.RightButton)
control.rightClicked(mouse)
else
control.clicked(mouse)
}
onPressed: {
control.pressed(mouse)
popupTips.hide()
}
onPositionChanged: {
if (pressed) {
if (mouse.source !== Qt.MouseEventSynthesizedByQt) {
drag.target = icon
icon.grabToImage(function(result) {
control.Drag.imageSource = result.url
})
} else {
drag.target = null
}
}
control.positionChanged()
}
onPressAndHold : control.pressAndHold(mouse)
onReleased: {
drag.target = null
control.released()
}
onContainsMouseChanged: {
if (containsMouse && control.popupText !== "") {
popupTips.popupText = control.popupText
if (Settings.direction === DockSettings.Left)
2021-04-09 07:38:15 -07:00
popupTips.position = Qt.point(root.width + FishUI.Units.largeSpacing,
2021-03-15 20:17:11 -07:00
control.mapToGlobal(0, 0).y + (control.height / 2 - popupTips.height / 2))
2021-03-24 09:14:48 -07:00
else if (Settings.direction === DockSettings.Right)
2021-04-09 07:38:15 -07:00
popupTips.position = Qt.point(control.mapToGlobal(0, 0).x - popupTips.width - FishUI.Units.smallSpacing / 2,
2021-03-24 09:14:48 -07:00
control.mapToGlobal(0, 0).y + (control.height / 2 - popupTips.height / 2))
2021-03-15 20:17:11 -07:00
else
popupTips.position = Qt.point(control.mapToGlobal(0, 0).x + (control.width / 2 - popupTips.width / 2),
2021-04-09 07:38:15 -07:00
control.mapToGlobal(0, 0).y - popupTips.height - FishUI.Units.smallSpacing)
2021-03-15 20:17:11 -07:00
popupTips.show()
} else {
popupTips.hide()
}
}
}
Rectangle {
id: activeLine
2021-03-24 09:14:48 -07:00
width: !isBottom ? parent.width * 0.06 : (isActive ? parent.height * 0.4 : parent.height * 0.06)
height: !isBottom ? (isActive ? parent.height * 0.4 : parent.height * 0.06) : parent.height * 0.06
2021-04-09 07:38:15 -07:00
color: FishUI.Theme.textColor
2021-03-24 09:14:48 -07:00
radius: !isBottom ? width / 2 : height / 2
2021-03-15 20:17:11 -07:00
visible: enableActivateDot && !dragStarted
opacity: isActive ? 1 : 0.6
2021-03-24 09:14:48 -07:00
property var leftX: 3
property var leftY: (parent.height - height) / 2
property var bottomX: (parent.width - width) / 2
property var bottomY: icon.y + icon.height + activeLine.height / 2 - 2
property var rightX: icon.x + icon.width + activeLine.width / 2 - 2
property var rightY: (parent.height - height) / 2
x: isLeft ? leftX : isBottom ? bottomX : rightX
y: isLeft ? leftY : isBottom ? bottomY : rightY
2021-03-15 20:17:11 -07:00
Behavior on opacity {
NumberAnimation {
duration: 125
easing.type: Easing.InOutCubic
}
}
Behavior on width {
NumberAnimation {
2021-03-24 09:14:48 -07:00
duration: isBottom ? 125 : 0
2021-03-15 20:17:11 -07:00
easing.type: Easing.InOutCubic
}
}
Behavior on height {
NumberAnimation {
2021-03-24 09:14:48 -07:00
duration: !isBottom ? 125 : 0
2021-03-15 20:17:11 -07:00
easing.type: Easing.InOutCubic
}
}
}
}