MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / paintEvent

Method paintEvent

pj_widgets/src/DateRangePicker.cpp:265–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265void CalendarWidget::paintEvent(QPaintEvent* /*event*/) {
266 QPainter p(this);
267 p.setRenderHint(QPainter::Antialiasing);
268
269 // Source colors from the active theme's tokens instead of palette() roles:
270 // the app pins QPalette at Fusion defaults regardless of the QSS theme, so
271 // palette() would resolve to Fusion light-grey on both themes. pickerTokens()
272 // picks the right light/dark shades off the persisted "StyleSheet::theme" key.
273 const PickerTokens tok = pickerTokens();
274 p.fillRect(rect(), tok.surface);
275
276 int hh = headerHeight();
277 int cell_w = width() / kCols;
278 int fm_h = fontMetrics().height();
279
280 // Month/Year title
281 QFont title_font = font();
282 title_font.setBold(true);
283 title_font.setPointSize(font().pointSize() + 2);
284 p.setFont(title_font);
285 QString title = QDate(year_, month_, 1).toString("MMMM yyyy");
286 p.setPen(tok.text);
287 p.drawText(QRect(0, 0, width(), fm_h + kHeaderPad * 2), Qt::AlignCenter, title);
288
289 // Day name headers
290 p.setFont(font());
291 static const char* day_names[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
292 int day_header_y = fm_h + kHeaderPad * 2;
293 QColor weekend_color(0xef, 0x53, 0x50);
294 QColor header_color = tok.muted;
295 for (int c = 0; c < kCols; ++c) {
296 QRect r(c * cell_w, day_header_y, cell_w, fm_h + kHeaderPad);
297 p.setPen((c >= 5) ? weekend_color : header_color);
298 p.drawText(r, Qt::AlignCenter, day_names[c]);
299 }
300
301 // Effective range for painting
302 QDate eff_from = range_from_;
303 QDate eff_to = range_to_;
304 if (eff_from.isValid() && !eff_to.isValid() && hover_date_.isValid()) {
305 eff_to = hover_date_;
306 }
307 if (eff_from.isValid() && eff_to.isValid() && eff_from > eff_to) {
308 std::swap(eff_from, eff_to);
309 }
310
311 int days_in_month = QDate(year_, month_, 1).daysInMonth();
312 int first_col = firstDayColumn();
313
314 QColor from_color(0x2e, 0xcc, 0x71);
315 QColor to_color(0xe7, 0x4c, 0x3c);
316 QColor range_color = tok.selection_range;
317 range_color.setAlpha(60);
318 QColor hover_brush = tok.hover_fill;
319 QColor hover_border = tok.hover_border;
320
321 for (int day = 1; day <= days_in_month; ++day) {
322 int idx = (day - 1) + first_col;

Callers

nothing calls this directly

Calls 15

pickerTokensFunction · 0.85
heightMethod · 0.80
toStringMethod · 0.80
drawRectMethod · 0.80
yMethod · 0.80
drawLineMethod · 0.60
QRectClass · 0.50
QPenClass · 0.50
setRenderHintMethod · 0.45
fillRectMethod · 0.45
setFontMethod · 0.45
setPenMethod · 0.45

Tested by

no test coverage detected