tdesktop/Telegram/SourceFiles/ui/chat/message_bar.h

119 lines
2.9 KiB
C
Raw Normal View History

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;
std::any context;
2020-10-10 09:15:37 +00:00
QImage preview;
style::margins margins;
2020-10-10 09:15:37 +00:00
};
class MessageBar final {
public:
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;
}
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 &currentContent,
const MessageBarContent &nextContent);
const style::MessageBar &_st;
Ui::RpWidget _widget;
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;
bool _customEmojiRepaintScheduled = false;
2020-10-10 09:15:37 +00:00
};
} // namespace Ui