matrixion/qml/dialogs/ImagePackSettingsDialog.qml

231 lines
8.9 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
// SPDX-License-Identifier: GPL-3.0-or-later
2022-04-16 03:13:01 +03:00
import "../"
import "../components"
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import im.nheko
ApplicationWindow {
id: win
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 2.3)
property SingleImagePackModel currentPack: packlist.packAt(currentPackIndex)
property int currentPackIndex: 0
2022-04-16 03:13:01 +03:00
property ImagePackListModel packlist
property Room room
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.NonModal
palette: timelineRoot.palette
title: qsTr("Image pack settings")
width: 800
footer: DialogButtonBox {
id: buttons
Button {
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
text: qsTr("Close")
onClicked: win.close()
}
}
2021-08-06 02:45:47 +03:00
Component {
id: packEditor
ImagePackEditorDialog {
}
}
AdaptiveLayout {
id: adaptiveView
anchors.fill: parent
pageIndex: 0
2022-04-16 03:13:01 +03:00
singlePageMode: false
AdaptiveLayoutElement {
id: packlistC
collapsedWidth: 200
maximumWidth: 300
2022-04-16 03:13:01 +03:00
minimumWidth: 200
preferredWidth: 300
visible: Settings.groupView
ListView {
clip: true
2022-04-16 03:13:01 +03:00
model: packlist
2021-08-06 05:31:30 +03:00
2021-08-06 02:45:47 +03:00
delegate: AvatarListTile {
id: packItem
2022-04-11 05:18:16 +03:00
property color background: timelineRoot.palette.window
property color bubbleBackground: timelineRoot.palette.highlight
property color bubbleText: timelineRoot.palette.highlightedText
required property string displayName
required property bool fromAccountData
required property bool fromCurrentRoom
2022-04-16 03:13:01 +03:00
property color importantText: timelineRoot.palette.text
2021-09-15 01:39:57 +03:00
required property string statekey
2022-04-16 03:13:01 +03:00
property color unimportantText: timelineRoot.palette.placeholderText
2022-04-16 03:13:01 +03:00
roomid: statekey
selectedIndex: currentPackIndex
2021-08-06 02:45:47 +03:00
subtitle: {
if (fromAccountData)
return qsTr("Private pack");
else if (fromCurrentRoom)
return qsTr("Pack from this room");
else
return qsTr("Globally enabled pack");
}
2022-04-16 03:13:01 +03:00
title: displayName
TapHandler {
onSingleTapped: currentPackIndex = index
}
}
2022-04-16 03:13:01 +03:00
footer: ColumnLayout {
Button {
palette: timelineRoot.palette
text: qsTr("Create account pack")
visible: !packlist.containsAccountPack
width: packlistC.width
2022-04-16 03:13:01 +03:00
onClicked: {
var dialog = packEditor.createObject(timelineRoot, {
"imagePack": packlist.newPack(false)
});
dialog.show();
timelineRoot.destroyOnClose(dialog);
}
}
Button {
palette: timelineRoot.palette
text: qsTr("New room pack")
visible: room.permissions.canChange(MtxEvent.ImagePackInRoom)
width: packlistC.width
2022-04-16 03:13:01 +03:00
onClicked: {
var dialog = packEditor.createObject(timelineRoot, {
"imagePack": packlist.newPack(true)
});
dialog.show();
timelineRoot.destroyOnClose(dialog);
}
}
}
}
}
AdaptiveLayoutElement {
id: packinfoC
Rectangle {
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.window
ColumnLayout {
id: packinfo
2021-08-06 02:45:47 +03:00
property string attribution: currentPack ? currentPack.attribution : ""
property string avatarUrl: currentPack ? currentPack.avatarUrl : ""
2022-04-16 03:13:01 +03:00
property string packName: currentPack ? currentPack.packname : ""
2021-09-07 04:14:45 +03:00
property string statekey: currentPack ? currentPack.statekey : ""
anchors.fill: parent
anchors.margins: Nheko.paddingLarge
spacing: Nheko.paddingLarge
Avatar {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignHCenter
displayName: packinfo.packName
2022-04-16 03:13:01 +03:00
enabled: false
height: 100
2022-04-16 03:13:01 +03:00
roomid: packinfo.statekey
url: packinfo.avatarUrl.replace("mxc://", "image://MxcImage/")
width: 100
}
MatrixText {
2021-08-06 02:45:47 +03:00
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: packinfoC.width - Nheko.paddingLarge * 2
2022-04-16 03:13:01 +03:00
font.pixelSize: Math.ceil(fontMetrics.pixelSize * 1.1)
horizontalAlignment: TextEdit.AlignHCenter
text: packinfo.packName
2021-08-06 02:45:47 +03:00
}
MatrixText {
Layout.alignment: Qt.AlignHCenter
2021-08-06 02:45:47 +03:00
Layout.preferredWidth: packinfoC.width - Nheko.paddingLarge * 2
2022-04-16 03:13:01 +03:00
horizontalAlignment: TextEdit.AlignHCenter
text: packinfo.attribution
wrapMode: TextEdit.Wrap
}
GridLayout {
Layout.alignment: Qt.AlignHCenter
columns: 2
rowSpacing: Nheko.paddingMedium
2022-04-16 03:13:01 +03:00
visible: currentPack && currentPack.roomid != ""
MatrixText {
text: qsTr("Enable globally")
}
ToggleButton {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignRight
ToolTip.text: qsTr("Enables this pack to be used in all rooms")
checked: currentPack ? currentPack.isGloballyEnabled : false
2022-04-16 03:13:01 +03:00
2022-01-09 02:28:03 +03:00
onCheckedChanged: currentPack.isGloballyEnabled = checked
}
}
2021-08-06 02:45:47 +03:00
Button {
Layout.alignment: Qt.AlignHCenter
enabled: currentPack.canEdit
2022-04-16 03:13:01 +03:00
text: qsTr("Edit")
2021-08-06 02:45:47 +03:00
onClicked: {
var dialog = packEditor.createObject(timelineRoot, {
2022-04-16 03:13:01 +03:00
"imagePack": currentPack
});
2021-08-06 02:45:47 +03:00
dialog.show();
timelineRoot.destroyOnClose(dialog);
2021-08-06 02:45:47 +03:00
}
}
GridView {
Layout.fillHeight: true
Layout.fillWidth: true
boundsBehavior: Flickable.StopAtBounds
2022-04-16 03:13:01 +03:00
cacheBuffer: 500
cellHeight: stickerDimPad
cellWidth: stickerDimPad
clip: true
currentIndex: -1 // prevent sorting from stealing focus
2022-04-16 03:13:01 +03:00
model: currentPack
// Individual emoji
delegate: AbstractButton {
2021-08-06 02:45:47 +03:00
ToolTip.text: ":" + model.shortCode + ": - " + model.body
ToolTip.visible: hovered
2022-04-16 03:13:01 +03:00
height: stickerDim
hoverEnabled: true
width: stickerDim
background: Rectangle {
anchors.fill: parent
2022-04-11 05:18:16 +03:00
color: hovered ? timelineRoot.palette.highlight : 'transparent'
radius: 5
}
2022-04-16 03:13:01 +03:00
contentItem: Image {
fillMode: Image.PreserveAspectFit
height: stickerDim
source: model.url.replace("mxc://", "image://MxcImage/") + "?scale"
width: stickerDim
}
}
}
}
}
}
}
}