matrixion/qml/dialogs/ImagePackEditorDialog.qml

306 lines
12 KiB
QML
Raw Permalink Normal View History

2021-08-06 02:45:47 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-08-06 02:45:47 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
2022-04-16 03:13:01 +03:00
import "../"
2021-08-06 02:45:47 +03:00
import "../components"
2021-08-06 04:28:56 +03:00
import Qt.labs.platform 1.1
2021-08-06 02:45:47 +03:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import im.nheko
2021-08-06 02:45:47 +03:00
ApplicationWindow {
id: win
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 2.3)
property int currentImageIndex: -1
2022-04-16 03:13:01 +03:00
property SingleImagePackModel imagePack
2021-08-06 02:45:47 +03:00
readonly property int stickerDim: 128
readonly property int stickerDimPad: 128 + Nheko.paddingSmall
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.base
2021-08-19 17:55:54 +03:00
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
2022-04-16 03:13:01 +03:00
height: 600
modality: Qt.WindowModal
palette: timelineRoot.palette
title: qsTr("Editing image pack")
width: 600
footer: DialogButtonBox {
id: buttons
standardButtons: DialogButtonBox.Save | DialogButtonBox.Cancel
onAccepted: {
imagePack.save();
win.close();
}
onRejected: win.close()
}
2021-08-06 02:45:47 +03:00
AdaptiveLayout {
id: adaptiveView
anchors.fill: parent
pageIndex: 0
2022-04-16 03:13:01 +03:00
singlePageMode: false
2021-08-06 02:45:47 +03:00
AdaptiveLayoutElement {
id: packlistC
2022-04-16 03:13:01 +03:00
clip: true
2021-08-06 02:45:47 +03:00
collapsedWidth: 200
maximumWidth: 300
2022-04-16 03:13:01 +03:00
minimumWidth: 200
preferredWidth: 300
visible: Settings.groupView
2021-08-06 02:45:47 +03:00
ListView {
//required property bool isEmote
//required property bool isSticker
model: imagePack
2022-04-16 03:13:01 +03:00
delegate: AvatarListTile {
id: packItem
2021-08-06 02:45:47 +03:00
2022-04-16 03:13:01 +03:00
property color background: timelineRoot.palette.window
required property string body
property color bubbleBackground: timelineRoot.palette.highlight
property color bubbleText: timelineRoot.palette.highlightedText
property color importantText: timelineRoot.palette.text
required property string shortCode
property color unimportantText: timelineRoot.palette.placeholderText
required property string url
avatarUrl: url
crop: false
2021-08-06 02:45:47 +03:00
selectedIndex: currentImageIndex
2022-04-16 03:13:01 +03:00
subtitle: body
title: shortCode
2021-08-06 02:45:47 +03:00
TapHandler {
2022-04-16 03:13:01 +03:00
onSingleTapped: currentImageIndex = index
2021-08-06 02:45:47 +03:00
}
}
2021-08-06 04:28:56 +03:00
footer: Button {
2022-04-11 05:18:16 +03:00
palette: timelineRoot.palette
2021-08-06 04:28:56 +03:00
text: qsTr("Add images")
2022-04-16 03:13:01 +03:00
width: ListView.view.width
onClicked: addFilesDialog.open()
2021-08-06 04:28:56 +03:00
FileDialog {
id: addFilesDialog
2022-04-16 03:13:01 +03:00
acceptLabel: qsTr("Add to pack")
2021-08-06 04:28:56 +03:00
fileMode: FileDialog.OpenFiles
2022-04-16 03:13:01 +03:00
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
2021-12-13 08:18:30 +03:00
nameFilters: [qsTr("Images (*.png *.webp *.gif *.jpg *.jpeg)")]
title: qsTr("Select images for pack")
2022-04-16 03:13:01 +03:00
2021-08-06 04:28:56 +03:00
onAccepted: imagePack.addStickers(files)
}
}
2022-04-16 03:13:01 +03:00
header: AvatarListTile {
avatarUrl: imagePack.avatarUrl
index: -1
roomid: imagePack.statekey
2021-08-06 02:45:47 +03:00
selectedIndex: currentImageIndex
2022-04-16 03:13:01 +03:00
subtitle: imagePack.statekey
title: imagePack.packname
2021-08-06 02:45:47 +03:00
TapHandler {
2022-04-16 03:13:01 +03:00
onSingleTapped: currentImageIndex = -1
}
Rectangle {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
color: timelineRoot.palette.highlight
height: parent.height - Nheko.paddingSmall * 2
width: 3
2021-08-06 02:45:47 +03:00
}
}
}
}
AdaptiveLayoutElement {
id: packinfoC
Rectangle {
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.window
2021-08-06 02:45:47 +03:00
GridLayout {
anchors.fill: parent
anchors.margins: Nheko.paddingMedium
columns: 2
2022-04-16 03:13:01 +03:00
enabled: visible
2021-08-06 02:45:47 +03:00
rowSpacing: Nheko.paddingLarge
2022-04-16 03:13:01 +03:00
visible: currentImageIndex == -1
2021-08-06 02:45:47 +03:00
Avatar {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignHCenter
2021-08-06 02:45:47 +03:00
Layout.columnSpan: 2
2022-04-16 03:13:01 +03:00
crop: false
2021-08-06 02:45:47 +03:00
displayName: imagePack.packname
height: 130
2022-04-16 03:13:01 +03:00
roomid: imagePack.statekey
url: imagePack.avatarUrl.replace("mxc://", "image://MxcImage/")
2021-08-06 02:45:47 +03:00
width: 130
2021-12-13 08:00:32 +03:00
ImageButton {
ToolTip.text: qsTr("Change the overview image for this pack")
2022-04-16 03:13:01 +03:00
ToolTip.visible: hovered
2021-12-13 08:00:32 +03:00
anchors.left: parent.left
anchors.leftMargin: Nheko.paddingMedium
2022-04-16 03:13:01 +03:00
anchors.top: parent.top
2021-12-13 08:00:32 +03:00
anchors.topMargin: Nheko.paddingMedium
2022-04-16 03:13:01 +03:00
hoverEnabled: true
2021-12-13 08:00:32 +03:00
image: ":/icons/icons/ui/edit.svg"
2022-04-16 03:13:01 +03:00
2021-12-13 08:00:32 +03:00
onClicked: addAvatarDialog.open()
FileDialog {
id: addAvatarDialog
fileMode: FileDialog.OpenFile
2022-04-16 03:13:01 +03:00
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
2021-12-13 08:00:32 +03:00
nameFilters: [qsTr("Overview Image (*.png *.webp *.jpg *.jpeg)")]
2021-12-13 08:18:30 +03:00
title: qsTr("Select overview image for pack")
2022-04-16 03:13:01 +03:00
2021-12-13 08:00:32 +03:00
onAccepted: imagePack.setAvatar(file)
}
}
2021-08-06 02:45:47 +03:00
}
MatrixTextField {
2022-01-24 02:41:55 +03:00
id: statekeyField
Layout.columnSpan: 2
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
2022-01-24 02:41:55 +03:00
label: qsTr("State key")
2021-08-06 02:45:47 +03:00
text: imagePack.statekey
2022-04-16 03:13:01 +03:00
visible: imagePack.roomid
2021-08-06 02:45:47 +03:00
onTextEdited: imagePack.statekey = text
}
MatrixTextField {
2022-01-24 02:41:55 +03:00
Layout.columnSpan: 2
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
2022-01-24 02:41:55 +03:00
label: qsTr("Packname")
2021-08-06 02:45:47 +03:00
text: imagePack.packname
2022-04-16 03:13:01 +03:00
2021-08-06 02:45:47 +03:00
onTextEdited: imagePack.packname = text
}
MatrixTextField {
2022-01-24 02:41:55 +03:00
Layout.columnSpan: 2
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
2022-01-24 02:41:55 +03:00
label: qsTr("Attribution")
2021-08-06 02:45:47 +03:00
text: imagePack.attribution
2022-04-16 03:13:01 +03:00
2021-08-06 02:45:47 +03:00
onTextEdited: imagePack.attribution = text
}
MatrixText {
2022-01-24 02:41:55 +03:00
Layout.margins: statekeyField.textPadding
font.letterSpacing: font.pixelSize * 0.02
2022-04-16 03:13:01 +03:00
font.weight: Font.DemiBold
2021-08-06 02:45:47 +03:00
text: qsTr("Use as Emoji")
}
ToggleButton {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignRight
2021-08-06 02:45:47 +03:00
checked: imagePack.isEmotePack
2022-04-16 03:13:01 +03:00
2022-01-09 02:28:03 +03:00
onCheckedChanged: imagePack.isEmotePack = checked
2021-08-06 02:45:47 +03:00
}
MatrixText {
2022-01-24 02:41:55 +03:00
Layout.margins: statekeyField.textPadding
font.letterSpacing: font.pixelSize * 0.02
2022-04-16 03:13:01 +03:00
font.weight: Font.DemiBold
2021-08-06 02:45:47 +03:00
text: qsTr("Use as Sticker")
}
ToggleButton {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignRight
2021-08-06 02:45:47 +03:00
checked: imagePack.isStickerPack
2022-04-16 03:13:01 +03:00
2022-01-09 02:28:03 +03:00
onCheckedChanged: imagePack.isStickerPack = checked
2021-08-06 02:45:47 +03:00
}
Item {
Layout.columnSpan: 2
Layout.fillHeight: true
}
}
GridLayout {
anchors.fill: parent
anchors.margins: Nheko.paddingMedium
columns: 2
2022-04-16 03:13:01 +03:00
enabled: visible
2021-08-06 02:45:47 +03:00
rowSpacing: Nheko.paddingLarge
2022-04-16 03:13:01 +03:00
visible: currentImageIndex >= 0
2021-08-06 02:45:47 +03:00
Avatar {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignHCenter
2021-08-06 02:45:47 +03:00
Layout.columnSpan: 2
2022-04-16 03:13:01 +03:00
crop: false
2021-08-06 02:45:47 +03:00
displayName: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.ShortCode)
height: 130
2022-04-16 03:13:01 +03:00
roomid: displayName
url: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.Url).replace("mxc://", "image://MxcImage/") + "?scale"
2021-08-06 02:45:47 +03:00
width: 130
}
MatrixTextField {
2022-01-24 02:41:55 +03:00
Layout.columnSpan: 2
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
2022-01-24 02:41:55 +03:00
label: qsTr("Shortcode")
2021-08-06 02:45:47 +03:00
text: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.ShortCode)
2022-04-16 03:13:01 +03:00
2021-08-06 02:45:47 +03:00
onTextEdited: imagePack.setData(imagePack.index(currentImageIndex, 0), text, SingleImagePackModel.ShortCode)
}
MatrixTextField {
2022-01-24 02:41:55 +03:00
id: bodyField
Layout.columnSpan: 2
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
2022-01-24 02:41:55 +03:00
label: qsTr("Body")
2021-08-06 02:45:47 +03:00
text: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.Body)
2022-04-16 03:13:01 +03:00
2021-08-06 02:45:47 +03:00
onTextEdited: imagePack.setData(imagePack.index(currentImageIndex, 0), text, SingleImagePackModel.Body)
}
MatrixText {
2022-01-24 02:41:55 +03:00
Layout.margins: bodyField.textPadding
font.letterSpacing: font.pixelSize * 0.02
2022-04-16 03:13:01 +03:00
font.weight: Font.DemiBold
2021-08-06 02:45:47 +03:00
text: qsTr("Use as Emoji")
}
ToggleButton {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignRight
2021-08-06 02:45:47 +03:00
checked: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.IsEmote)
2022-04-16 03:13:01 +03:00
2022-01-09 02:28:03 +03:00
onCheckedChanged: imagePack.setData(imagePack.index(currentImageIndex, 0), checked, SingleImagePackModel.IsEmote)
2021-08-06 02:45:47 +03:00
}
MatrixText {
2022-01-24 02:41:55 +03:00
Layout.margins: bodyField.textPadding
font.letterSpacing: font.pixelSize * 0.02
2022-04-16 03:13:01 +03:00
font.weight: Font.DemiBold
2021-08-06 02:45:47 +03:00
text: qsTr("Use as Sticker")
}
ToggleButton {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignRight
2021-08-06 02:45:47 +03:00
checked: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.IsSticker)
2022-04-16 03:13:01 +03:00
2022-01-09 02:28:03 +03:00
onCheckedChanged: imagePack.setData(imagePack.index(currentImageIndex, 0), checked, SingleImagePackModel.IsSticker)
2021-08-06 02:45:47 +03:00
}
MatrixText {
2022-01-24 02:41:55 +03:00
Layout.margins: bodyField.textPadding
font.letterSpacing: font.pixelSize * 0.02
2022-04-16 03:13:01 +03:00
font.weight: Font.DemiBold
text: qsTr("Remove from pack")
}
Button {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignRight
text: qsTr("Remove")
2022-04-16 03:13:01 +03:00
onClicked: {
let temp = currentImageIndex;
currentImageIndex = -1;
imagePack.remove(temp);
}
}
2021-08-06 02:45:47 +03:00
Item {
Layout.columnSpan: 2
Layout.fillHeight: true
}
}
}
}
}
}