Create account sticker editor
This commit is contained in:
@@ -38,6 +38,12 @@ Kirigami.CategorizedSettings {
|
||||
icon.name: "preferences-desktop-emoticons"
|
||||
page: Qt.resolvedUrl("Emoticons.qml")
|
||||
},
|
||||
Kirigami.SettingAction {
|
||||
actionName: "stickers"
|
||||
text: i18n("Stickers")
|
||||
icon.name: "stickers"
|
||||
page: Qt.resolvedUrl("StickersPage.qml")
|
||||
},
|
||||
Kirigami.SettingAction {
|
||||
actionName: "spellChecking"
|
||||
text: i18n("Spell Checking")
|
||||
|
||||
148
src/qml/Settings/StickerEditorPage.qml
Normal file
148
src/qml/Settings/StickerEditorPage.qml
Normal file
@@ -0,0 +1,148 @@
|
||||
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
import Qt.labs.platform 1.1
|
||||
import QtQuick.Window 2.15
|
||||
|
||||
import org.kde.kirigami 2.19 as Kirigami
|
||||
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
Kirigami.ScrollablePage {
|
||||
id: root
|
||||
|
||||
required property string description
|
||||
required property string index
|
||||
required property string url
|
||||
required property string shortcode
|
||||
required property var model
|
||||
required property var proxyModel
|
||||
property bool newSticker: false
|
||||
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
|
||||
title: newSticker ? i18nc("@title", "Add Sticker") : i18nc("@title", "Edit Sticker")
|
||||
|
||||
ColumnLayout {
|
||||
MobileForm.FormCard {
|
||||
Layout.topMargin: Kirigami.Units.largeSpacing
|
||||
Layout.fillWidth: true
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 0
|
||||
MobileForm.FormCardHeader {
|
||||
title: i18n("Sticker")
|
||||
}
|
||||
MobileForm.AbstractFormDelegate {
|
||||
Layout.fillWidth: true
|
||||
background: Item {}
|
||||
contentItem: RowLayout {
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Image {
|
||||
id: image
|
||||
Layout.alignment: Qt.AlignRight
|
||||
source: root.url
|
||||
sourceSize.width: Kirigami.Units.gridUnit * 4
|
||||
sourceSize.height: Kirigami.Units.gridUnit * 4
|
||||
width: Kirigami.Units.gridUnit * 4
|
||||
height: Kirigami.Units.gridUnit * 4
|
||||
|
||||
Kirigami.Icon {
|
||||
source: "stickers"
|
||||
anchors.fill: parent
|
||||
visible: parent.status !== Image.Ready
|
||||
}
|
||||
|
||||
QQC2.Button {
|
||||
icon.name: "edit-entry"
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
onClicked: mouseArea.clicked()
|
||||
text: image.source != "" ? i18n("Change Image") : i18n("Set Image")
|
||||
QQC2.ToolTip.text: text
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
display: QQC2.Button.IconOnly
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
anchors.fill: parent
|
||||
property var fileDialog: null;
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
onClicked: {
|
||||
if (fileDialog != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
fileDialog = openFileDialog.createObject(QQC2.ApplicationWindow.Overlay)
|
||||
fileDialog.chosen.connect(function(receivedSource) {
|
||||
mouseArea.fileDialog = null;
|
||||
if (!receivedSource) {
|
||||
return;
|
||||
}
|
||||
parent.source = receivedSource;
|
||||
});
|
||||
fileDialog.onRejected.connect(function() {
|
||||
mouseArea.fileDialog = null;
|
||||
});
|
||||
fileDialog.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
MobileForm.FormTextFieldDelegate {
|
||||
id: shortcode
|
||||
label: i18n("Shortcode:")
|
||||
text: root.shortcode
|
||||
}
|
||||
MobileForm.FormTextFieldDelegate {
|
||||
id: description
|
||||
label: i18n("Description:")
|
||||
text: root.description
|
||||
}
|
||||
MobileForm.FormButtonDelegate {
|
||||
id: save
|
||||
text: i18n("Save")
|
||||
icon.name: "document-save"
|
||||
enabled: !root.newSticker || (image.source && shortcode.text && description.text)
|
||||
onClicked: {
|
||||
if (root.newSticker) {
|
||||
model.addSticker(image.source, shortcode.text, description.text)
|
||||
} else {
|
||||
if (description.text !== root.description) {
|
||||
root.model.setStickerBody(proxyModel.mapToSource(proxyModel.index(model.index, 0)).row, description.text)
|
||||
}
|
||||
if (shortcode.text !== root.shortcode) {
|
||||
root.model.setStickerShortcode(proxyModel.mapToSource(proxyModel.index(model.index, 0)).row, shortcode.text)
|
||||
}
|
||||
if (image.source + "" !== root.url) {
|
||||
root.model.setStickerImage(proxyModel.mapToSource(proxyModel.index(model.index, 0)).row, image.source)
|
||||
}
|
||||
}
|
||||
root.closeDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Component {
|
||||
id: openFileDialog
|
||||
|
||||
OpenFileDialog {
|
||||
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
|
||||
parentWindow: root.Window.window
|
||||
}
|
||||
}
|
||||
}
|
||||
128
src/qml/Settings/StickersPage.qml
Normal file
128
src/qml/Settings/StickersPage.qml
Normal file
@@ -0,0 +1,128 @@
|
||||
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.19 as Kirigami
|
||||
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
Kirigami.ScrollablePage {
|
||||
title: i18n("Stickers")
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
|
||||
ColumnLayout {
|
||||
MobileForm.FormCard {
|
||||
Layout.topMargin: Kirigami.Units.largeSpacing
|
||||
Layout.fillWidth: true
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 0
|
||||
MobileForm.FormCardHeader {
|
||||
title: i18n("Stickers")
|
||||
}
|
||||
Flow {
|
||||
id: stickerFlow
|
||||
Layout.fillWidth: true
|
||||
Repeater {
|
||||
model: EmoticonFilterModel {
|
||||
id: emoticonFilterModel
|
||||
sourceModel: AccountStickerModel {
|
||||
id: stickerModel
|
||||
connection: Controller.activeConnection
|
||||
}
|
||||
showStickers: true
|
||||
showEmojis: false
|
||||
}
|
||||
|
||||
delegate: MobileForm.AbstractFormDelegate {
|
||||
id: stickerDelegate
|
||||
|
||||
width: stickerFlow.width / 4
|
||||
height: width
|
||||
|
||||
onClicked: pageSettingStack.pushDialogLayer(stickerEditorPage, {
|
||||
description: model.body ?? "",
|
||||
index: model.index,
|
||||
url: model.url,
|
||||
shortcode: model.shortcode,
|
||||
model: stickerModel,
|
||||
proxyModel: emoticonFilterModel
|
||||
}, {
|
||||
title: i18nc("@title", "Edit Sticker")
|
||||
});
|
||||
|
||||
contentItem: ColumnLayout {
|
||||
Image {
|
||||
source: model.url
|
||||
Layout.fillWidth: true
|
||||
sourceSize.height: parent.width * 0.8
|
||||
fillMode: Image.PreserveAspectFit
|
||||
autoTransform: true
|
||||
Kirigami.Icon {
|
||||
source: "stickers"
|
||||
anchors.fill: parent
|
||||
visible: parent.status !== Image.Ready
|
||||
}
|
||||
}
|
||||
QQC2.Label {
|
||||
id: descriptionLabel
|
||||
text: model.body ?? i18nc("As in 'This sticker has no description'", "No Description")
|
||||
horizontalAlignment: Qt.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.Wrap
|
||||
maximumLineCount: 2
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
}
|
||||
QQC2.Button {
|
||||
icon.name: "edit-delete"
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
anchors.margins: Kirigami.Units.smallSpacing
|
||||
z: 2
|
||||
onClicked: stickerModel.deleteSticker(emoticonFilterModel.mapToSource(emoticonFilterModel.index(model.index, 0)).row)
|
||||
}
|
||||
}
|
||||
}
|
||||
MobileForm.AbstractFormDelegate {
|
||||
width: stickerFlow.width / 4
|
||||
height: width
|
||||
|
||||
onClicked: pageSettingStack.pushDialogLayer(stickerEditorPage, {
|
||||
description: "",
|
||||
index: -1,
|
||||
url: "",
|
||||
shortcode: "",
|
||||
model: stickerModel,
|
||||
proxyModel: emoticonFilterModel,
|
||||
newSticker: true
|
||||
}, {
|
||||
title: i18nc("@title", "Add Sticker")
|
||||
});
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 0
|
||||
Kirigami.Icon {
|
||||
source: "list-add"
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
QQC2.Label {
|
||||
text: i18n("Add Sticker")
|
||||
horizontalAlignment: Qt.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: stickerEditorPage
|
||||
StickerEditorPage {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user