mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved creation of flexible bottom content of password section to module.
This commit is contained in:
parent
01eacadca5
commit
2eaa17b938
3 changed files with 104 additions and 70 deletions
|
@ -20,6 +20,73 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace Settings::CloudPassword {
|
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> &§ionGeometryValue,
|
||||||
|
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(
|
void SetupHeader(
|
||||||
not_null<Ui::VerticalLayout*> content,
|
not_null<Ui::VerticalLayout*> content,
|
||||||
const QString &lottie,
|
const QString &lottie,
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
|
#include "ui/widgets/box_content_divider.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class FlatLabel;
|
class FlatLabel;
|
||||||
|
@ -41,6 +42,31 @@ void SetupHeader(
|
||||||
void AddSkipInsteadOfField(not_null<Ui::VerticalLayout*> content);
|
void AddSkipInsteadOfField(not_null<Ui::VerticalLayout*> content);
|
||||||
void AddSkipInsteadOfError(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> &§ionGeometryValue,
|
||||||
|
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 {
|
class AbstractStep : public AbstractSection {
|
||||||
public:
|
public:
|
||||||
AbstractStep(
|
AbstractStep(
|
||||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lottie/lottie_icon.h"
|
#include "lottie/lottie_icon.h"
|
||||||
#include "main/main_domain.h"
|
#include "main/main_domain.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "settings/cloud_password/settings_cloud_password_common.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
#include "storage/storage_domain.h"
|
#include "storage/storage_domain.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
@ -51,43 +52,6 @@ void SetupAutoCloseTimer(rpl::lifetime &lifetime, Fn<void()> callback) {
|
||||||
timer->callEach(kTimerCheck);
|
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
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
@ -525,6 +489,7 @@ void LocalPasscodeManage::setupContent() {
|
||||||
|
|
||||||
AddSkip(content);
|
AddSkip(content);
|
||||||
|
|
||||||
|
using Divider = CloudPassword::OneEdgeBoxContentDivider;
|
||||||
const auto divider = Ui::CreateChild<Divider>(this);
|
const auto divider = Ui::CreateChild<Divider>(this);
|
||||||
divider->lower();
|
divider->lower();
|
||||||
const auto about = content->add(
|
const auto about = content->add(
|
||||||
|
@ -554,15 +519,7 @@ void LocalPasscodeManage::setupContent() {
|
||||||
|
|
||||||
QPointer<Ui::RpWidget> LocalPasscodeManage::createPinnedToBottom(
|
QPointer<Ui::RpWidget> LocalPasscodeManage::createPinnedToBottom(
|
||||||
not_null<Ui::RpWidget*> parent) {
|
not_null<Ui::RpWidget*> parent) {
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(parent.get());
|
auto callback = [=] {
|
||||||
|
|
||||||
AddSkip(content);
|
|
||||||
|
|
||||||
AddButton(
|
|
||||||
content,
|
|
||||||
tr::lng_settings_passcode_disable(),
|
|
||||||
st::settingsAttentionButton
|
|
||||||
)->addClickHandler([=] {
|
|
||||||
_controller->show(
|
_controller->show(
|
||||||
Ui::MakeConfirmBox({
|
Ui::MakeConfirmBox({
|
||||||
.text = tr::lng_settings_passcode_disable_sure(),
|
.text = tr::lng_settings_passcode_disable_sure(),
|
||||||
|
@ -575,32 +532,16 @@ QPointer<Ui::RpWidget> LocalPasscodeManage::createPinnedToBottom(
|
||||||
.confirmText = tr::lng_settings_auto_night_disable(),
|
.confirmText = tr::lng_settings_auto_night_disable(),
|
||||||
.confirmStyle = &st::attentionBoxButton,
|
.confirmStyle = &st::attentionBoxButton,
|
||||||
}));
|
}));
|
||||||
});
|
};
|
||||||
|
auto bottomButton = CloudPassword::CreateBottomDisableButton(
|
||||||
const auto divider = Ui::CreateChild<Divider>(parent.get());
|
parent,
|
||||||
divider->skipEdge(Qt::TopEdge, true);
|
|
||||||
rpl::combine(
|
|
||||||
geometryValue(),
|
geometryValue(),
|
||||||
parent->geometryValue(),
|
tr::lng_settings_passcode_disable(),
|
||||||
content->geometryValue()
|
std::move(callback));
|
||||||
) | 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;
|
|
||||||
});
|
|
||||||
|
|
||||||
return Ui::MakeWeak(not_null<Ui::RpWidget*>{ content });
|
_isBottomFillerShown = base::take(bottomButton.isBottomFillerShown);
|
||||||
|
|
||||||
|
return bottomButton.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPasscodeManage::showFinished() {
|
void LocalPasscodeManage::showFinished() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue