-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
EditorAttachmentGrid.qml
111 lines (83 loc) · 3.49 KB
/
EditorAttachmentGrid.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-FileCopyrightText: 2021 Carl Schwan <[email protected]>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import org.kde.kirigami 2 as Kirigami
import QtQuick.Controls 2 as QQC2
import QtQml.Models
import QtQuick.Layouts
import "../Components"
GridLayout {
id: root
required property var attachmentEditorModel
visible: attachmentsRepeater.count > 0
columns: Math.min(attachmentsRepeater.count, 2)
implicitHeight: Kirigami.Units.gridUnit * 20
Repeater {
id: attachmentsRepeater
model: root.attachmentEditorModel
FocusedImage {
id: img
required property int index
required property string preview
required property string description
required property real focalX
required property real focalY
readonly property var mediaRatio: 9.0 / 16.0
// If there is three attachments, the first one is bigger than the other two.
readonly property bool isSpecialAttachment: index === 0 && attachmentsRepeater.count === 3
readonly property var heightDivisor: (isSpecialAttachment || attachmentsRepeater.count < 3) ? 1 : 2
source: img.preview
focusX: img.focalX
focusY: img.focalY
Layout.rowSpan: isSpecialAttachment ? 2 : 1
readonly property real extraSpacing: isSpecialAttachment ? root.rowSpacing : 0
Layout.preferredWidth: parent.width / root.columns
Layout.preferredHeight: (parent.width * mediaRatio / heightDivisor) + extraSpacing
layer.enabled: true
layer.effect: RoundedEffect {}
QQC2.RoundButton {
id: editButton
QQC2.ToolTip.text: i18n("Edit")
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
QQC2.ToolTip.visible: hovered
icon.name: 'document-edit'
onClicked: {
const dialog = attachmentInfoDialog.createObject(applicationWindow(), {
text: img.description,
preview: img.preview,
focusX: img.focalX,
focusY: img.focalY,
});
dialog.open();
dialog.applied.connect(() => {
root.attachmentEditorModel.setDescription(img.index, dialog.text);
root.attachmentEditorModel.setFocusPoint(img.index, dialog.focusX, dialog.focusY);
});
}
anchors {
right: removeButton.left
top: parent.top
margins: Kirigami.Units.smallSpacing
rightMargin: Kirigami.Units.largeSpacing
}
Component {
id: attachmentInfoDialog
AttachmentInfoDialog {}
}
}
QQC2.RoundButton {
id: removeButton
QQC2.ToolTip.text: i18n("Remove")
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
QQC2.ToolTip.visible: hovered
icon.name: 'edit-delete-remove'
onClicked: backend.attachmentEditorModel.removeAttachment(img.index)
anchors {
right: parent.right
top: parent.top
margins: Kirigami.Units.smallSpacing
}
}
}
}
}