logo资料库

Qt_Creater开发万年历(C++).doc

第1页 / 共25页
第2页 / 共25页
第3页 / 共25页
第4页 / 共25页
第5页 / 共25页
第6页 / 共25页
第7页 / 共25页
第8页 / 共25页
资料共25页,剩余部分请下载后查看
1.Calendar.cpp #include #include "calendar.h" #include #include #include #include #include "itembutton.h" #include "lunarday.h" using namespace lunar; Calendar::Calendar(QWidget *parent) :QWidget(parent) { //当前年份 QDateTime dt; QTime time; QDate date; dt.setTime(time.currentTime()); dt.setDate(date.currentDate()); QString currentDate = dt.toString("yyyy:MM:dd:hh:mm:ss"); QStringList currentDateList = currentDate.split(":"); newyear=currentDateList.at(0).toInt(); newmonth=currentDateList.at(1).toInt(); newday=currentDateList.at(2).toInt(); m_bgBlackPixmap = QPixmap::fromImage(QImage(tr("./images/cumputerback.png")));// m_barPixmap= QPixmap::fromImage(QImage(tr("./images/bar.png")));// m_bgPixmap = QPixmap::fromImage(QImage(tr("./images/calendarback.png")));// //退出按钮 m_btnQuit = new QLabel(this); QPixmap quitPixmap = QPixmap::fromImage(QImage("./images/quit.png")); //setPixmap 设置图片, m_btnQuit->setPixmap(quitPixmap); //设置大小 m_btnQuit->resize(78, 65); //移动 m_btnQuit->move(800 - 78, 0);
// // // // // // // Box = new QLabel(this); QPixmap BoxPixmap1 = QPixmap::fromImage(QImage("./images/stand_light")); Box->setPixmap(BoxPixmap1); Box->resize(58,48); //qDebug()<move(210+83*m_i,180+40*m_j); Box->show(); //向下年份按钮 yearreduce = new QLabel(this); QPixmap leftPixmap1 = QPixmap::fromImage(QImage("./images/left.png")); yearreduce->setPixmap(leftPixmap1); yearreduce->resize(54,54); yearreduce->move(230,80); //向下月份按钮 monthreduce = new QLabel(this); QPixmap leftPixmap2 = QPixmap::fromImage(QImage("./images/left.png")); monthreduce->setPixmap(leftPixmap2); monthreduce->resize(54,54); monthreduce->move(530,80); //向上年份按钮 yearadd = new QLabel(this); QPixmap rightPixmap1 = QPixmap::fromImage(QImage("./images/right.png")); yearadd->setPixmap(rightPixmap1); yearadd->resize(54,54); yearadd->move(435,80); //向上月份按钮 monthadd = new QLabel(this); QPixmap rightPixmap2 = QPixmap::fromImage(QImage("./images/right.png")); monthadd->setPixmap(rightPixmap2); monthadd->resize(54,54); monthadd->move(730,80); //设置公历 m_gregorian = new itemButton(this); m_gregorian->setTextColor(Qt::white); m_gregorian->resize(176, 49); m_gregorian->setRect(QRect(0,0 , 176, 49)); m_gregorian->setAlignment(Qt::AlignLeft);
m_gregorian->setTextFont(QFont("宋体", 18)); m_gregorian->setText(tr("公历")); m_gregorian->move(20, 95); QString currentgregorian=currentDateList.at(0)+"-"+currentDateList.at(1)+"-"+currentDateList.at(2); gregoriandisplay=new itemButton(this); gregoriandisplay->setTextColor(Qt::white); gregoriandisplay->resize(176, 49); gregoriandisplay->setRect(QRect(20,0 , 176, 49)); gregoriandisplay->setAlignment(Qt::AlignLeft); gregoriandisplay->setTextFont(QFont("宋体", 18)); gregoriandisplay->setText(currentgregorian); gregoriandisplay->move(55,95); //设置万年历 m_btncalendar=new itemButton(this); m_btncalendar->setTextColor(Qt::white); m_btncalendar->resize(176, 49); m_btncalendar->setRect(QRect(0,0 , 176, 49)); m_btncalendar->setAlignment(Qt::AlignLeft); m_btncalendar->setTextFont(QFont("宋体", 20)); m_btncalendar->setText(tr("万年历")); m_btncalendar->move(45,20); //设置农历 m_lunar = new itemButton(this); m_lunar->setTextColor(Qt::white); m_lunar->resize(176, 49); m_lunar->setRect(QRect(0,0 , 176, 49)); m_lunar->setAlignment(Qt::AlignLeft); m_lunar->setTextFont(QFont("宋体", 20)); m_lunar->setText(tr("农历")); m_lunar->move(20, 145); QString b[30]={"初一","初二","初三","初四","初五","初六","初七","初八","初九","初十 ","十一","十二","十三","十四", "十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四"," 廿五","廿六","廿七","廿八","廿九","三十"}; QString c[12]={"正月","二月","三月","四月","五月","六月","七月","八月","九月","十月 ","十一月","腊月",}; bool ok;
rili(); int tempmonth=currentDateList.at(1).toInt(&ok,10)-1; if(currentDateList.at(1).toInt(&ok,10)==1) { tempmonth=12; } lunardisplay=new itemButton(this); lunardisplay->setTextColor(Qt::white); lunardisplay->resize(176, 49); lunardisplay->setRect(QRect(40,0 ,176, 49)); lunardisplay->setAlignment(Qt::AlignLeft); lunardisplay->setTextFont(QFont("宋体", 18)); lunardisplay->setText(c[tempmonth-1]); lunardisplay->move(55,145); //返回今日 m_getback = new itemButton(this); m_getback->setTextColor(Qt::white); m_getback->resize(176, 49); m_getback->setRect(QRect(0,0 , 176, 49)); m_getback->setAlignment(Qt::AlignCenter); m_getback->setTextFont(QFont("宋体", 18)); m_getback->setText(tr("返回今日")); m_getback->move(5, 185); //当前年份 year=new itemButton(this); year->setTextColor(Qt::white); year->resize(130, 50); year->setRect(QRect(0,0 ,130,50)); year->setAlignment(Qt::AlignCenter); year->setTextFont(QFont("宋体", 20)); if(currentDateList.count() > 0) { year->setText(currentDateList.at(0)); } year->move(300,80); //当前月份 month=new itemButton(this); month->setTextColor(Qt::white); month->resize(130, 50); month->setRect(QRect(0,0 ,130,50)); month->setAlignment(Qt::AlignCenter); month->setTextFont(QFont("宋体", 20));
if(currentDateList.count() > 0) { month->setText(currentDateList.at(1)); } month->move(580,80); //星期条 QString strweek[7]={"日","一","二","三","四","五","六"}; for(int i=0;i<7;i++) { itemButton *week= new itemButton(this); week->setTextColor(Qt::white); week->resize(83, 40); week->setRect(QRect(0,0 , 83, 40)); week->setAlignment(Qt::AlignCenter); week->setTextFont(QFont("宋体", 15)); week->setText(strweek[i]); week->move(210+83*i,140); } } void Calendar::mousePressEvent(QMouseEvent *event) { QDateTime dt; QTime time; QDate date; dt.setTime(time.currentTime()); dt.setDate(date.currentDate()); QString currentDate = dt.toString("yyyy:MM:dd:hh:mm:ss"); QStringList currentDateList = currentDate.split(":"); QPoint clickPoint = event->pos(); if(isFocus(clickPoint, m_gregorian)) { m_gregorian->setLightScene(true); } if(isFocus(clickPoint, yearreduce)) { newyear--; QString newtime=QString::number(newyear,10);
year->setText(newtime); year->update(); QPixmap leftPixmap1 = QPixmap::fromImage(QImage("./images/left_clicked.png")); yearreduce->setPixmap(leftPixmap1); rili(); } else if(isFocus(clickPoint,yearadd)) { newyear++; QString newtime=QString::number(newyear,10); year->setText(newtime); year->update(); QPixmap rightPixmap1 QPixmap::fromImage(QImage("./images/right_clicked.png")); yearadd->setPixmap(rightPixmap1); rili(); } else if(isFocus(clickPoint,monthreduce)) { if(newmonth==1) { = newmonth=12; newyear--; QString newtime=QString::number(newyear,10); year->setText(newtime); year->update(); QPixmap leftPixmap1 = QPixmap::fromImage(QImage("./images/left_clicked.png")); monthreduce->setPixmap(leftPixmap1); rili(); } else { newmonth--; } QString newtime=QString::number(newmonth,10); month->setText(newtime); month->update(); QPixmap leftPixmap1 = QPixmap::fromImage(QImage("./images/left_clicked.png")); monthreduce->setPixmap(leftPixmap1); rili(); } else if(isFocus(clickPoint,monthadd)) { if(newmonth==12)
= = { newmonth=1; newyear++; QString newtime=QString::number(newyear,10); year->setText(newtime); year->update(); month->setText("1"); month->update(); QPixmap rightPixmap2 QPixmap::fromImage(QImage("./images/right_clicked.png")); monthadd->setPixmap(rightPixmap2); rili(); } else { newmonth++; QString newtime=QString::number(newmonth,10); month->setText(newtime); month->update(); QPixmap rightPixmap2 QPixmap::fromImage(QImage("./images/right_clicked.png")); monthadd->setPixmap(rightPixmap2); rili(); } } else if(isFocus(clickPoint,m_getback)) { bool ok; if(currentDateList.count() > 0) { newyear=currentDateList.at(0).toInt(&ok,10); year->setText(currentDateList.at(0)); year->update(); } if(currentDateList.count() > 0) { newmonth=currentDateList.at(1).toInt(&ok,10); month->setText(currentDateList.at(1)); month->update(); } rili(); } else if(isFocus(clickPoint,m_btnQuit))
QPixmap rightPixmap1 = QPixmap::fromImage(QImage("./images/quit_clicked.png")); m_btnQuit->setPixmap(rightPixmap1); { } } void Calendar::mouseMoveEvent(QMouseEvent *event) { } void Calendar::mouseReleaseEvent(QMouseEvent *event) { QPoint clickPoint = event->pos(); if(isFocus(clickPoint, m_gregorian)) { m_gregorian->setLightScene(false); this->onKeyYearreduce(); } else if(isFocus(clickPoint, yearreduce)) { QPixmap leftPixmap1 = QPixmap::fromImage(QImage("./images/left.png")); yearreduce->setPixmap(leftPixmap1); } else if(isFocus(clickPoint, yearadd)) { QPixmap rightPixmap1 = QPixmap::fromImage(QImage("./images/right.png")); yearadd->setPixmap(rightPixmap1); } else if(isFocus(clickPoint, monthreduce)) { QPixmap leftPixmap1 = QPixmap::fromImage(QImage("./images/left.png")); monthreduce->setPixmap(leftPixmap1); } else if(isFocus(clickPoint, monthadd)) { QPixmap rightPixmap1 = QPixmap::fromImage(QImage("./images/right.png")); monthadd->setPixmap(rightPixmap1); } else if(isFocus(clickPoint,m_btnQuit)) { close(); } }
分享到:
收藏