Debian Codegraph @

examples/Image Colors/components/PaletteTable.qml

raw
1 /*
2 * SPDX-FileCopyrightText: 2024 ivan tkachenko <[email protected]>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 pragma ComponentBehavior: Bound
8
9 import QtQuick
10 import QtQuick.Controls as QQC2
11 import QtQuick.Layouts
12 import org.kde.kirigami as Kirigami
13
14 ColumnLayout {
15 id: root
16
17 required property list<Kirigami.imageColorsPaletteSwatch> swatches
18
19 spacing: Kirigami.Units.smallSpacing
20
21 RowLayout {
22 spacing: Kirigami.Units.smallSpacing
23
24 QQC2.Label {
25 text: "Color"
26 }
27
28 Item {
29 Layout.fillWidth: true
30 }
31
32 QQC2.Label {
33 text: "Contrast Color"
34 elide: Text.ElideRight
35 }
36 }
37
38 Repeater {
39 model: root.swatches
40
41 delegate: RowLayout {
42 id: delegate
43
44 required property Kirigami.imageColorsPaletteSwatch modelData
45
46 spacing: Kirigami.Units.smallSpacing
47 Layout.fillWidth: true
48
49 Item {
50 implicitHeight: colorItem.height
51 Layout.fillWidth: true
52
53 ColorWell {
54 id: colorItem
55 anchors.left: parent.left
56 width: Math.max(12, parent.width * delegate.modelData.ratio)
57 color: delegate.modelData.color
58 showLabel: false
59 }
60
61 ShadowedLabel {
62 id: label
63
64 anchors {
65 top: parent.top
66 left: colorItem.right
67 bottom: parent.bottom
68 }
69 verticalAlignment: Text.AlignVCenter
70 text: `${(delegate.modelData.ratio * 100).toFixed(2)}%`
71
72 states: [
73 State {
74 when: delegate.modelData.ratio > 0.66
75 name: "inside"
76
77 PropertyChanges {
78 label.anchors.leftMargin: - label.width - Kirigami.Units.largeSpacing
79 label.layer.enabled: true
80 // The contrast color sometimes isn't really usable
81 // color: delegate.modelData.contrastColor
82 }
83 },
84 State {
85 when: true
86 name: "side-by-side"
87
88 PropertyChanges {
89 label.anchors.leftMargin: Kirigami.Units.smallSpacing
90 }
91 }
92 ]
93 }
94 }
95 ColorWell {
96 Layout.fillWidth: false
97 Layout.alignment: Qt.AlignRight
98 color: delegate.modelData.contrastColor
99 showLabel: false
100 }
101 }
102 }
103 }