/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "base/object_ptr.h" #include "mtproto/sender.h" #include "ui/rp_widget.h" #include "ui/effects/animations.h" namespace Main { class Account; } // namespace Main; namespace Ui { class SlideAnimation; class CrossFadeAnimation; class FlatLabel; template class FadeWrap; } // namespace Ui namespace Intro { namespace details { struct Data; enum class StackAction; enum class Animate; class Step : public Ui::RpWidget, protected base::Subscriber { public: Step( QWidget *parent, not_null account, not_null data, bool hasCover = false); ~Step(); [[nodiscard]] Main::Account &account() const { return *_account; } // It should not be called in StartWidget, in other steps it should be // present and not changing. [[nodiscard]] MTP::Sender &api() const; void apiClear(); virtual void finishInit() { } virtual void setInnerFocus() { setFocus(); } void setGoCallback( Fn callback); void setShowResetCallback(Fn callback); void setShowTermsCallback(Fn callback); void setCancelNearestDcCallback(Fn callback); void setAcceptTermsCallback( Fn callback)> callback); void prepareShowAnimated(Step *after); void showAnimated(Animate animate); void showFast(); [[nodiscard]] bool animating() const; void setShowAnimationClipping(QRect clipping); [[nodiscard]] bool hasCover() const; [[nodiscard]] virtual bool hasBack() const; virtual void activate(); virtual void cancelled(); virtual void finished(); virtual void submit() = 0; [[nodiscard]] virtual rpl::producer nextButtonText() const; [[nodiscard]] int contentLeft() const; [[nodiscard]] int contentTop() const; void setErrorCentered(bool centered); void showError(rpl::producer text); void hideError() { showError(rpl::single(QString())); } protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; void setTitleText(rpl::producer titleText); void setDescriptionText(rpl::producer descriptionText); void setDescriptionText( rpl::producer richDescriptionText); bool paintAnimated(Painter &p, QRect clip); void fillSentCodeData(const MTPDauth_sentCode &type); void showDescription(); void hideDescription(); [[nodiscard]] not_null getData() const { return _data; } void finish(const MTPUser &user, QImage &&photo = QImage()); void goBack(); template void goNext() { goNext(new StepType(parentWidget(), _account, _data)); } template void goReplace(Animate animate) { goReplace(new StepType(parentWidget(), _account, _data), animate); } void showResetButton() { if (_showResetCallback) _showResetCallback(); } void showTerms() { if (_showTermsCallback) _showTermsCallback(); } void acceptTerms(Fn callback) { if (_acceptTermsCallback) { _acceptTermsCallback(callback); } } void cancelNearestDcRequest() { if (_cancelNearestDcCallback) _cancelNearestDcCallback(); } virtual int errorTop() const; private: struct CoverAnimation { CoverAnimation() = default; CoverAnimation(CoverAnimation &&other) = default; CoverAnimation &operator=(CoverAnimation &&other) = default; ~CoverAnimation(); std::unique_ptr title; std::unique_ptr description; // From content top till the next button top. QPixmap contentSnapshotWas; QPixmap contentSnapshotNow; QRect clipping; }; void updateLabelsPosition(); void paintContentSnapshot( Painter &p, const QPixmap &snapshot, float64 alpha, float64 howMuchHidden); void refreshError(const QString &text); void goNext(Step *step); void goReplace(Step *step, Animate animate); [[nodiscard]] CoverAnimation prepareCoverAnimation(Step *step); [[nodiscard]] QPixmap prepareContentSnapshot(); [[nodiscard]] QPixmap prepareSlideAnimation(); void showFinished(); void prepareCoverMask(); void paintCover(Painter &p, int top); const not_null _account; const not_null _data; mutable std::optional _api; bool _hasCover = false; Fn _goCallback; Fn _showResetCallback; Fn _showTermsCallback; Fn _cancelNearestDcCallback; Fn callback)> _acceptTermsCallback; rpl::variable _titleText; object_ptr _title; rpl::variable _descriptionText; object_ptr> _description; bool _errorCentered = false; rpl::variable _errorText; object_ptr> _error = { nullptr }; Ui::Animations::Simple _a_show; CoverAnimation _coverAnimation; std::unique_ptr _slideAnimation; QPixmap _coverMask; }; } // namespace details } // namespace Intro