2018-03-31 01:45:40 +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
|
|
|
|
*/
|
|
|
|
#include "passport/passport_panel_form.h"
|
|
|
|
|
|
|
|
#include "passport/passport_panel_controller.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "boxes/abstract_box.h"
|
2018-04-03 18:24:31 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2018-03-31 01:45:40 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "ui/wrap/fade_wrap.h"
|
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2019-06-12 20:11:41 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2018-03-31 01:45:40 +00:00
|
|
|
#include "ui/text_options.h"
|
|
|
|
#include "ui/special_buttons.h"
|
|
|
|
#include "styles/style_passport.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
|
|
|
|
namespace Passport {
|
|
|
|
|
|
|
|
class PanelForm::Row : public Ui::RippleButton {
|
|
|
|
public:
|
2018-04-13 17:42:28 +00:00
|
|
|
explicit Row(QWidget *parent);
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-04-13 17:42:28 +00:00
|
|
|
void updateContent(
|
|
|
|
const QString &title,
|
|
|
|
const QString &description,
|
|
|
|
bool ready,
|
|
|
|
bool error,
|
|
|
|
anim::type animated);
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int countAvailableWidth() const;
|
|
|
|
int countAvailableWidth(int newWidth) const;
|
|
|
|
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String _title;
|
|
|
|
Ui::Text::String _description;
|
2018-03-31 01:45:40 +00:00
|
|
|
int _titleHeight = 0;
|
|
|
|
int _descriptionHeight = 0;
|
|
|
|
bool _ready = false;
|
2018-04-13 17:42:28 +00:00
|
|
|
bool _error = false;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _errorAnimation;
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-13 17:42:28 +00:00
|
|
|
PanelForm::Row::Row(QWidget *parent)
|
2018-03-31 01:45:40 +00:00
|
|
|
: RippleButton(parent, st::passportRowRipple)
|
2018-04-13 17:42:28 +00:00
|
|
|
, _title(st::boxWideWidth / 2)
|
|
|
|
, _description(st::boxWideWidth / 2) {
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 17:42:28 +00:00
|
|
|
void PanelForm::Row::updateContent(
|
|
|
|
const QString &title,
|
|
|
|
const QString &description,
|
|
|
|
bool ready,
|
|
|
|
bool error,
|
|
|
|
anim::type animated) {
|
|
|
|
_title.setText(
|
|
|
|
st::semiboldTextStyle,
|
|
|
|
title,
|
|
|
|
Ui::NameTextOptions());
|
|
|
|
_description.setText(
|
|
|
|
st::defaultTextStyle,
|
|
|
|
description,
|
2018-04-17 17:54:52 +00:00
|
|
|
TextParseOptions {
|
|
|
|
TextParseMultiline,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
Qt::LayoutDirectionAuto
|
|
|
|
});
|
|
|
|
_ready = ready && !error;
|
2018-04-13 17:42:28 +00:00
|
|
|
if (_error != error) {
|
|
|
|
_error = error;
|
|
|
|
if (animated == anim::type::instant) {
|
2019-04-02 09:13:30 +00:00
|
|
|
_errorAnimation.stop();
|
2018-04-13 17:42:28 +00:00
|
|
|
} else {
|
|
|
|
_errorAnimation.start(
|
|
|
|
[=] { update(); },
|
|
|
|
_error ? 0. : 1.,
|
|
|
|
_error ? 1. : 0.,
|
|
|
|
st::fadeWrapDuration);
|
|
|
|
}
|
|
|
|
}
|
2018-03-31 01:45:40 +00:00
|
|
|
resizeToWidth(width());
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PanelForm::Row::resizeGetHeight(int newWidth) {
|
|
|
|
const auto availableWidth = countAvailableWidth(newWidth);
|
|
|
|
_titleHeight = _title.countHeight(availableWidth);
|
|
|
|
_descriptionHeight = _description.countHeight(availableWidth);
|
|
|
|
const auto result = st::passportRowPadding.top()
|
|
|
|
+ _titleHeight
|
|
|
|
+ st::passportRowSkip
|
|
|
|
+ _descriptionHeight
|
|
|
|
+ st::passportRowPadding.bottom();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PanelForm::Row::countAvailableWidth(int newWidth) const {
|
|
|
|
return newWidth
|
|
|
|
- st::passportRowPadding.left()
|
|
|
|
- st::passportRowPadding.right()
|
2018-04-12 10:20:54 +00:00
|
|
|
- (_ready
|
|
|
|
? st::passportRowReadyIcon
|
2018-04-13 16:43:17 +00:00
|
|
|
: st::passportRowEmptyIcon).width()
|
|
|
|
- st::passportRowIconSkip;
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PanelForm::Row::countAvailableWidth() const {
|
|
|
|
return countAvailableWidth(width());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelForm::Row::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, 0, 0);
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
const auto left = st::passportRowPadding.left();
|
|
|
|
const auto availableWidth = countAvailableWidth();
|
|
|
|
auto top = st::passportRowPadding.top();
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
const auto error = _errorAnimation.value(_error ? 1. : 0.);
|
2018-04-13 17:42:28 +00:00
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
p.setPen(st::passportRowTitleFg);
|
|
|
|
_title.drawLeft(p, left, top, availableWidth, width());
|
|
|
|
top += _titleHeight + st::passportRowSkip;
|
|
|
|
|
2018-04-13 17:42:28 +00:00
|
|
|
p.setPen(anim::pen(
|
|
|
|
st::passportRowDescriptionFg,
|
|
|
|
st::boxTextFgError,
|
|
|
|
error));
|
2018-03-31 01:45:40 +00:00
|
|
|
_description.drawLeft(p, left, top, availableWidth, width());
|
|
|
|
top += _descriptionHeight + st::passportRowPadding.bottom();
|
|
|
|
|
|
|
|
const auto &icon = _ready
|
|
|
|
? st::passportRowReadyIcon
|
|
|
|
: st::passportRowEmptyIcon;
|
2018-04-13 17:42:28 +00:00
|
|
|
if (error > 0. && !_ready) {
|
|
|
|
icon.paint(
|
|
|
|
p,
|
|
|
|
width() - st::passportRowPadding.right() - icon.width(),
|
|
|
|
(height() - icon.height()) / 2,
|
|
|
|
width(),
|
|
|
|
anim::color(st::menuIconFgOver, st::boxTextFgError, error));
|
|
|
|
} else {
|
|
|
|
icon.paint(
|
|
|
|
p,
|
|
|
|
width() - st::passportRowPadding.right() - icon.width(),
|
|
|
|
(height() - icon.height()) / 2,
|
|
|
|
width());
|
|
|
|
}
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PanelForm::PanelForm(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PanelController*> controller)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _controller(controller)
|
|
|
|
, _scroll(this, st::passportPanelScroll)
|
|
|
|
, _topShadow(this)
|
|
|
|
, _bottomShadow(this)
|
|
|
|
, _submit(
|
|
|
|
this,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_passport_authorize(),
|
2018-03-31 01:45:40 +00:00
|
|
|
st::passportPanelAuthorize) {
|
|
|
|
setupControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelForm::setupControls() {
|
|
|
|
const auto inner = setupContent();
|
|
|
|
|
2018-04-12 15:45:04 +00:00
|
|
|
_submit->addClickHandler([=] {
|
|
|
|
_controller->submitForm();
|
|
|
|
});
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
_topShadow->toggleOn(
|
|
|
|
_scroll->scrollTopValue() | rpl::map(_1 > 0));
|
|
|
|
_bottomShadow->toggleOn(rpl::combine(
|
|
|
|
_scroll->scrollTopValue(),
|
|
|
|
_scroll->heightValue(),
|
|
|
|
inner->heightValue(),
|
|
|
|
_1 + _2 < _3));
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Ui::RpWidget*> PanelForm::setupContent() {
|
|
|
|
const auto bot = _controller->bot();
|
|
|
|
|
|
|
|
const auto inner = _scroll->setOwnedWidget(
|
|
|
|
object_ptr<Ui::VerticalLayout>(this));
|
|
|
|
_scroll->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
inner->resizeToWidth(width);
|
|
|
|
}, inner->lifetime());
|
|
|
|
|
|
|
|
const auto userpicWrap = inner->add(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
inner,
|
|
|
|
st::passportFormUserpic.size.height()),
|
|
|
|
st::passportFormUserpicPadding);
|
|
|
|
_userpic = Ui::AttachParentChild(
|
|
|
|
userpicWrap,
|
|
|
|
object_ptr<Ui::UserpicButton>(
|
|
|
|
userpicWrap,
|
|
|
|
bot,
|
|
|
|
Ui::UserpicButton::Role::Custom,
|
|
|
|
st::passportFormUserpic));
|
|
|
|
userpicWrap->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
_userpic->move((width - _userpic->width()) / 2, _userpic->y());
|
|
|
|
}, _userpic->lifetime());
|
|
|
|
|
2018-04-16 17:02:40 +00:00
|
|
|
_about1 = inner->add(
|
|
|
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
|
|
|
inner,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
inner,
|
2019-09-13 06:06:02 +00:00
|
|
|
tr::lng_passport_request1(tr::now, lt_bot, bot->name),
|
2018-04-16 17:02:40 +00:00
|
|
|
st::passportPasswordLabelBold)),
|
|
|
|
st::passportFormAbout1Padding)->entity();
|
|
|
|
|
|
|
|
_about2 = inner->add(
|
|
|
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
|
|
|
inner,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
inner,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passport_request2(tr::now),
|
2018-04-16 17:02:40 +00:00
|
|
|
st::passportPasswordLabel)),
|
|
|
|
st::passportFormAbout2Padding)->entity();
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
inner->add(object_ptr<BoxContentDivider>(
|
|
|
|
inner,
|
|
|
|
st::passportFormDividerHeight));
|
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
inner,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passport_header(tr::now),
|
2018-03-31 01:45:40 +00:00
|
|
|
st::passportFormHeader),
|
|
|
|
st::passportFormHeaderPadding);
|
|
|
|
|
|
|
|
auto index = 0;
|
|
|
|
_controller->fillRows([&](
|
|
|
|
QString title,
|
|
|
|
QString description,
|
2018-04-13 17:42:28 +00:00
|
|
|
bool ready,
|
|
|
|
bool error) {
|
|
|
|
_rows.push_back(inner->add(object_ptr<Row>(this)));
|
2018-03-31 01:45:40 +00:00
|
|
|
_rows.back()->addClickHandler([=] {
|
2018-04-03 18:24:31 +00:00
|
|
|
_controller->editScope(index);
|
2018-03-31 01:45:40 +00:00
|
|
|
});
|
2018-04-13 17:42:28 +00:00
|
|
|
_rows.back()->updateContent(
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
ready,
|
|
|
|
error,
|
|
|
|
anim::type::instant);
|
2018-04-03 18:24:31 +00:00
|
|
|
++index;
|
2018-03-31 01:45:40 +00:00
|
|
|
});
|
2018-04-13 17:42:28 +00:00
|
|
|
_controller->refillRows(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto index = 0;
|
|
|
|
_controller->fillRows([&](
|
|
|
|
QString title,
|
|
|
|
QString description,
|
|
|
|
bool ready,
|
|
|
|
bool error) {
|
|
|
|
Expects(index < _rows.size());
|
|
|
|
|
|
|
|
_rows[index++]->updateContent(
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
ready,
|
|
|
|
error,
|
|
|
|
anim::type::normal);
|
|
|
|
});
|
|
|
|
}, lifetime());
|
2018-04-03 18:24:31 +00:00
|
|
|
const auto policyUrl = _controller->privacyPolicyUrl();
|
2019-06-18 16:53:27 +00:00
|
|
|
auto text = policyUrl.isEmpty()
|
|
|
|
? tr::lng_passport_allow(
|
|
|
|
lt_bot,
|
|
|
|
rpl::single('@' + bot->username)
|
|
|
|
) | Ui::Text::ToWithEntities()
|
|
|
|
: tr::lng_passport_accept_allow(
|
2019-06-12 20:11:41 +00:00
|
|
|
lt_policy,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_passport_policy(
|
|
|
|
lt_bot,
|
2019-09-13 06:06:02 +00:00
|
|
|
rpl::single(bot->name)
|
2019-06-18 16:53:27 +00:00
|
|
|
) | Ui::Text::ToLink(policyUrl),
|
2019-06-12 20:11:41 +00:00
|
|
|
lt_bot,
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::single('@' + bot->username) | Ui::Text::ToWithEntities(),
|
|
|
|
Ui::Text::WithEntities);
|
2018-03-31 01:45:40 +00:00
|
|
|
const auto policy = inner->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
inner,
|
2019-06-18 16:53:27 +00:00
|
|
|
std::move(text),
|
2018-03-31 01:45:40 +00:00
|
|
|
st::passportFormPolicy),
|
|
|
|
st::passportFormPolicyPadding);
|
2019-06-12 20:11:41 +00:00
|
|
|
policy->setLinksTrusted();
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
return inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelForm::resizeEvent(QResizeEvent *e) {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelForm::updateControlsGeometry() {
|
|
|
|
const auto submitTop = height() - _submit->height();
|
|
|
|
_scroll->setGeometry(0, 0, width(), submitTop);
|
|
|
|
_topShadow->resizeToWidth(width());
|
|
|
|
_topShadow->moveToLeft(0, 0);
|
|
|
|
_bottomShadow->resizeToWidth(width());
|
|
|
|
_bottomShadow->moveToLeft(0, submitTop - st::lineWidth);
|
2018-06-08 19:26:08 +00:00
|
|
|
_submit->setFullWidth(width());
|
2018-03-31 01:45:40 +00:00
|
|
|
_submit->moveToLeft(0, submitTop);
|
|
|
|
|
|
|
|
_scroll->updateBars();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Passport
|