Open khalili-mahdi opened 5 years ago
i used some of your code and created something like this :
import QtQuick 2.8 import QtQuick.Window 2.2 import QtQuick.Controls 2.1 Rectangle { property date currentDate: new Date() width: frame.implicitWidth + 10 height: frame.implicitHeight + 10 function formatText(count, modelData) { var data = count === 12 ? modelData + 1 : modelData; return data.toString().length < 2 ? "0" + data : data; } FontMetrics { id: fontMetrics } Component { id: delegateComponent Label { text: formatText(Tumbler.tumbler.count, modelData) opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2) horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter font.pixelSize: fontMetrics.font.pixelSize * 1.25 } } Frame { id: frame padding: 0 anchors.centerIn: parent Row { id: row Tumbler { id: yearTumbler model: getYearList() currentIndex: today_as_jalali() delegate: delegateComponent } Tumbler { id: monthTumbler model: getMonthList() delegate: delegateComponent } Tumbler { id: dayTumbler model: getDayList() delegate: delegateComponent } } } function getDayList(){ var temp = [] var x = dayInMonth(yearTumbler.currentItem,monthTumbler.currentIndex+1) for(var i = 1;i<=x;i++){ temp.push(i) } return temp; } function dayInMonth(year,month) { month = month - 1 if(month<0)return -1; if(month<6)return 31; if(month<11)return 30; var ary = [1, 5, 9, 13, 17, 22, 26, 30]; var b = year % 33; for (var i = 0;i < ary.length; i++) if (b === ary[i]) return 30; return 29; } function getYearList(){ var temp = []; for (var i = 1300;i<=1410;i++){ temp.push(i); } return temp } function getMonthList(){ var temp = [] for(var i = 1;i<=12;i++){ temp.push(monthName(i)); } return temp; } function monthName(i){ switch(i) { case 1: return "فروردین"; case 2: return "اردیبهشت"; case 3: return "خرداد"; case 4: return "تیر"; case 5: return "مرداد"; case 6: return "شهریور"; case 7: return "مهر"; case 8: return "آبان"; case 9: return "آذر"; case 10: return "دی"; case 11: return "بهمن"; case 12: return "اسفند"; } } function today_as_jalali(){ var cur = Qt.formatDateTime(new Date(), "yyMMdd") var x = gregorian_to_jalali(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDay()); return x[0]%100; } function gregorian_to_jalali(gy,gm,gd){ var g_d_m=[0,31,59,90,120,151,181,212,243,273,304,334]; var jy=(gy<=1600)?0:979; gy-=(gy<=1600)?621:1600; var gy2=(gm>2)?(gy+1):gy; var days=(365*gy) +(parseInt((gy2+3)/4)) -(parseInt((gy2+99)/100)) +(parseInt((gy2+399)/400)) -80 +gd +g_d_m[gm-1]; jy+=33*(parseInt(days/12053)); days%=12053; jy+=4*(parseInt(days/1461)); days%=1461; jy+=parseInt((days-1)/365); if(days > 365)days=(days-1)%365; var jm=(days < 186)?1+parseInt(days/31):7+parseInt((days-186)/30); var jd=1+((days < 186)?(days%31):((days-186)%30)); return [jy,jm,jd]; } }
you may want to edit and add this to your files too
i used some of your code and created something like this :