info_section_widget.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "info/info_section_widget.h"
  8. #include "window/window_adaptive.h"
  9. #include "window/window_connecting_widget.h"
  10. #include "window/window_session_controller.h"
  11. #include "main/main_session.h"
  12. #include "info/info_content_widget.h"
  13. #include "info/info_wrap_widget.h"
  14. #include "info/info_layer_widget.h"
  15. #include "info/info_memento.h"
  16. #include "info/info_controller.h"
  17. #include "styles/style_layers.h"
  18. namespace Info {
  19. SectionWidget::SectionWidget(
  20. QWidget *parent,
  21. not_null<Window::SessionController*> window,
  22. Wrap wrap,
  23. not_null<Memento*> memento)
  24. : Window::SectionWidget(parent, window)
  25. , _content(this, window, wrap, memento) {
  26. init();
  27. }
  28. SectionWidget::SectionWidget(
  29. QWidget *parent,
  30. not_null<Window::SessionController*> window,
  31. Wrap wrap,
  32. not_null<MoveMemento*> memento)
  33. : Window::SectionWidget(parent, window)
  34. , _content(memento->takeContent(this, wrap)) {
  35. init();
  36. }
  37. void SectionWidget::init() {
  38. Expects(_connecting == nullptr);
  39. rpl::combine(
  40. sizeValue(),
  41. _content->desiredHeightValue()
  42. ) | rpl::filter([=] {
  43. return (_content != nullptr);
  44. }) | rpl::start_with_next([=](QSize size, int) {
  45. const auto expanding = false;
  46. const auto full = !_content->scrollBottomSkip();
  47. const auto additionalScroll = (full ? st::boxRadius : 0);
  48. const auto height = size.height() - (full ? 0 : st::boxRadius);
  49. const auto wrapGeometry = QRect{ 0, 0, size.width(), height };
  50. _content->updateGeometry(
  51. wrapGeometry,
  52. expanding,
  53. additionalScroll,
  54. size.height());
  55. }, lifetime());
  56. _connecting = std::make_unique<Window::ConnectionState>(
  57. _content.data(),
  58. &controller()->session().account(),
  59. controller()->adaptive().oneColumnValue());
  60. _content->contentChanged(
  61. ) | rpl::start_with_next([=] {
  62. _connecting->raise();
  63. }, _connecting->lifetime());
  64. }
  65. Dialogs::RowDescriptor SectionWidget::activeChat() const {
  66. return _content->activeChat();
  67. }
  68. bool SectionWidget::hasTopBarShadow() const {
  69. return _content->hasTopBarShadow();
  70. }
  71. QPixmap SectionWidget::grabForShowAnimation(
  72. const Window::SectionSlideParams &params) {
  73. return _content->grabForShowAnimation(params);
  74. }
  75. void SectionWidget::doSetInnerFocus() {
  76. _content->setInnerFocus();
  77. }
  78. void SectionWidget::showFinishedHook() {
  79. _topBarSurrogate.destroy();
  80. _content->showFast();
  81. }
  82. void SectionWidget::showAnimatedHook(
  83. const Window::SectionSlideParams &params) {
  84. _topBarSurrogate = _content->createTopBarSurrogate(this);
  85. }
  86. void SectionWidget::paintEvent(QPaintEvent *e) {
  87. Window::SectionWidget::paintEvent(e);
  88. if (!animatingShow()) {
  89. QPainter(this).fillRect(e->rect(), st::windowBg);
  90. }
  91. }
  92. bool SectionWidget::showInternal(
  93. not_null<Window::SectionMemento*> memento,
  94. const Window::SectionShow &params) {
  95. return _content->showInternal(memento, params);
  96. }
  97. std::shared_ptr<Window::SectionMemento> SectionWidget::createMemento() {
  98. return _content->createMemento();
  99. }
  100. object_ptr<Ui::LayerWidget> SectionWidget::moveContentToLayer(
  101. QRect bodyGeometry) {
  102. if (_content->controller()->wrap() != Wrap::Narrow
  103. || width() < LayerWidget::MinimalSupportedWidth()) {
  104. return nullptr;
  105. }
  106. return MoveMemento(
  107. std::move(_content)).createLayer(
  108. controller(),
  109. bodyGeometry);
  110. }
  111. rpl::producer<> SectionWidget::removeRequests() const {
  112. return _content->removeRequests();
  113. }
  114. bool SectionWidget::floatPlayerHandleWheelEvent(QEvent *e) {
  115. return _content->floatPlayerHandleWheelEvent(e);
  116. }
  117. QRect SectionWidget::floatPlayerAvailableRect() {
  118. return _content->floatPlayerAvailableRect();
  119. }
  120. } // namespace Info