还剩22页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
1.Calendar.cpp#include QtGui#include calendar.h#include QIcon#include QDebug#include QPainter#include QDateTime#include Hitembutton.hn#include nlunarday.hn using namespace lunar;Calendar::CalendarQWidget parent:QWidgetparent〃当前年份QDateTime dt;QTime time;QDate date;dt.setTimetime.currentTime;dt.setDatedate.currentDate;QString currentDate=dt.toStringnyyyy:MM:dd:hh:mm:ssH;:;QStringList currentDateList=currentDate.splitnewyear=currentDateList.at
0.toInt;newmonth=currentDateList.at
1.tolnt;newday=currentDateList.at
2.toInt;m_bgBlackPixmap=QPixmap::fromImageQImagetrn./images/cumputerback.pngn;//m_barPixmap=QPixmap::fromImageQTmagetr,./images/bar.png,;//m_bgPixmap=QPixmap::fromImageQImagetrn./images/calendarback.pngn;//〃退出按钮m_btnQuit=new QLabelthis;QPixmap quitPixmap=QPixmap::fromImageQImagen./images/quit.pngn;设置图片,//setPixmapm_btnQuit-setPixmapquitPixmap;〃设置大小m_btnQuit-resize78,65;〃移动m_btnQuit-move800-78,0;int tempyear=newyear-1901;int m=tempyear/4;int n=tempyear%4;double lunartempday=l4*m+
10.6*1+n;forint i=0;inewmonth-1;i++lunartempday4-=a[i];forint var=0;varm_listWeekItem.count;++var{itemButton*lundarweek=m_l istWeekitem.at var;lundarweek-deleteLater;lundarweek=NULL;m_l istWeekltem.removeAtvar;—var;for intvar=0;varm_listWeekItem.count;++var{itemButton*week=m_listWeekItem.atvar;week-deleteLater;week=NULL;m_listWeekItem.removeAtvar;—var;int newday=1;forint m=0;m6;m++forint n=0;n7;n++ifm==0nsignyQString newdate=QString::numbernewday,10;itemButton*week=newitemButtonthis;week-setTextColorQt::white;week-resize83,40;wcck-sctRcctQRcct0,0,83,40;week-setAlignmentQt::AlignCenter;week-setTextFontQFont宋体,15;week-setTexttrn H;week-update;week-move210+83*n/80+40*m;week-show;m_listWeekItem.appendweek;else{lunartempday=lunartempday+1;int lunardayl=lunartempday^lO;lunarday=lunardayl%295;iflunarday200lunarday=lunarday/l0;else iflunarday100lunarday=lunarday/10;else iflunarday10lunarday=lunarday/10;elselunarday=30;QString newdate=QString::numbernewday,10;itemButton*week=new itemButtonthis;week-setTextColorQt::white;week-resize83,40;week-setRectQRect0,0,83,40;week-setAlignmentQt::AlignCenter;宋体,week-setTextFontQFont15;week-setTextnewdate;week-update;week-move210+83*n/80+40*m;week-show;m_listWeekItem.appendweek;itemButton*lundarweek=new itemButtonthis;lundarweek-setTextColorQt::white;lundarweek-resize83,40;lundarweek-setRectQRect25,0,83,40;lundarwcck-sctAlignmcntQt::AlignCcntcr;宋体,lundarweek-setTextFontQFont13;lundarweek-setTextb[lunarday-l];lundarweek-update;lundarweek-move210+83*n,180+40*m;lundarweek-show;m_listWeekItem.appendlundarweek;newday++;ifnewday==currentDateList.at
2.toInt//templunar=b[lunarday-l];ifnewdaya[newmonth-l]return;}bool Calendar::isleapint newyearifnewyear%4==0newyear%100!=0||newyear%4==0newyear%400==0returntrue;else return false;int Calendar::getDay sint a
[12]={31,28,31,30,31,30,31,31,30,31,30,31;inti;int sumDay=l;fori=0;inewyear;i++ifisleapi sumDay+=366;else sumDay+=365;ifislcapncwycar a
[1]=29;else a[l]=28;fori=0;inewmonth-1;i++sumDay=sumDay-i-a[i];}return sumDay;int Calendar::getWeekint newweek=getDays%7;二new weeknew week+5;newweek=newweek%7;return newweek;void Calendar::paintEventQPaintEvent*eventQ_UNUSEDevent;QPainter painterthis;绘制图片,先绘制的在底层,后绘制的在上层//QWidget painter.drawPixmapO,0,800,480,m_bgBlackPixmap;painter.drawPixmapO,0,800,480,m_bgPixmap;painter.drawPixmap0,0,800,68,m_barPixmap;#include itembutton.h〃ftinclude QDateTimeftincludeQDebugftinclude QPainteritemButton::itemButtonQWidget*parent:QWidgetparent,m_textColorQt::white,m_alignmentQt::AlignLeft,m isLightfalse}void itemButton:刀方方QPaintEvent*event{Q_UNUSEDevent;quint64nTime=QDateTime::currentMSecsSinceEpoch;QPainter painterthis;if!m_isLight{if!m_bgPixmap.isNull{painter.drawPixmapm_imageRect,m bgPixmap;1}else{ifIm bgPixmapS.isNull{painter.drawPixmapm_imageRect,m bgPixmapS;!ifIm strText.isEmpty{QPen pen;pen.setColorm_textColor;painter.setPen pen;painter.setFontm_textFont;painter.drawText mworkRect,m alignment,m strText;1~qDebugO«_FUNCTI0N_«_LINE_«QDateTime::currentMSecsSinceEpoch-nTime;ftinclude QtGui/QApplicationftinclude z/ma inwindow.h〃ftinclude calendar.h〃ftinclude QTextCodecftincludeQDateftinclude QDebugintmainint argc,char*argv[]{QApplication aargc,argv;QTextCodec::setCodecForCStrings QTextCodec::codecForName/ZGB2312/Z;//1QTextCodec::setCodecForLocaleQTextCodec::codecForName//GB2312//;//2QTextCodec::setCodecForTrQTextCodec::codecForName,ZGB2312/Z;//3如上三句是关键语句Calendar*cld二new Calendar;cld-setGeometry QRect250,250,350,250;〃设置窗口显示方位与大小cld-setWindowFlags Qt::FramelessWindowHint;〃隐藏标题框cld-rili;//cld-getbackday;cld-resize800,480;cld-show;return a.exec;ftifndef ITEMBUTT0N_H^define ITEMBUTTON_Hftinclude QWidget/***©brief实现贴图,写字的功能*/class itemButton:public QWidgetQ_0BJECTpublic:explicit itemButtonQWidgetparent=0;/**©brief设置字体颜色**/inline voidsetTextColorconst QColortextColor{mtextColor=textColor;/**©brief设置字体对齐方向**/inline voidsetAlignmentconst Qt::Alignment alignmentm_alignment=alignment;/**©brief设置字体的位置*@param rect.x-针对控件的x的值**/inline voidsetTextRect constQRect rect{m_workRect=rect;一/***©brief设置显示的字符串*/inline voidsetText constQString text{mstrText=text;一1/***©brief设置字体大小inline voidsetTextFont constQFont font{m_textFont=font;1~/vt*xL*SL*KL*XL**JL*KJKJXL**Jt**X**JL*KL*KL**JL**JL**JXKJ/XIXXrxxjxZTXXTXXT^XTXxjxZjxxjxX7XXTXXTXXjX✓TxXjXXgXXTXXTXZjXXjXXjXXjXXTXXTXzlxxjxX7X✓jXXTXXTXXjX✓TxXjXXgXXTXxTxXTXX7X*一下操作是图片操作KLZKLZvtzKIX SJVLZvtzKLZ sXzsX^KLZ/✓jxXT%XlXX|XXjXXjXXTXXlXXjX XlXZlXXTx*TXXjX*TXxjsZlXXjXX|X✓TX#TXXjXXTX T^✓Txr^T**TS/inline voidsetBGImageconst QPixmappixmapmbgPixmap=pixmap;inline voidsetBGImageconst QStringstrPixmap{this-setBGImageQP ixmap::fromlmageQlmagestrPixmap;/***@brief设置选中之后的图片*/inline voidsetBGImageSconst QPixmappixmap{m_bgPixmapS=pixmap;一1inline voidsetBGImageSconst QStringstrPixmap{thi s-setBGImageSQPixmap::fromlmageQlmagestrPixmap;inline voidsetRect constQRect rect{mimageRect=rect;this-setTextRectrect;}inline voidsetLightSceneconst boolisLight{misLight=isLight;this-update;protected:void pain^£re/^QPaintEvent*event;private:QString m_strText;QColor m_textColor;QFont m_textFont;Qt::Alignment malignment;QRect mworkRect;bool misLight;QRect m_iinageRect;QPixmap mbgPixmap;QPixmap mbgPixmapS;QStringList m_templist;signals:public slots:;ttendif//ITEMBUTTON JI
5.calendar,hftifndef CALENDAR』^define CALENDARSftincludeQLabelftinclude/zitembutton.h/zftinclude QDateclassQWidget;class QPushButton;class Calendar:public QWidgetpublic:Calendar QWidget^parent=0;void rili;bool isleapintnewyear;〃获取闰年int getWeek;〃返回星期int getDays;〃返回从0开始总天数;//void getbackday;〃返I回农历日期protected:/***@brief QWidget绘制背景*/void paintEventQPaintEvent*event;void勿ous67Yess£pe/QMouseEvent*event;void mouseMoveEventQMouseEvent*event;void勿〃方QMouseEvent*event;private:void onKeyYearreduce;void lightScene;bool isFocusconst QPointpoint,QWidget*button;private slots:〃取年份和月份private:QLabel*m_btnQuit;//退出QLabel*yearadd;〃向上调年份QLabel*yearreduce;〃向下调年份QLabel*monthadd;//向上调月份QLabel*monthreduce;〃向下调月份QLabel*Box;itemButton*m_gr egorian;〃公历itemButton*m_btncalendar;〃万年历itemButton*m_lunar;〃农历itemButton*m_ge tback;〃返回今日itemButton*year;〃年份itemButton*month;〃月份itemButton*week;〃星期itemButton*gregoriandisplay;itemButton*lunardisplay;QListitemButton*mlistWeekltem;QPixmap mbarPixmap;QPixmap mbgPixmap;QPixmap mbgBlackPixmap;intnewyear;〃变动后的年份newmonth;〃变动后的月份newday;〃天数intlunaryear;//农历年lunarmonth;//农历月lunarday;//农历日neweek;int//星期几a[];intm_i;intm_j;intQString b[];intint);int ttendif//CALENDARJIint.工程文件6Calendar.pro#-----------------------------------------------------------------------------------#Project createdby QtCreator2013-10-18T10:24:53#tt---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------QT+=core guiTARGET=calendarTEMPLATE=appSOURCES+=main.cpp\mainwindow.cpp\calendar,cpp\itembutton,cppHEADERS+=mainwindow.h\calendar,h\itembutton,h\C:/Documents andSettings/Administrator/^®/dada/lunarday.h FORMS+=mainwindow.ui OTHERFILES+=\right_three.png\right_S.png\quithigh.png\quit,png\left_three.png\calendarback.png\bar.png\stand_light.png\right_clicked.png\right,png\quit_clicked.png\left_clicked.png\left,png\calendar_fini shed,png.以上代码图片名和图片路径仅供参考,1农历算法稍有误差,下面给出正确农历算法自己组装代
2.码,lunarday.h#ifndefLUNARDAY_H#define LUNARDAY.H//file:lunarday.h//author://2007-02-1311:22:04//url:namespace lunar//保存一个农历日期〃年typedef structT_Date int year;//Box=new QLabelthis;//QPixmap BoxPixmapl二QPixmap::fromImageQImage,,./images/stand_lightM;//Box-setPixmapBoxPixmap1;//Box-resize58,48;////qDebug«m_i«m_j;」;//Box-move210+83*m_i,180+40*m//Box-show;〃向下年份按钮yearreduce=new QLabelthis;QPixmap leftPixmapl=QPixmap::fromImageQImage,,./images/left.png,;yearreduce-setPixmapleftPixmap1;yearreduce-resize54,54;yearreduce-move230,80;〃向下月份按钮monthreduce=new QLabelthis;QPixmap leftPixmap2=QPixmap::fromImageQImagen./images/left.pngn;monthreduce-setPixmapleftPixmap2;monthreduce-resize54,54;monthreduce-move530,80;〃向上年份按钮yearadd=new QLabelthis;QPixmap rightPixmapl=QPixmap::fromImageQImage./images/right.pngn;yearadd-setPixmaprightPixmap1;yearadd-resize54,54;yearadd-move435,80;〃向上月份按钮monthadd=new QLabelthis;QPixmap rightPixmap2=QPixmap::fromImageQImage./images/right.pngn;monthadd-setPixmaprightPixmap2;monthadd-resize54,54;monthadd-move730,80;〃设置公历m_gregorian=new itemButtonthis;m_gregorian-setTextColorQt::white;m_gregorian-resize176,49;m_gregorian-setRectQRect0,0,176,49;m_gregorian-setAlignmentQt::AlignLeft;〃月int month;〃日int day;〃是否闰月bool leap;}Date;//公历转农历Date LuanrDateint solar_year,int solar_month,int solar_day;#endif//LUNARDAY_Hlunarday.cpp#include nlunarday.hH#include ctime#include cassert#include cstring#include iostream//file:lunarday.cpp//author://2007-02-1311:22:48〃公历转农历usingnamespacestd;using lunar::Date;//使用比特位记录每年的情况〃0〜4共5bit春节日份〃5〜6共2bit春节月份〃7〜19共13bit13个月的大小月情况(如果无闰月,最后位无效),大月为1,小月为0〃2〜23共4bit记录闰月的月份,如果没有闰月为0static const int BEGIN_YEAR=1901;static constint NUMBER_YEAR=199;static constunsigned intLUNAR_YEARS
[199]={0x04AE53,0x0A5748,0x5526BD,0x0D2650,0x0D9544,0x46AAB9,0x056A4D,0x09AD42,0x24AEB6,0x04AE4A,//1901-19100x6A4DBE,0x0A4D52,0x0D2546,0x5D52BA,0x0B544E,0x0D6A43,0x296D37,0x095B4B,0x749BC1,0x049754,//1911-19200x0A4B48,0x5B25BC,0x06A550,0x06D445,0x4ADAB8,0x02B64D,0x095742,0x2497B7,0x04974A,0x664B3E,//1921-19300x0D4A51,0x0EA546,0x56D4BA,0x05AD4E,0x02B644,0x393738,0x092E4B,0x7C96BF,0x0C9553,0x0D4A48,//193M9400x6DA53B,0x0B554F,0x056A45,0x4AADB9,0x025D4D,0x092D42,0x2C95B6,0x0A954A,0x7B4ABD,0x06CA51,//1941-19500x0B5546,0x555ABB,0x04DA4E,0x0A5B43,0x352BB8,0x052B4C,0x8A953F,0x0E9552,0x06AA48,0x7AD53C,//1951-l9600x0AB54F,0x04B645,0x4A5739,0x0A574D,0x052642,0x3E9335,0x0D9549,0x75AABE,0x056A5l,0x096D46,//1961-19700x54AEBB,0x04AD4F,0x0A4D43,0x4D26B7,0x0D254B,0x8D52BF,0x0B5452,0x0B6A47,0x696D3C,0x095B50,//197M9800x049B45,0x4A4BB9,0x0A4B4D,0xAB25C2,0x06A554,0x06D449,0x6ADA3D,0x0AB651,0x093746,0x5497BB,//1981-19900x04974F,0x064B44,0x36A537,0x0EA54A,0x86B2BF,0x05AC53,0x0AB647,0x5936BC,0x092E50,0x0C9645,//1991-20000x4D4AB8,0x0D4A4C,0x0DA541,0x25AAB6,0x056A49,0x7AADBD,0x025D52,0x092D47,0x5C95BA,0x0A954E,//2001-20100x0B4A43,0x4B5537,0x0AD54A,0x955ABF,0x04BA53,0x0A5B48,0x652BBC,0x052B50,0x0A9345,0x474AB9,//2011-20200x06AA4C,0x0AD541,0x24DAB6,0x04B64A,0x69573D,0x0A4E51,0x0D2646,0x5E933A,0x0D534D,0x05AA43,//2021-20300x36B537,0x096D4B,0xB4AEBF,0x04AD53,0x0A4D48,0x6D25BC,0x0D254F,0x0D5244,0x5DAA38,0x0B5A4C,//2031-20400x056D41,0x24ADB6,0x049B4A,0x7A4BBE,0x0A4B51,0x0AA546,0x5B52BA,0x06D24E,0x0ADA42,0x355B37,//2041-20500x09374B,0x8497Cl,0x049753,0x064B48,0x66A53C,0x0EA54F,0x06B244,0x4AB638,0x0AAE4C,0x092E42,//2051-20600x3C9735,0x0C9649,0x7D4ABD,0x0D4A5l,0x0DA545,0x55AABA,0x056A4E,0x0A6D43,0x452EB7,0x052D4B,//2061-20700x8A95BF,0x0A9553,0x0B4A47,0x6B553B,0x0AD54F,0x055A45,0x4A5D38,0x0A5B4C,0x052B42,0x3A93B6,//2071-20800x069349,0x7729BD,0x06AA51,0X0AD546,0X54DABA,0x04B64E,OxOA5743,0x452738,0x0D264A,0x8E933E,//2081-20900x0D5252,0x0DAA47,0x66B53B,0x056D4F,0x04AE45,0x4A4EB9,0x0A4D4C,0x0D1541,0x2D92B5//2091-2099;〃计算这个公历日期是一年中的第几天static intDayOfSolarYearint year,int month,int day〃为了提高效率,记录每月一日是一年中的第几天static constint NORMAL_YDAY
[12]={1,32,60,91/21,152,182,213,244,274,305,335};〃闰年的情况static constint LEAP_YDAY
[12]={1,32,61,92,122,153,183,214,245,275,306,336};constint*t_year_yday_=NORMAL_YDAY;〃判断是否是公历闰年ifyear%100!=0t_year_yday_=LEAP_YDAY;ifyear%400==0t_year_yday_=LE AP_YD AY;return t_year_yday_[month-1]+day-1;Date lunar::LuanrDateint solar_year,int solar__month,intsolar_day Dateluanr_date;二luanr_date.year solar_year;luanr date.month=0;luanr_date.day=0;luanr_date.leap=false;//越界检查,如果越界,返回无效日期ifsolar_year=BEGIN.YEAR||solar_yearBEGIN.YEAR+NUMBER_YEAR-1returnluanr_date;二int year_index solar_year-BEGIN_YEAR;//计算春节的公历日期int spring_ny_month=LUNAR_YEARS[year_index]0x60»5;int spring_ny_day=LUNAR_YEARS[year_index]Ox If;//计算今天是公历年的第几天int today_solar_yd=DayOfSolarYearsolar_year,solar_month,solar_day;//计算春节是公历年的第几天〃计算今int spring_ny_yd=DayOfSolarYearsolar_year,spring_ny_month,spring_ny_day;天是农历年的第几天int today_luanr_yd=today_solar_yd-spring_ny_yd+1;//如果今天在春节的前面,重新计算today_luanr_ydif today_luanr_yd0〃农历年比当前公历年小1year_index luanr_date.year—;//越界,返回无效日期ifyear_index0return luanr_date;spring_ny_month=LUNAR_YEARS[year_index]0x60»5;二spring_ny_day LUNAR_YEARS[year_index]Oxlf;spring_ny_yd=DayOfSolarYearsolar_year,spring_ny_month,spring_ny_day;intyear_total_day=DayOfSolarYearluanr_date.year,12,31;today_luanr_yd=today_solar_yd+year_total_day-spring_ny_yd+1;int luanr_month=1;〃计算月份和日期for;luanr_month=13;luanr_month++int month_day=29;if LUNAR_YEARS[year_index]»6+luanr_month0x1month_day=30;if today_luanr_yd=month_day break;elsetoday_luanr_yd-=month_day;luanr_date.day=today_luanr_yd;〃处理闰月int leap_month=LUNAR_YEARS[year_index]»20Oxf;ifleap_month0leap_monthluanr_month luanr_month—;〃如果当前月为闰月,设置闰月标志if luanr_month==leap_month luanr_date.leap=true;asscrtlcap_month=12;luanr date.month=luanr month;return luanr_date;m_gregorian-setTextFontQFont宋体,18;m_gregorian-setTexttr“公历”;m_gregorian-move20,95;QStringcurrentgregorian=currentDateList.at0+H-n+currentDateList.atl+n-n+currentDateList.at2;gregoriandisplay=new itemButtonthis;gregoriandisplay-setTextColorQt::white;gregoriandisplay-resize176,49;gregoriandisplay-setRectQRect20,0,176,49;gregoriandisplay-setAlignmentQt::AlignLeft;gregoriandisplay-setTextFontQFontn^^n,18;gregoriandisplay-setTextcurrentgregorian;gregoriandisplay-move55,95;//设置万年历m_btncalendar=new itemButtonthis;m_btncalendar-setTextColorQt::white;m_btncalendar-resize176,49;m_btncalendar-setRectQRect0,0,176,49;m_btncalendar-setAlignmentQt::AlignLeft;“宋体,m_btncalendar-setTextFontQFont20;m_btncalendar-setTexttr“万年历”;m_btncalendar-move45,20;〃设置农历mjunar=new itemButtonthis;m_lunar-setTextColorQt::white;m_lunar-resize176,49;m_lunar-setRectQRect0,0,176,49;m_lunar-setAlignmentQt::AIignLeft;」“宋体,m unar-setTextFontQFont20;m_lunar-setTexttr“农历”;m_lunar-move20,145;{“初一,“初二/初三”初四/初五”初六“初七,“初八初九”QString b
[30]=J J J J J初十^一十二十三丫十四”,J“十五“十六“,“十七十八/十九二十”廿一/廿二”,廿三/廿J77J四”廿五廿六”廿七“,“廿八“廿九“,“三十“};J7J J{正月/二月三月四月“,“五月六月七月八月九月:‘十月十一月腊QString c
[12]=V月”,};bool ok;rili;int tempmonth=currentDateList.at
1.tolntok,10-1;ifcurrentDateList.at
1.tolntok,10==1tempmonth=12;lunardisplay=new itemButtonthis;lunardisplay-setTextColorQt::white;lunardisplay-resize176,49;lunardisplay-setRectQRect40,0,176,49;lunardisplay-setAlignmentQt::AlignLeft;“宋体,lunardisplay-setTextFontQFont18;lunardisplay-setTextc|tempmonth-1];lunardisplay-move55,145;〃返回今日m_getback=new itemButtonthis;m_getback-setTextColorQt::white;m_getback-resize176,49;m_getback-setRectQRect0,0,176,49;m_getback-set AlignmentQt::AlignCenter;m_getback-setTextFontQFontM体,18;m_getback-setTexttr返回今日“;m_getback-move5,185;〃当前年份year=new itemButtonthis;year-setTextColorQt::white;year-resize130,50;year-setRectQRect0,0,130,50;year-setAlignmentQt::AlignCenter;宋体,year-setTextFontQFont20;ifcurrentDateList.count0{year-setTextcurrentDateList.atO;year-move300,80;〃当前月份month=ncw itcmButtonthis;month-setTextColorQt::white;month-resize130,50;month-setRectQRect0,0,130,50;month-setAlignmentQt::AlignCenter;宋体,month-setTextFontQFont20;ifcurrentDateList.count0month-setTextcurrentDateList.at1;month-move580,80;//星期条{“日一丫二三四五六};QString strweek
[7]=7J7forint i=0;i7;i++itemButton*week=new itemButtonthis;week-setTextColorQt::white;week-resize83,40;week-setRectQRect0,0,83,40;week-setAlignmentQt::AlignCenter;宋体,week-setTextFontQFont15;week-setTextstrweek[i];week-move210+83*i,140;void Calendar::mousePressEventQMouseEvent*eventQDateTime dt;QTime time;QDate date;dt.setTimetime.currentTime;dt.setDatedate.currentDate;QString cun-entDate=dt.toStringnyyyy:MM:dd:hh:mm:ssH;QStringList currentDateList=currentDate.splitn:n;QPoint clickPoint=event-pos;ifisFocusclickPoint,m_gregorianm_gregorian-setLightScenetrue;ifisFocusclickPoint,yearreducenewyear—;QString newtime=QString::numbernewyear,10;year-setTextnewtime;year-update;QPixmap leftPixmapl=QPixmap::fromImageQImage,,./images/left_clicked.pngn;yearreduce-setPixmapleftPixmap1;rili;else ifisFocusclickPoint,yearadd{newyear++;QString newtime=QString::numbernewyear,10;year-setTextnewtime;year-update;QPixmap rightPixmap1QPixmap::fromImageQImagen./images/right_clicked.pngn;yearadd-setPixmaprightPixmap1;rili;}else ifisFocusclickPoint,monthreduceifnewmonth==lnewmonth=12;newyear-;QString newtime=QString::numbernewyear,10;year-setTextnewtime;year-update;QPixmap leftPixmapl=QPixmap::fromImageQImage,,./images/left_clicked.png,;monthreduce-setPixmapleftPixmap1;elsenewmonth—;QString newtime=QString::numbernewmonth,10;month-setTextnewtime;month-update;QPixmap leftPixmapl=QPixmap::fromImageQImagen./images/left_clicked.pngn;monthrcducc-sctPixmaplcftPixmap1;rili;}else ifisFocusclickPoint,monthaddifnewmonth==12newmonth=1;newyear+4-;QString newtime=QString::numbernewyear,10;year-setTextnewtime;year-update;month-setTextn1;month-update;QPixmap rightPixmap2QPixmap::fromImageQImagen./images/right_clicked.pngn;monthadd-setPixmaprightPixmap2;rili;elsenewmonth+4-;QString newtime=QString::numbernewmonth,10;month-setTextnewtime;month-update;QPixmap rightPixmap2QPixmap::fromImageQImagen./images/right_clicked.pngn;monthadd-setPixmaprightPixmap2;rili;}else ifisFocusclickPoint,m_getbackbool ok;ifcurrentDateList.count0newyear=currentDateList.at
0.toIntok,l0;year-setTextcurrentDateList.atO;year-update;ifcurrentDateList.count0newmonth=currentDateList.at
1.tolntok,10;month-sctTcxtcurrcntDatcList.at1;month-update;rili;else ifisFocusclickPoint,m_btnQuitQPixmap rightPixmapl=QPixmap::fromImageQImagen./images/quit_clicked.pngH;m_btnQuit-setPixmaprightPixmap1;void Calendar::mouseMoveEventQMouseEvent*eventvoid Calendar::mouseReleaseEventQMouseEvent*event QPointclickPoint=event-pos;ifisFocusclickPoint,m_gregorian{m_gregorian-setLightScenefalse;this-onKeyYearreduce;else ifisFocusclickPoint,yearreduce QPixmapleftPixmapl=QPixmap::fromImageQImage,./images/left.pngn;yearreduce-setPixmapleftPixmap1;else ifisFocusclickPoint,yearadd{QPixmap rightPixmap1=QPixmap::fromImageQImagen./images/right.pngn;yearadd-setPixmaprightPixmap1;else ifisFocusclickPoint,monthreduceQPixmap leftPixmapl=QPixmap::fromImageQImagen./images/left.png;monthreduce-setPixmapleftPixmap1;else ifisFocusclickPoint,monthaddQPixmap rightPixmapl=QPixmap::fromImageQImageH./images/right.pngn;monthadd-setPixmaprightPixmap1;else ifisFocusclickPoint,m_btnQuitclose;bool Calendar::isFocusconst QPointpoint,QWidget buttonifbutton point.xbutton-x point.yObutton-y point.xbutton-x+button-width point.yObutton-y+button-height{return true;returnfalse;void Calendar::onKeyYearreducevoid Calendar::rili QDateTimedt;QTime time;QDate date;dt.setTimetime.currentTime;dt.setDatedate.currentDate;QString currentDate=dt.toStringnyyyy:MM:dcl:hh:mm:ssn;QStringList currentDateList=currentDate.splitn:n;inta
[12]={31,28,31,30,31,30,31,31,30,31,30,31;{初一;初二丫初三初四“,“初五“初六初七初八初九”初十^一QString b
[30]=J7J7十二十三丫十四”,J“十五“十六“,“十七“十八“十九“二十”廿一;廿二“,JJJJJ“廿三”J廿四廿五7廿六J廿七,”廿八7廿九「三十“};int signy=getWeek;ifnewyear%4==0newyear%100!=0||newyear%4==0newyear%400==0a[l]=29;elsea[l]=28;。
个人认证
优秀文档
获得点赞 0