2016-05-19 12:03:51 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-05-19 12:03:51 +00:00
|
|
|
*/
|
|
|
|
#include "window/section_widget.h"
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "mainwidget.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2021-08-26 15:02:21 +00:00
|
|
|
#include "ui/chat/chat_theme.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2022-05-27 15:42:05 +00:00
|
|
|
#include "boxes/premium_preview_box.h"
|
2021-08-26 13:25:48 +00:00
|
|
|
#include "data/data_peer.h"
|
2022-04-21 11:06:50 +00:00
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "data/data_document.h"
|
2023-04-17 09:43:08 +00:00
|
|
|
#include "data/data_document_media.h"
|
2021-08-26 13:25:48 +00:00
|
|
|
#include "data/data_changes.h"
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_cloud_themes.h"
|
2022-04-21 15:34:00 +00:00
|
|
|
#include "data/data_message_reactions.h"
|
2022-05-27 19:57:40 +00:00
|
|
|
#include "data/data_peer_values.h"
|
|
|
|
#include "history/history.h"
|
2022-04-21 15:34:00 +00:00
|
|
|
#include "history/history_item.h"
|
2022-05-20 13:12:56 +00:00
|
|
|
#include "settings/settings_premium.h"
|
2021-08-26 13:25:48 +00:00
|
|
|
#include "main/main_session.h"
|
2017-09-16 16:53:41 +00:00
|
|
|
#include "window/section_memento.h"
|
2017-10-03 13:05:58 +00:00
|
|
|
#include "window/window_slide_animation.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2021-08-26 13:25:48 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
#include <rpl/range.h>
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
namespace Window {
|
2021-08-26 13:25:48 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<QString> PeerThemeEmojiValue(
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
return peer->session().changes().peerFlagsValue(
|
|
|
|
peer,
|
|
|
|
Data::PeerUpdate::Flag::ChatThemeEmoji
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return peer->themeEmoji();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-17 09:43:08 +00:00
|
|
|
struct ResolvedPaper {
|
|
|
|
Data::WallPaper paper;
|
|
|
|
std::shared_ptr<Data::DocumentMedia> media;
|
|
|
|
};
|
|
|
|
|
2023-12-16 23:52:55 +00:00
|
|
|
[[nodiscard]] rpl::producer<const Data::WallPaper*> PeerWallPaperMapped(
|
2023-04-17 09:43:08 +00:00
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
return peer->session().changes().peerFlagsValue(
|
|
|
|
peer,
|
|
|
|
Data::PeerUpdate::Flag::ChatWallPaper
|
2023-12-16 23:52:55 +00:00
|
|
|
) | rpl::map([=]() -> rpl::producer<const Data::WallPaper*> {
|
2023-12-21 01:44:34 +00:00
|
|
|
return WallPaperResolved(&peer->owner(), peer->wallPaper());
|
2023-12-16 23:52:55 +00:00
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<std::optional<ResolvedPaper>> PeerWallPaperValue(
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
return PeerWallPaperMapped(
|
|
|
|
peer
|
|
|
|
) | rpl::map([=](const Data::WallPaper *paper)
|
|
|
|
-> rpl::producer<std::optional<ResolvedPaper>> {
|
2023-04-17 09:43:08 +00:00
|
|
|
const auto single = [](std::optional<ResolvedPaper> value) {
|
|
|
|
return rpl::single(std::move(value));
|
|
|
|
};
|
|
|
|
if (!paper) {
|
|
|
|
return single({});
|
|
|
|
}
|
|
|
|
const auto document = paper->document();
|
|
|
|
auto value = ResolvedPaper{
|
|
|
|
*paper,
|
|
|
|
document ? document->createMediaView() : nullptr,
|
|
|
|
};
|
|
|
|
if (!value.media || value.media->loaded(true)) {
|
|
|
|
return single(std::move(value));
|
|
|
|
}
|
|
|
|
paper->loadDocument();
|
|
|
|
return single(
|
|
|
|
value
|
|
|
|
) | rpl::then(document->session().downloaderTaskFinished(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return value.media->loaded(true);
|
|
|
|
}) | rpl::take(1) | rpl::map_to(
|
|
|
|
std::optional<ResolvedPaper>(value)
|
|
|
|
));
|
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
}
|
|
|
|
|
2021-08-26 13:25:48 +00:00
|
|
|
[[nodiscard]] auto MaybeChatThemeDataValueFromPeer(
|
|
|
|
not_null<PeerData*> peer)
|
2021-10-22 18:14:44 +00:00
|
|
|
-> rpl::producer<std::optional<Data::CloudTheme>> {
|
2021-08-26 13:25:48 +00:00
|
|
|
return PeerThemeEmojiValue(
|
|
|
|
peer
|
|
|
|
) | rpl::map([=](const QString &emoji)
|
2021-10-22 18:14:44 +00:00
|
|
|
-> rpl::producer<std::optional<Data::CloudTheme>> {
|
2021-08-26 13:25:48 +00:00
|
|
|
return peer->owner().cloudThemes().themeForEmojiValue(emoji);
|
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
}
|
|
|
|
|
2023-04-18 12:47:31 +00:00
|
|
|
[[nodiscard]] rpl::producer<> DebouncedPaletteValue() {
|
|
|
|
return [=](auto consumer) {
|
|
|
|
auto lifetime = rpl::lifetime();
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
base::has_weak_ptr guard;
|
|
|
|
bool scheduled = false;
|
|
|
|
};
|
|
|
|
const auto state = lifetime.make_state<State>();
|
|
|
|
|
|
|
|
consumer.put_next_copy(rpl::empty);
|
|
|
|
style::PaletteChanged(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (state->scheduled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state->scheduled = true;
|
|
|
|
Ui::PostponeCall(&state->guard, [=] {
|
|
|
|
state->scheduled = false;
|
|
|
|
consumer.put_next_copy(rpl::empty);
|
|
|
|
});
|
|
|
|
}, lifetime);
|
|
|
|
|
|
|
|
return lifetime;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-22 18:14:44 +00:00
|
|
|
struct ResolvedTheme {
|
|
|
|
std::optional<Data::CloudTheme> theme;
|
2023-04-17 09:43:08 +00:00
|
|
|
std::optional<ResolvedPaper> paper;
|
2021-10-22 18:14:44 +00:00
|
|
|
bool dark = false;
|
|
|
|
};
|
|
|
|
|
2021-08-26 13:25:48 +00:00
|
|
|
[[nodiscard]] auto MaybeCloudThemeValueFromPeer(
|
|
|
|
not_null<PeerData*> peer)
|
2021-10-22 18:14:44 +00:00
|
|
|
-> rpl::producer<ResolvedTheme> {
|
2021-08-26 13:25:48 +00:00
|
|
|
return rpl::combine(
|
|
|
|
MaybeChatThemeDataValueFromPeer(peer),
|
2023-04-17 09:43:08 +00:00
|
|
|
PeerWallPaperValue(peer),
|
2021-09-24 15:10:25 +00:00
|
|
|
Theme::IsThemeDarkValue() | rpl::distinct_until_changed()
|
2023-04-17 09:43:08 +00:00
|
|
|
) | rpl::map([](
|
|
|
|
std::optional<Data::CloudTheme> theme,
|
|
|
|
std::optional<ResolvedPaper> paper,
|
2023-04-18 12:47:31 +00:00
|
|
|
bool night) -> rpl::producer<ResolvedTheme> {
|
|
|
|
if (theme || !paper) {
|
|
|
|
return rpl::single<ResolvedTheme>({
|
|
|
|
std::move(theme),
|
|
|
|
std::move(paper),
|
|
|
|
night,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return DebouncedPaletteValue(
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return ResolvedTheme{
|
|
|
|
.paper = paper,
|
|
|
|
.dark = night,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}) | rpl::flatten_latest();
|
2021-08-26 13:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2023-12-21 01:44:34 +00:00
|
|
|
|
|
|
|
rpl::producer<const Data::WallPaper*> WallPaperResolved(
|
|
|
|
not_null<Data::Session*> owner,
|
|
|
|
const Data::WallPaper *paper) {
|
|
|
|
const auto id = paper ? paper->emojiId() : QString();
|
|
|
|
if (id.isEmpty()) {
|
|
|
|
return rpl::single(paper);
|
|
|
|
}
|
|
|
|
const auto themes = &owner->cloudThemes();
|
|
|
|
auto fromThemes = [=](bool force)
|
|
|
|
-> rpl::producer<const Data::WallPaper*> {
|
|
|
|
if (themes->chatThemes().empty() && !force) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return Window::Theme::IsNightModeValue(
|
|
|
|
) | rpl::map([=](bool dark) -> const Data::WallPaper* {
|
|
|
|
const auto &list = themes->chatThemes();
|
|
|
|
const auto i = ranges::find(
|
|
|
|
list,
|
|
|
|
id,
|
|
|
|
&Data::CloudTheme::emoticon);
|
|
|
|
if (i != end(list)) {
|
|
|
|
using Type = Data::CloudThemeType;
|
|
|
|
const auto type = dark ? Type::Dark : Type::Light;
|
|
|
|
const auto j = i->settings.find(type);
|
|
|
|
if (j != end(i->settings) && j->second.paper) {
|
|
|
|
return &*j->second.paper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
if (auto result = fromThemes(false)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
themes->refreshChatThemes();
|
|
|
|
return themes->chatThemesUpdated(
|
|
|
|
) | rpl::take(1) | rpl::map([=] {
|
|
|
|
return fromThemes(true);
|
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2021-08-13 18:18:06 +00:00
|
|
|
AbstractSectionWidget::AbstractSectionWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<SessionController*> controller,
|
2021-08-26 13:25:48 +00:00
|
|
|
rpl::producer<PeerData*> peerForBackground)
|
2021-08-13 18:18:06 +00:00
|
|
|
: RpWidget(parent)
|
|
|
|
, _controller(controller) {
|
2021-08-26 13:25:48 +00:00
|
|
|
std::move(
|
|
|
|
peerForBackground
|
|
|
|
) | rpl::map([=](PeerData *peer) -> rpl::producer<> {
|
|
|
|
if (!peer) {
|
2022-03-11 05:55:21 +00:00
|
|
|
return rpl::single(rpl::empty) | rpl::then(
|
2021-09-01 16:28:02 +00:00
|
|
|
controller->defaultChatTheme()->repaintBackgroundRequests()
|
|
|
|
);
|
2021-08-26 13:25:48 +00:00
|
|
|
}
|
|
|
|
return ChatThemeValueFromPeer(
|
|
|
|
controller,
|
|
|
|
peer
|
2021-08-26 15:02:21 +00:00
|
|
|
) | rpl::map([](const std::shared_ptr<Ui::ChatTheme> &theme) {
|
2022-03-11 05:55:21 +00:00
|
|
|
return rpl::single(rpl::empty) | rpl::then(
|
2021-08-26 13:25:48 +00:00
|
|
|
theme->repaintBackgroundRequests()
|
|
|
|
);
|
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
}) | rpl::flatten_latest() | rpl::start_with_next([=] {
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2021-08-13 18:18:06 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &AbstractSectionWidget::session() const {
|
2019-04-16 14:05:56 +00:00
|
|
|
return _controller->session();
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
SectionWidget::SectionWidget(
|
|
|
|
QWidget *parent,
|
2021-08-13 18:18:06 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2021-08-26 13:25:48 +00:00
|
|
|
rpl::producer<PeerData*> peerForBackground)
|
|
|
|
: AbstractSectionWidget(parent, controller, std::move(peerForBackground)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionWidget::SectionWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<PeerData*> peerForBackground)
|
|
|
|
: AbstractSectionWidget(
|
|
|
|
parent,
|
|
|
|
controller,
|
|
|
|
rpl::single(peerForBackground.get())) {
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
void SectionWidget::setGeometryWithTopMoved(
|
|
|
|
const QRect &newGeometry,
|
|
|
|
int topDelta) {
|
2016-05-19 12:03:51 +00:00
|
|
|
_topDelta = topDelta;
|
|
|
|
bool willBeResized = (size() != newGeometry.size());
|
|
|
|
if (geometry() != newGeometry) {
|
2019-09-13 12:22:54 +00:00
|
|
|
auto weak = Ui::MakeWeak(this);
|
2016-05-19 12:03:51 +00:00
|
|
|
setGeometry(newGeometry);
|
2017-11-30 18:04:13 +00:00
|
|
|
if (!weak) {
|
2017-09-15 17:34:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
|
|
|
if (!willBeResized) {
|
|
|
|
resizeEvent(nullptr);
|
|
|
|
}
|
|
|
|
_topDelta = 0;
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
void SectionWidget::showAnimated(
|
|
|
|
SlideDirection direction,
|
|
|
|
const SectionSlideParams ¶ms) {
|
2022-11-30 12:55:51 +00:00
|
|
|
if (_showAnimation) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
|
|
|
|
showChildren();
|
|
|
|
auto myContentCache = grabForShowAnimation(params);
|
|
|
|
hideChildren();
|
2017-10-03 17:41:44 +00:00
|
|
|
showAnimatedHook(params);
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
_showAnimation = std::make_unique<SlideAnimation>();
|
2016-05-19 12:03:51 +00:00
|
|
|
_showAnimation->setDirection(direction);
|
2016-09-26 12:09:59 +00:00
|
|
|
_showAnimation->setRepaintCallback([this] { update(); });
|
|
|
|
_showAnimation->setFinishedCallback([this] { showFinished(); });
|
2017-09-13 17:01:23 +00:00
|
|
|
_showAnimation->setPixmaps(
|
|
|
|
params.oldContentCache,
|
|
|
|
myContentCache);
|
2016-05-19 12:03:51 +00:00
|
|
|
_showAnimation->setTopBarShadow(params.withTopBarShadow);
|
2017-10-03 17:41:44 +00:00
|
|
|
_showAnimation->setWithFade(params.withFade);
|
2022-02-23 10:53:27 +00:00
|
|
|
_showAnimation->setTopSkip(params.topSkip);
|
2022-05-19 07:51:03 +00:00
|
|
|
_showAnimation->setTopBarMask(params.topMask);
|
2016-05-19 12:03:51 +00:00
|
|
|
_showAnimation->start();
|
|
|
|
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:48:10 +00:00
|
|
|
std::shared_ptr<SectionMemento> SectionWidget::createMemento() {
|
2017-09-16 16:53:41 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
void SectionWidget::showFast() {
|
|
|
|
show();
|
|
|
|
showFinished();
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
QPixmap SectionWidget::grabForShowAnimation(
|
|
|
|
const SectionSlideParams ¶ms) {
|
|
|
|
return Ui::GrabWidget(this);
|
|
|
|
}
|
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
void SectionWidget::PaintBackground(
|
|
|
|
not_null<Window::SessionController*> controller,
|
2021-08-26 15:02:21 +00:00
|
|
|
not_null<Ui::ChatTheme*> theme,
|
2020-06-10 18:08:17 +00:00
|
|
|
not_null<QWidget*> widget,
|
|
|
|
QRect clip) {
|
2023-01-05 10:48:46 +00:00
|
|
|
PaintBackground(
|
|
|
|
theme,
|
|
|
|
widget,
|
|
|
|
controller->content()->height(),
|
|
|
|
controller->content()->backgroundFromY(),
|
|
|
|
clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionWidget::PaintBackground(
|
|
|
|
not_null<Ui::ChatTheme*> theme,
|
|
|
|
not_null<QWidget*> widget,
|
|
|
|
int fillHeight,
|
|
|
|
int fromy,
|
|
|
|
QRect clip) {
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(widget);
|
2023-01-05 10:48:46 +00:00
|
|
|
if (fromy) {
|
|
|
|
p.translate(0, fromy);
|
|
|
|
clip = clip.translated(0, -fromy);
|
|
|
|
}
|
|
|
|
PaintBackground(p, theme, QSize(widget->width(), fillHeight), clip);
|
|
|
|
}
|
2018-01-09 17:08:31 +00:00
|
|
|
|
2023-01-05 10:48:46 +00:00
|
|
|
void SectionWidget::PaintBackground(
|
|
|
|
QPainter &p,
|
|
|
|
not_null<Ui::ChatTheme*> theme,
|
|
|
|
QSize fill,
|
|
|
|
QRect clip) {
|
2021-08-26 15:02:21 +00:00
|
|
|
const auto &background = theme->background();
|
|
|
|
if (background.colorForFill) {
|
|
|
|
p.fillRect(clip, *background.colorForFill);
|
2019-01-17 08:18:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-08-26 15:02:21 +00:00
|
|
|
const auto &gradient = background.gradientForFill;
|
2021-08-26 13:25:48 +00:00
|
|
|
auto state = theme->backgroundState(fill);
|
2021-08-26 15:02:21 +00:00
|
|
|
const auto paintCache = [&](const Ui::CachedBackground &cache) {
|
2021-08-13 17:19:06 +00:00
|
|
|
const auto to = QRect(
|
2023-01-05 10:48:46 +00:00
|
|
|
QPoint(cache.x, cache.y),
|
2021-08-13 18:18:06 +00:00
|
|
|
cache.pixmap.size() / cIntRetinaFactor());
|
2021-09-14 13:36:30 +00:00
|
|
|
if (cache.waitingForNegativePattern) {
|
|
|
|
// While we wait for pattern being loaded we paint just gradient.
|
|
|
|
// But in case of negative patter opacity we just fill-black.
|
|
|
|
p.fillRect(to, Qt::black);
|
|
|
|
} else if (cache.area == fill) {
|
2021-08-13 18:18:06 +00:00
|
|
|
p.drawPixmap(to, cache.pixmap);
|
2021-08-13 17:19:06 +00:00
|
|
|
} else {
|
2021-08-13 18:18:06 +00:00
|
|
|
const auto sx = fill.width() / float64(cache.area.width());
|
|
|
|
const auto sy = fill.height() / float64(cache.area.height());
|
2021-08-13 17:19:06 +00:00
|
|
|
const auto round = [](float64 value) -> int {
|
|
|
|
return (value >= 0.)
|
|
|
|
? int(std::ceil(value))
|
|
|
|
: int(std::floor(value));
|
|
|
|
};
|
|
|
|
const auto sto = QPoint(round(to.x() * sx), round(to.y() * sy));
|
|
|
|
p.drawPixmap(
|
|
|
|
sto.x(),
|
|
|
|
sto.y(),
|
|
|
|
round((to.x() + to.width()) * sx) - sto.x(),
|
|
|
|
round((to.y() + to.height()) * sy) - sto.y(),
|
2021-08-13 18:18:06 +00:00
|
|
|
cache.pixmap);
|
|
|
|
}
|
|
|
|
};
|
2021-08-16 10:24:15 +00:00
|
|
|
const auto hasNow = !state.now.pixmap.isNull();
|
|
|
|
const auto goodNow = hasNow && (state.now.area == fill);
|
2021-08-17 14:35:10 +00:00
|
|
|
const auto useCache = goodNow || !gradient.isNull();
|
2021-08-13 18:18:06 +00:00
|
|
|
if (useCache) {
|
2023-01-05 10:48:46 +00:00
|
|
|
const auto fade = (state.shown < 1. && !gradient.isNull());
|
|
|
|
if (fade) {
|
2021-08-13 18:18:06 +00:00
|
|
|
paintCache(state.was);
|
|
|
|
p.setOpacity(state.shown);
|
2021-08-13 17:19:06 +00:00
|
|
|
}
|
2021-08-13 18:18:06 +00:00
|
|
|
paintCache(state.now);
|
2023-01-05 10:48:46 +00:00
|
|
|
if (fade) {
|
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
2021-08-13 15:39:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-08-26 15:02:21 +00:00
|
|
|
const auto &prepared = background.prepared;
|
2021-08-19 14:22:12 +00:00
|
|
|
if (prepared.isNull()) {
|
2021-08-13 15:39:50 +00:00
|
|
|
return;
|
2021-08-26 15:02:21 +00:00
|
|
|
} else if (background.isPattern) {
|
2021-08-20 13:24:26 +00:00
|
|
|
const auto w = prepared.width() * fill.height() / prepared.height();
|
|
|
|
const auto cx = qCeil(fill.width() / float64(w));
|
|
|
|
const auto cols = (cx / 2) * 2 + 1;
|
|
|
|
const auto xshift = (fill.width() - w * cols) / 2;
|
|
|
|
for (auto i = 0; i != cols; ++i) {
|
|
|
|
p.drawImage(
|
|
|
|
QRect(xshift + i * w, 0, w, fill.height()),
|
|
|
|
prepared,
|
|
|
|
QRect(QPoint(), prepared.size()));
|
|
|
|
}
|
2021-08-26 15:02:21 +00:00
|
|
|
} else if (background.tile) {
|
|
|
|
const auto &tiled = background.preparedForTiled;
|
2021-08-19 14:22:12 +00:00
|
|
|
const auto left = clip.left();
|
|
|
|
const auto top = clip.top();
|
|
|
|
const auto right = clip.left() + clip.width();
|
|
|
|
const auto bottom = clip.top() + clip.height();
|
|
|
|
const auto w = tiled.width() / cRetinaFactor();
|
|
|
|
const auto h = tiled.height() / cRetinaFactor();
|
|
|
|
const auto sx = qFloor(left / w);
|
2023-01-05 10:48:46 +00:00
|
|
|
const auto sy = qFloor(top / h);
|
2021-08-19 14:22:12 +00:00
|
|
|
const auto cx = qCeil(right / w);
|
2023-01-05 10:48:46 +00:00
|
|
|
const auto cy = qCeil(bottom / h);
|
2021-08-13 15:39:50 +00:00
|
|
|
for (auto i = sx; i < cx; ++i) {
|
|
|
|
for (auto j = sy; j < cy; ++j) {
|
2023-01-05 10:48:46 +00:00
|
|
|
p.drawImage(QPointF(i * w, j * h), tiled);
|
2021-08-12 14:51:44 +00:00
|
|
|
}
|
2018-01-09 17:08:31 +00:00
|
|
|
}
|
2021-08-19 14:22:12 +00:00
|
|
|
} else {
|
|
|
|
const auto hq = PainterHighQualityEnabler(p);
|
2021-08-26 15:02:21 +00:00
|
|
|
const auto rects = Ui::ComputeChatBackgroundRects(
|
2021-08-19 14:22:12 +00:00
|
|
|
fill,
|
|
|
|
prepared.size());
|
2023-01-05 10:48:46 +00:00
|
|
|
p.drawImage(rects.to, prepared, rects.from);
|
2018-01-09 17:08:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void SectionWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
if (_showAnimation) {
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2022-02-23 10:53:27 +00:00
|
|
|
_showAnimation->paintContents(p);
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 10:53:27 +00:00
|
|
|
bool SectionWidget::animatingShow() const {
|
|
|
|
return (_showAnimation != nullptr);
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void SectionWidget::showFinished() {
|
2016-05-27 15:45:35 +00:00
|
|
|
_showAnimation.reset();
|
2016-05-19 12:03:51 +00:00
|
|
|
if (isHidden()) return;
|
|
|
|
|
|
|
|
showChildren();
|
|
|
|
showFinishedHook();
|
|
|
|
|
|
|
|
setInnerFocus();
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
rpl::producer<int> SectionWidget::desiredHeight() const {
|
|
|
|
return rpl::single(height());
|
|
|
|
}
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
SectionWidget::~SectionWidget() = default;
|
|
|
|
|
2021-08-27 20:44:47 +00:00
|
|
|
auto ChatThemeValueFromPeer(
|
|
|
|
not_null<SessionController*> controller,
|
|
|
|
not_null<PeerData*> peer)
|
|
|
|
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>> {
|
2021-09-24 15:10:25 +00:00
|
|
|
auto cloud = MaybeCloudThemeValueFromPeer(
|
2021-08-27 20:44:47 +00:00
|
|
|
peer
|
2021-10-22 18:14:44 +00:00
|
|
|
) | rpl::map([=](ResolvedTheme resolved)
|
2021-08-27 20:44:47 +00:00
|
|
|
-> rpl::producer<std::shared_ptr<Ui::ChatTheme>> {
|
2023-04-17 09:43:08 +00:00
|
|
|
if (!resolved.theme && !resolved.paper) {
|
|
|
|
return rpl::single(controller->defaultChatTheme());
|
|
|
|
}
|
|
|
|
const auto theme = resolved.theme.value_or(Data::CloudTheme());
|
|
|
|
const auto paper = resolved.paper
|
|
|
|
? resolved.paper->paper
|
|
|
|
: Data::WallPaper(0);
|
|
|
|
const auto type = resolved.dark
|
|
|
|
? Data::CloudThemeType::Dark
|
|
|
|
: Data::CloudThemeType::Light;
|
|
|
|
if (paper.document()
|
|
|
|
&& resolved.paper->media
|
|
|
|
&& !resolved.paper->media->loaded()
|
|
|
|
&& !controller->chatThemeAlreadyCached(theme, paper, type)) {
|
|
|
|
return rpl::single(controller->defaultChatTheme());
|
|
|
|
}
|
|
|
|
return controller->cachedChatThemeValue(theme, paper, type);
|
2021-08-27 20:44:47 +00:00
|
|
|
}) | rpl::flatten_latest(
|
|
|
|
) | rpl::distinct_until_changed();
|
2021-09-24 15:10:25 +00:00
|
|
|
|
|
|
|
return rpl::combine(
|
|
|
|
std::move(cloud),
|
|
|
|
controller->peerThemeOverrideValue()
|
|
|
|
) | rpl::map([=](
|
|
|
|
std::shared_ptr<Ui::ChatTheme> &&cloud,
|
|
|
|
PeerThemeOverride &&overriden) {
|
2023-04-17 09:43:08 +00:00
|
|
|
return (overriden.peer == peer.get()
|
|
|
|
&& Ui::Emoji::Find(peer->themeEmoji()) != overriden.emoji)
|
2021-09-24 15:10:25 +00:00
|
|
|
? std::move(overriden.theme)
|
|
|
|
: std::move(cloud);
|
|
|
|
});
|
2021-08-27 20:44:47 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:06:50 +00:00
|
|
|
bool ShowSendPremiumError(
|
|
|
|
not_null<SessionController*> controller,
|
|
|
|
not_null<DocumentData*> document) {
|
2023-05-26 16:30:02 +00:00
|
|
|
return ShowSendPremiumError(controller->uiShow(), document);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShowSendPremiumError(
|
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
|
|
|
not_null<DocumentData*> document) {
|
2022-04-21 11:06:50 +00:00
|
|
|
if (!document->isPremiumSticker()
|
2022-06-08 07:26:53 +00:00
|
|
|
|| document->session().premium()) {
|
2022-04-21 11:06:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
2023-05-26 16:30:02 +00:00
|
|
|
ShowStickerPreviewBox(std::move(show), document);
|
2022-04-21 11:06:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:34:00 +00:00
|
|
|
bool ShowReactPremiumError(
|
|
|
|
not_null<SessionController*> controller,
|
|
|
|
not_null<HistoryItem*> item,
|
2022-08-16 11:28:17 +00:00
|
|
|
const Data::ReactionId &id) {
|
2024-01-29 07:07:53 +00:00
|
|
|
if (item->reactionsAreTags()) {
|
|
|
|
if (controller->session().premium()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ShowPremiumPreviewBox(controller, PremiumPreview::TagsForMessages);
|
|
|
|
return true;
|
|
|
|
} else if (controller->session().premium()
|
2023-12-22 02:06:10 +00:00
|
|
|
|| ranges::contains(item->chosenReactions(), id)
|
|
|
|
|| item->history()->peer->isBroadcast()) {
|
2022-04-21 15:34:00 +00:00
|
|
|
return false;
|
2024-01-26 13:10:51 +00:00
|
|
|
} else if (!id.custom()) {
|
|
|
|
return false;
|
2022-04-21 15:34:00 +00:00
|
|
|
}
|
2022-09-06 16:53:42 +00:00
|
|
|
ShowPremiumPreviewBox(controller, PremiumPreview::InfiniteReactions);
|
2022-04-21 15:34:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
} // namespace Window
|