Warning, /maui/mauikit/src/controls.6/ColorsRow.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick
0002 import QtQuick.Controls
0003
0004 import org.mauikit.controls 1.3 as Maui
0005
0006 /**
0007 * @inherit QtQuick.Flow
0008 * @brief A row of color buttons
0009 *
0010 * @image html Misc/colorsrow.png "Demo"
0011 *
0012 * @code
0013 * Column
0014 * {
0015 * width: 400
0016 * anchors.centerIn: parent
0017 * spacing: Maui.Style.space.big
0018 *
0019 * Maui.ColorsRow
0020 * {
0021 * id: _colorsRow
0022 * width: parent.width
0023 *
0024 * currentColor: "#CBFF8C"
0025 * defaultColor : "#CBFF8C"
0026 *
0027 * colors: ["#E3E36A", "#CBFF8C", "#C16200", "#881600", "#6A3937", "#706563", "#748386", "#157A6E", "#77B28C", "#36311F"]
0028 *
0029 * onColorPicked: (color) =>
0030 * {
0031 * currentColor = color
0032 * }
0033 * }
0034 *
0035 * Rectangle
0036 * {
0037 * radius: 10
0038 * height: 400
0039 * width: parent.width
0040 * color: _colorsRow.currentColor
0041 * }
0042 * }
0043 * @endcode
0044 *
0045 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/ColorsRow.qml">You can find a more complete example at this link.</a>
0046 */
0047 Flow
0048 {
0049 id: control
0050
0051 spacing: Maui.Style.defaultSpacing
0052
0053 /**
0054 * @brief The list of colors to be used.
0055 */
0056 default property var colors : []
0057
0058 /**
0059 * @brief The default color. This is used as the color when the reset/clear button is clicked. The color to reset back to.
0060 */
0061 property string defaultColor
0062
0063 /**
0064 * @brief The current color. This is useful to be set at startup, it is binded to the `defaultColor` as default.
0065 */
0066 property string currentColor : defaultColor
0067
0068 /**
0069 * @brief The size of the elements in the row.
0070 */
0071 property int size : Maui.Handy.isMobile ? 26 : Maui.Style.iconSizes.medium
0072
0073 /**
0074 * @brief Emitted when one of the color buttons has been clicked. The argument is the color picked.
0075 * @param color the color picked.
0076 *
0077 * @code
0078 * onColorPicked: (color) =>
0079 * {
0080 * currentColor = color
0081 }
0082 * @endcode
0083 */
0084 signal colorPicked (string color)
0085
0086 Repeater
0087 {
0088 model: control.colors
0089
0090 AbstractButton
0091 {
0092 id: _button
0093 checked : control.currentColor === modelData
0094 implicitHeight: control.size + topPadding + bottomPadding
0095 implicitWidth: implicitHeight + leftPadding + rightPadding
0096 hoverEnabled: true
0097 onClicked: control.colorPicked(modelData)
0098
0099 property color color : modelData
0100
0101 contentItem: Item
0102 {
0103 Maui.Icon
0104 {
0105 visible: opacity > 0
0106 color: Maui.ColorUtils.brightnessForColor(_button.color) === Maui.ColorUtils.Light ? "#333" : "#fff"
0107 anchors.centerIn: parent
0108 height: Math.round(parent.height * 0.9)
0109 width: height
0110 opacity: checked || hovered ? 1 : 0
0111 isMask: true
0112
0113 source: "qrc:/assets/checkmark.svg"
0114
0115 Behavior on opacity
0116 {
0117 NumberAnimation
0118 {
0119 duration: Maui.Style.units.shortDuration
0120 easing.type: Easing.InOutQuad
0121 }
0122 }
0123 }
0124 }
0125
0126 background: Rectangle
0127 {
0128 radius: Maui.Style.radiusV
0129 color: enabled ? modelData : "transparent"
0130 }
0131 }
0132 }
0133
0134 Loader
0135 {
0136 asynchronous: true
0137 active: control.defaultColor.length
0138 sourceComponent: Item
0139 {
0140 implicitHeight: control.size
0141 implicitWidth: implicitHeight
0142
0143 ToolButton
0144 {
0145 flat: true
0146 anchors.centerIn: parent
0147 icon.name: "edit-clear"
0148 onClicked:
0149 {
0150 control.colorPicked(control.defaultColor)
0151 }
0152 }
0153 }
0154 }
0155 }