tdesktop/Telegram/SourceFiles/info/feed/info_feed_cover.cpp

119 lines
2.9 KiB
C++
Raw Normal View History

2018-01-22 19:51:38 +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 "info/feed/info_feed_cover.h"
#include "data/data_feed.h"
2018-02-06 14:46:00 +00:00
#include "data/data_session.h"
2018-01-22 19:51:38 +00:00
#include "info/info_controller.h"
#include "info/info_memento.h"
2018-01-22 19:51:38 +00:00
#include "lang/lang_keys.h"
#include "ui/widgets/labels.h"
2018-02-06 14:46:00 +00:00
#include "ui/special_buttons.h"
#include "auth_session.h"
2018-01-22 19:51:38 +00:00
#include "styles/style_info.h"
namespace Info {
namespace FeedProfile {
Cover::Cover(
QWidget *parent,
not_null<Controller*> controller)
: FixedHeightWidget(
parent,
st::infoProfilePhotoTop
+ st::infoProfilePhoto.size.height()
+ st::infoProfilePhotoBottom)
, _controller(controller)
, _feed(_controller->key().feed())
2018-02-06 14:46:00 +00:00
, _userpic(
this,
controller->parentController(),
_feed,
st::infoFeedProfilePhoto)
2018-01-22 19:51:38 +00:00
, _name(this, st::infoProfileNameLabel)
, _status(
2018-02-06 14:46:00 +00:00
this,
st::infoProfileMegagroupStatusLabel) {
_userpic->setPointerCursor(false);
2018-01-22 19:51:38 +00:00
_name->setSelectable(true);
_name->setContextCopyText(lang(lng_profile_copy_fullname));
2018-02-06 14:46:00 +00:00
refreshNameText();
refreshStatusText();
2018-01-22 19:51:38 +00:00
initViewers();
setupChildGeometry();
}
void Cover::setupChildGeometry() {
2018-02-06 14:46:00 +00:00
widthValue(
) | rpl::start_with_next([=](int newWidth) {
_userpic->moveToLeft(
st::infoProfilePhotoLeft,
st::infoProfilePhotoTop,
newWidth);
refreshNameGeometry(newWidth);
refreshStatusGeometry(newWidth);
}, lifetime());
2018-01-22 19:51:38 +00:00
}
void Cover::initViewers() {
2018-02-06 14:46:00 +00:00
Auth().data().feedUpdated(
) | rpl::filter([](const Data::FeedUpdate &update) {
return (update.flag == Data::FeedUpdateFlag::Channels);
2018-02-06 14:46:00 +00:00
}) | rpl::start_with_next(
[=] { refreshStatusText(); },
lifetime());
2018-01-22 19:51:38 +00:00
}
void Cover::refreshNameText() {
2019-01-15 11:57:45 +00:00
_name->setText(_feed->chatListName());
2018-01-22 19:51:38 +00:00
refreshNameGeometry(width());
}
void Cover::refreshStatusText() {
2018-02-06 14:46:00 +00:00
const auto statusText = [&] {
if (!_feed->channelsLoaded() || _feed->channels().empty()) {
return QString();
}
return lng_feed_channels(lt_count, _feed->channels().size());
}();
_status->setRichText(textcmdLink(1, statusText));
_status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
_controller->showSection(Info::Memento(
_feed,
Section::Type::Channels));
}));
2018-01-22 19:51:38 +00:00
refreshStatusGeometry(width());
}
void Cover::refreshNameGeometry(int newWidth) {
auto nameLeft = st::infoProfileNameLeft;
auto nameTop = st::infoProfileNameTop;
auto nameWidth = newWidth
- nameLeft
- st::infoProfileNameRight;
_name->resizeToNaturalWidth(nameWidth);
_name->moveToLeft(nameLeft, nameTop, newWidth);
}
void Cover::refreshStatusGeometry(int newWidth) {
auto statusWidth = newWidth
- st::infoProfileStatusLeft
- st::infoProfileStatusRight;
_status->resizeToWidth(statusWidth);
_status->moveToLeft(
st::infoProfileStatusLeft,
st::infoProfileStatusTop,
newWidth);
}
2018-02-06 14:46:00 +00:00
Cover::~Cover() = default;
2018-01-22 19:51:38 +00:00
} // namespace FeedProfile
} // namespace Info