| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015 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 |
|
| 17 |
import QtQuick 2.9 |
| 18 |
import Gallery 1.0 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
|
| 21 |
/*! |
| 22 |
EditingHUD is an itme to connect to the HUD services. |
| 23 |
It exports all possible actions and triggers the edit functionality inside of gallery. |
| 24 |
*/ |
| 25 |
Item { |
| 26 |
id: root |
| 27 |
|
| 28 |
/// The current photo to be edited |
| 29 |
property variant photo: null |
| 30 |
/// Is true when a HUD action with parameters is active |
| 31 |
property bool actionActive: false |
| 32 |
|
| 33 |
/// Exposure compensation from -1.0 (dark) to +1.0 (bright) |
| 34 |
property double exposureValue: 0.0 |
| 35 |
|
| 36 |
/// Brightnes value of the color balance |
| 37 |
property double brightness: 0.0 |
| 38 |
/// Contrast value of the color balance |
| 39 |
property double contrast: 0.0 |
| 40 |
/// Saturation value of the color balance |
| 41 |
property double saturation: 0.0 |
| 42 |
/// Hue value of the color balance |
| 43 |
property double hue: 0.0 |
| 44 |
|
| 45 |
/// Emitted when the exposure action is started |
| 46 |
signal exposureActivated() |
| 47 |
/// Emitted when the color balance action is started |
| 48 |
signal colorBalanceActivated() |
| 49 |
|
| 50 |
Component.onCompleted: { |
| 51 |
hudCtx.addAction(deleteAction); |
| 52 |
hudCtx.addAction(shareAction); |
| 53 |
hudCtx.addAction(addAction); |
| 54 |
hudCtx.addAction(undoAction); |
| 55 |
hudCtx.addAction(redoAction); |
| 56 |
hudCtx.addAction(autoEnhanceAction); |
| 57 |
hudCtx.addAction(rotateAction); |
| 58 |
hudCtx.addAction(cropAction); |
| 59 |
hudCtx.addAction(revertAction); |
| 60 |
hudCtx.addAction(exposureAction); |
| 61 |
hudCtx.addAction(colorBalanceAction); |
| 62 |
} |
| 63 |
|
| 64 |
Action { |
| 65 |
id: deleteAction |
| 66 |
text: i18n.tr("Delete") |
| 67 |
keywords: i18n.tr("Trash;Erase") |
| 68 |
} |
| 69 |
Action { |
| 70 |
id: shareAction |
| 71 |
text: i18n.tr("Share") |
| 72 |
keywords: i18n.tr("Post;Upload;Attach") |
| 73 |
} |
| 74 |
Action { |
| 75 |
id: addAction |
| 76 |
text: i18n.tr("Add") |
| 77 |
keywords: i18n.tr("Add Photo to Album") |
| 78 |
} |
| 79 |
Action { |
| 80 |
id: undoAction |
| 81 |
text: i18n.tr("Undo") |
| 82 |
keywords: i18n.tr("Cancel Action;Backstep") |
| 83 |
} |
| 84 |
Action { |
| 85 |
id: redoAction |
| 86 |
text: i18n.tr("Redo") |
| 87 |
keywords: i18n.tr("Reapply;Make Again") |
| 88 |
} |
| 89 |
Action { |
| 90 |
id: autoEnhanceAction |
| 91 |
text: i18n.tr("Auto Enhance") |
| 92 |
description: i18n.tr("Adjust the image automatically") |
| 93 |
keywords: i18n.tr("Automatically Adjust Photo") |
| 94 |
onTriggered: photo.autoEnhance() |
| 95 |
} |
| 96 |
Action { |
| 97 |
id: rotateAction |
| 98 |
text: i18n.tr("Rotate") |
| 99 |
keywords: i18n.tr("Turn Clockwise") |
| 100 |
description: i18n.tr("Rotate the image clockwise") |
| 101 |
onTriggered: photo.rotateRight() |
| 102 |
} |
| 103 |
Action { |
| 104 |
id: cropAction |
| 105 |
text: i18n.tr("Crop") |
| 106 |
keywords: i18n.tr("Trim;Cut") |
| 107 |
description: i18n.tr("Crop the image") |
| 108 |
onTriggered: cropper.show(photo) |
| 109 |
} |
| 110 |
Action { |
| 111 |
id: revertAction |
| 112 |
text: i18n.tr("Revert to Original") |
| 113 |
keywords: i18n.tr("Discard Changes") |
| 114 |
description: i18n.tr("Discard all changes") |
| 115 |
} |
| 116 |
PreviewAction { |
| 117 |
id: exposureAction |
| 118 |
text: i18n.tr("Exposure") |
| 119 |
description: i18n.tr("Adjust the exposure") |
| 120 |
keywords: i18n.tr("Underexposed;Overexposed") |
| 121 |
commitLabel: i18n.tr("Confirm") // string to show in the confirm button |
| 122 |
|
| 123 |
PreviewRangeParameter { |
| 124 |
id: compensationParam |
| 125 |
text: i18n.tr("Compensation") |
| 126 |
|
| 127 |
minimumValue: 0.0 |
| 128 |
maximumValue: 100.0 |
| 129 |
value: 50.0 |
| 130 |
|
| 131 |
onValueChanged: root.exposureValue = (value / 50.0) - 1.0 |
| 132 |
} |
| 133 |
|
| 134 |
onStarted: { |
| 135 |
root.exposureActivated() |
| 136 |
resetValues() |
| 137 |
root.actionActive = true |
| 138 |
} |
| 139 |
|
| 140 |
onResetted: compensationParam.value = 50 |
| 141 |
|
| 142 |
onCancelled: { |
| 143 |
compensationParam.value = 50 |
| 144 |
root.actionActive = false |
| 145 |
} |
| 146 |
|
| 147 |
function resetValues() { |
| 148 |
root.exposureValue = 0.0 |
| 149 |
} |
| 150 |
|
| 151 |
onTriggered: { |
| 152 |
photo.exposureCompensation(root.exposureValue) |
| 153 |
root.actionActive = false |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
PreviewAction { |
| 158 |
id: colorBalanceAction |
| 159 |
text: i18n.tr("Color Balance") |
| 160 |
description: i18n.tr("Adjust color balance") |
| 161 |
keywords: i18n.tr("Saturation;Hue") |
| 162 |
commitLabel: i18n.tr("Confirm") |
| 163 |
|
| 164 |
PreviewRangeParameter { |
| 165 |
id: brightnessParam |
| 166 |
text: i18n.tr("Brightness") |
| 167 |
|
| 168 |
minimumValue: 0.0 |
| 169 |
maximumValue: 100.0 |
| 170 |
value: 20.0 |
| 171 |
|
| 172 |
onValueChanged: root.brightness = value / 20.0 |
| 173 |
} |
| 174 |
|
| 175 |
PreviewRangeParameter { |
| 176 |
id: contrastParam |
| 177 |
text: i18n.tr("Contrast") |
| 178 |
|
| 179 |
minimumValue: 0.0 |
| 180 |
maximumValue: 100.0 |
| 181 |
value: 20.0 |
| 182 |
|
| 183 |
onValueChanged: root.contrast = value / 20.0 |
| 184 |
} |
| 185 |
|
| 186 |
PreviewRangeParameter { |
| 187 |
id: saturationParam |
| 188 |
text: i18n.tr("Saturation") |
| 189 |
|
| 190 |
minimumValue: 0.0 |
| 191 |
maximumValue: 100.0 |
| 192 |
value: 20.0 |
| 193 |
|
| 194 |
onValueChanged: root.saturation = value / 20.0 |
| 195 |
} |
| 196 |
|
| 197 |
PreviewRangeParameter { |
| 198 |
id: hueParam |
| 199 |
text: i18n.tr("Hue") |
| 200 |
|
| 201 |
minimumValue: 0.0 |
| 202 |
maximumValue: 100.0 |
| 203 |
value: 0.0 |
| 204 |
|
| 205 |
onValueChanged: root.hue = value * 3.6 |
| 206 |
} |
| 207 |
|
| 208 |
onStarted: { |
| 209 |
root.colorBalanceActivated() |
| 210 |
resetValues() |
| 211 |
root.actionActive = true |
| 212 |
} |
| 213 |
|
| 214 |
onResetted: { |
| 215 |
resetValues() |
| 216 |
} |
| 217 |
|
| 218 |
function resetValues() { |
| 219 |
brightnessParam.value = 20 |
| 220 |
root.brightness = 1.0 |
| 221 |
contrastParam.value = 20 |
| 222 |
root.contrast = 1.0 |
| 223 |
saturationParam.value = 20 |
| 224 |
saturation = 1.0 |
| 225 |
hueParam.value = 0 |
| 226 |
root.hue = 0.0 |
| 227 |
} |
| 228 |
|
| 229 |
onCancelled: root.actionActive = false |
| 230 |
|
| 231 |
onTriggered: { |
| 232 |
photo.colorBalance(root.brightness, root.contrast, root.saturation, root.hue) |
| 233 |
root.actionActive = false |
| 234 |
} |
| 235 |
} |
| 236 |
} |