jump_down_button.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/jump_down_button.h"
  8. #include "ui/effects/ripple_animation.h"
  9. #include "ui/unread_badge_paint.h"
  10. #include "styles/style_chat_helpers.h"
  11. namespace Ui {
  12. JumpDownButton::JumpDownButton(
  13. QWidget *parent,
  14. const style::TwoIconButton &st)
  15. : RippleButton(parent, st.ripple)
  16. , _st(st) {
  17. resize(_st.width, _st.height);
  18. setCursor(style::cur_pointer);
  19. hide();
  20. }
  21. QImage JumpDownButton::prepareRippleMask() const {
  22. return Ui::RippleAnimation::EllipseMask(
  23. QSize(_st.rippleAreaSize, _st.rippleAreaSize));
  24. }
  25. QPoint JumpDownButton::prepareRippleStartPosition() const {
  26. return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition;
  27. }
  28. void JumpDownButton::paintEvent(QPaintEvent *e) {
  29. auto p = QPainter(this);
  30. const auto over = isOver();
  31. const auto down = isDown();
  32. ((over || down)
  33. ? _st.iconBelowOver
  34. : _st.iconBelow).paint(p, _st.iconPosition, width());
  35. paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y());
  36. ((over || down)
  37. ? _st.iconAboveOver
  38. : _st.iconAbove).paint(p, _st.iconPosition, width());
  39. if (_unreadCount > 0) {
  40. auto unreadString = QString::number(_unreadCount);
  41. Ui::UnreadBadgeStyle st;
  42. st.align = style::al_center;
  43. st.font = st::historyToDownBadgeFont;
  44. st.size = st::historyToDownBadgeSize;
  45. st.sizeId = Ui::UnreadBadgeSize::HistoryToDown;
  46. Ui::PaintUnreadBadge(p, unreadString, width(), 0, st, 4);
  47. }
  48. }
  49. void JumpDownButton::setUnreadCount(int unreadCount) {
  50. if (_unreadCount != unreadCount) {
  51. _unreadCount = unreadCount;
  52. update();
  53. }
  54. }
  55. } // namespace Ui