55 const QStyleOptionViewItem &o,
56 const QModelIndex &index)
const
58 QStyleOptionViewItem option = o;
63 QPalette palette = option.palette;
64 QColor solarColor, lunarColor, tasksColor, taskNumberColor, workColor;
66 QTableView *pView =
dynamic_cast<QTableView*
>(option.styleObject);
69 qCritical(Logger) <<
"The style object is null";
79 bool bSolar = index.data(CLunarCalendarModel::ROLE::CalendarTypeRole).toInt()
81 bool bLunar = index.data(CLunarCalendarModel::ROLE::CalendarTypeRole).toInt()
84 QFont fontSolar = option.font;
85 QFont fontLunar = option.font;
86 QFont fontTasks = option.font;
87 QFont fontWork = option.font;
89 if(-1 != fontWork.pointSize())
90 fontWork.setPointSizeF(fontWork.pointSize() >> 1);
91 if(-1 != fontWork.pixelSize())
92 fontWork.setPixelSize(fontWork.pixelSize() >> 1);
93 if(-1 != fontTasks.pointSize())
94 fontTasks.setPointSizeF(fontTasks.pointSize() >> 1);
95 if(-1 != fontTasks.pixelSize())
96 fontTasks.setPixelSize(fontTasks.pixelSize() >> 1);
98 QString szSolar, szLunar, szWork;
99 uint nTasks = index.data(CLunarCalendarModel::ROLE::Tasks).toUInt();
100 szWork = index.data(CLunarCalendarModel::ROLE::WorkDayRole).toString();
117 fontSolar = GetFontRole(fontSolar,
118 index.data(CLunarCalendarModel::ROLE::SolarFontRole).toInt());
119 szSolar = index.data(CLunarCalendarModel::ROLE::SolarRole).toString();
121 painter->setFont(fontSolar);
122 QFontMetrics m = painter->fontMetrics();
123 solarHeight = m.height();
124#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
125 solarWidth = m.horizontalAdvance(szSolar);
127 solarWidth = m.width(szSolar);
129 width = qMax(width, solarWidth);
130 height = qMax(height, solarHeight);
136 fontLunar = GetFontRole(fontLunar,
137 index.data(CLunarCalendarModel::ROLE::LunarFontRole).toInt());
138 szLunar = index.data(CLunarCalendarModel::ROLE::LunarRole).toString();
139 if(szLunar.length() > 3)
141 szLunar = szLunar.left(2) +
"...";
143 painter->setFont(fontLunar);
144 QFontMetrics m = painter->fontMetrics();
145 lunarHeight = m.height();
146#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
147 lunarWidth = m.horizontalAdvance(szLunar);
149 lunarWidth = m.width(szLunar);
152 width = qMax(width, lunarWidth);
153 height = qMax(height, lunarHeight);
165 if(pView->horizontalHeader()->minimumSectionSize() < width)
168 pView->horizontalHeader()->setMinimumSectionSize(width);
169 pView->updateGeometry();
175 if(pView->verticalHeader()->minimumSectionSize() < nRow * height)
178 pView->verticalHeader()->setMinimumSectionSize(nRow * height);
179 pView->updateGeometry();
186 if(option.rect.width() > width)
187 width = option.rect.width();
188 if(option.rect.height() > height * nRow && nRow)
189 height = option.rect.height() / nRow;
192 if(index.data(CLunarCalendarModel::ROLE::TodayRole).toBool())
194 painter->setPen(palette.brush(QPalette::Active, QPalette::Highlight).color());
196 painter->drawRect(option.rect.adjusted(1, 1, -1, -1));
200 if(pView->currentIndex() == index)
202 painter->setPen(QPen(Qt::NoPen));
203 painter->setBrush(palette.brush(QPalette::Active, QPalette::Highlight));
204 painter->drawRect(option.rect);
206 solarColor = palette.color(QPalette::Active, QPalette::HighlightedText);
207 lunarColor = solarColor;
208 tasksColor = solarColor;
209 taskNumberColor = palette.color(QPalette::Active, QPalette::Highlight);
210 workColor = solarColor;
215 solarColor = GetColorRole(palette,
216 index.data(CLunarCalendarModel::ROLE::SolarColorRole).toInt());
218 lunarColor = GetColorRole(palette,
219 index.data(CLunarCalendarModel::ROLE::LunarColorRole).toInt());
223 tasksColor = GetColorRole(palette,
224 index.data(CLunarCalendarModel::ROLE::TasksColorRole).toInt());
225 if(CLunarCalendarModel::_COLOR_ROLE::ColorHighlight
226 == index.data(CLunarCalendarModel::ROLE::TasksColorRole))
228 = palette.color(QPalette::Active, QPalette::HighlightedText);
230 taskNumberColor = GetColorRole(palette, CLunarCalendarModel::_COLOR_ROLE::ColorNormal);
232 workColor = GetColorRole(palette,
233 index.data(CLunarCalendarModel::ROLE::WorkDayColorRole).toInt());
236 if(!szWork.isEmpty() && bSolar)
238 painter->setFont(fontWork);
239 painter->setPen(workColor);
240 painter->drawText(option.rect.left(),
244 Qt::AlignLeft| Qt::AlignTop,
248 if(nTasks && (bSolar || bLunar))
250 painter->setFont(fontTasks);
251 int h = qMin(taskHeight, taskWidth) >> 1;
252 painter->setBrush(QBrush(tasksColor, Qt::SolidPattern));
253 painter->setPen(tasksColor);
255 QRect rect(option.rect.left() + (width - h) / 2,
256 option.rect.top() + (height - h) / 2,
260 painter->drawEllipse(rect);
280 painter->setFont(fontSolar);
281 painter->setPen(solarColor);
282 painter->drawText(option.rect.left(),
283 option.rect.top() + height * nHadRow,
286 Qt::AlignHCenter | Qt::AlignVCenter,
293 painter->setFont(fontLunar);
294 painter->setPen(lunarColor);
295 painter->drawText(option.rect.left(),
296 option.rect.top() + height * nHadRow,
299 Qt::AlignHCenter | Qt::AlignVCenter,