-
Notifications
You must be signed in to change notification settings - Fork 3
/
ColorHistory.qml
129 lines (104 loc) · 3.3 KB
/
ColorHistory.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
pragma ComponentBehavior: Bound
import QtQuick
import ColorPicker
import Origin.Controls
Control {
id: control
required property ColorPickerBackend backend
property alias historySize: model.historySize
property real swatchSize: 30
function addToHistory() : void {
model.append(control.backend.currentColor)
}
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, topPadding + bottomPadding)
background: Flickable {
clip: true
boundsBehavior: Flickable.OvershootBounds
implicitHeight: control.swatchSize
flickableDirection: Flickable.HorizontalFlick
contentHeight: control.swatchSize
contentWidth: Math.max(control.width, repeater.count * (control.swatchSize + row.spacing))
Row {
id: row
spacing: 2
anchors.fill: parent
Repeater {
id: repeater
property int index: -1
model: ColorHistoryModel { id: model }
delegate: Item {
id: swatchDelegate
required property color colorRole
required property int index
anchors.verticalCenter: parent.verticalCenter
width: control.swatchSize
height: width
Image {
anchors.fill: parent
visible: swatchDelegate.colorRole.a < 1
fillMode: Image.Tile
horizontalAlignment: Image.AlignLeft
verticalAlignment: Image.AlignTop
source: Qt.resolvedUrl("assets/alphaBackground.png")
}
Rectangle {
id: sampler
anchors.fill: parent
color: swatchDelegate.colorRole
}
Item {
id: draggable
anchors.fill: parent
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.CopyAction
Drag.mimeData: {
"application/x-color": swatchDelegate.colorRole
}
}
DragHandler {
id: dragHandler
target: draggable
onActiveChanged: draggable.Drag.active = active
}
MouseArea {
id: mouseHist
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
propagateComposedEvents: false
hoverEnabled: true
ToolTip {
visible: mouseHist.containsMouse
delay: Application.styleHints.mousePressAndHoldInterval
text: swatchDelegate.colorRole.toString()
}
onClicked: _mouse => {
if (_mouse.button === Qt.LeftButton) {
control.backend.currentColor = swatchDelegate.colorRole
} else if (_mouse.button === Qt.RightButton) {
repeater.index = swatchDelegate.index
menu.x = mapToItem(row, mouseX, mouseY).x + (control.swatchSize - mouseX) + 2
menu.y = mouseY
menu.open()
}
}
}
}
}
}
}
Menu {
id: menu
MenuItem {
text: qsTr("Delete")
onTriggered: {
model.removeRows(repeater.index, repeater.index)
}
}
MenuSeparator {}
MenuItem {
text: qsTr("Clear History")
onTriggered: model.clear()
}
}
}