chart_header_widget.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "statistics/widgets/chart_header_widget.h"
  8. #include "ui/painter.h"
  9. #include "styles/style_statistics.h"
  10. namespace Statistic {
  11. Header::Header(not_null<Ui::RpWidget*> parent)
  12. : Ui::RpWidget(parent)
  13. , _height(st::statisticsChartHeaderHeight) {
  14. }
  15. QString Header::title() const {
  16. return _title.toString();
  17. }
  18. void Header::setTitle(QString title) {
  19. _title.setText(st::statisticsHeaderTitleTextStyle, std::move(title));
  20. }
  21. int Header::resizeGetHeight(int newWidth) {
  22. return _height;
  23. }
  24. void Header::setSubTitle(QString subTitle) {
  25. _height = subTitle.isEmpty()
  26. ? st::statisticsHeaderTitleTextStyle.font->height
  27. : st::statisticsChartHeaderHeight;
  28. _subTitle.setText(
  29. st::statisticsHeaderDatesTextStyle,
  30. std::move(subTitle));
  31. }
  32. void Header::paintEvent(QPaintEvent *e) {
  33. auto p = Painter(this);
  34. p.fillRect(rect(), st::boxBg);
  35. p.setPen(st::windowActiveTextFg);
  36. _title.drawLeftElided(p, 0, 0, width(), width());
  37. p.setPen(st::windowSubTextFg);
  38. _subTitle.drawLeftElided(p, 0, _infoTop, width(), width());
  39. }
  40. void Header::resizeEvent(QResizeEvent *e) {
  41. _infoTop = e->size().height()
  42. - st::statisticsHeaderDatesTextStyle.font->height;
  43. }
  44. } // namespace Statistic