| 1 |
/* |
| 2 |
* Copyright (C) 2016 Canonical Ltd |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
* |
| 16 |
* Authored-by: Florian Boucault <[email protected]> |
| 17 |
*/ |
| 18 |
|
| 19 |
import QtQuick 2.4 |
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import Lomiri.Components.Popups 1.3 |
| 22 |
|
| 23 |
Popover { |
| 24 |
id: colorPickerPopup |
| 25 |
|
| 26 |
contentWidth: units.gu(38) |
| 27 |
grabDismissAreaEvents: false |
| 28 |
|
| 29 |
property color originalColor |
| 30 |
property var setColor |
| 31 |
property color currentColor: Qt.rgba(redComponent.value / 255, |
| 32 |
greenComponent.value / 255, |
| 33 |
blueComponent.value / 255, |
| 34 |
1.0) |
| 35 |
onCurrentColorChanged: setColor(currentColor) |
| 36 |
|
| 37 |
property bool square: true |
| 38 |
|
| 39 |
function setCurrentColor(color) { |
| 40 |
redComponent.value = color.r * 255; |
| 41 |
greenComponent.value = color.g * 255; |
| 42 |
blueComponent.value = color.b * 255; |
| 43 |
} |
| 44 |
|
| 45 |
Component.onCompleted: setCurrentColor(originalColor) |
| 46 |
|
| 47 |
|
| 48 |
Rectangle { |
| 49 |
anchors { |
| 50 |
left: parent.left |
| 51 |
right: parent.right |
| 52 |
} |
| 53 |
height: childrenRect.height + 2*units.gu(2) |
| 54 |
|
| 55 |
// This adds a contour to the Popover |
| 56 |
function newColorWithAlpha(color, alpha) { |
| 57 |
return Qt.rgba(color.r, color.g, color.b, alpha); |
| 58 |
} |
| 59 |
color: "transparent" |
| 60 |
radius: units.dp(5) |
| 61 |
border.color: newColorWithAlpha(theme.palette.normal.base, 0.2) |
| 62 |
border.width: units.dp(1) |
| 63 |
|
| 64 |
Column { |
| 65 |
anchors { |
| 66 |
top: parent.top |
| 67 |
left: parent.left |
| 68 |
right: parent.right |
| 69 |
margins: units.gu(2) |
| 70 |
} |
| 71 |
spacing: units.gu(1) |
| 72 |
|
| 73 |
ColorComponentSlider { |
| 74 |
id: redComponent |
| 75 |
anchors { |
| 76 |
left: parent.left |
| 77 |
right: parent.right |
| 78 |
} |
| 79 |
label: i18n.tr("R:") |
| 80 |
} |
| 81 |
ColorComponentSlider { |
| 82 |
id: greenComponent |
| 83 |
anchors { |
| 84 |
left: parent.left |
| 85 |
right: parent.right |
| 86 |
} |
| 87 |
label: i18n.tr("G:") |
| 88 |
} |
| 89 |
ColorComponentSlider { |
| 90 |
id: blueComponent |
| 91 |
anchors { |
| 92 |
left: parent.left |
| 93 |
right: parent.right |
| 94 |
} |
| 95 |
label: i18n.tr("B:") |
| 96 |
} |
| 97 |
|
| 98 |
Button { |
| 99 |
text: i18n.tr("Undo") |
| 100 |
color: theme.palette.selected.overlay |
| 101 |
onClicked: setCurrentColor(originalColor) |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |