2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "base/binary_guard.h"
|
2017-03-31 19:08:25 +00:00
|
|
|
#include "emoji.h"
|
2014-10-07 17:57:57 +00:00
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
namespace Ui {
|
|
|
|
namespace Emoji {
|
2018-12-26 17:05:06 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2019-03-28 08:48:32 +00:00
|
|
|
[[nodiscard]] QString CacheFileFolder();
|
2018-12-26 17:05:06 +00:00
|
|
|
[[nodiscard]] QString SetDataPath(int id);
|
|
|
|
|
|
|
|
} // namespace internal
|
2017-03-29 15:09:16 +00:00
|
|
|
|
2017-11-14 10:26:12 +00:00
|
|
|
constexpr auto kRecentLimit = 42;
|
2017-03-29 15:09:16 +00:00
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
void Init();
|
2018-10-13 17:35:30 +00:00
|
|
|
void Clear();
|
|
|
|
|
2018-10-24 13:29:19 +00:00
|
|
|
void ClearIrrelevantCache();
|
|
|
|
|
2018-12-10 13:26:53 +00:00
|
|
|
struct Set {
|
|
|
|
int id = 0;
|
|
|
|
int postId = 0;
|
2018-12-26 14:00:08 +00:00
|
|
|
int size = 0;
|
2018-12-10 13:26:53 +00:00
|
|
|
QString name;
|
2019-01-02 12:11:13 +00:00
|
|
|
QString previewPath;
|
2018-12-10 13:26:53 +00:00
|
|
|
};
|
|
|
|
|
2018-12-27 08:01:03 +00:00
|
|
|
// Thread safe, callback is called on main thread.
|
|
|
|
void SwitchToSet(int id, Fn<void(bool)> callback);
|
|
|
|
|
2018-12-10 13:26:53 +00:00
|
|
|
std::vector<Set> Sets();
|
|
|
|
int CurrentSetId();
|
2018-12-26 14:00:08 +00:00
|
|
|
bool SetIsReady(int id);
|
2018-12-10 13:26:53 +00:00
|
|
|
rpl::producer<> Updated();
|
|
|
|
|
2018-10-13 17:35:30 +00:00
|
|
|
int GetSizeNormal();
|
|
|
|
int GetSizeLarge();
|
2017-02-15 08:50:11 +00:00
|
|
|
|
|
|
|
class One {
|
2017-03-22 09:24:53 +00:00
|
|
|
struct CreationTag {
|
|
|
|
};
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
public:
|
2017-02-25 20:35:55 +00:00
|
|
|
One(One &&other) = default;
|
2018-10-13 17:35:30 +00:00
|
|
|
One(const QString &id, EmojiPtr original, uint32 index, bool hasPostfix, bool colorizable, const CreationTag &)
|
2017-03-22 09:24:53 +00:00
|
|
|
: _id(id)
|
2018-10-13 17:35:30 +00:00
|
|
|
, _original(original)
|
|
|
|
, _index(index)
|
2017-03-22 09:24:53 +00:00
|
|
|
, _hasPostfix(hasPostfix)
|
2018-10-13 17:35:30 +00:00
|
|
|
, _colorizable(colorizable) {
|
2017-03-22 09:24:53 +00:00
|
|
|
Expects(!_colorizable || !colored());
|
|
|
|
}
|
2017-02-25 20:35:55 +00:00
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
QString id() const {
|
|
|
|
return _id;
|
2015-05-12 15:01:49 +00:00
|
|
|
}
|
2017-02-15 08:50:11 +00:00
|
|
|
QString text() const {
|
|
|
|
return hasPostfix() ? (_id + QChar(kPostfix)) : _id;
|
2015-05-12 15:01:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
bool colored() const {
|
|
|
|
return (_original != nullptr);
|
|
|
|
}
|
|
|
|
EmojiPtr original() const {
|
|
|
|
return _original ? _original : this;
|
|
|
|
}
|
|
|
|
QString nonColoredId() const {
|
|
|
|
return original()->id();
|
2015-05-08 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
bool hasPostfix() const {
|
|
|
|
return _hasPostfix;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasVariants() const {
|
|
|
|
return _colorizable || colored();
|
2015-05-08 12:45:14 +00:00
|
|
|
}
|
2017-02-15 08:50:11 +00:00
|
|
|
int variantsCount() const;
|
|
|
|
int variantIndex(EmojiPtr variant) const;
|
|
|
|
EmojiPtr variant(int index) const;
|
|
|
|
|
2018-10-13 17:35:30 +00:00
|
|
|
int index() const {
|
|
|
|
return _index;
|
2017-02-15 08:50:11 +00:00
|
|
|
}
|
2018-10-13 17:35:30 +00:00
|
|
|
int sprite() const {
|
|
|
|
return int(_index >> 9);
|
2017-02-15 08:50:11 +00:00
|
|
|
}
|
2018-10-13 17:35:30 +00:00
|
|
|
int row() const {
|
|
|
|
return int((_index >> 5) & 0x0FU);
|
|
|
|
}
|
|
|
|
int column() const {
|
|
|
|
return int(_index & 0x1FU);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString toUrl() const {
|
|
|
|
return qsl("emoji://e.") + QString::number(index());
|
2015-05-08 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
private:
|
2017-02-25 20:35:55 +00:00
|
|
|
const QString _id;
|
2018-10-13 17:35:30 +00:00
|
|
|
const EmojiPtr _original = nullptr;
|
|
|
|
const uint32 _index = 0;
|
2017-02-25 20:35:55 +00:00
|
|
|
const bool _hasPostfix = false;
|
|
|
|
const bool _colorizable = false;
|
2017-02-15 08:50:11 +00:00
|
|
|
|
2017-03-31 19:08:25 +00:00
|
|
|
friend void internal::Init();
|
2017-02-15 08:50:11 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline EmojiPtr FromUrl(const QString &url) {
|
|
|
|
auto start = qstr("emoji://e.");
|
|
|
|
if (url.startsWith(start)) {
|
|
|
|
return internal::ByIndex(url.midRef(start.size()).toInt()); // skip emoji://e.
|
|
|
|
}
|
|
|
|
return nullptr;
|
2015-05-08 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
2017-02-17 17:31:46 +00:00
|
|
|
inline EmojiPtr Find(const QChar *start, const QChar *end, int *outLength = nullptr) {
|
|
|
|
return internal::Find(start, end, outLength);
|
2017-02-15 08:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline EmojiPtr Find(const QString &text, int *outLength = nullptr) {
|
|
|
|
return Find(text.constBegin(), text.constEnd(), outLength);
|
|
|
|
}
|
|
|
|
|
2017-07-25 18:16:37 +00:00
|
|
|
QString IdFromOldKey(uint64 oldKey);
|
2016-01-09 11:24:16 +00:00
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
inline EmojiPtr FromOldKey(uint64 oldKey) {
|
|
|
|
return Find(IdFromOldKey(oldKey));
|
2016-01-09 11:24:16 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
inline int ColorIndexFromCode(uint32 code) {
|
|
|
|
switch (code) {
|
2017-07-25 18:16:37 +00:00
|
|
|
case 0xD83CDFFBU: return 1;
|
|
|
|
case 0xD83CDFFCU: return 2;
|
|
|
|
case 0xD83CDFFDU: return 3;
|
|
|
|
case 0xD83CDFFEU: return 4;
|
|
|
|
case 0xD83CDFFFU: return 5;
|
2015-05-08 12:45:14 +00:00
|
|
|
}
|
2017-02-15 08:50:11 +00:00
|
|
|
return 0;
|
2015-05-08 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
inline int ColorIndexFromOldKey(uint64 oldKey) {
|
|
|
|
return ColorIndexFromCode(uint32(oldKey & 0xFFFFFFFFLLU));
|
|
|
|
}
|
2015-04-30 13:56:33 +00:00
|
|
|
|
2017-07-25 18:16:37 +00:00
|
|
|
void ReplaceInText(TextWithEntities &result);
|
|
|
|
RecentEmojiPack &GetRecent();
|
|
|
|
void AddRecent(EmojiPtr emoji);
|
2017-03-28 12:30:38 +00:00
|
|
|
|
2018-10-13 17:35:30 +00:00
|
|
|
const QPixmap &SinglePixmap(EmojiPtr emoji, int fontHeight);
|
|
|
|
void Draw(QPainter &p, EmojiPtr emoji, int size, int x, int y);
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
} // namespace Emoji
|
|
|
|
} // namespace Ui
|