/* 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 . */ import QtQuick 2.9 import QtQuick.Controls 2.4 import "../Components" DataListView { id: control property string title: (params.nation === "" ? "IFSC":params.nation === "GER" ? "DAV":"SAC") + " " + qsTr("competition calendar") property Component headerComponent: Item { anchors.fill: parent Row { anchors.fill: parent anchors.rightMargin: 5 spacing: width * 0.05 Label { id: yearLa anchors.verticalCenter: parent.verticalCenter width: parent.width * 0.4 height: parent.height * 0.6 fontSizeMode: Text.Fit font.pixelSize: height verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter minimumPixelSize: 1 text: control.year Behavior on text { FadeAnimation { target: yearLa } } } Button { id:yearToolBt anchors { verticalCenter: parent.verticalCenter } height: parent.height * 0.5 width: parent.width * 0.25 onClicked: { control.changeYear() } onPressed: yearToolBt.scale = 0.9 onReleased: yearToolBt.scale = 1.0 background: Image { anchors.centerIn: parent source: "qrc:/icons/calendar.png" height: parent.height > parent.width ? parent.width : parent.height width: height mipmap: true fillMode: Image.PreserveAspectFit Behavior on scale { PropertyAnimation { duration: 100 } } } } Button { id: cupToolBt anchors { verticalCenter: parent.verticalCenter } height: parent.height * 0.5 width: parent.width * 0.25 onClicked: { cupSelectPu.open() } onPressed: cupToolBt.scale = 0.9 onReleased: cupToolBt.scale = 1.0 background: Image { anchors.centerIn: parent source: "qrc:/icons/cup.png" height: parent.height > parent.width ? parent.width : parent.height width: height mipmap: true fillMode: Image.PreserveAspectFit Behavior on scale { PropertyAnimation { duration: 100 } } } } } } property var widgetData property int year: new Date().getFullYear() anchors.fill: parent //boundsBehavior: Flickable.StopAtBounds model: widgetData["competitions"].length status: root.status onRefresh: { updateData({}, false) } onModelChanged: { autoScroll() } function autoScroll() { var compList = control.widgetData["competitions"] if(parseInt(control.year) === new Date().getFullYear()){ for(var i = 0; i < compList.length; i ++){ // get the start date pf the competition var startDate = Date.fromLocaleString(Qt.locale(), compList[i]["date"], "yyyy-MM-dd") // get the duration of the competition var durationString = compList[i]["duration"] === undefined ? "1":compList[i]["duration"] var days = parseInt(durationString.replace(/\D/g,'')) // calculate the end date of the competition var endDate = new Date(startDate.valueOf()) endDate.setDate(endDate.getDate() + days); //console.log(compList[i]["date"] + ": " + startDate + " to " + endDate) if(endDate.getTime() < new Date().getTime()){ // end date is already over -> move the list view down! control.positionViewAtIndex(i, ListView.Top) //console.log("moving down!") } } } } function getCompCatData(compCatId) { var obj = app.compCats for(var prop in obj) { // go through the whole array and search for data keys if (obj.hasOwnProperty(prop) && obj[prop]["cat_id"].indexOf(compCatId) >= 0) { //console.log("found cat: " + obj[prop]['label']) return obj[prop] } } } function openComp(compIndex){ var cats = control.widgetData["competitions"][compIndex]["cats"] cats.sort(function(a, b) { return parseInt(a["GrpId"]) - parseInt(b["GrpId"]); }); var selectOptions = [] for(var prop in cats){ if (cats.hasOwnProperty(prop)) { selectOptions.push({text: cats[prop]["name"], data:{cat: cats[prop]["GrpId"], comp: control.widgetData["competitions"][compIndex]["WetId"], status:cats[prop]["status"]}}) } } selector.appear(selectOptions) } function changeYear(){ var years = control.widgetData["years"] var selectOptions = [] for(var prop in years){ if (years.hasOwnProperty(prop)) { selectOptions.push({text: years[prop], data:{year: years[prop]}}) } } selector.appear(selectOptions) } Connections { target: selector onSelectionFinished: { if(data.comp !== undefined){ console.log(data.status) app.openWidget({comp: data.comp, cat: data.cat, type:data.status === 4 ? 'starters':''}) } else if(data.year !== undefined){ updateData({year: data.year}, true) control.year = data.year } } } delegate: ItemDelegate { id: competitionDel property bool over property var thisData: control.widgetData["competitions"][index] property string name: thisData["name"] property string date: thisData["date_span"] property var cats: thisData["cats"] property int catId: thisData["cat_id"] === undefined ? 0:thisData["cat_id"] width: parent.width height: compDelCol.height + 10 enabled: thisData["cats"] !== undefined && thisData["cats"].length > 0 opacity: 0 scale: 0.9 onThisDataChanged: { fadeInPa.start() } onClicked: { control.openComp(index) } ParallelAnimation { id: fadeInPa NumberAnimation { target: competitionDel; property: "opacity"; from: 0; to: 1.0; duration: 400 } NumberAnimation { target: competitionDel; property: "scale"; from: 0.8; to: 1.0; duration: 400 } } Rectangle { id: delBackroundRect anchors.fill: parent opacity: 0.5 color: control.getCompCatData(catId) === undefined ? "white":control.getCompCatData(catId)["bgcolor"] } Column { id: compDelCol anchors.centerIn: parent width: parent.width * 0.97 spacing: 10 Label { id: nameLa width: parent.width font.bold: true wrapMode: Text.WordWrap text: name } /* Label { id: infola width: parent.width text: thisData.info }*/ Label { id: dateLa color: "grey" text: date } } Rectangle { id: bottomLineRa anchors { bottom: parent.bottom left: parent.left right: parent.right } height: 1 color: "lightgrey" } } }