mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Simplify Info::Profile::Cover code, remove toggling.
This commit is contained in:
parent
b7259615a7
commit
8ca2f6a444
5 changed files with 6 additions and 134 deletions
|
@ -163,66 +163,6 @@ auto ChatStatusText(int fullCount, int onlineCount, bool isGroup) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
SectionWithToggle *SectionWithToggle::setToggleShown(
|
|
||||||
rpl::producer<bool> &&shown) {
|
|
||||||
_toggle.create(
|
|
||||||
this,
|
|
||||||
QString(),
|
|
||||||
st::infoToggleCheckbox,
|
|
||||||
std::make_unique<SectionToggle>(
|
|
||||||
st::infoToggle,
|
|
||||||
false,
|
|
||||||
[this] { _toggle->updateCheck(); }));
|
|
||||||
_toggle->hide();
|
|
||||||
_toggle->lower();
|
|
||||||
_toggle->setCheckAlignment(style::al_right);
|
|
||||||
widthValue(
|
|
||||||
) | rpl::start_with_next([this](int newValue) {
|
|
||||||
_toggle->setGeometry(0, 0, newValue, height());
|
|
||||||
}, _toggle->lifetime());
|
|
||||||
std::move(
|
|
||||||
shown
|
|
||||||
) | rpl::start_with_next([this](bool shown) {
|
|
||||||
if (_toggle->isHidden() == shown) {
|
|
||||||
_toggle->setVisible(shown);
|
|
||||||
_toggleShown.fire_copy(shown);
|
|
||||||
}
|
|
||||||
}, lifetime());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SectionWithToggle::toggle(bool toggled, anim::type animated) {
|
|
||||||
if (_toggle) {
|
|
||||||
_toggle->setChecked(toggled);
|
|
||||||
if (animated == anim::type::instant) {
|
|
||||||
_toggle->finishAnimating();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SectionWithToggle::toggled() const {
|
|
||||||
return _toggle ? _toggle->checked() : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
rpl::producer<bool> SectionWithToggle::toggledValue() const {
|
|
||||||
if (_toggle) {
|
|
||||||
return _toggle->checkedValue();
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
rpl::producer<bool> SectionWithToggle::toggleShownValue() const {
|
|
||||||
return _toggleShown.events_starting_with(
|
|
||||||
_toggle && !_toggle->isHidden());
|
|
||||||
}
|
|
||||||
|
|
||||||
int SectionWithToggle::toggleSkip() const {
|
|
||||||
return (!_toggle || _toggle->isHidden())
|
|
||||||
? 0
|
|
||||||
: st::infoToggleCheckbox.checkPosition.x()
|
|
||||||
+ _toggle->checkRect().width();
|
|
||||||
}
|
|
||||||
|
|
||||||
Cover::Cover(
|
Cover::Cover(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
|
@ -239,7 +179,7 @@ Cover::Cover(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
rpl::producer<QString> title)
|
rpl::producer<QString> title)
|
||||||
: SectionWithToggle(
|
: FixedHeightWidget(
|
||||||
parent,
|
parent,
|
||||||
st::infoProfilePhotoTop
|
st::infoProfilePhotoTop
|
||||||
+ st::infoProfilePhoto.size.height()
|
+ st::infoProfilePhoto.size.height()
|
||||||
|
@ -279,11 +219,7 @@ Cover::Cover(
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cover::setupChildGeometry() {
|
void Cover::setupChildGeometry() {
|
||||||
using namespace rpl::mappers;
|
widthValue(
|
||||||
rpl::combine(
|
|
||||||
toggleShownValue(),
|
|
||||||
widthValue(),
|
|
||||||
_2
|
|
||||||
) | rpl::start_with_next([this](int newWidth) {
|
) | rpl::start_with_next([this](int newWidth) {
|
||||||
_userpic->moveToLeft(
|
_userpic->moveToLeft(
|
||||||
st::infoProfilePhotoLeft,
|
st::infoProfilePhotoLeft,
|
||||||
|
@ -451,8 +387,7 @@ void Cover::refreshNameGeometry(int newWidth) {
|
||||||
auto nameTop = st::infoProfileNameTop;
|
auto nameTop = st::infoProfileNameTop;
|
||||||
auto nameWidth = newWidth
|
auto nameWidth = newWidth
|
||||||
- nameLeft
|
- nameLeft
|
||||||
- st::infoProfileNameRight
|
- st::infoProfileNameRight;
|
||||||
- toggleSkip();
|
|
||||||
if (_verifiedCheck) {
|
if (_verifiedCheck) {
|
||||||
nameWidth -= st::infoVerifiedCheckPosition.x()
|
nameWidth -= st::infoVerifiedCheckPosition.x()
|
||||||
+ _verifiedCheck->width();
|
+ _verifiedCheck->width();
|
||||||
|
@ -484,8 +419,7 @@ void Cover::refreshNameGeometry(int newWidth) {
|
||||||
void Cover::refreshStatusGeometry(int newWidth) {
|
void Cover::refreshStatusGeometry(int newWidth) {
|
||||||
auto statusWidth = newWidth
|
auto statusWidth = newWidth
|
||||||
- st::infoProfileStatusLeft
|
- st::infoProfileStatusLeft
|
||||||
- st::infoProfileStatusRight
|
- st::infoProfileStatusRight;
|
||||||
- toggleSkip();
|
|
||||||
_status->resizeToWidth(statusWidth);
|
_status->resizeToWidth(statusWidth);
|
||||||
_status->moveToLeft(
|
_status->moveToLeft(
|
||||||
st::infoProfileStatusLeft,
|
st::infoProfileStatusLeft,
|
||||||
|
|
|
@ -36,26 +36,7 @@ namespace Profile {
|
||||||
|
|
||||||
enum class Badge;
|
enum class Badge;
|
||||||
|
|
||||||
class SectionWithToggle : public Ui::FixedHeightWidget {
|
class Cover : public Ui::FixedHeightWidget {
|
||||||
public:
|
|
||||||
using FixedHeightWidget::FixedHeightWidget;
|
|
||||||
|
|
||||||
SectionWithToggle *setToggleShown(rpl::producer<bool> &&shown);
|
|
||||||
void toggle(bool toggled, anim::type animated);
|
|
||||||
bool toggled() const;
|
|
||||||
rpl::producer<bool> toggledValue() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
rpl::producer<bool> toggleShownValue() const;
|
|
||||||
int toggleSkip() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
object_ptr<Ui::Checkbox> _toggle = { nullptr };
|
|
||||||
rpl::event_stream<bool> _toggleShown;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class Cover : public SectionWithToggle {
|
|
||||||
public:
|
public:
|
||||||
Cover(
|
Cover(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
|
@ -69,11 +50,6 @@ public:
|
||||||
|
|
||||||
Cover *setOnlineCount(rpl::producer<int> &&count);
|
Cover *setOnlineCount(rpl::producer<int> &&count);
|
||||||
|
|
||||||
Cover *setToggleShown(rpl::producer<bool> &&shown) {
|
|
||||||
return static_cast<Cover*>(
|
|
||||||
SectionWithToggle::setToggleShown(std::move(shown)));
|
|
||||||
}
|
|
||||||
|
|
||||||
rpl::producer<Section> showSection() const {
|
rpl::producer<Section> showSection() const {
|
||||||
return _showSection.events();
|
return _showSection.events();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,16 +61,6 @@ InnerWidget::InnerWidget(
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InnerWidget::canHideDetailsEver() const {
|
|
||||||
return false;// (_peer->isChat() || _peer->isMegagroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
rpl::producer<bool> InnerWidget::canHideDetails() const {
|
|
||||||
using namespace rpl::mappers;
|
|
||||||
return MembersCountValue(_peer)
|
|
||||||
| rpl::map(_1 > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
object_ptr<Ui::RpWidget> InnerWidget::setupContent(
|
object_ptr<Ui::RpWidget> InnerWidget::setupContent(
|
||||||
not_null<RpWidget*> parent) {
|
not_null<RpWidget*> parent) {
|
||||||
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
||||||
|
@ -85,19 +75,7 @@ object_ptr<Ui::RpWidget> InnerWidget::setupContent(
|
||||||
}, _cover->lifetime());
|
}, _cover->lifetime());
|
||||||
_cover->setOnlineCount(rpl::single(0));
|
_cover->setOnlineCount(rpl::single(0));
|
||||||
auto details = SetupDetails(_controller, parent, _peer);
|
auto details = SetupDetails(_controller, parent, _peer);
|
||||||
if (canHideDetailsEver()) {
|
result->add(std::move(details));
|
||||||
_cover->setToggleShown(canHideDetails());
|
|
||||||
_infoWrap = result->add(object_ptr<Ui::SlideWrap<>>(
|
|
||||||
result,
|
|
||||||
std::move(details))
|
|
||||||
)->setDuration(
|
|
||||||
st::infoSlideDuration
|
|
||||||
)->toggleOn(
|
|
||||||
_cover->toggledValue()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
result->add(std::move(details));
|
|
||||||
}
|
|
||||||
result->add(setupSharedMedia(result.data()));
|
result->add(setupSharedMedia(result.data()));
|
||||||
if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) {
|
if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) {
|
||||||
result->add(std::move(members));
|
result->add(std::move(members));
|
||||||
|
@ -244,20 +222,15 @@ void InnerWidget::visibleTopBottomUpdated(
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::saveState(not_null<Memento*> memento) {
|
void InnerWidget::saveState(not_null<Memento*> memento) {
|
||||||
memento->setInfoExpanded(_cover->toggled());
|
|
||||||
if (_members) {
|
if (_members) {
|
||||||
memento->setMembersState(_members->saveState());
|
memento->setMembersState(_members->saveState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
||||||
_cover->toggle(memento->infoExpanded(), anim::type::instant);
|
|
||||||
if (_members) {
|
if (_members) {
|
||||||
_members->restoreState(memento->membersState());
|
_members->restoreState(memento->membersState());
|
||||||
}
|
}
|
||||||
if (_infoWrap) {
|
|
||||||
_infoWrap->finishAnimating();
|
|
||||||
}
|
|
||||||
if (_sharedMediaWrap) {
|
if (_sharedMediaWrap) {
|
||||||
_sharedMediaWrap->finishAnimating();
|
_sharedMediaWrap->finishAnimating();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,16 +62,12 @@ private:
|
||||||
_desiredHeight.fire(countDesiredHeight());
|
_desiredHeight.fire(countDesiredHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canHideDetailsEver() const;
|
|
||||||
rpl::producer<bool> canHideDetails() const;
|
|
||||||
|
|
||||||
const not_null<Controller*> _controller;
|
const not_null<Controller*> _controller;
|
||||||
const not_null<PeerData*> _peer;
|
const not_null<PeerData*> _peer;
|
||||||
PeerData * const _migrated = nullptr;
|
PeerData * const _migrated = nullptr;
|
||||||
|
|
||||||
Members *_members = nullptr;
|
Members *_members = nullptr;
|
||||||
Cover *_cover = nullptr;
|
Cover *_cover = nullptr;
|
||||||
Ui::SlideWrap<RpWidget> *_infoWrap = nullptr;
|
|
||||||
Ui::SlideWrap<RpWidget> *_sharedMediaWrap = nullptr;
|
Ui::SlideWrap<RpWidget> *_sharedMediaWrap = nullptr;
|
||||||
object_ptr<RpWidget> _content;
|
object_ptr<RpWidget> _content;
|
||||||
|
|
||||||
|
|
|
@ -28,19 +28,12 @@ public:
|
||||||
|
|
||||||
Section section() const override;
|
Section section() const override;
|
||||||
|
|
||||||
void setInfoExpanded(bool expanded) {
|
|
||||||
_infoExpanded = expanded;
|
|
||||||
}
|
|
||||||
bool infoExpanded() const {
|
|
||||||
return _infoExpanded;
|
|
||||||
}
|
|
||||||
void setMembersState(std::unique_ptr<MembersState> state);
|
void setMembersState(std::unique_ptr<MembersState> state);
|
||||||
std::unique_ptr<MembersState> membersState();
|
std::unique_ptr<MembersState> membersState();
|
||||||
|
|
||||||
~Memento();
|
~Memento();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _infoExpanded = true;
|
|
||||||
std::unique_ptr<MembersState> _membersState;
|
std::unique_ptr<MembersState> _membersState;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue