2020-10-10 09:15:37 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/rp_widget.h"
|
2020-10-12 15:05:54 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
|
|
|
|
class Painter;
|
|
|
|
|
|
|
|
namespace style {
|
|
|
|
struct MessageBar;
|
|
|
|
} // namespace style
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
struct MessageBarContent {
|
2020-10-20 11:37:03 +00:00
|
|
|
int index = 0;
|
|
|
|
int count = 1;
|
2020-10-10 09:15:37 +00:00
|
|
|
QString title;
|
|
|
|
TextWithEntities text;
|
2022-07-04 08:49:31 +00:00
|
|
|
std::any context;
|
2020-10-10 09:15:37 +00:00
|
|
|
QImage preview;
|
2022-04-22 13:07:10 +00:00
|
|
|
style::margins margins;
|
2020-10-10 09:15:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MessageBar final {
|
|
|
|
public:
|
2022-07-04 08:49:31 +00:00
|
|
|
MessageBar(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
const style::MessageBar &st,
|
|
|
|
Fn<bool()> customEmojiPaused);
|
2020-10-10 09:15:37 +00:00
|
|
|
|
|
|
|
void set(MessageBarContent &&content);
|
|
|
|
void set(rpl::producer<MessageBarContent> content);
|
|
|
|
|
|
|
|
[[nodiscard]] not_null<Ui::RpWidget*> widget() {
|
|
|
|
return &_widget;
|
|
|
|
}
|
|
|
|
|
2022-07-06 06:10:02 +00:00
|
|
|
void customEmojiRepaint();
|
2020-10-10 09:15:37 +00:00
|
|
|
void finishAnimating();
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum class BodyAnimation : char {
|
|
|
|
Full,
|
|
|
|
Text,
|
|
|
|
None,
|
|
|
|
};
|
|
|
|
struct Animation {
|
|
|
|
Ui::Animations::Simple bodyMoved;
|
|
|
|
Ui::Animations::Simple imageShown;
|
2020-10-20 11:37:03 +00:00
|
|
|
Ui::Animations::Simple barScroll;
|
|
|
|
Ui::Animations::Simple barTop;
|
2020-10-10 09:15:37 +00:00
|
|
|
QPixmap bodyOrTextFrom;
|
|
|
|
QPixmap bodyOrTextTo;
|
2020-10-23 08:08:43 +00:00
|
|
|
QPixmap titleSame;
|
|
|
|
QPixmap titleFrom;
|
|
|
|
QPixmap titleTo;
|
2020-10-10 09:15:37 +00:00
|
|
|
QPixmap imageFrom;
|
|
|
|
QPixmap imageTo;
|
|
|
|
BodyAnimation bodyAnimation = BodyAnimation::None;
|
|
|
|
RectPart movingTo = RectPart::None;
|
|
|
|
};
|
2020-10-20 11:37:03 +00:00
|
|
|
struct BarState {
|
|
|
|
float64 scroll = 0.;
|
|
|
|
float64 size = 0.;
|
|
|
|
float64 skip = 0.;
|
|
|
|
float64 offset = 0.;
|
|
|
|
};
|
2020-10-10 09:15:37 +00:00
|
|
|
void setup();
|
|
|
|
void paint(Painter &p);
|
2020-10-20 11:37:03 +00:00
|
|
|
void paintLeftBar(Painter &p);
|
2020-10-10 09:15:37 +00:00
|
|
|
void tweenTo(MessageBarContent &&content);
|
|
|
|
void updateFromContent(MessageBarContent &&content);
|
|
|
|
[[nodiscard]] QPixmap prepareImage(const QImage &preview);
|
|
|
|
|
|
|
|
[[nodiscard]] QRect imageRect() const;
|
2020-10-23 08:08:43 +00:00
|
|
|
[[nodiscard]] QRect titleRangeRect(int from, int till) const;
|
2020-10-10 09:15:37 +00:00
|
|
|
[[nodiscard]] QRect bodyRect(bool withImage) const;
|
|
|
|
[[nodiscard]] QRect bodyRect() const;
|
|
|
|
[[nodiscard]] QRect textRect() const;
|
|
|
|
|
|
|
|
auto makeGrabGuard();
|
|
|
|
[[nodiscard]] QPixmap grabBodyOrTextPart(BodyAnimation type);
|
2020-10-23 08:08:43 +00:00
|
|
|
[[nodiscard]] QPixmap grabTitleBase(int till);
|
|
|
|
[[nodiscard]] QPixmap grabTitlePart(int from);
|
|
|
|
[[nodiscard]] QPixmap grabTitleRange(int from, int till);
|
2020-10-10 09:15:37 +00:00
|
|
|
[[nodiscard]] QPixmap grabImagePart();
|
|
|
|
[[nodiscard]] QPixmap grabBodyPart();
|
|
|
|
[[nodiscard]] QPixmap grabTextPart();
|
|
|
|
|
2020-10-20 11:37:03 +00:00
|
|
|
[[nodiscard]] BarState countBarState(int index) const;
|
|
|
|
[[nodiscard]] BarState countBarState() const;
|
|
|
|
void ensureGradientsCreated(int size);
|
|
|
|
|
2020-10-10 09:15:37 +00:00
|
|
|
[[nodiscard]] static BodyAnimation DetectBodyAnimationType(
|
|
|
|
Animation *currentAnimation,
|
|
|
|
const MessageBarContent ¤tContent,
|
|
|
|
const MessageBarContent &nextContent);
|
|
|
|
|
|
|
|
const style::MessageBar &_st;
|
|
|
|
Ui::RpWidget _widget;
|
2022-07-04 08:49:31 +00:00
|
|
|
Fn<bool()> _customEmojiPaused;
|
2020-10-10 09:15:37 +00:00
|
|
|
MessageBarContent _content;
|
|
|
|
rpl::lifetime _contentLifetime;
|
|
|
|
Ui::Text::String _title, _text;
|
2020-10-20 11:37:03 +00:00
|
|
|
QPixmap _image, _topBarGradient, _bottomBarGradient;
|
2020-10-10 09:15:37 +00:00
|
|
|
std::unique_ptr<Animation> _animation;
|
2022-07-06 06:10:02 +00:00
|
|
|
bool _customEmojiRepaintScheduled = false;
|
2020-10-10 09:15:37 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|