forked from andreagen0r/ColorPicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorHistory.qml
More file actions
120 lines (98 loc) · 2.89 KB
/
ColorHistory.qml
File metadata and controls
120 lines (98 loc) · 2.89 KB
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
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import ColorTools
Control {
id: root
property alias historySize: model.historySize
property real swatchSize: 30
readonly property color color: internal.color
function addToHistory(_color) {
model.append(_color)
}
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, topPadding + bottomPadding)
ColorSampler_p {
id: internal
}
ColorHistoryModel {
id: model
}
background: Flickable {
clip: true
boundsBehavior: Flickable.OvershootBounds
implicitHeight: root.swatchSize
flickableDirection: Flickable.HorizontalFlick
contentHeight: root.swatchSize
contentWidth: Math.max(root.width, repeater.count * (root.swatchSize + row.spacing))
Row {
id: row
spacing: 2
anchors.fill: parent
Repeater {
id: repeater
property int index: -1
model: model
delegate: Item {
anchors.verticalCenter: parent.verticalCenter
width: root.swatchSize
height: width
Image {
anchors.fill: parent
visible: model.color.a < 1
fillMode: Image.Tile
horizontalAlignment: Image.AlignLeft
verticalAlignment: Image.AlignTop
source: "assets/alphaBackground.png"
}
Rectangle {
id: sampler
anchors.fill: parent
color: model.color
}
Item {
id: draggable
anchors.fill: parent
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.CopyAction
Drag.mimeData: {
"application/x-color": model.color
}
}
DragHandler {
id: dragHandler
target: draggable
onActiveChanged: draggable.Drag.active = active
}
MouseArea {
id: mouseHist
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
propagateComposedEvents: false
onClicked: _mouse => {
if (_mouse.button === Qt.LeftButton) {
internal.setColor(sampler.color)
} else if (_mouse.button === Qt.RightButton) {
menu.x = mapToItem(row, mouseX, mouseY).x + (root.swatchSize - mouseX) + 2
repeater.index = index
menu.open()
}
}
}
}
}
}
}
Menu {
id: menu
MenuItem {
text: qsTr("Delete")
onTriggered: model.removeAt(repeater.index, 1)
}
MenuSeparator {}
MenuItem {
text: qsTr("Clear History")
onTriggered: model.clear()
}
}
}