intro_step.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #pragma once
  8. #include "base/object_ptr.h"
  9. #include "mtproto/sender.h"
  10. #include "ui/text/text_variant.h"
  11. #include "ui/rp_widget.h"
  12. #include "ui/effects/animations.h"
  13. namespace style {
  14. struct RoundButton;
  15. } // namespace style;
  16. namespace Main {
  17. class Account;
  18. } // namespace Main;
  19. namespace Ui {
  20. class SlideAnimation;
  21. class CrossFadeAnimation;
  22. class FlatLabel;
  23. template <typename Widget>
  24. class FadeWrap;
  25. } // namespace Ui
  26. namespace Intro {
  27. namespace details {
  28. struct Data;
  29. enum class StackAction;
  30. enum class Animate;
  31. class Step : public Ui::RpWidget {
  32. public:
  33. Step(
  34. QWidget *parent,
  35. not_null<Main::Account*> account,
  36. not_null<Data*> data,
  37. bool hasCover = false);
  38. ~Step();
  39. [[nodiscard]] Main::Account &account() const {
  40. return *_account;
  41. }
  42. // It should not be called in StartWidget, in other steps it should be
  43. // present and not changing.
  44. [[nodiscard]] MTP::Sender &api() const;
  45. void apiClear();
  46. virtual void finishInit() {
  47. }
  48. virtual void setInnerFocus() {
  49. setFocus();
  50. }
  51. void setGoCallback(
  52. Fn<void(Step *step, StackAction action, Animate animate)> callback);
  53. void setShowResetCallback(Fn<void()> callback);
  54. void setShowTermsCallback(Fn<void()> callback);
  55. void setCancelNearestDcCallback(Fn<void()> callback);
  56. void setAcceptTermsCallback(
  57. Fn<void(Fn<void()> callback)> callback);
  58. void prepareShowAnimated(Step *after);
  59. void showAnimated(Animate animate);
  60. void showFast();
  61. [[nodiscard]] bool animating() const;
  62. void setShowAnimationClipping(QRect clipping);
  63. [[nodiscard]] bool hasCover() const;
  64. [[nodiscard]] virtual bool hasBack() const;
  65. virtual void activate();
  66. virtual void cancelled();
  67. virtual void finished();
  68. virtual void submit() = 0;
  69. [[nodiscard]] virtual rpl::producer<QString> nextButtonText() const;
  70. [[nodiscard]] virtual auto nextButtonStyle() const
  71. -> rpl::producer<const style::RoundButton*>;
  72. [[nodiscard]] int contentLeft() const;
  73. [[nodiscard]] int contentTop() const;
  74. void setErrorCentered(bool centered);
  75. void showError(rpl::producer<QString> text);
  76. void hideError() {
  77. showError(rpl::single(QString()));
  78. }
  79. protected:
  80. void paintEvent(QPaintEvent *e) override;
  81. void resizeEvent(QResizeEvent *e) override;
  82. void setTitleText(rpl::producer<QString> titleText);
  83. void setDescriptionText(v::text::data &&descriptionText);
  84. bool paintAnimated(QPainter &p, QRect clip);
  85. void fillSentCodeData(const MTPDauth_sentCode &type);
  86. void showDescription();
  87. void hideDescription();
  88. [[nodiscard]] not_null<Data*> getData() const {
  89. return _data;
  90. }
  91. void finish(const MTPauth_Authorization &auth, QImage &&photo = {});
  92. void finish(const MTPUser &user, QImage &&photo = {});
  93. void createSession(
  94. const MTPUser &user,
  95. QImage photo,
  96. const QVector<MTPDialogFilter> &filters,
  97. bool tagsEnabled);
  98. void goBack();
  99. template <typename StepType>
  100. void goNext() {
  101. goNext(new StepType(parentWidget(), _account, _data));
  102. }
  103. template <typename StepType>
  104. void goReplace(Animate animate) {
  105. goReplace(new StepType(parentWidget(), _account, _data), animate);
  106. }
  107. void showResetButton() {
  108. if (_showResetCallback) _showResetCallback();
  109. }
  110. void showTerms() {
  111. if (_showTermsCallback) _showTermsCallback();
  112. }
  113. void acceptTerms(Fn<void()> callback) {
  114. if (_acceptTermsCallback) {
  115. _acceptTermsCallback(callback);
  116. }
  117. }
  118. void cancelNearestDcRequest() {
  119. if (_cancelNearestDcCallback) _cancelNearestDcCallback();
  120. }
  121. virtual int errorTop() const;
  122. private:
  123. struct CoverAnimation {
  124. CoverAnimation() = default;
  125. CoverAnimation(CoverAnimation &&other) = default;
  126. CoverAnimation &operator=(CoverAnimation &&other) = default;
  127. ~CoverAnimation();
  128. std::unique_ptr<Ui::CrossFadeAnimation> title;
  129. std::unique_ptr<Ui::CrossFadeAnimation> description;
  130. // From content top till the next button top.
  131. QPixmap contentSnapshotWas;
  132. QPixmap contentSnapshotNow;
  133. QRect clipping;
  134. };
  135. void updateLabelsPosition();
  136. void paintContentSnapshot(
  137. QPainter &p,
  138. const QPixmap &snapshot,
  139. float64 alpha,
  140. float64 howMuchHidden);
  141. void refreshError(const QString &text);
  142. void goNext(Step *step);
  143. void goReplace(Step *step, Animate animate);
  144. [[nodiscard]] CoverAnimation prepareCoverAnimation(Step *step);
  145. [[nodiscard]] QPixmap prepareContentSnapshot();
  146. [[nodiscard]] QPixmap prepareSlideAnimation();
  147. void showFinished();
  148. void prepareCoverMask();
  149. void paintCover(QPainter &p, int top);
  150. const not_null<Main::Account*> _account;
  151. const not_null<Data*> _data;
  152. mutable std::optional<MTP::Sender> _api;
  153. bool _hasCover = false;
  154. Fn<void(Step *step, StackAction action, Animate animate)> _goCallback;
  155. Fn<void()> _showResetCallback;
  156. Fn<void()> _showTermsCallback;
  157. Fn<void()> _cancelNearestDcCallback;
  158. Fn<void(Fn<void()> callback)> _acceptTermsCallback;
  159. rpl::variable<QString> _titleText;
  160. object_ptr<Ui::FlatLabel> _title;
  161. rpl::variable<TextWithEntities> _descriptionText;
  162. object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _description;
  163. bool _errorCentered = false;
  164. rpl::variable<QString> _errorText;
  165. object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _error = { nullptr };
  166. Ui::Animations::Simple _a_show;
  167. CoverAnimation _coverAnimation;
  168. std::unique_ptr<Ui::SlideAnimation> _slideAnimation;
  169. QPixmap _coverMask;
  170. };
  171. } // namespace details
  172. } // namespace Intro