-
Notifications
You must be signed in to change notification settings - Fork 3
/
ColorSampler.qml
78 lines (66 loc) · 1.9 KB
/
ColorSampler.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import QtQuick
import QtQuick.Templates as T
import ColorPicker
T.Control {
id: control
implicitWidth: Math.max( implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding )
implicitHeight: Math.max( implicitBackgroundHeight + topInset + bottomInset,
implicitContentHeight + topPadding + bottomPadding )
required property ColorPickerBackend backend
signal clicked
signal doubleClicked
background: Item {
implicitWidth: 50
implicitHeight: implicitWidth
Image {
anchors.fill: parent
visible: control.backend.currentColor.a < 1
fillMode: Image.Tile
horizontalAlignment: Image.AlignLeft
verticalAlignment: Image.AlignTop
source: Qt.resolvedUrl("assets/alphaBackground.png")
}
Rectangle {
anchors.fill: parent
color: control.backend.currentColor
border.color: "lightgray"
}
}
DropArea {
id: dropArea
anchors.fill: parent
keys: ["application/x-color"]
onEntered: drag => {
if (!drag.hasColor) {
drag.accepted = false
}
}
onDropped: drop => {
if (drop.hasColor) {
if (drop.proposedAction === Qt.CopyAction) {
control.backend.currentColor = drop.colorData
drop.acceptProposedAction()
}
}
}
}
Item {
id: draggable
anchors.fill: parent
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.CopyAction
Drag.mimeData: {
"application/x-color": control.backend.currentColor
}
MouseArea {
anchors.fill: parent
onClicked: control.clicked()
onDoubleClicked: control.doubleClicked()
}
}
DragHandler {
target: draggable
onActiveChanged: draggable.Drag.active = active
}
}