profile_back_button.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "profile/profile_back_button.h"
  8. //#include "history/view/history_view_top_bar_widget.h"
  9. #include "main/main_session.h"
  10. #include "data/data_session.h"
  11. #include "ui/painter.h"
  12. #include "styles/style_widgets.h"
  13. #include "styles/style_window.h"
  14. #include "styles/style_profile.h"
  15. #include "styles/style_info.h"
  16. namespace Profile {
  17. BackButton::BackButton(
  18. QWidget *parent,
  19. not_null<Main::Session*> session,
  20. const QString &text,
  21. rpl::producer<bool> oneColumnValue)
  22. : Ui::AbstractButton(parent)
  23. , _session(session)
  24. , _text(text) {
  25. setCursor(style::cur_pointer);
  26. std::move(
  27. oneColumnValue
  28. ) | rpl::start_with_next([=](bool oneColumn) {
  29. if (!oneColumn) {
  30. _unreadBadgeLifetime.destroy();
  31. } else if (!_unreadBadgeLifetime) {
  32. _session->data().unreadBadgeChanges(
  33. ) | rpl::start_with_next([=] {
  34. rtlupdate(
  35. 0,
  36. 0,
  37. st::titleUnreadCounterRight,
  38. st::titleUnreadCounterTop);
  39. }, _unreadBadgeLifetime);
  40. }
  41. }, lifetime());
  42. }
  43. void BackButton::setText(const QString &text) {
  44. _text = text;
  45. update();
  46. }
  47. int BackButton::resizeGetHeight(int newWidth) {
  48. return st::profileTopBarHeight;
  49. }
  50. void BackButton::paintEvent(QPaintEvent *e) {
  51. Painter p(this);
  52. p.fillRect(e->rect(), st::profileBg);
  53. st::topBarBack.paint(p, (st::topBarArrowPadding.left() - st::topBarBack.width()) / 2, (st::topBarHeight - st::topBarBack.height()) / 2, width());
  54. p.setFont(st::topBarButton.style.font);
  55. p.setPen(st::topBarButton.textFg);
  56. p.drawTextLeft(st::topBarArrowPadding.left(), st::topBarButton.padding.top() + st::topBarButton.textTop, width(), _text);
  57. }
  58. void BackButton::onStateChanged(State was, StateChangeSource source) {
  59. if (isDown() && !(was & StateFlag::Down)) {
  60. clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
  61. }
  62. }
  63. } // namespace Profile