tdesktop/Telegram/SourceFiles/intro/intro_step.h

215 lines
5.4 KiB
C
Raw Normal View History

2019-11-26 11:10:44 +00:00
/*
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 style {
struct RoundButton;
} // namespace style;
2019-11-26 11:10:44 +00:00
namespace Main {
class Account;
} // namespace Main;
namespace Ui {
class SlideAnimation;
class CrossFadeAnimation;
class FlatLabel;
template <typename Widget>
class FadeWrap;
} // namespace Ui
namespace Intro {
namespace details {
struct Data;
enum class StackAction;
enum class Animate;
2019-11-26 11:10:44 +00:00
class Step : public Ui::RpWidget {
2019-11-26 11:10:44 +00:00
public:
Step(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Data*> data,
bool hasCover = false);
~Step();
[[nodiscard]] Main::Account &account() const {
return *_account;
}
2020-06-11 13:07:14 +00:00
// It should not be called in StartWidget, in other steps it should be
// present and not changing.
[[nodiscard]] MTP::Sender &api() const;
2020-06-11 13:07:14 +00:00
void apiClear();
2019-11-26 11:10:44 +00:00
virtual void finishInit() {
}
virtual void setInnerFocus() {
setFocus();
}
void setGoCallback(
Fn<void(Step *step, StackAction action, Animate animate)> callback);
2019-11-26 11:10:44 +00:00
void setShowResetCallback(Fn<void()> callback);
void setShowTermsCallback(Fn<void()> callback);
void setCancelNearestDcCallback(Fn<void()> callback);
2019-11-26 11:10:44 +00:00
void setAcceptTermsCallback(
Fn<void(Fn<void()> callback)> callback);
void prepareShowAnimated(Step *after);
void showAnimated(Animate animate);
2019-11-26 11:10:44 +00:00
void showFast();
[[nodiscard]] bool animating() const;
2019-11-29 13:42:42 +00:00
void setShowAnimationClipping(QRect clipping);
2019-11-26 11:10:44 +00:00
[[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<QString> nextButtonText() const;
[[nodiscard]] virtual auto nextButtonStyle() const
-> rpl::producer<const style::RoundButton*>;
2019-11-26 11:10:44 +00:00
[[nodiscard]] int contentLeft() const;
[[nodiscard]] int contentTop() const;
void setErrorCentered(bool centered);
void showError(rpl::producer<QString> text);
void hideError() {
showError(rpl::single(QString()));
}
protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void setTitleText(rpl::producer<QString> titleText);
void setDescriptionText(rpl::producer<QString> descriptionText);
void setDescriptionText(
rpl::producer<TextWithEntities> richDescriptionText);
2022-09-16 20:23:27 +00:00
bool paintAnimated(QPainter &p, QRect clip);
2019-11-26 11:10:44 +00:00
void fillSentCodeData(const MTPDauth_sentCode &type);
void showDescription();
void hideDescription();
[[nodiscard]] not_null<Data*> getData() const {
return _data;
}
2023-01-10 13:10:34 +00:00
void finish(const MTPauth_Authorization &auth, QImage &&photo = {});
void finish(const MTPUser &user, QImage &&photo = {});
void createSession(
const MTPUser &user,
QImage photo,
const QVector<MTPDialogFilter> &filters);
2019-11-26 11:10:44 +00:00
void goBack();
template <typename StepType>
void goNext() {
goNext(new StepType(parentWidget(), _account, _data));
}
template <typename StepType>
void goReplace(Animate animate) {
goReplace(new StepType(parentWidget(), _account, _data), animate);
2019-11-26 11:10:44 +00:00
}
void showResetButton() {
if (_showResetCallback) _showResetCallback();
}
void showTerms() {
if (_showTermsCallback) _showTermsCallback();
}
void acceptTerms(Fn<void()> callback) {
if (_acceptTermsCallback) {
_acceptTermsCallback(callback);
}
}
void cancelNearestDcRequest() {
if (_cancelNearestDcCallback) _cancelNearestDcCallback();
}
2019-11-26 11:10:44 +00:00
2019-11-26 14:27:09 +00:00
virtual int errorTop() const;
2019-11-26 11:10:44 +00:00
private:
struct CoverAnimation {
CoverAnimation() = default;
CoverAnimation(CoverAnimation &&other) = default;
CoverAnimation &operator=(CoverAnimation &&other) = default;
~CoverAnimation();
std::unique_ptr<Ui::CrossFadeAnimation> title;
std::unique_ptr<Ui::CrossFadeAnimation> description;
// From content top till the next button top.
QPixmap contentSnapshotWas;
QPixmap contentSnapshotNow;
2019-11-29 13:42:42 +00:00
QRect clipping;
2019-11-26 11:10:44 +00:00
};
void updateLabelsPosition();
void paintContentSnapshot(
2022-09-16 20:23:27 +00:00
QPainter &p,
2019-11-26 11:10:44 +00:00
const QPixmap &snapshot,
float64 alpha,
float64 howMuchHidden);
void refreshError(const QString &text);
void goNext(Step *step);
void goReplace(Step *step, Animate animate);
2019-11-26 11:10:44 +00:00
[[nodiscard]] CoverAnimation prepareCoverAnimation(Step *step);
[[nodiscard]] QPixmap prepareContentSnapshot();
[[nodiscard]] QPixmap prepareSlideAnimation();
void showFinished();
void prepareCoverMask();
2022-09-16 20:23:27 +00:00
void paintCover(QPainter &p, int top);
2019-11-26 11:10:44 +00:00
const not_null<Main::Account*> _account;
const not_null<Data*> _data;
2020-06-11 13:07:14 +00:00
mutable std::optional<MTP::Sender> _api;
2019-11-26 11:10:44 +00:00
bool _hasCover = false;
Fn<void(Step *step, StackAction action, Animate animate)> _goCallback;
2019-11-26 11:10:44 +00:00
Fn<void()> _showResetCallback;
Fn<void()> _showTermsCallback;
Fn<void()> _cancelNearestDcCallback;
2019-11-26 11:10:44 +00:00
Fn<void(Fn<void()> callback)> _acceptTermsCallback;
rpl::variable<QString> _titleText;
object_ptr<Ui::FlatLabel> _title;
rpl::variable<TextWithEntities> _descriptionText;
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _description;
bool _errorCentered = false;
rpl::variable<QString> _errorText;
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _error = { nullptr };
Ui::Animations::Simple _a_show;
CoverAnimation _coverAnimation;
std::unique_ptr<Ui::SlideAnimation> _slideAnimation;
QPixmap _coverMask;
};
} // namespace details
} // namespace Intro