Warning, /network/tokodon/src/content/ui/StatusDelegate/StatusPoll.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003
0004 import QtQuick
0005 import org.kde.kirigami 2 as Kirigami
0006 import QtQuick.Controls 2 as QQC2
0007 import QtQuick.Layouts
0008 import org.kde.tokodon
0009
0010 // Polls inside of a status
0011 ColumnLayout {
0012 id: root
0013
0014 required property var index
0015 required property var poll
0016 readonly property bool showResults: poll.voted || poll.expired
0017
0018 QQC2.ButtonGroup {
0019 id: pollGroup
0020 exclusive: !root.poll.multiple
0021 }
0022
0023 Repeater {
0024 model: root.showResults ? root.poll.options : []
0025
0026 ColumnLayout {
0027 id: votedPollDelegate
0028
0029 required property var modelData
0030
0031 RowLayout {
0032 spacing: root.poll.votesCount !== 0 ? Kirigami.Units.largeSpacing : 0
0033 QQC2.Label {
0034 text: if (modelData.votesCount === -1) {
0035 return ''
0036 } else if (root.poll.votesCount === 0) {
0037 return ''
0038 } else {
0039 return i18nc("Votes percentage", "%1%", Math.round(votedPollDelegate.modelData.votesCount / root.poll.votesCount * 100))
0040 }
0041 Layout.alignment: Qt.AlignVCenter
0042 Layout.minimumWidth: root.poll.votesCount !== 0 ? Kirigami.Units.gridUnit * 2 : 0
0043 }
0044
0045 QQC2.Label {
0046 text: votedPollDelegate.modelData.title
0047 Layout.fillWidth: true
0048 Layout.alignment: Qt.AlignVCenter
0049 }
0050 }
0051
0052 RowLayout {
0053 QQC2.ProgressBar {
0054 from: 0
0055 to: 100
0056 value: votedPollDelegate.modelData.votesCount / root.poll.votesCount * 100
0057 Layout.maximumWidth: Kirigami.Units.gridUnit * 10
0058 Layout.minimumWidth: Kirigami.Units.gridUnit * 10
0059 Layout.alignment: Qt.AlignVCenter
0060 }
0061
0062 QQC2.Label {
0063 text: i18n("(No votes)")
0064 visible: root.poll.votesCount === 0
0065 }
0066 }
0067 }
0068 }
0069
0070 Repeater {
0071 model: !root.showResults ? poll.options : []
0072 RowLayout {
0073 QQC2.CheckBox {
0074 visible: poll.multiple
0075 Layout.alignment: Qt.AlignVCenter
0076 QQC2.ButtonGroup.group: pollGroup
0077 property int choiceIndex: index
0078 }
0079
0080 QQC2.RadioButton {
0081 visible: !poll.multiple
0082 Layout.alignment: Qt.AlignVCenter
0083 QQC2.ButtonGroup.group: pollGroup
0084 property int choiceIndex: index
0085 }
0086
0087 QQC2.Label {
0088 text: modelData.title
0089 Layout.fillWidth: true
0090 Layout.alignment: Qt.AlignVCenter
0091 }
0092 }
0093 }
0094
0095 QQC2.Button {
0096 visible: !root.showResults
0097 text: i18n("Vote")
0098 enabled: pollGroup.checkState !== Qt.Unchecked
0099 onClicked: {
0100 let choices = [];
0101 const buttons = pollGroup.buttons;
0102 for (let i in buttons) {
0103 const button = buttons[i];
0104 if (!button.visible) {
0105 continue;
0106 }
0107
0108 if (button.checked) {
0109 choices.push(button.choiceIndex);
0110 }
0111 }
0112 timelineModel.actionVote(timelineModel.index(root.index, 0), choices)
0113 }
0114 }
0115 }