2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "intro/introwidget.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_file_parser.h"
|
2016-03-14 16:59:18 +00:00
|
|
|
#include "intro/introstart.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "intro/introphone.h"
|
|
|
|
#include "intro/introcode.h"
|
|
|
|
#include "intro/introsignup.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "intro/intropwdcheck.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2017-07-18 15:15:02 +00:00
|
|
|
#include "apiwrap.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "messenger.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "application.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2016-04-14 11:00:23 +00:00
|
|
|
#include "ui/text/text.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/effects/slide_animation.h"
|
2018-04-26 16:14:21 +00:00
|
|
|
#include "core/update_checker.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "window/window_slide_animation.h"
|
2018-05-07 17:44:33 +00:00
|
|
|
#include "window/window_connecting_widget.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "styles/style_intro.h"
|
|
|
|
#include "styles/style_window.h"
|
2017-02-18 11:29:19 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2017-05-30 09:31:40 +00:00
|
|
|
#include "lang/lang_cloud_manager.h"
|
2017-02-23 09:32:28 +00:00
|
|
|
#include "auth_session.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
namespace Intro {
|
2017-04-13 17:59:05 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr str_const kDefaultCountry = "US";
|
|
|
|
|
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-04-26 16:14:21 +00:00
|
|
|
Widget::Widget(QWidget *parent) : RpWidget(parent)
|
2017-09-30 18:26:45 +00:00
|
|
|
, _back(this, object_ptr<Ui::IconButton>(this, st::introBackButton))
|
|
|
|
, _settings(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::RoundButton>(
|
|
|
|
this,
|
|
|
|
langFactory(lng_menu_settings),
|
|
|
|
st::defaultBoxButton))
|
2017-05-30 15:21:05 +00:00
|
|
|
, _next(this, base::lambda<QString()>(), st::introNextButton) {
|
2017-04-13 17:59:05 +00:00
|
|
|
auto country = Platform::SystemCountry();
|
|
|
|
if (country.isEmpty()) {
|
|
|
|
country = str_const_toString(kDefaultCountry);
|
|
|
|
}
|
|
|
|
getData()->country = country;
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
_back->entity()->setClickedCallback([this] { historyMove(Direction::Back); });
|
2017-09-30 19:20:40 +00:00
|
|
|
_back->hide(anim::type::instant);
|
2014-11-26 16:45:52 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
_next->setClickedCallback([this] { getStep()->submit(); });
|
|
|
|
|
|
|
|
_settings->entity()->setClickedCallback([] { App::wnd()->showSettings(); });
|
2016-11-05 08:36:24 +00:00
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
getNearestDC();
|
2018-05-07 17:44:33 +00:00
|
|
|
setupConnectingWidget();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
appendStep(new StartWidget(this, getData()));
|
|
|
|
fixOrder();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
subscribe(Lang::CurrentCloudManager().firstLanguageSuggestion(), [this] { createLanguageLink(); });
|
|
|
|
createLanguageLink();
|
2017-09-30 19:20:40 +00:00
|
|
|
if (_changeLanguage) _changeLanguage->finishAnimating();
|
2017-05-30 13:54:05 +00:00
|
|
|
|
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
show();
|
2016-11-24 19:28:23 +00:00
|
|
|
showControls();
|
|
|
|
getStep()->showFast();
|
2014-11-26 16:45:52 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
cSetPasswordRecovered(false);
|
|
|
|
|
2016-04-14 19:24:42 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
2018-04-26 16:14:21 +00:00
|
|
|
Core::UpdateChecker checker;
|
|
|
|
checker.isLatest() | rpl::start_with_next([=] {
|
|
|
|
onCheckUpdateStatus();
|
|
|
|
}, lifetime());
|
|
|
|
checker.failed() | rpl::start_with_next([=] {
|
|
|
|
onCheckUpdateStatus();
|
|
|
|
}, lifetime());
|
|
|
|
checker.ready() | rpl::start_with_next([=] {
|
|
|
|
onCheckUpdateStatus();
|
|
|
|
}, lifetime());
|
|
|
|
checker.start();
|
2016-11-05 08:36:24 +00:00
|
|
|
onCheckUpdateStatus();
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 17:44:33 +00:00
|
|
|
void Widget::setupConnectingWidget() {
|
|
|
|
_connecting = Window::ConnectingWidget::CreateDefaultWidget(
|
|
|
|
this,
|
|
|
|
rpl::single(true));
|
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void Widget::refreshLang() {
|
2017-05-30 16:58:13 +00:00
|
|
|
_changeLanguage.destroy();
|
|
|
|
createLanguageLink();
|
2017-05-30 15:21:05 +00:00
|
|
|
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
2017-05-30 13:54:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
void Widget::createLanguageLink() {
|
|
|
|
if (_changeLanguage) return;
|
|
|
|
|
|
|
|
auto createLink = [this](const QString &text, const QString &languageId) {
|
2017-09-30 18:26:45 +00:00
|
|
|
_changeLanguage.create(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::LinkButton>(this, text));
|
2017-09-30 19:20:40 +00:00
|
|
|
_changeLanguage->hide(anim::type::instant);
|
2018-04-07 08:47:08 +00:00
|
|
|
_changeLanguage->entity()->setClickedCallback([=] {
|
2017-05-30 09:31:40 +00:00
|
|
|
Lang::CurrentCloudManager().switchToLanguage(languageId);
|
|
|
|
});
|
2017-09-30 19:20:40 +00:00
|
|
|
_changeLanguage->toggle(!_resetAccount, anim::type::normal);
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
2017-05-30 09:31:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto currentId = Lang::Current().id();
|
|
|
|
auto defaultId = Lang::DefaultLanguageId();
|
|
|
|
auto suggestedId = Lang::CurrentCloudManager().suggestedLanguage();
|
2017-05-30 16:58:13 +00:00
|
|
|
if (!currentId.isEmpty() && currentId != defaultId) {
|
|
|
|
createLink(Lang::GetOriginalValue(lng_switch_to_this), defaultId);
|
|
|
|
} else if (!suggestedId.isEmpty() && suggestedId != currentId) {
|
2018-04-07 08:47:08 +00:00
|
|
|
request(MTPlangpack_GetStrings(
|
|
|
|
MTP_string(suggestedId),
|
|
|
|
MTP_vector<MTPstring>(1, MTP_string("lng_switch_to_this"))
|
|
|
|
)).done([=](const MTPVector<MTPLangPackString> &result) {
|
2017-05-30 09:31:40 +00:00
|
|
|
auto strings = Lang::Instance::ParseStrings(result);
|
|
|
|
auto it = strings.find(lng_switch_to_this);
|
|
|
|
if (it != strings.end()) {
|
|
|
|
createLink(it->second, suggestedId);
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::onCheckUpdateStatus() {
|
2018-04-26 16:14:21 +00:00
|
|
|
if (Core::UpdateChecker().state() == Core::UpdateChecker::State::Ready) {
|
2016-11-05 08:36:24 +00:00
|
|
|
if (_update) return;
|
2017-09-30 18:26:45 +00:00
|
|
|
_update.create(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::RoundButton>(
|
|
|
|
this,
|
|
|
|
langFactory(lng_menu_update),
|
|
|
|
st::defaultBoxButton));
|
2017-09-30 19:20:40 +00:00
|
|
|
if (!_a_show.animating()) {
|
|
|
|
_update->setVisible(true);
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
_update->entity()->setClickedCallback([] {
|
2018-04-26 16:14:21 +00:00
|
|
|
Core::checkReadyUpdate();
|
2016-11-05 08:36:24 +00:00
|
|
|
App::restart();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (!_update) return;
|
|
|
|
_update.destroy();
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
#endif // TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::setInnerFocus() {
|
|
|
|
if (getStep()->animating()) {
|
|
|
|
setFocus();
|
|
|
|
} else {
|
|
|
|
getStep()->setInnerFocus();
|
|
|
|
}
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::historyMove(Direction direction) {
|
|
|
|
if (getStep()->animating()) return;
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_stepHistory.size() > 1);
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
auto wasStep = getStep((direction == Direction::Back) ? 0 : 1);
|
|
|
|
if (direction == Direction::Back) {
|
2016-03-14 16:59:18 +00:00
|
|
|
_stepHistory.pop_back();
|
2016-11-24 19:28:23 +00:00
|
|
|
wasStep->cancelled();
|
|
|
|
} else if (direction == Direction::Replace) {
|
2016-03-14 16:59:18 +00:00
|
|
|
_stepHistory.removeAt(_stepHistory.size() - 2);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
getStep()->prepareShowAnimated(wasStep);
|
|
|
|
if (wasStep->hasCover() != getStep()->hasCover()) {
|
|
|
|
_nextTopFrom = wasStep->contentTop() + st::introStepHeight;
|
|
|
|
_controlsTopFrom = wasStep->hasCover() ? st::introCoverHeight : 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
_coverShownAnimation.start([this] { updateControlsGeometry(); }, 0., 1., st::introCoverDuration, wasStep->hasCover() ? anim::linear : anim::easeOutCirc);
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
if (direction == Direction::Forward || direction == Direction::Replace) {
|
|
|
|
wasStep->finished();
|
|
|
|
}
|
|
|
|
if (direction == Direction::Back || direction == Direction::Replace) {
|
|
|
|
delete base::take(wasStep);
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
_back->toggle(getStep()->hasBack(), anim::type::normal);
|
2017-04-14 12:12:40 +00:00
|
|
|
|
|
|
|
auto stepHasCover = getStep()->hasCover();
|
2017-09-30 19:20:40 +00:00
|
|
|
_settings->toggle(!stepHasCover, anim::type::normal);
|
|
|
|
if (_update) _update->toggle(!stepHasCover, anim::type::normal);
|
|
|
|
if (_changeLanguage) _changeLanguage->toggle(!_resetAccount, anim::type::normal);
|
2017-05-30 15:21:05 +00:00
|
|
|
_next->setText([this] { return getStep()->nextButtonText(); });
|
2017-09-30 19:20:40 +00:00
|
|
|
if (_resetAccount) _resetAccount->hide(anim::type::normal);
|
2016-11-24 19:28:23 +00:00
|
|
|
getStep()->showAnimated(direction);
|
|
|
|
fixOrder();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::fixOrder() {
|
|
|
|
_next->raise();
|
|
|
|
if (_update) _update->raise();
|
|
|
|
_settings->raise();
|
|
|
|
_back->raise();
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->raise();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::moveToStep(Step *step, Direction direction) {
|
|
|
|
appendStep(step);
|
2016-10-26 10:06:00 +00:00
|
|
|
_back->raise();
|
2016-11-05 08:36:24 +00:00
|
|
|
_settings->raise();
|
|
|
|
if (_update) {
|
|
|
|
_update->raise();
|
|
|
|
}
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->raise();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
historyMove(direction);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::appendStep(Step *step) {
|
|
|
|
_stepHistory.push_back(step);
|
|
|
|
step->setGeometry(calculateStepRect());
|
|
|
|
step->setGoCallback([this](Step *step, Direction direction) {
|
|
|
|
if (direction == Direction::Back) {
|
|
|
|
historyMove(direction);
|
|
|
|
} else {
|
|
|
|
moveToStep(step, direction);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
step->setShowResetCallback([this] {
|
|
|
|
showResetButton();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showResetButton() {
|
|
|
|
if (!_resetAccount) {
|
2017-05-30 15:21:05 +00:00
|
|
|
auto entity = object_ptr<Ui::RoundButton>(this, langFactory(lng_signin_reset_account), st::introResetButton);
|
2017-09-30 18:26:45 +00:00
|
|
|
_resetAccount.create(
|
|
|
|
this,
|
|
|
|
std::move(entity));
|
2017-09-30 19:20:40 +00:00
|
|
|
_resetAccount->hide(anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
_resetAccount->entity()->setClickedCallback([this] { resetAccount(); });
|
|
|
|
updateControlsGeometry();
|
2016-04-14 19:24:42 +00:00
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
_resetAccount->show(anim::type::normal);
|
|
|
|
if (_changeLanguage) _changeLanguage->hide(anim::type::normal);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::resetAccount() {
|
|
|
|
if (_resetRequest) return;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(lang(lng_signin_sure_reset), lang(lng_signin_reset), st::attentionBoxButton, base::lambda_guarded(this, [this] {
|
|
|
|
if (_resetRequest) return;
|
2017-05-30 09:31:40 +00:00
|
|
|
_resetRequest = request(MTPaccount_DeleteAccount(MTP_string("Forgot password"))).done([this](const MTPBool &result) {
|
|
|
|
_resetRequest = 0;
|
|
|
|
|
|
|
|
Ui::hideLayer();
|
|
|
|
moveToStep(new SignupWidget(this, getData()), Direction::Replace);
|
|
|
|
}).fail([this](const RPCError &error) {
|
|
|
|
_resetRequest = 0;
|
|
|
|
|
|
|
|
auto type = error.type();
|
|
|
|
if (type.startsWith(qstr("2FA_CONFIRM_WAIT_"))) {
|
2017-06-02 11:46:02 +00:00
|
|
|
auto seconds = type.mid(qstr("2FA_CONFIRM_WAIT_").size()).toInt();
|
|
|
|
auto days = (seconds + 59) / 86400;
|
|
|
|
auto hours = ((seconds + 59) % 86400) / 3600;
|
|
|
|
auto minutes = ((seconds + 59) % 3600) / 60;
|
|
|
|
auto when = lng_signin_reset_minutes(lt_count, minutes);
|
2017-05-30 09:31:40 +00:00
|
|
|
if (days > 0) {
|
2017-06-02 11:46:02 +00:00
|
|
|
auto daysCount = lng_signin_reset_days(lt_count, days);
|
|
|
|
auto hoursCount = lng_signin_reset_hours(lt_count, hours);
|
|
|
|
when = lng_signin_reset_in_days(lt_days_count, daysCount, lt_hours_count, hoursCount, lt_minutes_count, when);
|
2017-05-30 09:31:40 +00:00
|
|
|
} else if (hours > 0) {
|
2017-06-02 11:46:02 +00:00
|
|
|
auto hoursCount = lng_signin_reset_hours(lt_count, hours);
|
|
|
|
when = lng_signin_reset_in_hours(lt_hours_count, hoursCount, lt_minutes_count, when);
|
2017-05-30 09:31:40 +00:00
|
|
|
}
|
|
|
|
Ui::show(Box<InformBox>(lng_signin_reset_wait(lt_phone_number, App::formatPhone(getData()->phone), lt_when, when)));
|
|
|
|
} else if (type == qstr("2FA_RECENT_CONFIRM")) {
|
|
|
|
Ui::show(Box<InformBox>(lang(lng_signin_reset_cancelled)));
|
|
|
|
} else {
|
|
|
|
Ui::hideLayer();
|
2017-09-28 20:11:10 +00:00
|
|
|
getStep()->showError(&Lang::Hard::ServerError);
|
2017-05-30 09:31:40 +00:00
|
|
|
}
|
|
|
|
}).send();
|
2016-12-13 17:07:56 +00:00
|
|
|
})));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
void Widget::getNearestDC() {
|
|
|
|
request(MTPhelp_GetNearestDc()).done([this](const MTPNearestDc &result) {
|
|
|
|
auto &nearest = result.c_nearestDc();
|
|
|
|
DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3").arg(qs(nearest.vcountry)).arg(nearest.vnearest_dc.v).arg(nearest.vthis_dc.v));
|
|
|
|
Messenger::Instance().suggestMainDcId(nearest.vnearest_dc.v);
|
|
|
|
auto nearestCountry = qs(nearest.vcountry);
|
|
|
|
if (getData()->country != nearestCountry) {
|
|
|
|
getData()->country = nearestCountry;
|
|
|
|
getData()->updated.notify();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2017-05-30 09:31:40 +00:00
|
|
|
}).send();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showControls() {
|
|
|
|
getStep()->show();
|
|
|
|
_next->show();
|
2017-05-30 15:21:05 +00:00
|
|
|
_next->setText([this] { return getStep()->nextButtonText(); });
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->setForceHidden(false);
|
2017-03-15 15:10:18 +00:00
|
|
|
auto hasCover = getStep()->hasCover();
|
2017-09-30 19:20:40 +00:00
|
|
|
_settings->toggle(!hasCover, anim::type::instant);
|
|
|
|
if (_update) _update->toggle(!hasCover, anim::type::instant);
|
|
|
|
if (_changeLanguage) _changeLanguage->toggle(!_resetAccount, anim::type::instant);
|
|
|
|
_back->toggle(getStep()->hasBack(), anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::hideControls() {
|
|
|
|
getStep()->hide();
|
|
|
|
_next->hide();
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->setForceHidden(true);
|
2017-09-30 19:20:40 +00:00
|
|
|
_settings->hide(anim::type::instant);
|
|
|
|
if (_update) _update->hide(anim::type::instant);
|
|
|
|
if (_changeLanguage) _changeLanguage->hide(anim::type::instant);
|
|
|
|
_back->hide(anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void Widget::showAnimated(const QPixmap &bgAnimCache, bool back) {
|
|
|
|
_showBack = back;
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
(_showBack ? _cacheOver : _cacheUnder) = bgAnimCache;
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
_a_show.finish();
|
2016-11-24 19:28:23 +00:00
|
|
|
showControls();
|
2017-12-26 12:41:48 +00:00
|
|
|
(_showBack ? _cacheUnder : _cacheOver) = Ui::GrabWidget(this);
|
2016-11-24 19:28:23 +00:00
|
|
|
hideControls();
|
2015-10-17 14:52:26 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
_a_show.start([this] { animationCallback(); }, 0., 1., st::slideDuration, Window::SlideAnimation::transition());
|
2015-10-17 14:52:26 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void Widget::animationCallback() {
|
|
|
|
update();
|
|
|
|
if (!_a_show.animating()) {
|
2015-10-17 14:52:26 +00:00
|
|
|
_cacheUnder = _cacheOver = QPixmap();
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
showControls();
|
|
|
|
getStep()->activate();
|
2015-10-17 14:52:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::paintEvent(QPaintEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
bool trivial = (rect() == e->rect());
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_coverShownAnimation.animating()) {
|
|
|
|
_coverShownAnimation.step(getms());
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
QPainter p(this);
|
|
|
|
if (!trivial) {
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
}
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(e->rect(), st::windowBg);
|
2016-12-05 11:01:08 +00:00
|
|
|
auto progress = _a_show.current(getms(), 1.);
|
2015-10-17 14:52:26 +00:00
|
|
|
if (_a_show.animating()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto coordUnder = _showBack ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress);
|
|
|
|
auto coordOver = _showBack ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress);
|
|
|
|
auto shadow = _showBack ? (1. - progress) : progress;
|
|
|
|
if (coordOver > 0) {
|
|
|
|
p.drawPixmap(QRect(0, 0, coordOver, height()), _cacheUnder, QRect(-coordUnder * cRetinaFactor(), 0, coordOver * cRetinaFactor(), height() * cRetinaFactor()));
|
|
|
|
p.setOpacity(shadow);
|
|
|
|
p.fillRect(0, 0, coordOver, height(), st::slideFadeOutBg);
|
2015-10-17 14:52:26 +00:00
|
|
|
p.setOpacity(1);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
p.drawPixmap(coordOver, 0, _cacheOver);
|
|
|
|
p.setOpacity(shadow);
|
|
|
|
st::slideShadow.fill(p, QRect(coordOver - st::slideShadow.width(), 0, st::slideShadow.width(), height()));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
QRect Widget::calculateStepRect() const {
|
|
|
|
auto stepInnerTop = (height() - st::introHeight) / 2;
|
|
|
|
accumulate_max(stepInnerTop, st::introStepTopMin);
|
|
|
|
auto nextTop = stepInnerTop + st::introStepHeight;
|
|
|
|
auto additionalHeight = st::introStepHeightAdd;
|
|
|
|
auto stepWidth = width();
|
|
|
|
auto stepHeight = nextTop + additionalHeight;
|
|
|
|
return QRect(0, 0, stepWidth, stepHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::resizeEvent(QResizeEvent *e) {
|
|
|
|
auto stepRect = calculateStepRect();
|
|
|
|
for_const (auto step, _stepHistory) {
|
|
|
|
step->setGeometry(stepRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateControlsGeometry();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::updateControlsGeometry() {
|
|
|
|
auto shown = _coverShownAnimation.current(1.);
|
|
|
|
|
|
|
|
auto controlsTopTo = getStep()->hasCover() ? st::introCoverHeight : 0;
|
|
|
|
auto controlsTop = anim::interpolate(_controlsTopFrom, controlsTopTo, shown);
|
|
|
|
_settings->moveToRight(st::introSettingsSkip, controlsTop + st::introSettingsSkip);
|
|
|
|
if (_update) {
|
|
|
|
_update->moveToRight(st::introSettingsSkip + _settings->width() + st::introSettingsSkip, _settings->y());
|
|
|
|
}
|
|
|
|
_back->moveToLeft(0, controlsTop);
|
|
|
|
|
|
|
|
auto nextTopTo = getStep()->contentTop() + st::introStepHeight;
|
|
|
|
auto nextTop = anim::interpolate(_nextTopFrom, nextTopTo, shown);
|
|
|
|
_next->moveToLeft((width() - _next->width()) / 2, nextTop);
|
|
|
|
if (_changeLanguage) {
|
|
|
|
_changeLanguage->moveToLeft((width() - _changeLanguage->width()) / 2, _next->y() + _next->height() + _changeLanguage->height());
|
|
|
|
}
|
|
|
|
if (_resetAccount) {
|
|
|
|
_resetAccount->moveToLeft((width() - _resetAccount->width()) / 2, height() - st::introResetBottom - _resetAccount->height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Widget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (_a_show.animating() || getStep()->animating()) return;
|
|
|
|
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
if (getStep()->hasBack()) {
|
|
|
|
historyMove(Direction::Back);
|
|
|
|
}
|
|
|
|
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
|
|
|
|
getStep()->submit();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
Widget::~Widget() {
|
|
|
|
for (auto step : base::take(_stepHistory)) {
|
|
|
|
delete step;
|
|
|
|
}
|
|
|
|
if (App::wnd()) App::wnd()->noIntro(this);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
QString Widget::Step::nextButtonText() const {
|
|
|
|
return lang(lng_intro_next);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void Widget::Step::finish(const MTPUser &user, QImage &&photo) {
|
2017-03-04 19:36:59 +00:00
|
|
|
if (user.type() != mtpc_user || !user.c_user().is_self()) {
|
|
|
|
// No idea what to do here.
|
|
|
|
// We could've reset intro and MTP, but this really should not happen.
|
|
|
|
Ui::show(Box<InformBox>("Internal error: bad user.is_self() after sign in."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-01 15:18:00 +00:00
|
|
|
// Save the default language if we've suggested some other and user ignored it.
|
|
|
|
auto currentId = Lang::Current().id();
|
|
|
|
auto defaultId = Lang::DefaultLanguageId();
|
|
|
|
auto suggestedId = Lang::CurrentCloudManager().suggestedLanguage();
|
|
|
|
if (currentId.isEmpty() && !suggestedId.isEmpty() && suggestedId != defaultId) {
|
|
|
|
Lang::Current().switchToId(defaultId);
|
|
|
|
Local::writeLangPack();
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
Messenger::Instance().authSessionCreate(user.c_user().vid.v);
|
2017-04-03 18:59:13 +00:00
|
|
|
Local::writeMtpData();
|
2016-11-24 19:28:23 +00:00
|
|
|
App::wnd()->setupMain(&user);
|
|
|
|
|
|
|
|
// "this" is already deleted here by creating the main widget.
|
2017-07-18 15:15:02 +00:00
|
|
|
if (auto user = App::self()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestFullPeer(user);
|
2017-07-18 15:15:02 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
if (!photo.isNull()) {
|
2017-11-13 12:02:53 +00:00
|
|
|
Messenger::Instance().uploadProfilePhoto(
|
|
|
|
std::move(photo),
|
|
|
|
Auth().userId());
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
paintAnimated(p, e->rect());
|
2015-08-31 14:27:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::resizeEvent(QResizeEvent *e) {
|
|
|
|
updateLabelsPosition();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::updateLabelsPosition() {
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(_description->entity());
|
2016-11-24 19:28:23 +00:00
|
|
|
if (hasCover()) {
|
|
|
|
_title->moveToLeft((width() - _title->width()) / 2, contentTop() + st::introCoverTitleTop);
|
|
|
|
_description->moveToLeft((width() - _description->width()) / 2, contentTop() + st::introCoverDescriptionTop);
|
|
|
|
} else {
|
|
|
|
_title->moveToLeft(contentLeft() + st::buttonRadius, contentTop() + st::introTitleTop);
|
|
|
|
_description->moveToLeft(contentLeft() + st::buttonRadius, contentTop() + st::introDescriptionTop);
|
|
|
|
}
|
|
|
|
if (_error) {
|
|
|
|
if (_errorCentered) {
|
|
|
|
_error->entity()->resizeToWidth(width());
|
|
|
|
}
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(_error->entity());
|
2016-11-24 19:28:23 +00:00
|
|
|
auto errorLeft = _errorCentered ? 0 : (contentLeft() + st::buttonRadius);
|
|
|
|
auto errorTop = contentTop() + (_errorBelowLink ? st::introErrorBelowLinkTop : st::introErrorTop);
|
|
|
|
_error->moveToLeft(errorLeft, errorTop);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void Widget::Step::setTitleText(base::lambda<QString()> richTitleTextFactory) {
|
|
|
|
_titleTextFactory = std::move(richTitleTextFactory);
|
|
|
|
refreshTitle();
|
2016-11-24 19:28:23 +00:00
|
|
|
updateLabelsPosition();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void Widget::Step::refreshTitle() {
|
|
|
|
_title->setRichText(_titleTextFactory());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::setDescriptionText(base::lambda<QString()> richDescriptionTextFactory) {
|
|
|
|
_descriptionTextFactory = std::move(richDescriptionTextFactory);
|
|
|
|
refreshDescription();
|
|
|
|
updateLabelsPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::refreshDescription() {
|
|
|
|
_description->entity()->setRichText(_descriptionTextFactory());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::refreshLang() {
|
|
|
|
refreshTitle();
|
|
|
|
refreshDescription();
|
|
|
|
refreshError();
|
2016-11-24 19:28:23 +00:00
|
|
|
updateLabelsPosition();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::showFinished() {
|
|
|
|
_a_show.finish();
|
|
|
|
_coverAnimation = CoverAnimation();
|
|
|
|
_slideAnimation.reset();
|
|
|
|
prepareCoverMask();
|
|
|
|
activate();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
bool Widget::Step::paintAnimated(Painter &p, QRect clip) {
|
|
|
|
if (_slideAnimation) {
|
|
|
|
_slideAnimation->paintFrame(p, (width() - st::introStepWidth) / 2, contentTop(), width(), getms());
|
|
|
|
if (!_slideAnimation->animating()) {
|
|
|
|
showFinished();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dt = _a_show.current(getms(), 1.);
|
|
|
|
if (!_a_show.animating()) {
|
2017-08-13 16:16:48 +00:00
|
|
|
if (hasCover()) {
|
|
|
|
paintCover(p, 0);
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_coverAnimation.title) {
|
|
|
|
showFinished();
|
|
|
|
}
|
|
|
|
if (!QRect(0, contentTop(), width(), st::introStepHeight).intersects(clip)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto progress = (hasCover() ? anim::easeOutCirc(1., dt) : anim::linear(1., dt));
|
|
|
|
auto arrivingAlpha = progress;
|
|
|
|
auto departingAlpha = 1. - progress;
|
|
|
|
auto showCoverMethod = progress;
|
|
|
|
auto hideCoverMethod = progress;
|
2016-11-24 19:28:23 +00:00
|
|
|
auto coverTop = (hasCover() ? anim::interpolate(-st::introCoverHeight, 0, showCoverMethod) : anim::interpolate(0, -st::introCoverHeight, hideCoverMethod));
|
|
|
|
|
|
|
|
paintCover(p, coverTop);
|
|
|
|
|
|
|
|
auto positionReady = hasCover() ? showCoverMethod : hideCoverMethod;
|
|
|
|
_coverAnimation.title->paintFrame(p, positionReady, departingAlpha, arrivingAlpha);
|
|
|
|
_coverAnimation.description->paintFrame(p, positionReady, departingAlpha, arrivingAlpha);
|
|
|
|
|
|
|
|
paintContentSnapshot(p, _coverAnimation.contentSnapshotWas, departingAlpha, showCoverMethod);
|
|
|
|
paintContentSnapshot(p, _coverAnimation.contentSnapshotNow, arrivingAlpha, 1. - hideCoverMethod);
|
|
|
|
|
|
|
|
return true;
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::fillSentCodeData(const MTPauth_SentCodeType &type) {
|
|
|
|
switch (type.type()) {
|
|
|
|
case mtpc_auth_sentCodeTypeApp: {
|
|
|
|
getData()->codeByTelegram = true;
|
|
|
|
getData()->codeLength = type.c_auth_sentCodeTypeApp().vlength.v;
|
|
|
|
} break;
|
|
|
|
case mtpc_auth_sentCodeTypeSms: {
|
|
|
|
getData()->codeByTelegram = false;
|
|
|
|
getData()->codeLength = type.c_auth_sentCodeTypeSms().vlength.v;
|
|
|
|
} break;
|
|
|
|
case mtpc_auth_sentCodeTypeCall: {
|
|
|
|
getData()->codeByTelegram = false;
|
|
|
|
getData()->codeLength = type.c_auth_sentCodeTypeCall().vlength.v;
|
|
|
|
} break;
|
|
|
|
case mtpc_auth_sentCodeTypeFlashCall: LOG(("Error: should not be flashcall!")); break;
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::showDescription() {
|
2017-09-30 19:20:40 +00:00
|
|
|
_description->show(anim::type::normal);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::hideDescription() {
|
2017-09-30 19:20:40 +00:00
|
|
|
_description->hide(anim::type::normal);
|
2015-08-31 14:27:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::paintContentSnapshot(Painter &p, const QPixmap &snapshot, float64 alpha, float64 howMuchHidden) {
|
|
|
|
if (!snapshot.isNull()) {
|
|
|
|
auto contentTop = anim::interpolate(height() - (snapshot.height() / cIntRetinaFactor()), height(), howMuchHidden);
|
|
|
|
if (contentTop < height()) {
|
|
|
|
p.setOpacity(alpha);
|
|
|
|
p.drawPixmap(QPoint(contentLeft(), contentTop), snapshot, QRect(0, 0, snapshot.width(), (height() - contentTop) * cIntRetinaFactor()));
|
|
|
|
}
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::prepareCoverMask() {
|
|
|
|
if (!_coverMask.isNull()) return;
|
|
|
|
|
|
|
|
auto maskWidth = cIntRetinaFactor();
|
|
|
|
auto maskHeight = st::introCoverHeight * cIntRetinaFactor();
|
|
|
|
auto mask = QImage(maskWidth, maskHeight, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
auto maskInts = reinterpret_cast<uint32*>(mask.bits());
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(mask.depth() == (sizeof(uint32) << 3));
|
2016-11-24 19:28:23 +00:00
|
|
|
auto maskIntsPerLineAdded = (mask.bytesPerLine() >> 2) - maskWidth;
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(maskIntsPerLineAdded >= 0);
|
2016-11-24 19:28:23 +00:00
|
|
|
auto realHeight = static_cast<float64>(maskHeight - 1);
|
|
|
|
for (auto y = 0; y != maskHeight; ++y) {
|
|
|
|
auto color = anim::color(st::introCoverTopBg, st::introCoverBottomBg, y / realHeight);
|
|
|
|
auto colorInt = anim::getPremultiplied(color);
|
|
|
|
for (auto x = 0; x != maskWidth; ++x) {
|
|
|
|
*maskInts++ = colorInt;
|
|
|
|
}
|
|
|
|
maskInts += maskIntsPerLineAdded;
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
2017-02-21 13:45:56 +00:00
|
|
|
_coverMask = App::pixmapFromImageInPlace(std::move(mask));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::Step::paintCover(Painter &p, int top) {
|
|
|
|
auto coverHeight = top + st::introCoverHeight;
|
|
|
|
if (coverHeight > 0) {
|
|
|
|
p.drawPixmap(QRect(0, 0, width(), coverHeight), _coverMask, QRect(0, -top * cIntRetinaFactor(), _coverMask.width(), coverHeight * cIntRetinaFactor()));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto left = 0;
|
|
|
|
auto right = 0;
|
|
|
|
if (width() < st::introCoverMaxWidth) {
|
|
|
|
auto iconsMaxSkip = st::introCoverMaxWidth - st::introCoverLeft.width() - st::introCoverRight.width();
|
|
|
|
auto iconsSkip = st::introCoverIconsMinSkip + (iconsMaxSkip - st::introCoverIconsMinSkip) * (width() - st::introStepWidth) / (st::introCoverMaxWidth - st::introStepWidth);
|
|
|
|
auto outside = iconsSkip + st::introCoverLeft.width() + st::introCoverRight.width() - width();
|
|
|
|
left = -outside / 2;
|
|
|
|
right = -outside - left;
|
|
|
|
}
|
|
|
|
if (top < 0) {
|
|
|
|
auto shown = float64(coverHeight) / st::introCoverHeight;
|
|
|
|
auto leftShown = qRound(shown * (left + st::introCoverLeft.width()));
|
|
|
|
left = leftShown - st::introCoverLeft.width();
|
|
|
|
auto rightShown = qRound(shown * (right + st::introCoverRight.width()));
|
|
|
|
right = rightShown - st::introCoverRight.width();
|
|
|
|
}
|
|
|
|
st::introCoverLeft.paint(p, left, coverHeight - st::introCoverLeft.height(), width());
|
|
|
|
st::introCoverRight.paint(p, width() - right - st::introCoverRight.width(), coverHeight - st::introCoverRight.height(), width());
|
|
|
|
|
|
|
|
auto planeLeft = (width() - st::introCoverIcon.width()) / 2 - st::introCoverIconLeft;
|
|
|
|
auto planeTop = top + st::introCoverIconTop;
|
|
|
|
if (top < 0 && !_hasCover) {
|
|
|
|
auto deltaLeft = -qRound(float64(st::introPlaneWidth / st::introPlaneHeight) * top);
|
|
|
|
// auto deltaTop = top;
|
|
|
|
planeLeft += deltaLeft;
|
|
|
|
// planeTop += top;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
st::introCoverIcon.paint(p, planeLeft, planeTop, width());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
int Widget::Step::contentLeft() const {
|
|
|
|
return (width() - st::introNextButton.width) / 2;
|
|
|
|
}
|
2015-10-17 14:52:26 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
int Widget::Step::contentTop() const {
|
|
|
|
auto result = height() - st::introStepHeight - st::introStepHeightAdd;
|
|
|
|
if (_hasCover) {
|
|
|
|
auto added = 1. - snap(float64(height() - st::windowMinHeight) / (st::introStepHeightFull - st::windowMinHeight), 0., 1.);
|
|
|
|
result += qRound(added * st::introStepHeightAdd);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::setErrorCentered(bool centered) {
|
|
|
|
_errorCentered = centered;
|
|
|
|
_error.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::setErrorBelowLink(bool below) {
|
|
|
|
_errorBelowLink = below;
|
|
|
|
if (_error) {
|
|
|
|
updateLabelsPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void Widget::Step::showError(base::lambda<QString()> textFactory) {
|
|
|
|
_errorTextFactory = std::move(textFactory);
|
|
|
|
refreshError();
|
|
|
|
updateLabelsPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::refreshError() {
|
|
|
|
if (!_errorTextFactory) {
|
2017-09-30 19:20:40 +00:00
|
|
|
if (_error) _error->hide(anim::type::normal);
|
2016-11-24 19:28:23 +00:00
|
|
|
} else {
|
|
|
|
if (!_error) {
|
2017-09-30 18:26:45 +00:00
|
|
|
_error.create(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
this,
|
|
|
|
_errorCentered
|
|
|
|
? st::introErrorCentered
|
|
|
|
: st::introError));
|
2017-09-30 19:20:40 +00:00
|
|
|
_error->hide(anim::type::instant);
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2017-05-30 13:54:05 +00:00
|
|
|
_error->entity()->setText(_errorTextFactory());
|
2016-11-24 19:28:23 +00:00
|
|
|
updateLabelsPosition();
|
2017-09-30 19:20:40 +00:00
|
|
|
_error->show(anim::type::normal);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
Widget::Step::Step(QWidget *parent, Data *data, bool hasCover) : TWidget(parent)
|
|
|
|
, _data(data)
|
|
|
|
, _hasCover(hasCover)
|
2016-12-23 13:21:01 +00:00
|
|
|
, _title(this, _hasCover ? st::introCoverTitle : st::introTitle)
|
2017-09-30 18:26:45 +00:00
|
|
|
, _description(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
this,
|
|
|
|
_hasCover
|
|
|
|
? st::introCoverDescription
|
|
|
|
: st::introDescription)) {
|
2016-11-24 19:28:23 +00:00
|
|
|
hide();
|
2017-09-30 18:26:45 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](
|
|
|
|
const Window::Theme::BackgroundUpdate &update) {
|
2017-02-18 11:29:19 +00:00
|
|
|
if (update.paletteChanged()) {
|
|
|
|
if (!_coverMask.isNull()) {
|
|
|
|
_coverMask = QPixmap();
|
|
|
|
prepareCoverMask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-05-30 13:54:05 +00:00
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::prepareShowAnimated(Step *after) {
|
2016-12-23 13:21:01 +00:00
|
|
|
setInnerFocus();
|
2016-11-24 19:28:23 +00:00
|
|
|
if (hasCover() || after->hasCover()) {
|
|
|
|
_coverAnimation = prepareCoverAnimation(after);
|
|
|
|
prepareCoverMask();
|
|
|
|
} else {
|
|
|
|
auto leftSnapshot = after->prepareSlideAnimation();
|
|
|
|
auto rightSnapshot = prepareSlideAnimation();
|
2017-02-21 13:45:56 +00:00
|
|
|
_slideAnimation = std::make_unique<Ui::SlideAnimation>();
|
|
|
|
_slideAnimation->setSnapshots(std::move(leftSnapshot), std::move(rightSnapshot));
|
2016-11-24 19:28:23 +00:00
|
|
|
_slideAnimation->setOverflowHidden(false);
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2014-08-01 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
Widget::Step::CoverAnimation Widget::Step::prepareCoverAnimation(Step *after) {
|
|
|
|
auto result = CoverAnimation();
|
2017-12-26 12:41:48 +00:00
|
|
|
result.title = Ui::FlatLabel::CrossFade(
|
|
|
|
after->_title,
|
|
|
|
_title,
|
|
|
|
st::introBg);
|
|
|
|
result.description = Ui::FlatLabel::CrossFade(
|
|
|
|
after->_description->entity(),
|
|
|
|
_description->entity(),
|
|
|
|
st::introBg,
|
|
|
|
after->_description->pos(),
|
|
|
|
_description->pos());
|
2016-11-24 19:28:23 +00:00
|
|
|
result.contentSnapshotWas = after->prepareContentSnapshot();
|
|
|
|
result.contentSnapshotNow = prepareContentSnapshot();
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap Widget::Step::prepareContentSnapshot() {
|
|
|
|
auto otherTop = _description->y() + _description->height();
|
|
|
|
auto otherRect = myrtlrect(contentLeft(), otherTop, st::introStepWidth, height() - otherTop);
|
2017-12-26 12:41:48 +00:00
|
|
|
return Ui::GrabWidget(this, otherRect);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap Widget::Step::prepareSlideAnimation() {
|
|
|
|
auto grabLeft = (width() - st::introStepWidth) / 2;
|
|
|
|
auto grabTop = contentTop();
|
2017-12-26 12:41:48 +00:00
|
|
|
return Ui::GrabWidget(
|
|
|
|
this,
|
|
|
|
QRect(grabLeft, grabTop, st::introStepWidth, st::introStepHeight));
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::showAnimated(Direction direction) {
|
2018-03-11 19:17:58 +00:00
|
|
|
setFocus();
|
2016-11-24 19:28:23 +00:00
|
|
|
show();
|
|
|
|
hideChildren();
|
|
|
|
if (_slideAnimation) {
|
|
|
|
auto slideLeft = (direction == Direction::Back);
|
|
|
|
_slideAnimation->start(slideLeft, [this] { update(0, contentTop(), width(), st::introStepHeight); }, st::introSlideDuration);
|
|
|
|
} else {
|
|
|
|
_a_show.start([this] { update(); }, 0., 1., st::introCoverDuration);
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
void Widget::Step::setGoCallback(base::lambda<void(Step *step, Direction direction)> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_goCallback = std::move(callback);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
void Widget::Step::setShowResetCallback(base::lambda<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_showResetCallback = std::move(callback);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::showFast() {
|
|
|
|
show();
|
|
|
|
showFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::Step::animating() const {
|
|
|
|
return (_slideAnimation && _slideAnimation->animating()) || _a_show.animating();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::Step::hasCover() const {
|
|
|
|
return _hasCover;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::Step::hasBack() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::activate() {
|
|
|
|
_title->show();
|
2017-09-30 19:20:40 +00:00
|
|
|
_description->show(anim::type::instant);
|
2017-05-30 13:54:05 +00:00
|
|
|
if (_errorTextFactory) {
|
2017-09-30 19:20:40 +00:00
|
|
|
_error->show(anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::cancelled() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::Step::finished() {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2016-11-28 13:42:37 +00:00
|
|
|
Widget::Step::CoverAnimation::~CoverAnimation() = default;
|
|
|
|
|
|
|
|
Widget::Step::~Step() = default;
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
} // namespace Intro
|