You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
3.4 KiB
QML
157 lines
3.4 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Controls 6.3
|
|
|
|
|
|
Item {
|
|
width: 720
|
|
height: 480
|
|
visible: true
|
|
id: main
|
|
|
|
property int offset: 0;
|
|
|
|
XHR{id: http}
|
|
Data{id: cache}
|
|
|
|
Component.onCompleted: {
|
|
offset = 0;
|
|
init();
|
|
addDays(4);
|
|
}
|
|
|
|
function init(){
|
|
log.text = "Pobieranie danych..."
|
|
//daysModel.clear();
|
|
cache.refresh(function(){
|
|
offset = 0;
|
|
days.currentIndex = 0;
|
|
//addDays(4);
|
|
});
|
|
|
|
}
|
|
|
|
function addDays(n){
|
|
for(var i=0; i<=n; i++){
|
|
addDay();
|
|
}
|
|
}
|
|
|
|
function addDay(){
|
|
const d = new Date();
|
|
d.setDate(d.getDate() - offset);
|
|
daysModel.append({_day: d.getDate(), _month: d.getMonth()+1, _year: d.getFullYear(), _isToday: offset==0})
|
|
offset = offset +1;
|
|
}
|
|
|
|
NumberAnimation { id: anim; target: days; property: "contentX"; duration: 500 }
|
|
|
|
function gotoIndex(idx) {
|
|
anim.running = false;
|
|
|
|
var pos = days.contentX;
|
|
var destPos;
|
|
|
|
days.positionViewAtIndex(idx, ListView.Contain);
|
|
destPos = days.contentX;
|
|
|
|
anim.from = pos;
|
|
anim.to = destPos;
|
|
anim.running = true;
|
|
}
|
|
|
|
|
|
ListView {
|
|
id: days
|
|
anchors.fill: parent
|
|
highlightFollowsCurrentItem: true
|
|
anchors.topMargin: 54
|
|
snapMode: ListView.SnapToItem
|
|
cacheBuffer: 5000
|
|
layoutDirection: Qt.RightToLeft
|
|
orientation: ListView.Horizontal
|
|
focus: true
|
|
interactive: true
|
|
highlightMoveDuration: 50
|
|
currentIndex: 0
|
|
|
|
onAtXBeginningChanged: {
|
|
if (days.atXBeginning) {
|
|
addDays(5);
|
|
}
|
|
}
|
|
model: ListModel{
|
|
id: daysModel
|
|
}
|
|
delegate:
|
|
Day {
|
|
width: days.width
|
|
height: days.height
|
|
day: _day
|
|
month: _month
|
|
year: _year
|
|
isToday: _isToday
|
|
}
|
|
}
|
|
|
|
Text{id: log}
|
|
|
|
WorkerScript {
|
|
id: background
|
|
source: "background.mjs"
|
|
|
|
property var callback_number: 0;
|
|
property var callbacks: ({});
|
|
function send(type, data, cb){
|
|
background.callback_number++;
|
|
callbacks[callback_number] = cb
|
|
const message = {type, data, id: callback_number}
|
|
background.sendMessage(message)
|
|
}
|
|
function handleMessage(message){
|
|
const id = message.id;
|
|
if(callbacks[id]){
|
|
callbacks[id](message && message.data);
|
|
delete callbacks[id];
|
|
}
|
|
}
|
|
|
|
function setTimeout(callback){ // delay is assumed to be 0
|
|
send("set-timeout", 0, callback);
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
background.onMessage.connect(handleMessage)
|
|
}
|
|
}
|
|
|
|
Row {
|
|
id: row
|
|
x: 184
|
|
width: 448
|
|
height: 40
|
|
anchors.right: parent.right
|
|
anchors.top: parent.top
|
|
anchors.topMargin: 8
|
|
anchors.rightMargin: 8
|
|
spacing: 12
|
|
layoutDirection: Qt.RightToLeft
|
|
|
|
Button {
|
|
id: button
|
|
text: qsTr("Odśwież")
|
|
onClicked:{
|
|
init();
|
|
}
|
|
}
|
|
Button {
|
|
id: button1
|
|
text: qsTr("Dzisiaj")
|
|
visible: !days.atXEnd;
|
|
onClicked: {
|
|
gotoIndex(0)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|