| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2022 George Florea Bănuș <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
import QtQuick |
| 8 |
import QtQuick.Controls |
| 9 |
import QtQuick.Dialogs |
| 10 |
|
| 11 |
import org.kde.kirigami as Kirigami |
| 12 |
|
| 13 |
Rectangle { |
| 14 |
id: root |
| 15 |
|
| 16 |
// using onColorChanged causes a binding loop |
| 17 |
signal colorChosen(string color) |
| 18 |
|
| 19 |
implicitWidth: Math.ceil(Kirigami.Units.gridUnit * 1.7) |
| 20 |
implicitHeight: Math.ceil(Kirigami.Units.gridUnit * 1.7) |
| 21 |
border.width: 1 |
| 22 |
border.color: ma.containsMouse |
| 23 |
? Kirigami.Theme.highlightColor |
| 24 |
: Kirigami.Theme.alternateBackgroundColor |
| 25 |
|
| 26 |
onColorChosen: { |
| 27 |
root.color = colorPicker.selectedColor |
| 28 |
} |
| 29 |
|
| 30 |
MouseArea { |
| 31 |
id: ma |
| 32 |
|
| 33 |
anchors.fill: parent |
| 34 |
hoverEnabled: true |
| 35 |
onClicked: { |
| 36 |
colorPicker.open() |
| 37 |
} |
| 38 |
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor |
| 39 |
} |
| 40 |
|
| 41 |
ToolTip { |
| 42 |
text: i18nc("@info:tooltip", "Select a color") |
| 43 |
visible: ma.containsMouse |
| 44 |
} |
| 45 |
|
| 46 |
ColorDialog { |
| 47 |
id: colorPicker |
| 48 |
|
| 49 |
title: i18nc("@title:window", "Select Color") |
| 50 |
onAccepted: root.colorChosen(colorPicker.selectedColor) |
| 51 |
selectedColor: root.color |
| 52 |
parentWindow: root.Window.window |
| 53 |
} |
| 54 |
|
| 55 |
} |