Kirigami-addons

FormColorDelegate.qml
1// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3
4import QtQuick
5import QtQuick.Controls as Controls
6import QtQuick.Layouts
7import Qt.labs.platform
8
9import org.kde.kirigamiaddons.formcard as FormCard
10import org.kde.kirigami as Kirigami
11
12/**
13 * @brief A FormCard delegate for colors.
14 *
15 * Allow users to select colors. By default "Color" is the default label
16 * but this can be overwritten with the `text` property.
17 *
18 * @code{qml}
19 * FormCard.FormCard {
20 * FormCard.FormColorDelegate {
21 * color: "blue"
22 * }
23 *
24 * FormCard.FormDelegateSeparator {}
25 *
26 * FormCard.FormColorDelegate {
27 * text: i18nc("@label", "Active color")
28 * color: "blue"
29 * }
30 * }
31 * @endcode
32 * @image html formcardcolor.png
33 */
34FormCard.AbstractFormDelegate {
35 id: root
36
37 property color color: "transparent"
38
39 icon.name: "color-picker"
40 onClicked: colorDialog.open()
41
42 text: i18ndc("kirigami-addons6", "@action:button", "Color")
43 Accessible.description: i18ndc("kirigami-addons6", "Accessible description", "Current color \"%1\"", color)
44
45 contentItem: RowLayout {
46 spacing: 0
47
48 Kirigami.Icon {
49 source: "color-picker"
50 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
51 implicitWidth: root.icon.width
52 implicitHeight: root.icon.height
53 }
54
55 Controls.Label {
56 Layout.fillWidth: true
57 text: root.text
58 elide: Text.ElideRight
59 wrapMode: Text.Wrap
60 maximumLineCount: 2
61 Accessible.ignored: true // base class sets this text on root already
62 }
63
64 Rectangle {
65 id: colorRect
66 radius: height
67 color: root.color
68 Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
69 Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium
70 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
71 }
72
73 FormCard.FormArrow {
74 Layout.leftMargin: Kirigami.Units.smallSpacing
75 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
76 direction: Qt.RightArrow
77 visible: root.background.visible
78 }
79 }
80
81
82 ColorDialog {
83 id: colorDialog
84 onAccepted: {
85 root.color = colorDialog.color;
86 }
87 }
88}
A single card that follows a form style.
Definition FormCard.qml:35
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.