Moved creation of flexible bottom content of password section to module.

This commit is contained in:
23rd 2022-05-07 01:16:46 +03:00
parent 01eacadca5
commit 2eaa17b938
3 changed files with 104 additions and 70 deletions

View File

@ -20,6 +20,73 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings::CloudPassword {
void OneEdgeBoxContentDivider::skipEdge(Qt::Edge edge, bool skip) {
const auto was = _skipEdges;
if (skip) {
_skipEdges |= edge;
} else {
_skipEdges &= ~edge;
}
if (was != _skipEdges) {
update();
}
}
void OneEdgeBoxContentDivider::paintEvent(QPaintEvent *e) {
Painter p(this);
p.fillRect(e->rect(), Ui::BoxContentDivider::color());
if (!(_skipEdges & Qt::TopEdge)) {
Ui::BoxContentDivider::paintTop(p);
}
if (!(_skipEdges & Qt::BottomEdge)) {
Ui::BoxContentDivider::paintBottom(p);
}
}
BottomButton CreateBottomDisableButton(
not_null<Ui::RpWidget*> parent,
rpl::producer<QRect> &&sectionGeometryValue,
rpl::producer<QString> &&buttonText,
Fn<void()> &&callback) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(parent.get());
AddSkip(content);
AddButton(
content,
std::move(buttonText),
st::settingsAttentionButton
)->addClickHandler(std::move(callback));
const auto divider = Ui::CreateChild<OneEdgeBoxContentDivider>(
parent.get());
divider->skipEdge(Qt::TopEdge, true);
rpl::combine(
std::move(sectionGeometryValue),
parent->geometryValue(),
content->geometryValue()
) | rpl::start_with_next([=](
const QRect &r,
const QRect &parentRect,
const QRect &bottomRect) {
const auto top = r.y() + r.height();
divider->setGeometry(
0,
top,
r.width(),
parentRect.height() - top - bottomRect.height());
}, divider->lifetime());
divider->show();
return {
.content = Ui::MakeWeak(not_null<Ui::RpWidget*>{ content }),
.isBottomFillerShown = divider->geometryValue(
) | rpl::map([](const QRect &r) {
return r.height() > 0;
}),
};
}
void SetupHeader(
not_null<Ui::VerticalLayout*> content,
const QString &lottie,

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "settings/settings_common.h"
#include "ui/widgets/box_content_divider.h"
namespace Ui {
class FlatLabel;
@ -41,6 +42,31 @@ void SetupHeader(
void AddSkipInsteadOfField(not_null<Ui::VerticalLayout*> content);
void AddSkipInsteadOfError(not_null<Ui::VerticalLayout*> content);
struct BottomButton {
QPointer<Ui::RpWidget> content;
rpl::producer<bool> isBottomFillerShown;
};
BottomButton CreateBottomDisableButton(
not_null<Ui::RpWidget*> parent,
rpl::producer<QRect> &&sectionGeometryValue,
rpl::producer<QString> &&buttonText,
Fn<void()> &&callback);
class OneEdgeBoxContentDivider : public Ui::BoxContentDivider {
public:
using Ui::BoxContentDivider::BoxContentDivider;
void skipEdge(Qt::Edge edge, bool skip);
protected:
void paintEvent(QPaintEvent *e) override;
private:
Qt::Edges _skipEdges;
};
class AbstractStep : public AbstractSection {
public:
AbstractStep(

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lottie/lottie_icon.h"
#include "main/main_domain.h"
#include "main/main_session.h"
#include "settings/cloud_password/settings_cloud_password_common.h"
#include "settings/settings_common.h"
#include "storage/storage_domain.h"
#include "ui/boxes/confirm_box.h"
@ -51,43 +52,6 @@ void SetupAutoCloseTimer(rpl::lifetime &lifetime, Fn<void()> callback) {
timer->callEach(kTimerCheck);
}
class Divider : public Ui::BoxContentDivider {
public:
using Ui::BoxContentDivider::BoxContentDivider;
void skipEdge(Qt::Edge edge, bool skip);
protected:
void paintEvent(QPaintEvent *e) override;
private:
Qt::Edges _skipEdges;
};
void Divider::skipEdge(Qt::Edge edge, bool skip) {
const auto was = _skipEdges;
if (skip) {
_skipEdges |= edge;
} else {
_skipEdges &= ~edge;
}
if (was != _skipEdges) {
update();
}
}
void Divider::paintEvent(QPaintEvent *e) {
Painter p(this);
p.fillRect(e->rect(), Ui::BoxContentDivider::color());
if (!(_skipEdges & Qt::TopEdge)) {
Ui::BoxContentDivider::paintTop(p);
}
if (!(_skipEdges & Qt::BottomEdge)) {
Ui::BoxContentDivider::paintBottom(p);
}
}
} // namespace
namespace details {
@ -525,6 +489,7 @@ void LocalPasscodeManage::setupContent() {
AddSkip(content);
using Divider = CloudPassword::OneEdgeBoxContentDivider;
const auto divider = Ui::CreateChild<Divider>(this);
divider->lower();
const auto about = content->add(
@ -554,15 +519,7 @@ void LocalPasscodeManage::setupContent() {
QPointer<Ui::RpWidget> LocalPasscodeManage::createPinnedToBottom(
not_null<Ui::RpWidget*> parent) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(parent.get());
AddSkip(content);
AddButton(
content,
tr::lng_settings_passcode_disable(),
st::settingsAttentionButton
)->addClickHandler([=] {
auto callback = [=] {
_controller->show(
Ui::MakeConfirmBox({
.text = tr::lng_settings_passcode_disable_sure(),
@ -575,32 +532,16 @@ QPointer<Ui::RpWidget> LocalPasscodeManage::createPinnedToBottom(
.confirmText = tr::lng_settings_auto_night_disable(),
.confirmStyle = &st::attentionBoxButton,
}));
});
const auto divider = Ui::CreateChild<Divider>(parent.get());
divider->skipEdge(Qt::TopEdge, true);
rpl::combine(
};
auto bottomButton = CloudPassword::CreateBottomDisableButton(
parent,
geometryValue(),
parent->geometryValue(),
content->geometryValue()
) | rpl::start_with_next([=](
const QRect &r,
const QRect &parentRect,
const QRect &bottomRect) {
const auto top = r.y() + r.height();
divider->setGeometry(
0,
top,
r.width(),
parentRect.height() - top - bottomRect.height());
}, divider->lifetime());
divider->show();
_isBottomFillerShown = divider->geometryValue(
) | rpl::map([](const QRect &r) {
return r.height() > 0;
});
tr::lng_settings_passcode_disable(),
std::move(callback));
return Ui::MakeWeak(not_null<Ui::RpWidget*>{ content });
_isBottomFillerShown = base::take(bottomButton.isBottomFillerShown);
return bottomButton.content;
}
void LocalPasscodeManage::showFinished() {