app/resources/qml/Widgets/StartlistWidget.qml

213 lines
6 KiB
QML
Raw Normal View History

/*
blueROCK - for digital rock
Copyright (C) 2019 Dorian Zedler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.9
import QtQuick.Controls 2.4
import "../Components"
DataListView {
id: control
property string title: control.widgetData['comp_name']
property string subTitle: getSubtitle()
property bool titleIsPageTitle: true
property Component headerComponent: Item {
anchors.fill: parent
Button {
id: cupToolBt
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: parent.width * 0.1
}
height: parent.height * 0.5
width: height
onClicked: {
control.changeCat()
}
onPressed: cupToolBt.scale = 0.9
onReleased: cupToolBt.scale = 1.0
background: Image {
anchors.centerIn: parent
source: "qrc:/icons/more_black.png"
height: parent.height > parent.width ? parent.width : parent.height
width: height
mipmap: true
fillMode: Image.PreserveAspectFit
Behavior on scale {
PropertyAnimation {
duration: 100
}
}
}
}
}
function getSubtitle() {
var titleString
for(var i = 0; i < control.widgetData["categorys"].length; i ++ ){
//console.log("checking " + i + ": cat: " + parseInt(control.widgetData["categorys"][i]["GrpId"]) + " searched cat: " + params.cat)
if(parseInt(control.widgetData["categorys"][i]["GrpId"]) === parseInt(params.cat)){
titleString = control.widgetData["categorys"][i]["name"]
}
}
var addition = qsTr("(Startlist)")
return addition + " " + titleString
}
function changeCat(){
var cats = control.widgetData["categorys"]
cats.sort(function(a, b) {
return parseInt(a["GrpId"]) - parseInt(b["GrpId"]);
});
var selectOptions = []
for(var prop in cats){
if (cats.hasOwnProperty(prop) && !control.subTitle.includes(cats[prop]['name'])) {
// append all cats and ignore the current one
selectOptions.push({text: cats[prop]['name'], data:{cat: cats[prop]['GrpId']}})
}
}
selector.appear(selectOptions, qsTr("select cat"))
}
Connections {
target: selector
onSelectionFinished: {
if(data.cat !== undefined){
updateData({cat: data.cat}, true)
}
}
}
property var widgetData: ({})
model: widgetData[ "participants" ] === undefined ? 0:widgetData[ "participants" ].length
onRefresh: {
updateData({}, false)
}
delegate: ItemDelegate {
id: partDel
property var thisData: widgetData[ "participants" ][index]
width: parent.width
opacity: 0
scale: 0.9
onThisDataChanged: {
fadeInPa.start()
}
onClicked: {
app.openWidget({person:thisData["PerId"]})
}
ParallelAnimation {
id: fadeInPa
NumberAnimation { target: partDel; property: "opacity"; from: 0; to: 1.0; duration: 400 }
NumberAnimation { target: partDel; property: "scale"; from: 0.8; to: 1.0; duration: 400 }
}
text: ""
Row {
id: partDelFirstRow
width: parent.width
height: parent.height
Label {
height: parent.height
width: parent.width * 0.1
fontSizeMode: Text.Fit
font.bold: true
font.pixelSize: Math.abs( height * 0.6 )
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
text: widgetData[ "participants" ][index]["start_order"]
}
Label {
height: parent.height
width: parent.width * 0.5
fontSizeMode: Text.Fit
font.bold: true
font.pixelSize: Math.abs( height * 0.45 )
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
minimumPixelSize: 1
text: widgetData[ "participants" ][index]["firstname"] + " " + widgetData[ "participants" ][index]["lastname"]
}
Label {
height: parent.height
width: parent.width * 0.3
fontSizeMode: Text.Fit
font.bold: false
font.pixelSize: Math.abs( height * 0.4 )
minimumPixelSize: height * 0.3
elide: "ElideRight"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
text: "<html>(<a href=\"" + (widgetData[ "participants" ][index]["url"] === undefined ? "":widgetData[ "participants" ][index]["url"]).toString() + "\">" + (widgetData[ "display_athlete" ] === "nation" ? widgetData[ "participants" ][index]["nation"] : widgetData[ "participants" ][index]["federation"]) + "</a>)</html>"
onLinkActivated: {
Qt.openUrlExternally(link)
}
}
}
}
}