6#include "LunarCalendar.h"
7#include "LunarCalendarModel.h"
10#include <QLoggingCategory>
17#include <QApplication>
19#include <QStyleOption>
23#include <QGestureEvent>
24#include <QSwipeGesture>
28#include "CalendarLunar.h"
29#include "LunarCalendarDelegate.h"
30#include "CalendarLunar.h"
31#include "LunarTable.h"
32#include "RabbitCommonDir.h"
33#include "RabbitCommonTools.h"
35static Q_LOGGING_CATEGORY(Logger,
"Rabbit.LunarCalendar")
37static
bool g_bLundarCalendarInit = false;
38static QSharedPointer<QTranslator> g_Translator;
52 m_pToolLayout(
nullptr),
53 m_pHeadLayout(
nullptr),
54 m_pMainLayout(
nullptr),
55 m_Headposition(_HEAD_position::Top),
59 m_bShowBackgroupImage(false),
60 m_TouchFunction(_TOUCH_UP_DOWN_FUNCTION::TouchChangeMounth)
63 setWindowTitle(tr(
"Lunar calendar"));
67 m_tbPreYear.setArrowType(Qt::UpArrow);
68 m_tbPreYear.setToolTip(tr(
"Previous year"));
69 m_tbPreYear.setStatusTip(tr(
"Previous year"));
70 m_tbNextYear.setArrowType(Qt::DownArrow);
71 m_tbNextYear.setToolTip(tr(
"Next year"));
72 m_tbNextYear.setStatusTip(tr(
"Next year"));
73 m_tbPreMonth.setArrowType(Qt::UpArrow);
74 m_tbPreMonth.setToolTip(tr(
"Previous month"));
75 m_tbPreMonth.setStatusTip(tr(
"Previous month"));
76 m_tbNextMonth.setArrowType(Qt::DownArrow);
77 m_tbNextMonth.setToolTip(tr(
"Next month"));
78 m_tbNextMonth.setStatusTip(tr(
"Next month"));
89 m_pbToday.setIcon(QIcon::fromTheme(
"today"));
90 m_pbToday.setToolTip(tr(
"Today"));
91 m_pbToday.setStatusTip(tr(
"Today"));
92 m_pbToday.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
94 m_lbDate.setAlignment(Qt::AlignCenter);
95 m_lbTime.setAlignment(Qt::AlignCenter);
100 m_View.setModel(pModel);
108 m_View.setAttribute(Qt::WA_AcceptTouchEvents);
111 m_View.setFocusPolicy(Qt::WheelFocus);
112 m_View.setSelectionBehavior(QAbstractItemView::SelectItems);
113 m_View.setSelectionMode(QAbstractItemView::SingleSelection);
114 m_View.setEditTriggers(QAbstractItemView::NoEditTriggers);
115 m_View.horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
123 m_View.horizontalHeader()->setSectionsClickable(
false);
124 m_View.verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
125 m_View.verticalHeader()->setSectionsClickable(
false);
126 m_View.setFrameStyle(QFrame::NoFrame);
128 m_View.grabGesture(Qt::SwipeGesture);
129 m_View.installEventFilter(
this);
130 m_View.setAttribute(Qt::WA_AcceptTouchEvents,
true);
131 m_View.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
132 m_View.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
139 QFont font = m_View.font();
140 float nFontSize = 0, nPixSize = 0;
141 nFontSize = font.pointSize();
142 nPixSize = font.pixelSize();
143 qDebug(Logger) <<
"Font point size:" << nFontSize
144 <<
"pixel size:" << nPixSize;
146 font.setPointSize(nFontSize * 2 / 3);
148 font.setPixelSize(nPixSize * 2 / 3);
149#if defined(Q_OS_ANDROID)
150 m_View.setFont(font);
177 for(
int i = 0; i < 12; i++)
179 m_cmbMonth.addItem(locale().monthName(i + 1), i + 1);
181 m_cmbMonth.setToolTip(tr(
"Month"));
182 m_cmbMonth.setStatusTip(tr(
"Month"));
184 m_cmbMonth.setCurrentIndex(m_cmbMonth.findData(pModel->GetDate().month()));
185 SetSelectedDate(pModel->GetDate());
187 SetYearRange(pModel->GetMinimumDate().year(),
188 pModel->GetMaximumDate().year());
189 m_cmbYear.setCurrentIndex(m_cmbYear.findData(pModel->GetDate().year()));
190 m_cmbYear.setEditable(
true);
191 m_cmbYear.setToolTip(tr(
"Year"));
192 m_cmbYear.setStatusTip(tr(
"Year"));
197 m_pToolLayout =
new QHBoxLayout();
198 m_pToolLayout->addWidget(&m_tbPreYear);
199 m_pToolLayout->addWidget(&m_cmbYear);
200 m_pToolLayout->addWidget(&m_tbNextYear);
201 m_pToolLayout->addWidget(&m_tbPreMonth);
202 m_pToolLayout->addWidget(&m_cmbMonth);
203 m_pToolLayout->addWidget(&m_tbNextMonth);
204 m_pToolLayout->addWidget(&m_pbToday);
205#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
206 m_pToolLayout->setMargin(0);
208 m_pToolLayout->setContentsMargins(0, 0, 0, 0);
210 m_pToolLayout->setSpacing(0);
214 bool check = connect(&m_Timer, SIGNAL(timeout()),
215 this, SLOT(slotTimeout()));
217 check = connect(&m_tbPreYear, SIGNAL(clicked()),
218 this, SLOT(on_tbPreviousYear_clicked()));
220 check = connect(&m_tbNextYear, SIGNAL(clicked()),
221 this, SLOT(on_tbNextYear_clicked()));
223 check = connect(&m_tbPreMonth, SIGNAL(clicked()),
224 this, SLOT(on_tbPreviousMonth_clicked()));
226 check = connect(&m_tbNextMonth, SIGNAL(clicked()),
227 this, SLOT(on_tbNextMonth_clicked()));
229 check = connect(&m_pbToday, SIGNAL(clicked()),
230 this, SLOT(soltShowToday()));
235 check = connect(&m_cmbMonth, SIGNAL(currentIndexChanged(
int)),
236 this, SLOT(on_cbMonth_currentIndexChanged(
int)));
238 check = connect(&m_View, SIGNAL(pressed(
const QModelIndex&)),
239 this, SLOT(on_tvMonth_pressed(
const QModelIndex&)));
245CLunarCalendar::~CLunarCalendar()
248void CLunarCalendar::InitResource()
250 if(g_bLundarCalendarInit)
return;
252 g_bLundarCalendarInit =
true;
254 g_Translator = RabbitCommon::CTools::Instance()->InstallTranslator(
255 "LunarCalendar", RabbitCommon::CTools::TranslationType::Library);
257 Q_INIT_RESOURCE(ResourceLunarCalendar);
259 Q_INIT_RESOURCE(ResourceSql);
260 Q_INIT_RESOURCE(translations_LunarCalendar);
264void CLunarCalendar::CLeanResource()
266 RabbitCommon::CTools::Instance()->RemoveTranslator(g_Translator);
267 Q_CLEANUP_RESOURCE(ResourceLunarCalendar);
269 Q_CLEANUP_RESOURCE(ResourceSql);
270 Q_CLEANUP_RESOURCE(translations_LunarCalendar);
276 m_Headposition = pos;
279 m_pMainLayout->removeWidget(&m_View);
280 m_pMainLayout->removeItem(m_pHeadLayout);
281 delete m_pMainLayout;
282 m_pMainLayout =
nullptr;
286 m_pHeadLayout->removeItem(m_pToolLayout);
287 m_pHeadLayout->removeWidget(&m_lbDate);
288 m_pHeadLayout->removeWidget(&m_lbTime);
289 delete m_pHeadLayout;
290 m_pHeadLayout =
nullptr;
293 m_pMainLayout =
new QGridLayout(
this);
294#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
295 m_pMainLayout->setMargin(0);
297 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
299 m_pMainLayout->setSpacing(0);
300 setLayout(m_pMainLayout);
305 m_pMainLayout->addWidget(&m_View);
309 m_pHeadLayout =
new QVBoxLayout();
310 m_pHeadLayout->addLayout(m_pToolLayout);
311 m_pHeadLayout->addWidget(&m_lbDate);
312 m_pHeadLayout->addWidget(&m_lbTime);
313#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
314 m_pHeadLayout->setMargin(0);
316 m_pHeadLayout->setContentsMargins(0, 0, 0, 0);
318 m_pHeadLayout->setSpacing(0);
320 m_pMainLayout->addLayout(m_pHeadLayout, 0, 0);
321 m_pMainLayout->addWidget(&m_View);
325 m_pMainLayout->addWidget(&m_View);
327 m_pHeadLayout =
new QVBoxLayout();
328 m_pHeadLayout->addWidget(&m_lbDate);
329 m_pHeadLayout->addWidget(&m_lbTime);
330 m_pHeadLayout->addLayout(m_pToolLayout);
331#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
332 m_pHeadLayout->setMargin(0);
334 m_pHeadLayout->setContentsMargins(0, 0, 0, 0);
336 m_pHeadLayout->setSpacing(0);
338 m_pMainLayout->addLayout(m_pHeadLayout, 1, 0);
342 m_pHeadLayout =
new QVBoxLayout();
343 m_pHeadLayout->addStretch();
344 m_pHeadLayout->addLayout(m_pToolLayout);
345 m_pHeadLayout->addWidget(&m_lbDate);
346 m_pHeadLayout->addWidget(&m_lbTime);
347 m_pHeadLayout->addStretch();
348#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
349 m_pHeadLayout->setMargin(0);
351 m_pHeadLayout->setContentsMargins(0, 0, 0, 0);
353 m_pHeadLayout->setSpacing(0);
355 m_pMainLayout->addLayout(m_pHeadLayout, 0, 0);
356 m_pMainLayout->addWidget(&m_View, 0, 1);
360 m_pMainLayout->addWidget(&m_View);
361 m_pHeadLayout =
new QVBoxLayout();
362 m_pHeadLayout->addStretch();
363 m_pHeadLayout->addLayout(m_pToolLayout);
364 m_pHeadLayout->addWidget(&m_lbDate);
365 m_pHeadLayout->addWidget(&m_lbTime);
366 m_pHeadLayout->addStretch();
367#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
368 m_pHeadLayout->setMargin(0);
370 m_pHeadLayout->setContentsMargins(0, 0, 0, 0);
372 m_pHeadLayout->setSpacing(0);
374 m_pMainLayout->addLayout(m_pHeadLayout, 0, 1);
380int CLunarCalendar::ShowSelectTitle()
386 d = pModel->GetDate();
387 if(d.isNull())
return -2;
391 szDate = d.toString(locale().dateFormat(QLocale::LongFormat));
395 m_lbDate.setText(szDate);
399void CLunarCalendar::on_cbYear_currentIndexChanged(
int index)
401 qDebug(Logger) <<
"CLunarCalendar::on_cbYear_currentIndexChanged";
407void CLunarCalendar::on_tbNextYear_clicked()
409 int nIndex = m_cmbYear.currentIndex() + 1;
410 if(m_cmbYear.count() <= nIndex)
412 m_cmbYear.setCurrentIndex(nIndex);
415void CLunarCalendar::on_tbPreviousYear_clicked()
417 int nIndex = m_cmbYear.currentIndex() - 1;
420 m_cmbYear.setCurrentIndex(nIndex);
423void CLunarCalendar::on_tbNextMonth_clicked()
425 if(!m_tbNextMonth.isEnabled())
427 int i = m_cmbMonth.currentIndex() + 1;
428 if(i > m_cmbMonth.count() - 1)
431 m_cmbYear.setCurrentIndex(
432 m_cmbYear.findData(m_cmbYear.currentData().toInt() + 1));
434 m_cmbMonth.setCurrentIndex(i);
437void CLunarCalendar::on_tbPreviousMonth_clicked()
439 if(!m_tbPreMonth.isEnabled())
441 int i = m_cmbMonth.currentIndex() - 1;
444 m_cmbYear.setCurrentIndex(
445 m_cmbYear.findData(m_cmbYear.currentData().toInt() - 1));
446 i = m_cmbMonth.count() - 1;
448 m_cmbMonth.setCurrentIndex(i);
451void CLunarCalendar::on_cbMonth_currentIndexChanged(
int index)
453 qDebug(Logger) <<
"CLunarCalendar::on_cbMonth_currentIndexChanged:" << index;
459void CLunarCalendar::soltShowToday()
474int CLunarCalendar::UpdateViewModel(
bool bForce)
480 if (pModel->GetShowYear() != m_cmbYear.currentData().toInt()
481 || pModel->GetShowMonth() != m_cmbMonth.currentData().toInt()) {
483 m_View.selectionModel()->clear();
489 pModel->showMonth(m_cmbYear.currentData().toInt(),
490 m_cmbMonth.currentData().toInt(),
492 if(pModel && m_bShowBackgroupImage)
494 QString szBackgrpup =
":/image/" + QString::number(pModel->GetShowMonth());
497 szBackgrpup +=
"_zh_CN";
498 SetBackgroup(szBackgrpup);
504 pModel->showWeek(m_cmbYear.currentData().toInt(),
505 m_cmbMonth.currentData().toInt(),
518 m_View.setShowGrid(show);
528 m_bShowBackgroupImage = show;
529 if(m_bShowBackgroupImage)
532 m_View.setStyleSheet(
"border-image:none");
546 return pModel->EnableToolTip(enable);
551 if(m_bShowToday == bShow)
553 m_bShowToday = bShow;
554 m_pbToday.setVisible(m_bShowToday);
559 m_View.verticalHeader()->setVisible(bShow);
565 m_View.horizontalHeader()->setVisible(bShow);
578 m_tbPreYear.setVisible(bShow);
579 m_tbNextYear.setVisible(bShow);
580 m_cmbYear.setVisible(bShow);
581 m_tbNextMonth.setVisible(bShow);
582 m_tbPreMonth.setVisible(bShow);
583 m_cmbMonth.setVisible(bShow);
590 m_lbDate.setVisible(bShow);
597 if(!pModel)
return QDate();
598 return pModel->GetDate();
608 if(bForce || pModel->GetDate() != date)
610 pModel->setDate(date);
613 QDate newDate = pModel->GetDate();
614 m_cmbYear.setCurrentIndex(m_cmbYear.findData(newDate.year()));
617 m_cmbMonth.setCurrentIndex(m_cmbMonth.findData(newDate.month()));
623 week = newDate.weekNumber(&year);
624 if(year != newDate.year())
626 m_cmbYear.setCurrentIndex(m_cmbYear.findData(newDate.year()));
628 m_cmbMonth.setCurrentIndex(m_cmbMonth.findData(week));
636 pModel->cellForDate(pModel->GetDate(), &row, &col);
637 if(row >= 0 && col >= 0)
642 QString szJiQi = pModel->
data(pModel->index(row, col),
643 CLunarCalendarModel::ROLE::BackgroupImage).toString();
644 if(!szJiQi.isEmpty())
645 SetBackgroup(szJiQi);
648 m_View.selectionModel()->clear();
649 m_View.selectionModel()->setCurrentIndex(pModel->index(row, col),
650 QItemSelectionModel::SelectCurrent);
664 if(!pModel)
return QString();
665 QDate date = pModel->GetDate();
673 if(!pModel)
return QString();
674 QDate date = pModel->GetDate();
682 if(!pModel)
return -1;
683 QDate date = pModel->GetDate();
703 if(!pModel)
return -1;
704 return pModel->GetShowYear();
710 if(!pModel)
return -1;
711 return pModel->GetShowMonth();
717 if(!pModel)
return QDate();
718 return pModel->GetMaximumDate();
726 if(QDate::currentDate() > date)
727 m_pbToday.setVisible(
false);
733 QDate oldDate = pModel->GetDate();
734 pModel->SetMaximumDate(date);
735 int year = date.year();
738 date.weekNumber(&year);
741 SetYearRange(date.year(), pModel->GetMaximumDate().year());
742 m_cmbYear.setCurrentIndex(m_cmbYear.findData(pModel->GetShowYear()));
744 QDate newDate = pModel->GetDate();
745 if (oldDate != newDate) {
754 if(!pModel)
return QDate();
755 return pModel->GetMinimumDate();
763 if(QDate::currentDate() < date)
764 m_pbToday.setVisible(
false);
769 QDate oldDate = pModel->GetDate();
770 pModel->SetMinimumDate(date);
771 int year = date.year();
774 date.weekNumber(&year);
777 SetYearRange(date.year(), pModel->GetMaximumDate().year());
778 m_cmbYear.setCurrentIndex(m_cmbYear.findData(pModel->GetShowYear()));
780 QDate newDate = pModel->GetDate();
781 if (oldDate != newDate) {
789 if (!min.isValid() || !max.isValid())
794 qCritical() <<
"SetDateRange parameter error: min =" << min <<
" max =" << max;
800 if(pModel->GetMaximumDate() == max && pModel->GetMinimumDate() == min)
803 if(QDate::currentDate() < min || QDate::currentDate() > max)
804 m_pbToday.setVisible(
false);
808 QDate oldDate = pModel->GetDate();
809 pModel->setRange(min, max);
811 int yearMin = min.year();
814 min.weekNumber(&yearMin);
816 int yearMax = max.year();
818 max.weekNumber(&yearMax);
820 SetYearRange(min.year(), max.year());
821 m_cmbYear.setCurrentIndex(m_cmbYear.findData(pModel->GetShowYear()));
823 QDate newDate = pModel->GetDate();
824 if (oldDate != newDate) {
830int CLunarCalendar::SetYearRange(
int min,
int max)
835 bool check = m_cmbYear.disconnect();
838 for(
int i = min; i < max; i++)
842 m_cmbYear.addItem(QString::number(i), i);
844 check = connect(&m_cmbYear, SIGNAL(currentIndexChanged(
int)),
845 this, SLOT(on_cbYear_currentIndexChanged(
int)));
850int CLunarCalendar::EnableMonthMenu()
852 bool prevEnabled =
true;
853 bool nextEnabled =
true;
856 if(!pModel)
return -1;
858 int minYear = pModel->GetMinimumDate().year();
859 int maxYear = pModel->GetMaximumDate().year();
861 pModel->GetMinimumDate().weekNumber(&minYear);
862 pModel->GetMaximumDate().weekNumber(&maxYear);
865 if (pModel->GetShowYear() == minYear) {
869 if (pModel->GetShowMonth() == pModel->GetMinimumDate().month())
873 if (pModel->GetShowWeek() == pModel->GetMinimumDate().weekNumber())
879 if (pModel->GetShowYear() == maxYear) {
882 if (pModel->GetShowMonth() == pModel->GetMaximumDate().month())
886 if(pModel->GetShowWeek() == pModel->GetMaximumDate().weekNumber())
892 m_tbPreMonth.setEnabled(prevEnabled);
893 m_tbNextMonth.setEnabled(nextEnabled);
897int CLunarCalendar::UpdateMonthMenu()
899 int beg = 1, end = 12;
902 if(!pModel)
return -1;
906 int minYear = pModel->GetMinimumDate().year();
907 int maxYear = pModel->GetMaximumDate().year();
910 end = pModel->GetWeeksOfYear(m_cmbYear.currentData().toInt());
911 pModel->GetMinimumDate().weekNumber(&minYear);
912 pModel->GetMaximumDate().weekNumber(&maxYear);
915 if (pModel->GetShowYear() == minYear) {
919 beg = pModel->GetMinimumDate().month();
922 beg = pModel->GetMinimumDate().weekNumber();
927 if (pModel->GetShowYear() == maxYear) {
930 end = pModel->GetMaximumDate().month();
933 end = pModel->GetMaximumDate().weekNumber();
938 int index = m_cmbMonth.currentIndex();
939 bool check = m_cmbMonth.disconnect();
942 for (
int i = beg; i <= end; i++) {
945 m_cmbMonth.addItem(locale().monthName(i), i);
948 m_cmbMonth.addItem(QString::number(i), i);
952 check = connect(&m_cmbMonth, SIGNAL(currentIndexChanged(
int)),
953 this, SLOT(on_cbMonth_currentIndexChanged(
int)));
955 if(index >= m_cmbMonth.count())
956 index = m_cmbMonth.count() - 1;
959 m_cmbMonth.setCurrentIndex(index);
967 if(!pModel)
return locale().firstDayOfWeek();
968 return pModel->firstDayOfWeek();
978void CLunarCalendar::on_tvMonth_pressed(
const QModelIndex &index)
980 qDebug(Logger) <<
"CLunarCalendar::on_tvMonth_pressed" << index;
986 QDate d = pModel->dateForCell(index.row(), index.column());
990 m_oldCol = index.column();
991 m_oldRow = index.row();
994bool CLunarCalendar::eventFilter(QObject *watched, QEvent *event)
997 switch(event->type()){
1014 case QEvent::TouchBegin:
1022 case QEvent::TouchUpdate:
1030 case QEvent::TouchEnd:
1033 QTouchEvent *touchEvent =
static_cast<QTouchEvent *
>(event);
1034#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1035 QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->points();
1037 QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
1040 if(touchPoints.length() == 1)
1042 QTouchEvent::TouchPoint t = touchPoints.first();
1043#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1044 QLineF line(QLineF(t.pressPosition(), t.lastPosition()));
1046 QLineF line(QLineF(t.startPos(), t.lastPos()));
1048 if(qAbs(line.dx()) > qAbs(line.dy()))
1051 if(qAbs(line.dx()) > m_View.horizontalHeader()->minimumSectionSize())
1054 on_tbPreviousMonth_clicked();
1056 on_tbNextMonth_clicked();
1060 if(qAbs(line.dy()) > m_View.verticalHeader()->minimumSectionSize())
1065 && m_TouchFunction == _TOUCH_UP_DOWN_FUNCTION::TouchChangeView)
1068 on_tbPreviousMonth_clicked();
1073 && m_TouchFunction == _TOUCH_UP_DOWN_FUNCTION::TouchChangeView)
1076 on_tbNextMonth_clicked();
1080#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1081 on_tvMonth_pressed(m_View.indexAt(t.lastPosition().toPoint()));
1083 on_tvMonth_pressed(m_View.indexAt(t.lastPos().toPoint()));
1089#ifndef QT_NO_WHEELEVENT
1092 QWheelEvent *we =
dynamic_cast<QWheelEvent*
>(event);
1093 const int numDegrees = we->angleDelta().y() / 8;
1094 const int numSteps = numDegrees / 15;
1099 const QModelIndex index = m_View.currentIndex();
1102 QDate currentDate = pModel->dateForCell(index.row(), index.column());
1103 currentDate = currentDate.addDays(-numSteps * 7);
1110 case QEvent::KeyRelease:
1115 QKeyEvent* key =
dynamic_cast<QKeyEvent*
>(event);
1116 qDebug(Logger) <<
"CLunarCalendar::eventFilter key:" << key
1117 <<
"old:" << m_oldRow << m_oldCol
1118 <<
"current:" << m_View.currentIndex().row()
1119 << m_View.currentIndex().column();
1120 switch (key->key()) {
1123 QModelIndex index = m_View.currentIndex();
1126 QDate d = pModel->dateForCell(index.row(), index.column());
1127 if(index.row() == 0 && m_oldRow == 0)
1130 && d.month() == m_cmbMonth.currentData())
1141 QModelIndex index = m_View.currentIndex();
1144 QDate d = pModel->dateForCell(index.row(), index.column());
1145 if(index.row() >= pModel->rowCount() -1
1146 && m_oldRow == index.row())
1149 && d.month() == m_cmbMonth.currentData())
1161 QModelIndex index = m_View.currentIndex();
1164 QDate d = pModel->dateForCell(index.row(), index.column());
1165 if(index.column() == m_oldCol)
1173 QModelIndex index = m_View.currentIndex();
1176 QDate d = pModel->dateForCell(index.row(), index.column());
1177 if(index.column() == m_oldCol)
1192 return QWidget::eventFilter(watched, event);
1198 if(!pModel)
return true;
1199 return pModel->EnableHolidays(bEnable);
1205 if(!pModel)
return true;
1206 return pModel->EnableSolarTerm(bEnable);
1212 if(!pModel)
return -1;
1213 return pModel->SetTaskHandle(handler);
1218 std::function<uint (
const QDate&,
1219 QStringList &)> cbHandler)
1222 if(!pModel)
return -1;
1223 return pModel->SetTaskHandle(cbHandler);
1232 int nRet = pModel->SetViewType(type);
1234 int yearMin = pModel->GetMinimumDate().year();
1237 pModel->GetMinimumDate().weekNumber(&yearMin);
1238 if(m_bShowBackgroupImage)
1239 m_View.setStyleSheet(
"border-image:none");
1241 int yearMax = pModel->GetMaximumDate().year();
1243 pModel->GetMaximumDate().weekNumber(&yearMax);
1245 SetYearRange(yearMin, yearMax);
1246 m_cmbYear.setCurrentIndex(m_cmbYear.findData(pModel->GetShowYear()));
1252 m_cmbMonth.setToolTip(tr(
"Week"));
1253 m_cmbMonth.setStatusTip(tr(
"Week"));
1256 m_cmbMonth.setToolTip(tr(
"Month"));
1257 m_cmbMonth.setStatusTip(tr(
"Month"));
1270 return pModel->GetViewType();
1273int CLunarCalendar::SetTouchUpDownFunction(_TOUCH_UP_DOWN_FUNCTION f)
1275 m_TouchFunction = f;
1286 return pModel->GetCalendarType();
1294 int nRet = pModel->SetCalendarType(type);
1302 return CLunarTable::Instance()->Load(szFile);
1306 int nThreadNumber,
bool bClearCache,
1309 return CLunarTable::Instance()->Generate(
1318void CLunarCalendar::slotTimeout()
1320 m_lbTime.setText(QTime::currentTime().toString(locale().timeFormat()));
1325 m_lbTime.setVisible(bShow);
1327 m_Timer.start(1000);
1333int CLunarCalendar::SetBackgroup(
const QString &szFile)
1339 if(m_bShowBackgroupImage)
1340 m_View.setStyleSheet(
"border-image:url(" + szFile +
")");
1342 m_View.setStyleSheet(
"border-image:none");
1348 int nRet = UpdateViewModel(
true);
1353void CLunarCalendar::setFont(
const QFont& font)
1355 QWidget::setFont(font);
1356 m_View.setFont(font);
1357 m_View.horizontalHeader()->setFont(font);
1358 m_View.verticalHeader()->setFont(font);
1361QSize CLunarCalendar::sizeHint()
const
1363 return minimumSizeHint();
1366QSize CLunarCalendar::minimumSizeHint()
const
1376 int rows = pModel->rowCount();
1377 int cols = pModel->columnCount();
1379 int marginW = m_View.horizontalHeader()->style()->pixelMetric(
1380 QStyle::PM_FocusFrameHMargin) << 1;
1381 int marginH = m_View.verticalHeader()->style()->pixelMetric(
1382 QStyle::PM_FocusFrameVMargin) << 1;
1383 QMargins cm = m_View.horizontalHeader()->contentsMargins();
1384 w = (m_View.horizontalHeader()->minimumSectionSize() + marginW) * cols
1385 + marginW + cm.left() + cm.right();
1386 if(m_View.verticalHeader()->isVisible())
1389 w += m_View.verticalHeader()->sizeHint().width();
1391 cm = m_View.verticalHeader()->contentsMargins();
1393 h = (m_View.verticalHeader()->minimumSectionSize() + marginH) * rows;
1395 h = (m_View.verticalHeader()->minimumSectionSize() + marginH);
1396 h = h + marginH + cm.top() + cm.bottom();
1397 if(m_View.horizontalHeader()->isVisible())
1400 h += m_View.horizontalHeader()->sizeHint().height();
1415 if(m_tbPreYear.isVisible())
1417 QSize s = m_tbPreYear.sizeHint();
1418 headerH = s.height();
1419 headerW = s.width();
1421 if(m_cmbYear.isVisible())
1423 QSize s = m_cmbYear.sizeHint();
1424 headerH = qMax(headerH, s.height());
1425 headerW += s.width();
1427 if(m_tbNextYear.isVisible())
1429 QSize s = m_tbNextYear.sizeHint();
1430 headerH = qMax(headerH, s.height());
1431 headerW += s.width();
1433 if(m_tbPreMonth.isVisible())
1435 QSize s = m_tbPreMonth.sizeHint();
1436 headerH = qMax(headerH, s.height());
1437 headerW += s.width();
1439 if(m_cmbMonth.isVisible())
1441 QSize s = m_cmbMonth.sizeHint();
1442 headerH = qMax(headerH, s.height());
1443 headerW += s.width();
1445 if(m_tbNextMonth.isVisible())
1447 QSize s = m_tbNextMonth.sizeHint();
1448 headerH = qMax(headerH, s.height());
1449 headerW += s.width();
1451 if(m_pbToday.isVisible())
1453 QSize s = m_pbToday.sizeHint();
1454 headerH = qMax(headerH, s.height());
1455 headerW += s.width();
1457 if(m_lbDate.isVisible())
1459 QSize s = m_lbDate.sizeHint();
1460 headerH += s.height();
1461 headerW = qMax(headerW, s.width());
1463 if(m_lbTime.isVisible())
1465 QSize s = m_lbTime.sizeHint();
1466 headerH += s.height();
1467 headerW = qMax(headerW, s.width());
1470 switch (m_Headposition) {
1473 w = qMax(w, headerW);
1479 h = qMax(h, headerH);
1485 cm = contentsMargins();
1486 w += cm.left() + cm.right();
1487 h += cm.top() + cm.bottom();
1494const QString CLunarCalendar::Version()
1496 QString szVersion(tr(
"Version:"));
1498#ifdef LunarCalendar_VERSION
1499 szVersion += LunarCalendar_VERSION;
1502#ifdef LunarCalendar_REVISION
1503 szVersion +=
" (" + tr(
"Revision: [") + LunarCalendar_REVISION
1504 +
"](https://github.com/KangLin/LunarCalendar/tree/"
1505 + LunarCalendar_REVISION +
"))";
QString GetLunar()
得到指定日期的农历(汉字)
int GetMonth()
得到指定日期的农历月份
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
得到数据
const QDate SelectedDate() const
得到当前选择的日期。 当前选择的日期在指定的最小日期 MinimumDate() 与最大日期 MaximumDate() 的范围内。 默认为系统当前日期。
const QDate MaximumDate() const
得到日历的支持最大日期
void SetDateRange(const QDate &min, const QDate &max)
设置日历的支持日期的范围
bool EnableSolarTerm(bool bEnable=true)
允许或禁用节气
const int GetShowMonth() const
得到当前界面显示的月份
const int GetShowYear() const
得到当前界面显示的年份
const Qt::DayOfWeek FirstDayOfWeek() const
得到年周从哪天开始
int SetCalendarType(_CalendarType type)
设置日历类型(组合)
void SetSelectedDate(const QDate &date, bool bForce=false)
设置当前选择的日期
void SetMinimumDate(const QDate &date)
设置日历的支持最小日期
int SetTaskHandle(QSharedPointer< CTaskHandler > handler)
设置 使用者自定义任务接口
void ShowHead(bool bShow)
显示或隐藏日历头
void ShowBackgroupImage(bool show)
显示或隐藏背景图片
const QString SelectedLunar() const
得到当前选择的日期的农历的字符串
void ShowDate(bool bShow)
显示或隐藏选择日期
int LoadCalendarTable(const QString &szFile)
从缓存文件中得到农历
const _CalendarType GetCalendarType() const
得到日历类型
void sigSelectionChanged()
当前选择日期改变时触发 可以在相应的槽函数中调用下列函数
void ShowToday(bool bShow)
显示或隐藏今日工具按钮
const QString SelectedSolarTerm() const
得到当前选的节气
void ShowWeekHead(bool bShow)
显示或隐藏周
void ShowGrid(bool show)
显示或隐藏网格
const _VIEW_TYPE GetViewType() const
得到视图类型
void ShowTime(bool bShow)
显示或隐藏当前时间
int SetHeadposition(_HEAD_position pos=_HEAD_position::Top)
设置日历头的位置
bool EnableHolidays(bool bEnable=true)
允许或禁用节日
void ShowTools(bool bShow)
显示或隐藏日期工具按钮
int SetViewType(_VIEW_TYPE type)
设置视图类型
int GenerateCalendarTable(const QString &szFile, int nThreadNumber=2, bool bClearCache=false, bool bSaveAllDate=true)
产生日历缓存表
void SetMaximumDate(const QDate &date)
设置日历的支持最大日期
void ShowWeeks(bool bShow)
显示或隐藏第几周
const QDate MinimumDate() const
得到日历的支持最小日期
static int GetLunar(const QDate date, int &year, int &month, int &day)
得到给定日期的农历(公历转农历)
void EnableToolTip(bool show)
显示或隐藏工具提示