2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 10:47:11 +00:00
tdesktop/Telegram/SourceFiles/ui/unread_badge.h

113 lines
2.4 KiB
C
Raw Permalink Normal View History

2017-12-17 15:04:47 +04:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2017-12-17 15:04:47 +04:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2017-12-17 15:04:47 +04:00
*/
#pragma once
2024-12-10 20:59:32 +04:00
#include "ui/text/text_custom_emoji.h"
2017-12-17 15:04:47 +04:00
#include "ui/rp_widget.h"
2024-12-10 20:59:32 +04:00
namespace style {
struct VerifiedBadge;
} // namespace style
2017-12-17 15:04:47 +04:00
namespace Ui {
class UnreadBadge : public RpWidget {
public:
using RpWidget::RpWidget;
void setText(const QString &text, bool active);
2019-05-26 14:08:34 +02:00
int textBaseline() const;
2017-12-17 15:04:47 +04:00
protected:
void paintEvent(QPaintEvent *e) override;
private:
QString _text;
bool _active = false;
};
struct BotVerifyDetails {
2024-12-19 17:15:29 +04:00
UserId botId = 0;
DocumentId iconId = 0;
2024-12-10 20:59:32 +04:00
TextWithEntities description;
explicit operator bool() const {
return iconId != 0;
2024-12-10 20:59:32 +04:00
}
friend inline bool operator==(
const BotVerifyDetails &,
const BotVerifyDetails &) = default;
2024-12-10 20:59:32 +04:00
};
class PeerBadge {
public:
PeerBadge();
~PeerBadge();
struct Descriptor {
not_null<PeerData*> peer;
QRect rectForName;
int nameWidth = 0;
int outerWidth = 0;
const style::icon *verified = nullptr;
const style::icon *premium = nullptr;
const style::color *scam = nullptr;
2025-05-27 18:05:36 +04:00
const style::color *direct = nullptr;
2022-08-31 12:29:09 +04:00
const style::color *premiumFg = nullptr;
Fn<void()> customEmojiRepaint;
crl::time now = 0;
bool prioritizeVerification = false;
bool bothVerifyAndStatus = false;
bool paused = false;
};
int drawGetWidth(Painter &p, Descriptor &&descriptor);
void unload();
[[nodiscard]] bool ready(const BotVerifyDetails *details) const;
2024-12-10 20:59:32 +04:00
void set(
not_null<const BotVerifyDetails*> details,
2024-12-10 20:59:32 +04:00
Text::CustomEmojiFactory factory,
Fn<void()> repaint);
// How much horizontal space the badge took.
int drawVerified(
QPainter &p,
QPoint position,
const style::VerifiedBadge &st);
private:
2023-10-13 10:04:29 +04:00
struct EmojiStatus;
struct BotVerifiedData;
2024-12-10 20:59:32 +04:00
2025-05-27 18:05:36 +04:00
int drawTextBadge(Painter &p, const Descriptor &descriptor);
int drawVerifyCheck(Painter &p, const Descriptor &descriptor);
int drawPremiumEmojiStatus(Painter &p, const Descriptor &descriptor);
int drawPremiumStar(Painter &p, const Descriptor &descriptor);
std::unique_ptr<EmojiStatus> _emojiStatus;
mutable std::unique_ptr<BotVerifiedData> _botVerifiedData;
2019-06-23 14:18:33 +02:00
};
2025-05-27 18:05:36 +04:00
enum class TextBadgeType : uchar {
Scam,
Fake,
Direct,
};
QSize TextBadgeSize(TextBadgeType type);
void DrawTextBadge(
TextBadgeType,
2019-06-23 14:18:33 +02:00
Painter &p,
QRect rect,
int outerWidth,
const style::color &color);
2017-12-17 15:04:47 +04:00
} // namespace Ui