Debian Codegraph @

resources/qml/dialogs/ImagePackSettingsDialog.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import ".."
6 import "../components"
7 import QtQuick 2.12
8 import QtQuick.Controls 2.12
9 import QtQuick.Layouts 1.12
10 import im.nheko 1.0
11
12 ApplicationWindow {
13 id: win
14
15 property Room room
16 property ImagePackListModel packlist
17 property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 2.3)
18 property SingleImagePackModel currentPack: packlist.packAt(currentPackIndex)
19 property int currentPackIndex: 0
20 readonly property int stickerDim: 128
21 readonly property int stickerDimPad: 128 + Nheko.paddingSmall
22
23 title: qsTr("Image pack settings")
24 height: 600
25 width: 800
26 color: palette.base
27 modality: Qt.NonModal
28 flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
29
30 Component {
31 id: packEditor
32
33 ImagePackEditorDialog {
34 }
35 }
36
37 Component {
38 id: packDeleteDialog
39 ImagePackDeleteDialog {}
40 }
41
42 AdaptiveLayout {
43 id: adaptiveView
44
45 anchors.fill: parent
46 singlePageMode: false
47 pageIndex: 0
48
49 AdaptiveLayoutElement {
50 id: packlistC
51
52 visible: Settings.groupView
53 minimumWidth: 200
54 collapsedWidth: 200
55 preferredWidth: 300
56 maximumWidth: 300
57
58 ListView {
59 model: packlist
60 clip: true
61
62
63
64 footer: ColumnLayout {
65 Button {
66 onClicked: {
67 var dialog = packEditor.createObject(timelineRoot, {
68 "imagePack": packlist.newPack(false)
69 });
70 dialog.show();
71 timelineRoot.destroyOnClose(dialog);
72 }
73 Layout.preferredWidth: packlistC.width
74 visible: !packlist.containsAccountPack
75 text: qsTr("Create account pack")
76 }
77
78 Button {
79 onClicked: {
80 var dialog = packEditor.createObject(timelineRoot, {
81 "imagePack": packlist.newPack(true)
82 });
83 dialog.show();
84 timelineRoot.destroyOnClose(dialog);
85 }
86 Layout.preferredWidth: packlistC.width
87 visible: room.permissions.canChange(MtxEvent.ImagePackInRoom)
88 text: qsTr("New room pack")
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 displayName
102 required property bool fromAccountData
103 required property bool fromCurrentRoom
104 required property bool fromSpace
105 required property string statekey
106
107 title: displayName
108 subtitle: {
109 if (fromAccountData)
110 return qsTr("Private pack");
111 else if (fromCurrentRoom)
112 return qsTr("Pack from this room");
113 else if (fromSpace)
114 return qsTr("Pack from parent community");
115 else
116 return qsTr("Globally enabled pack");
117 }
118 selectedIndex: currentPackIndex
119 roomid: statekey
120
121 TapHandler {
122 onSingleTapped: currentPackIndex = index
123 }
124
125 }
126
127 }
128
129 }
130
131 AdaptiveLayoutElement {
132 id: packinfoC
133
134 Rectangle {
135 color: palette.window
136
137 ColumnLayout {
138 id: packinfo
139
140 property string packName: currentPack ? currentPack.packname : ""
141 property string attribution: currentPack ? currentPack.attribution : ""
142 property string avatarUrl: currentPack ? currentPack.avatarUrl : ""
143 property string statekey: currentPack ? currentPack.statekey : ""
144
145 anchors.fill: parent
146 anchors.margins: Nheko.paddingLarge
147 spacing: Nheko.paddingLarge
148
149 Avatar {
150 url: packinfo.avatarUrl.replace("mxc://", "image://MxcImage/")
151 displayName: packinfo.packName
152 roomid: packinfo.statekey
153 Layout.preferredHeight: 100
154 Layout.preferredWidth: 100
155 Layout.alignment: Qt.AlignHCenter
156 enabled: false
157 }
158
159 MatrixText {
160 text: packinfo.packName
161 font.pixelSize: Math.ceil(fontMetrics.pixelSize * 1.1)
162 horizontalAlignment: TextEdit.AlignHCenter
163 Layout.alignment: Qt.AlignHCenter
164 Layout.preferredWidth: packinfoC.width - Nheko.paddingLarge * 2
165 textFormat: TextEdit.PlainText
166 }
167
168 MatrixText {
169 text: packinfo.attribution
170 wrapMode: TextEdit.Wrap
171 horizontalAlignment: TextEdit.AlignHCenter
172 Layout.alignment: Qt.AlignHCenter
173 Layout.preferredWidth: packinfoC.width - Nheko.paddingLarge * 2
174 textFormat: TextEdit.PlainText
175 }
176
177 GridLayout {
178 Layout.alignment: Qt.AlignHCenter
179 visible: currentPack && currentPack.roomid != ""
180 columns: 2
181 rowSpacing: Nheko.paddingMedium
182
183 MatrixText {
184 text: qsTr("Enable globally")
185 }
186
187 ToggleButton {
188 ToolTip.text: qsTr("Enables this pack to be used in all rooms")
189 checked: currentPack ? currentPack.isGloballyEnabled : false
190 onCheckedChanged: currentPack.isGloballyEnabled = checked
191 Layout.alignment: Qt.AlignRight
192 }
193
194 }
195
196 RowLayout {
197 Layout.alignment: Qt.AlignHCenter
198
199 Button {
200 text: qsTr("Edit")
201 enabled: currentPack.canEdit
202 onClicked: {
203 var dialog = packEditor.createObject(timelineRoot, {
204 "imagePack": currentPack
205 });
206 dialog.show();
207 timelineRoot.destroyOnClose(dialog);
208 }
209 }
210 Button {
211 text: qsTr("Remove")
212 enabled: currentPack.canEdit
213 onClicked: {
214 var dialog = packDeleteDialog.createObject(timelineRoot, {
215 "imagePack": currentPack
216 });
217 dialog.open();
218 timelineRoot.destroyOnClose(dialog);
219 }
220 }
221 }
222
223 GridView {
224 Layout.fillHeight: true
225 Layout.fillWidth: true
226 model: currentPack
227 cellWidth: stickerDimPad
228 cellHeight: stickerDimPad
229 boundsBehavior: Flickable.StopAtBounds
230 clip: true
231 currentIndex: -1 // prevent sorting from stealing focus
232 cacheBuffer: 500
233
234
235 // Individual emoji
236 delegate: AbstractButton {
237 width: stickerDim
238 height: stickerDim
239 hoverEnabled: true
240 ToolTip.text: ":" + model.shortCode + ": - " + model.body
241 ToolTip.visible: hovered
242
243 contentItem: Image {
244 height: stickerDim
245 width: stickerDim
246 source: model.url.replace("mxc://", "image://MxcImage/") + "?scale"
247 fillMode: Image.PreserveAspectFit
248 }
249
250 background: Rectangle {
251 anchors.fill: parent
252 color: hovered ? palette.highlight : 'transparent'
253 radius: 5
254 }
255
256 }
257
258 }
259
260 }
261
262 }
263
264 }
265
266 }
267
268 footer: DialogButtonBox {
269 id: buttons
270
271 Button {
272 text: qsTr("Close")
273 DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
274 onClicked: win.close()
275 }
276
277 }
278
279 }