peer_list_dummy.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "ui/controls/peer_list_dummy.h"
  8. #include "ui/painter.h"
  9. #include "styles/style_widgets.h"
  10. PeerListDummy::PeerListDummy(
  11. QWidget *parent,
  12. int count,
  13. const style::PeerList &st)
  14. : _st(st)
  15. , _count(count) {
  16. resize(width(), _count * _st.item.height);
  17. }
  18. void PeerListDummy::paintEvent(QPaintEvent *e) {
  19. QPainter p(this);
  20. PainterHighQualityEnabler hq(p);
  21. const auto fill = e->rect();
  22. const auto bottom = fill.top() + fill.height();
  23. const auto from = std::clamp(fill.top() / _st.item.height, 0, _count);
  24. const auto till = std::clamp(
  25. (bottom + _st.item.height - 1) / _st.item.height,
  26. 0,
  27. _count);
  28. p.translate(0, _st.item.height * from);
  29. p.setPen(Qt::NoPen);
  30. for (auto i = from; i != till; ++i) {
  31. p.setBrush(st::windowBgOver);
  32. p.drawEllipse(
  33. _st.item.photoPosition.x(),
  34. _st.item.photoPosition.y(),
  35. _st.item.photoSize,
  36. _st.item.photoSize);
  37. const auto small = int(1.5 * _st.item.photoSize);
  38. const auto large = 2 * small;
  39. const auto second = (i % 2) ? large : small;
  40. const auto height = _st.item.nameStyle.font->height / 2;
  41. const auto radius = height / 2;
  42. const auto left = _st.item.namePosition.x();
  43. const auto top = _st.item.namePosition.y()
  44. + (_st.item.nameStyle.font->height - height) / 2;
  45. const auto skip = _st.item.namePosition.x()
  46. - _st.item.photoPosition.x()
  47. - _st.item.photoSize;
  48. const auto next = left + small + skip;
  49. p.drawRoundedRect(left, top, small, height, radius, radius);
  50. p.drawRoundedRect(next, top, second, height, radius, radius);
  51. p.translate(0, _st.item.height);
  52. }
  53. }