participants_check_view.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/widgets/participants_check_view.h"
  8. #include "ui/effects/ripple_animation.h"
  9. #include "ui/effects/toggle_arrow.h"
  10. #include "ui/painter.h"
  11. #include "ui/rect.h"
  12. #include "styles/style_boxes.h"
  13. namespace Ui {
  14. ParticipantsCheckView::ParticipantsCheckView(
  15. int count,
  16. int duration,
  17. bool checked,
  18. Fn<void()> updateCallback)
  19. : Ui::AbstractCheckView(duration, checked, std::move(updateCallback))
  20. , _text(QString::number(std::abs(count)))
  21. , _count(count) {
  22. }
  23. QSize ParticipantsCheckView::ComputeSize(int count) {
  24. return QSize(
  25. st::moderateBoxExpandHeight
  26. + st::moderateBoxExpand.width()
  27. + st::moderateBoxExpandInnerSkip * 4
  28. + st::moderateBoxExpandFont->width(
  29. QString::number(std::abs(count)))
  30. + st::moderateBoxExpandToggleSize,
  31. st::moderateBoxExpandHeight);
  32. }
  33. QSize ParticipantsCheckView::getSize() const {
  34. return ComputeSize(_count);
  35. }
  36. void ParticipantsCheckView::paint(
  37. QPainter &p,
  38. int left,
  39. int top,
  40. int outerWidth) {
  41. auto hq = PainterHighQualityEnabler(p);
  42. const auto size = getSize();
  43. const auto radius = size.height() / 2;
  44. p.setPen(Qt::NoPen);
  45. st::moderateBoxExpand.paint(
  46. p,
  47. radius,
  48. left + (size.height() - st::moderateBoxExpand.height()) / 2,
  49. top + size.width());
  50. const auto innerSkip = st::moderateBoxExpandInnerSkip;
  51. p.setBrush(Qt::NoBrush);
  52. p.setPen(st::boxTextFg);
  53. p.setFont(st::moderateBoxExpandFont);
  54. p.drawText(
  55. QRect(
  56. left + innerSkip + radius + st::moderateBoxExpand.width(),
  57. top,
  58. size.width(),
  59. size.height()),
  60. _text,
  61. style::al_left);
  62. const auto path = Ui::ToggleUpDownArrowPath(
  63. left + size.width() - st::moderateBoxExpandToggleSize - radius,
  64. top + size.height() / 2,
  65. st::moderateBoxExpandToggleSize,
  66. st::moderateBoxExpandToggleFourStrokes,
  67. Ui::AbstractCheckView::currentAnimationValue());
  68. p.fillPath(path, st::boxTextFg);
  69. }
  70. QImage ParticipantsCheckView::prepareRippleMask() const {
  71. const auto size = getSize();
  72. return Ui::RippleAnimation::RoundRectMask(size, size.height() / 2);
  73. }
  74. bool ParticipantsCheckView::checkRippleStartPosition(QPoint position) const {
  75. return Rect(getSize()).contains(position);
  76. }
  77. void ParticipantsCheckView::checkedChangedHook(anim::type animated) {
  78. }
  79. ParticipantsCheckView::~ParticipantsCheckView() = default;
  80. } // namespace Ui