summaryrefslogtreecommitdiffstats
path: root/resources/qml/UploadBox.qml
blob: 1d9415e5c2c25fc7b9b9e155b57b526aa99f7ae8 (plain)
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
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick 2.9
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import im.nheko 1.0

Page {
    id: uploadPopup

    Layout.fillWidth: true
    Layout.preferredHeight: 200
    clip: true
    padding: Nheko.paddingMedium
    visible: room && room.input.uploads.length > 0

    background: Rectangle {
        color: palette.base
    }
    contentItem: ListView {
        id: uploadsList

        anchors.horizontalCenter: parent.horizontalCenter
        boundsBehavior: Flickable.StopAtBounds
        model: room ? room.input.uploads : undefined
        orientation: ListView.Horizontal
        spacing: Nheko.paddingMedium
        width: Math.min(contentWidth, parent.availableWidth)

        ScrollBar.horizontal: ScrollBar {
            id: scr

        }
        delegate: Pane {
            id: pane

            height: uploadPopup.availableHeight - buttons.height - (scr.visible ? scr.height : 0)
            padding: Nheko.paddingSmall
            width: uploadPopup.availableHeight - buttons.height

            background: Rectangle {
                color: palette.window
                radius: Nheko.paddingMedium
            }
            contentItem: ColumnLayout {
                Image {
                    property string typeStr: switch (modelData.mediaType) {
                    case MediaUpload.Video:
                        return "video-file";
                    case MediaUpload.Audio:
                        return "music";
                    case MediaUpload.Image:
                        return "image";
                    default:
                        return "zip";
                    }

                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    fillMode: Image.PreserveAspectFit
                    mipmap: true
                    smooth: true
                    source: (modelData.thumbnail != "") ? modelData.thumbnail : ("image://colorimage/:/icons/icons/ui/" + typeStr + ".svg?" + palette.buttonText)
                    sourceSize.height: pane.availableHeight - namefield.height
                    sourceSize.width: pane.availableWidth
                }
                MatrixTextField {
                    id: namefield

                    Layout.fillWidth: true
                    text: modelData.filename

                    onTextEdited: modelData.filename = text
                }
            }
        }
    }
    footer: DialogButtonBox {
        id: buttons

        standardButtons: DialogButtonBox.Cancel

        onAccepted: room.input.acceptUploads()
        onRejected: room.input.declineUploads()

        Button {
            DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
            text: qsTr("Upload %n file(s)", "", (room ? room.input.uploads.length : 0))
        }
    }
}