| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import ".." |
| 6 |
import "../components" |
| 7 |
import Qt.labs.platform 1.1 |
| 8 |
import QtQuick 2.12 |
| 9 |
import QtQuick.Controls 2.12 |
| 10 |
import QtQuick.Layouts 1.12 |
| 11 |
import im.nheko 1.0 |
| 12 |
|
| 13 |
ApplicationWindow { |
| 14 |
id: win |
| 15 |
|
| 16 |
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 2.3) |
| 17 |
property SingleImagePackModel imagePack |
| 18 |
property int currentImageIndex: -1 |
| 19 |
readonly property int stickerDim: 128 |
| 20 |
readonly property int stickerDimPad: 128 + Nheko.paddingSmall |
| 21 |
|
| 22 |
title: qsTr("Editing image pack") |
| 23 |
height: 600 |
| 24 |
width: 600 |
| 25 |
color: palette.base |
| 26 |
modality: Qt.WindowModal |
| 27 |
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint |
| 28 |
|
| 29 |
AdaptiveLayout { |
| 30 |
id: adaptiveView |
| 31 |
|
| 32 |
anchors.fill: parent |
| 33 |
singlePageMode: false |
| 34 |
pageIndex: 0 |
| 35 |
|
| 36 |
AdaptiveLayoutElement { |
| 37 |
id: packlistC |
| 38 |
|
| 39 |
visible: Settings.groupView |
| 40 |
minimumWidth: 200 |
| 41 |
collapsedWidth: 200 |
| 42 |
preferredWidth: 300 |
| 43 |
maximumWidth: 300 |
| 44 |
clip: true |
| 45 |
|
| 46 |
ListView { |
| 47 |
//required property bool isEmote |
| 48 |
//required property bool isSticker |
| 49 |
|
| 50 |
model: imagePack |
| 51 |
|
| 52 |
|
| 53 |
header: AvatarListTile { |
| 54 |
title: imagePack.packname |
| 55 |
avatarUrl: imagePack.avatarUrl |
| 56 |
roomid: imagePack.statekey |
| 57 |
subtitle: imagePack.statekey |
| 58 |
index: -1 |
| 59 |
selectedIndex: currentImageIndex |
| 60 |
|
| 61 |
TapHandler { |
| 62 |
onSingleTapped: currentImageIndex = -1 |
| 63 |
} |
| 64 |
|
| 65 |
Rectangle { |
| 66 |
anchors.left: parent.left |
| 67 |
anchors.verticalCenter: parent.verticalCenter |
| 68 |
height: parent.height - Nheko.paddingSmall * 2 |
| 69 |
width: 3 |
| 70 |
color: palette.highlight |
| 71 |
} |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
footer: Button { |
| 76 |
onClicked: addFilesDialog.open() |
| 77 |
width: ListView.view.width |
| 78 |
text: qsTr("Add images") |
| 79 |
|
| 80 |
FileDialog { |
| 81 |
id: addFilesDialog |
| 82 |
|
| 83 |
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation) |
| 84 |
fileMode: FileDialog.OpenFiles |
| 85 |
nameFilters: [qsTr("Images (*.png *.webp *.gif *.jpg *.jpeg)")] |
| 86 |
title: qsTr("Select images for pack") |
| 87 |
acceptLabel: qsTr("Add to pack") |
| 88 |
onAccepted: imagePack.addStickers(files) |
| 89 |
} |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
delegate: AvatarListTile { |
| 94 |
id: packItem |
| 95 |
|
| 96 |
property color background: palette.window |
| 97 |
property color importantText: palette.text |
| 98 |
property color unimportantText: palette.buttonText |
| 99 |
property color bubbleBackground: palette.highlight |
| 100 |
property color bubbleText: palette.highlightedText |
| 101 |
required property string shortCode |
| 102 |
required property string url |
| 103 |
required property string body |
| 104 |
|
| 105 |
title: shortCode |
| 106 |
subtitle: body |
| 107 |
avatarUrl: url |
| 108 |
selectedIndex: currentImageIndex |
| 109 |
crop: false |
| 110 |
|
| 111 |
TapHandler { |
| 112 |
onSingleTapped: currentImageIndex = index |
| 113 |
} |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
AdaptiveLayoutElement { |
| 122 |
id: packinfoC |
| 123 |
|
| 124 |
Rectangle { |
| 125 |
color: palette.window |
| 126 |
|
| 127 |
GridLayout { |
| 128 |
anchors.fill: parent |
| 129 |
anchors.margins: Nheko.paddingMedium |
| 130 |
visible: currentImageIndex == -1 |
| 131 |
enabled: visible |
| 132 |
columns: 2 |
| 133 |
rowSpacing: Nheko.paddingLarge |
| 134 |
|
| 135 |
Avatar { |
| 136 |
Layout.columnSpan: 2 |
| 137 |
url: imagePack.avatarUrl.replace("mxc://", "image://MxcImage/") |
| 138 |
displayName: imagePack.packname |
| 139 |
roomid: imagePack.statekey |
| 140 |
Layout.preferredHeight: 130 |
| 141 |
Layout.preferredWidth: 130 |
| 142 |
crop: false |
| 143 |
Layout.alignment: Qt.AlignHCenter |
| 144 |
|
| 145 |
ImageButton { |
| 146 |
hoverEnabled: true |
| 147 |
ToolTip.visible: hovered |
| 148 |
ToolTip.text: qsTr("Change the overview image for this pack") |
| 149 |
anchors.left: parent.left |
| 150 |
anchors.top: parent.top |
| 151 |
anchors.leftMargin: Nheko.paddingMedium |
| 152 |
anchors.topMargin: Nheko.paddingMedium |
| 153 |
image: ":/icons/icons/ui/edit.svg" |
| 154 |
onClicked: addAvatarDialog.open() |
| 155 |
|
| 156 |
FileDialog { |
| 157 |
id: addAvatarDialog |
| 158 |
|
| 159 |
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation) |
| 160 |
fileMode: FileDialog.OpenFile |
| 161 |
nameFilters: [qsTr("Overview Image (*.png *.webp *.jpg *.jpeg)")] |
| 162 |
title: qsTr("Select overview image for pack") |
| 163 |
onAccepted: imagePack.setAvatar(file) |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
MatrixTextField { |
| 169 |
id: statekeyField |
| 170 |
|
| 171 |
visible: imagePack.roomid |
| 172 |
Layout.fillWidth: true |
| 173 |
Layout.columnSpan: 2 |
| 174 |
label: qsTr("State key") |
| 175 |
text: imagePack.statekey |
| 176 |
onTextEdited: imagePack.statekey = text |
| 177 |
} |
| 178 |
|
| 179 |
MatrixTextField { |
| 180 |
Layout.fillWidth: true |
| 181 |
Layout.columnSpan: 2 |
| 182 |
label: qsTr("Packname") |
| 183 |
text: imagePack.packname |
| 184 |
onTextEdited: imagePack.packname = text |
| 185 |
} |
| 186 |
|
| 187 |
MatrixTextField { |
| 188 |
Layout.fillWidth: true |
| 189 |
Layout.columnSpan: 2 |
| 190 |
label: qsTr("Attribution") |
| 191 |
text: imagePack.attribution |
| 192 |
onTextEdited: imagePack.attribution = text |
| 193 |
} |
| 194 |
|
| 195 |
MatrixText { |
| 196 |
Layout.margins: statekeyField.textPadding |
| 197 |
font.weight: Font.DemiBold |
| 198 |
font.letterSpacing: font.pixelSize * 0.02 |
| 199 |
text: qsTr("Use as Emoji") |
| 200 |
} |
| 201 |
|
| 202 |
ToggleButton { |
| 203 |
checked: imagePack.isEmotePack |
| 204 |
onCheckedChanged: imagePack.isEmotePack = checked |
| 205 |
Layout.alignment: Qt.AlignRight |
| 206 |
} |
| 207 |
|
| 208 |
MatrixText { |
| 209 |
Layout.margins: statekeyField.textPadding |
| 210 |
font.weight: Font.DemiBold |
| 211 |
font.letterSpacing: font.pixelSize * 0.02 |
| 212 |
text: qsTr("Use as Sticker") |
| 213 |
} |
| 214 |
|
| 215 |
ToggleButton { |
| 216 |
checked: imagePack.isStickerPack |
| 217 |
onCheckedChanged: imagePack.isStickerPack = checked |
| 218 |
Layout.alignment: Qt.AlignRight |
| 219 |
} |
| 220 |
|
| 221 |
Item { |
| 222 |
Layout.columnSpan: 2 |
| 223 |
Layout.fillHeight: true |
| 224 |
} |
| 225 |
|
| 226 |
} |
| 227 |
|
| 228 |
GridLayout { |
| 229 |
anchors.fill: parent |
| 230 |
anchors.margins: Nheko.paddingMedium |
| 231 |
visible: currentImageIndex >= 0 |
| 232 |
enabled: visible |
| 233 |
columns: 2 |
| 234 |
rowSpacing: Nheko.paddingLarge |
| 235 |
|
| 236 |
Avatar { |
| 237 |
Layout.columnSpan: 2 |
| 238 |
url: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.Url).replace("mxc://", "image://MxcImage/") + "?scale" |
| 239 |
displayName: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.ShortCode) |
| 240 |
roomid: displayName |
| 241 |
Layout.preferredHeight: 130 |
| 242 |
Layout.preferredWidth: 130 |
| 243 |
crop: false |
| 244 |
Layout.alignment: Qt.AlignHCenter |
| 245 |
} |
| 246 |
|
| 247 |
MatrixTextField { |
| 248 |
Layout.fillWidth: true |
| 249 |
Layout.columnSpan: 2 |
| 250 |
label: qsTr("Shortcode") |
| 251 |
property int bindingCounter: 0 |
| 252 |
text: bindingCounter, imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.ShortCode) |
| 253 |
onTextEdited: { |
| 254 |
imagePack.setData(imagePack.index(currentImageIndex, 0), text, SingleImagePackModel.ShortCode); |
| 255 |
// force text field to update in case the model disagreed with the new value. |
| 256 |
bindingCounter++; |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
MatrixTextField { |
| 261 |
id: bodyField |
| 262 |
|
| 263 |
Layout.fillWidth: true |
| 264 |
Layout.columnSpan: 2 |
| 265 |
label: qsTr("Body") |
| 266 |
text: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.Body) |
| 267 |
onTextEdited: imagePack.setData(imagePack.index(currentImageIndex, 0), text, SingleImagePackModel.Body) |
| 268 |
} |
| 269 |
|
| 270 |
MatrixText { |
| 271 |
Layout.margins: bodyField.textPadding |
| 272 |
font.weight: Font.DemiBold |
| 273 |
font.letterSpacing: font.pixelSize * 0.02 |
| 274 |
text: qsTr("Use as Emoji") |
| 275 |
} |
| 276 |
|
| 277 |
ToggleButton { |
| 278 |
checked: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.IsEmote) |
| 279 |
onCheckedChanged: imagePack.setData(imagePack.index(currentImageIndex, 0), checked, SingleImagePackModel.IsEmote) |
| 280 |
Layout.alignment: Qt.AlignRight |
| 281 |
} |
| 282 |
|
| 283 |
MatrixText { |
| 284 |
Layout.margins: bodyField.textPadding |
| 285 |
font.weight: Font.DemiBold |
| 286 |
font.letterSpacing: font.pixelSize * 0.02 |
| 287 |
text: qsTr("Use as Sticker") |
| 288 |
} |
| 289 |
|
| 290 |
ToggleButton { |
| 291 |
checked: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.IsSticker) |
| 292 |
onCheckedChanged: imagePack.setData(imagePack.index(currentImageIndex, 0), checked, SingleImagePackModel.IsSticker) |
| 293 |
Layout.alignment: Qt.AlignRight |
| 294 |
} |
| 295 |
|
| 296 |
MatrixText { |
| 297 |
Layout.margins: bodyField.textPadding |
| 298 |
font.weight: Font.DemiBold |
| 299 |
font.letterSpacing: font.pixelSize * 0.02 |
| 300 |
text: qsTr("Remove from pack") |
| 301 |
} |
| 302 |
|
| 303 |
Button { |
| 304 |
text: qsTr("Remove") |
| 305 |
onClicked: { |
| 306 |
let temp = currentImageIndex; |
| 307 |
currentImageIndex = -1; |
| 308 |
imagePack.remove(temp); |
| 309 |
} |
| 310 |
Layout.alignment: Qt.AlignRight |
| 311 |
} |
| 312 |
|
| 313 |
Item { |
| 314 |
Layout.columnSpan: 2 |
| 315 |
Layout.fillHeight: true |
| 316 |
} |
| 317 |
|
| 318 |
} |
| 319 |
|
| 320 |
} |
| 321 |
|
| 322 |
} |
| 323 |
|
| 324 |
} |
| 325 |
|
| 326 |
footer: DialogButtonBox { |
| 327 |
id: buttons |
| 328 |
|
| 329 |
standardButtons: DialogButtonBox.Save | DialogButtonBox.Cancel |
| 330 |
onAccepted: { |
| 331 |
imagePack.save(); |
| 332 |
win.close(); |
| 333 |
} |
| 334 |
onRejected: win.close() |
| 335 |
} |
| 336 |
|
| 337 |
} |