Improve single column layout forum / topic top bar.

This commit is contained in:
John Preston 2022-10-21 17:12:46 +04:00
parent b497e5ea21
commit b92b8e56cb
4 changed files with 136 additions and 105 deletions

View file

@ -838,7 +838,10 @@ void TopBarWidget::setCustomTitle(const QString &title) {
}
void TopBarWidget::refreshInfoButton() {
if (const auto peer = _activeChat.key.peer()) {
if (_activeChat.key.topic()
|| _activeChat.section == Section::ChatsList) {
_info.destroy();
} else if (const auto peer = _activeChat.key.peer()) {
auto info = object_ptr<Ui::UserpicButton>(
this,
_controller,
@ -924,6 +927,9 @@ void TopBarWidget::updateControlsGeometry() {
if (_info && !_info->isHidden()) {
_info->moveToLeft(_leftTaken, otherButtonsTop);
_leftTaken += _info->width();
} else if (_activeChat.key.topic()
|| _activeChat.section == Section::ChatsList) {
_leftTaken += st::topBarArrowPadding.right();
}
_rightTaken = 0;
@ -984,8 +990,8 @@ void TopBarWidget::updateControlsVisibility() {
_back->setVisible(backVisible && !_chooseForReportReason);
_cancelChoose->setVisible(_chooseForReportReason.has_value());
if (_info) {
_info->setVisible((isOneColumn || !_primaryWindow)
&& !_chooseForReportReason);
_info->setVisible(!_chooseForReportReason
&& (isOneColumn || !_primaryWindow));
}
if (_unreadBadge) {
_unreadBadge->setVisible(!_chooseForReportReason);

View file

@ -116,6 +116,106 @@ Cover::Cover(
: st::infoProfileCover;
}
TopicIconView::TopicIconView(
QWidget *parent,
not_null<Window::SessionController*> controller,
not_null<Data::ForumTopic*> topic)
: AbstractButton(parent) {
setup(topic, [=] {
return controller->isGifPausedAtLeastFor(
Window::GifPauseReason::Layer);
});
}
void TopicIconView::setup(
not_null<Data::ForumTopic*> topic,
Fn<bool()> paused) {
setupPlayer(topic);
setupImage(topic);
resize(st::infoTopicCover.photo.size);
paintRequest(
) | rpl::start_with_next([=] {
auto p = QPainter(this);
const auto paint = [&](const QImage &image) {
const auto size = image.size() / image.devicePixelRatio();
p.drawImage(
(st::infoTopicCover.photo.size.width() - size.width()) / 2,
(st::infoTopicCover.photo.size.height() - size.height()) / 2,
image);
};
if (_player && _player->ready()) {
paint(_player->frame(
st::infoTopicCover.photo.size,
QColor(0, 0, 0, 0),
false,
crl::now(),
paused()).image);
_player->markFrameShown();
} else if (!topic->iconId() && !_image.isNull()) {
paint(_image);
}
}, lifetime());
}
void TopicIconView::setupPlayer(not_null<Data::ForumTopic*> topic) {
IconIdValue(
topic
) | rpl::map([=](DocumentId id) {
return topic->owner().customEmojiManager().resolve(id);
}) | rpl::flatten_latest(
) | rpl::map([=](not_null<DocumentData*> document) {
const auto media = document->createMediaView();
media->checkStickerLarge();
media->goodThumbnailWanted();
return rpl::single() | rpl::then(
document->owner().session().downloaderTaskFinished()
) | rpl::filter([=] {
return media->loaded();
}) | rpl::take(1) | rpl::map([=] {
auto result = std::shared_ptr<StickerPlayer>();
const auto sticker = document->sticker();
if (sticker->isLottie()) {
result = std::make_shared<HistoryView::LottiePlayer>(
ChatHelpers::LottiePlayerFromDocument(
media.get(),
ChatHelpers::StickerLottieSize::StickerSet,
st::infoTopicCover.photo.size,
Lottie::Quality::High));
} else if (sticker->isWebm()) {
result = std::make_shared<HistoryView::WebmPlayer>(
media->owner()->location(),
media->bytes(),
st::infoTopicCover.photo.size);
} else {
result = std::make_shared<HistoryView::StaticStickerPlayer>(
media->owner()->location(),
media->bytes(),
st::infoTopicCover.photo.size);
}
result->setRepaintCallback([=] { update(); });
return result;
});
}) | rpl::flatten_latest(
) | rpl::start_with_next([=](std::shared_ptr<StickerPlayer> player) {
_player = std::move(player);
}, lifetime());
}
void TopicIconView::setupImage(not_null<Data::ForumTopic*> topic) {
rpl::combine(
TitleValue(topic),
ColorIdValue(topic)
) | rpl::map([=](const QString &title, int32 colorId) {
using namespace Data;
return ForumTopicIconFrame(colorId, title, st::infoForumTopicIcon);
}) | rpl::start_with_next([=](QImage &&image) {
_image = std::move(image);
update();
}, lifetime());
}
Cover::Cover(
QWidget *parent,
not_null<PeerData*> peer,
@ -147,14 +247,12 @@ Cover::Cover(
_peer,
Ui::UserpicButton::Role::OpenPhoto,
_st.photo))
, _iconView(topic ? object_ptr<Ui::RpWidget>(this) : nullptr)
, _iconView(topic
? object_ptr<TopicIconView>(this, controller, topic)
: nullptr)
, _name(this, _st.name)
, _status(this, _st.status)
, _refreshStatusTimer([this] { refreshStatusText(); }) {
if (topic) {
setupIcon(topic);
}
_peer->updateFull();
_name->setSelectable(true);
@ -190,94 +288,6 @@ Cover::Cover(
}
}
void Cover::setupIconPlayer(not_null<Data::ForumTopic*> topic) {
IconIdValue(
topic
) | rpl::map([=](DocumentId id) {
return topic->owner().customEmojiManager().resolve(id);
}) | rpl::flatten_latest(
) | rpl::map([=](not_null<DocumentData*> document) {
const auto media = document->createMediaView();
media->checkStickerLarge();
media->goodThumbnailWanted();
return rpl::single() | rpl::then(
document->owner().session().downloaderTaskFinished()
) | rpl::filter([=] {
return media->loaded();
}) | rpl::take(1) | rpl::map([=] {
auto result = std::shared_ptr<StickerPlayer>();
const auto sticker = document->sticker();
if (sticker->isLottie()) {
result = std::make_shared<HistoryView::LottiePlayer>(
ChatHelpers::LottiePlayerFromDocument(
media.get(),
ChatHelpers::StickerLottieSize::StickerSet,
_st.photo.size,
Lottie::Quality::High));
} else if (sticker->isWebm()) {
result = std::make_shared<HistoryView::WebmPlayer>(
media->owner()->location(),
media->bytes(),
_st.photo.size);
} else {
result = std::make_shared<HistoryView::StaticStickerPlayer>(
media->owner()->location(),
media->bytes(),
_st.photo.size);
}
result->setRepaintCallback([=] { _iconView->update(); });
return result;
});
}) | rpl::flatten_latest(
) | rpl::start_with_next([=](std::shared_ptr<StickerPlayer> player) {
_iconPlayer = std::move(player);
}, lifetime());
}
void Cover::setupIconImage(not_null<Data::ForumTopic*> topic) {
rpl::combine(
TitleValue(topic),
ColorIdValue(topic)
) | rpl::map([=](const QString &title, int32 colorId) {
using namespace Data;
return ForumTopicIconFrame(colorId, title, st::infoForumTopicIcon);
}) | rpl::start_with_next([=](QImage &&image) {
_iconImage = std::move(image);
_iconView->update();
}, lifetime());
}
void Cover::setupIcon(not_null<Data::ForumTopic*> topic) {
setupIconPlayer(topic);
setupIconImage(topic);
_iconView->resize(_st.photo.size);
_iconView->paintRequest(
) | rpl::start_with_next([=] {
auto p = QPainter(_iconView.data());
const auto paint = [&](const QImage &image) {
const auto size = image.size() / image.devicePixelRatio();
p.drawImage(
(_st.photo.size.width() - size.width()) / 2,
(_st.photo.size.height() - size.height()) / 2,
image);
};
if (_iconPlayer && _iconPlayer->ready()) {
paint(_iconPlayer->frame(
_st.photo.size,
QColor(0, 0, 0, 0),
false,
crl::now(),
_controller->isGifPausedAtLeastFor(
Window::GifPauseReason::Layer)).image);
_iconPlayer->markFrameShown();
} else if (!topic->iconId() && !_iconImage.isNull()) {
paint(_iconImage);
}
}, _iconView->lifetime());
}
void Cover::setupChildGeometry() {
widthValue(
) | rpl::start_with_next([this](int newWidth) {

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "ui/wrap/padding_wrap.h"
#include "ui/abstract_button.h"
#include "base/timer.h"
namespace Window {
@ -43,6 +44,27 @@ namespace Info::Profile {
class EmojiStatusPanel;
class Badge;
class TopicIconView final : public Ui::AbstractButton {
public:
TopicIconView(
QWidget *parent,
not_null<Window::SessionController*> controller,
not_null<Data::ForumTopic*> topic);
private:
using StickerPlayer = HistoryView::StickerPlayer;
void setup(
not_null<Data::ForumTopic*> topic,
Fn<bool()> paused);
void setupPlayer(not_null<Data::ForumTopic*> topic);
void setupImage(not_null<Data::ForumTopic*> topic);
std::shared_ptr<StickerPlayer> _player;
QImage _image;
};
class Cover final : public Ui::FixedHeightWidget {
public:
Cover(
@ -67,8 +89,6 @@ public:
}
private:
using StickerPlayer = HistoryView::StickerPlayer;
Cover(
QWidget *parent,
not_null<PeerData*> peer,
@ -76,9 +96,6 @@ private:
not_null<Window::SessionController*> controller,
rpl::producer<QString> title);
void setupIcon(not_null<Data::ForumTopic*> topic);
void setupIconPlayer(not_null<Data::ForumTopic*> topic);
void setupIconImage(not_null<Data::ForumTopic*> topic);
void setupChildGeometry();
void initViewers(rpl::producer<QString> title);
void refreshStatusText();
@ -95,9 +112,7 @@ private:
int _onlineCount = 0;
object_ptr<Ui::UserpicButton> _userpic;
object_ptr<Ui::RpWidget> _iconView;
std::shared_ptr<StickerPlayer> _iconPlayer;
QImage _iconImage;
object_ptr<TopicIconView> _iconView;
object_ptr<Ui::FlatLabel> _name = { nullptr };
object_ptr<Ui::FlatLabel> _status = { nullptr };
//object_ptr<CoverDropArea> _dropArea = { nullptr };

View file

@ -523,7 +523,7 @@ void Filler::addToggleUnreadMark() {
return;
}
const auto unread = IsUnreadThread(_thread);
if (_thread->asTopic() && !unread) {
if ((_thread->asTopic() || peer->isForum()) && !unread) {
return;
}
const auto weak = base::make_weak(_thread);