1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-06 19:12:30 +01:00
ScreenPlay/ScreenPlayWorkshop/qml/Sidebar.qml

363 lines
10 KiB
QML
Raw Normal View History

import QtQuick
2021-07-15 12:07:39 +02:00
import Qt5Compat.GraphicalEffects
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Material
import ScreenPlayWorkshop
2020-08-20 17:21:09 +02:00
Drawer {
id: root
2021-05-16 19:37:55 +02:00
property SteamWorkshop steamWorkshop
2020-08-20 17:21:09 +02:00
property url videoPreview
property alias imgUrl: img.source
property string name
property var publishedFileID
2020-08-20 17:21:09 +02:00
property int itemIndex
property int subscriptionCount
property bool subscribed: false
2021-05-16 19:37:55 +02:00
signal tagClicked(var tag)
2020-08-20 17:21:09 +02:00
2021-05-16 19:37:55 +02:00
function setWorkshopItem(publishedFileID, imgUrl, videoPreview, subscriptionCount) {
if (root.publishedFileID === publishedFileID) {
2021-05-16 19:37:55 +02:00
if (!root.visible)
2023-02-02 15:25:26 +01:00
root.open();
2021-05-16 19:37:55 +02:00
else
2023-02-02 15:25:26 +01:00
root.close();
return;
2020-08-20 17:21:09 +02:00
}
2023-02-02 15:25:26 +01:00
root.publishedFileID = publishedFileID;
root.imgUrl = imgUrl;
root.subscriptionCount = subscriptionCount;
root.videoPreview = videoPreview;
root.subscribed = false;
txtVotesUp.highlighted = false;
txtVotesDown.highlighted = false;
2021-05-16 19:37:55 +02:00
if (!root.visible)
2023-02-02 15:25:26 +01:00
root.open();
steamWorkshop.requestWorkshopItemDetails(publishedFileID);
2021-05-16 19:37:55 +02:00
}
2021-05-16 19:37:55 +02:00
edge: Qt.RightEdge
height: parent.height - 60
dim: false
modal: false
width: 400
interactive: false
2020-08-20 17:21:09 +02:00
Connections {
function onRequestItemDetailReturned(title, tags, steamIDOwner, description, votesUp, votesDown, url, fileSize, publishedFileId) {
2023-02-02 15:25:26 +01:00
tagListModel.clear();
// Even if the tags array is empty it still contains
// one empty string, resulting in an empty button
if (tags.length > 1) {
for (var i in tags) {
tagListModel.append({
2023-02-02 15:25:26 +01:00
"name": tags[i]
});
}
2023-02-02 15:25:26 +01:00
rpTagList.model = tagListModel;
} else {
2023-02-02 15:25:26 +01:00
rpTagList.model = null;
2020-08-20 17:21:09 +02:00
}
2023-02-02 15:25:26 +01:00
txtTitle.text = title;
const size = Math.floor((1000 * ((fileSize / 1024) / 1000)) / 1000);
txtFileSize.text = qsTr("Size: ") + size + " MB";
pbVotes.to = votesDown + votesUp;
pbVotes.value = votesUp;
txtVotesDown.text = votesDown;
txtVotesUp.text = votesUp;
2021-05-16 19:37:55 +02:00
if (description === "")
2023-02-02 15:25:26 +01:00
description = qsTr("No description...");
txtDescription.text = description;
pbVotes.hoverText = votesUp + " / " + votesDown;
2020-08-20 17:21:09 +02:00
}
2021-05-16 19:37:55 +02:00
target: steamWorkshop
2020-08-20 17:21:09 +02:00
}
Item {
id: imgWrapper
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
width: parent.width
height: 220
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
Image {
id: img
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
fillMode: Image.PreserveAspectCrop
anchors.fill: parent
}
2021-05-16 19:37:55 +02:00
Rectangle {
2020-08-20 17:21:09 +02:00
height: 50
anchors {
bottom: parent.bottom
right: parent.right
left: parent.left
}
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
gradient: Gradient {
GradientStop {
position: 1
2020-08-20 17:21:09 +02:00
color: "#EE000000"
}
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
GradientStop {
position: 0
2020-08-20 17:21:09 +02:00
color: "#00000000"
}
}
}
Text {
id: txtTitle
verticalAlignment: Text.AlignBottom
font.pointSize: 16
color: "white"
wrapMode: Text.WordWrap
elide: Text.ElideRight
height: 50
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
anchors {
bottom: parent.bottom
right: parent.right
margins: 20
left: parent.left
}
}
MouseArea {
id: button
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
height: 50
width: 50
anchors.top: parent.top
anchors.left: parent.left
cursorShape: Qt.PointingHandCursor
onClicked: root.close()
Image {
id: imgBack
2021-05-16 19:37:55 +02:00
2022-05-01 20:20:57 +02:00
source: "qrc:/qml/ScreenPlayWorkshop/assets/icons/icon_arrow_right.svg"
2020-08-20 17:21:09 +02:00
sourceSize: Qt.size(15, 15)
fillMode: Image.PreserveAspectFit
anchors.centerIn: parent
}
}
}
ColumnLayout {
2021-05-16 19:37:55 +02:00
spacing: 20
2020-08-20 17:21:09 +02:00
anchors {
top: imgWrapper.bottom
right: parent.right
left: parent.left
bottom: rlBottomButtons.top
2020-08-20 17:21:09 +02:00
margins: 20
}
ColumnLayout {
Layout.fillHeight: true
Layout.fillWidth: true
spacing: 20
ColumnLayout {
Layout.maximumWidth: 280
Layout.alignment: Qt.AlignHCenter
RowLayout {
Layout.fillWidth: true
spacing: 20
ToolButton {
id: txtVotesUp
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
Layout.fillWidth: true
2022-05-01 20:20:57 +02:00
icon.source: "qrc:/qml/ScreenPlayWorkshop/assets/icons/icon_thumb_up.svg"
2020-08-20 17:21:09 +02:00
ToolTip.visible: hovered
ToolTip.text: qsTr("Click here if you like the content")
onClicked: {
2023-02-02 15:25:26 +01:00
steamWorkshop.vote(root.publishedFileID, true);
txtVotesUp.highlighted = true;
txtVotesDown.highlighted = false;
2020-08-20 17:21:09 +02:00
}
}
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
ToolButton {
id: txtVotesDown
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
Layout.fillWidth: true
2022-05-01 20:20:57 +02:00
icon.source: "qrc:/qml/ScreenPlayWorkshop/assets/icons/icon_thumb_down.svg"
2020-08-20 17:21:09 +02:00
ToolTip.visible: hovered
ToolTip.text: qsTr("Click here if you do not like the content")
onClicked: {
2023-02-02 15:25:26 +01:00
steamWorkshop.vote(root.publishedFileID, false);
txtVotesUp.highlighted = false;
txtVotesDown.highlighted = true;
2020-08-20 17:21:09 +02:00
}
}
}
ProgressBar {
id: pbVotes
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
property string hoverText
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
ToolTip.visible: hovered
ToolTip.text: hoverText
}
}
2021-03-11 17:23:20 +01:00
Flickable {
id: tagsFlickable
Layout.preferredHeight: 55
Layout.maximumHeight: 55
2020-08-20 17:21:09 +02:00
Layout.fillWidth: true
2021-03-11 17:23:20 +01:00
clip: true
flickableDirection: Flickable.HorizontalFlick
ScrollBar.horizontal: ScrollBar {
height: 5
2020-08-20 17:21:09 +02:00
}
2023-02-02 15:25:26 +01:00
contentWidth: rpTagList.childrenRect.width + rowTagList.width + (rpTagList.count * rowTagList.spacing)
contentHeight: 40
2021-05-16 19:37:55 +02:00
2021-03-11 17:23:20 +01:00
Row {
id: rowTagList
height: parent.height
2021-03-11 17:23:20 +01:00
spacing: 10
2021-05-16 19:37:55 +02:00
ListModel {
id: tagListModel
}
2021-03-11 17:23:20 +01:00
Repeater {
id: rpTagList
delegate: Button {
id: txtTags
2021-05-16 19:37:55 +02:00
2021-03-11 17:23:20 +01:00
property string tags
2021-05-16 19:37:55 +02:00
2021-03-11 17:23:20 +01:00
text: name
font.pointSize: 8
onClicked: root.tagClicked(txtTags.text)
2021-02-20 17:39:23 +01:00
}
}
2020-08-20 17:21:09 +02:00
}
}
RowLayout {
Layout.fillWidth: true
spacing: 20
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
Text {
id: txtSubscriptionCount
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
color: Material.secondaryTextColor
font.pointSize: 11
text: qsTr("Subscribtions: ") + root.subscriptionCount
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
2021-05-16 19:37:55 +02:00
2021-01-07 18:07:19 +01:00
Item {
Layout.fillWidth: true
}
2020-08-20 17:21:09 +02:00
Text {
id: txtFileSize
2021-05-16 19:37:55 +02:00
color: Material.secondaryTextColor
font.pointSize: 11
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
2020-08-20 17:21:09 +02:00
}
}
Rectangle {
Layout.fillWidth: true
Layout.minimumHeight: 150
Layout.fillHeight: true //txtDescription.paintedHeight > 100
color: Material.backgroundColor
radius: 3
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
ScrollView {
anchors.fill: parent
anchors.margins: 20
2020-08-20 17:21:09 +02:00
clip: true
ScrollBar.vertical.policy: ScrollBar.AsNeeded
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
Text {
id: txtDescription
2021-05-16 19:37:55 +02:00
2020-08-20 17:21:09 +02:00
width: parent.width
color: Material.primaryTextColor
font.pointSize: 12
2020-08-20 17:21:09 +02:00
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
}
}
}
}
2021-05-16 19:37:55 +02:00
RowLayout {
id: rlBottomButtons
2021-05-16 19:37:55 +02:00
spacing: 20
2020-08-20 17:21:09 +02:00
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: 20
}
2021-05-16 19:37:55 +02:00
ToolButton {
id: btnOpenInSteam
2021-05-16 19:37:55 +02:00
font.pointSize: 10
2022-05-01 20:20:57 +02:00
icon.source: "qrc:/qml/ScreenPlayWorkshop/assets/icons/icon_open_in_new.svg"
height: 25
text: qsTr("Open In Steam")
2023-02-02 15:25:26 +01:00
onClicked: Qt.openUrlExternally("steam://url/CommunityFilePage/" + root.publishedFileID)
}
2021-05-16 19:37:55 +02:00
Button {
id: btnSubscribe
highlighted: !root.subscribed
enabled: !root.subscribed
2022-05-01 20:20:57 +02:00
icon.source: "qrc:/qml/ScreenPlayWorkshop/assets/icons/icon_download.svg"
text: root.subscribed ? qsTr("Subscribed!") : qsTr("Subscribe")
onClicked: {
2023-02-02 15:25:26 +01:00
root.subscribed = true;
root.steamWorkshop.subscribeItem(root.publishedFileID);
}
2020-08-20 17:21:09 +02:00
}
}
2021-05-16 19:37:55 +02:00
background: Rectangle {
2023-02-02 15:25:26 +01:00
color: Material.theme === Material.Light ? "white" : Qt.darker(Material.background)
2021-05-16 19:37:55 +02:00
opacity: 0.95
}
enter: Transition {
SmoothedAnimation {
velocity: 10
easing.type: Easing.InOutQuart
}
}
2020-08-20 17:21:09 +02:00
2021-05-16 19:37:55 +02:00
exit: Transition {
SmoothedAnimation {
velocity: 10
easing.type: Easing.InOutQuart
}
}
}