2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-14 11:00:23 +00:00
|
|
|
#include "ui/text/text.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 {
|
2017-03-29 15:09:16 +00:00
|
|
|
|
|
|
|
constexpr auto kPostfix = static_cast<ushort>(0xFE0F);
|
|
|
|
constexpr auto kPanelPerRow = 7;
|
|
|
|
constexpr auto kPanelRowsPerPage = 6;
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
void Init();
|
|
|
|
|
|
|
|
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;
|
2017-03-23 11:56:38 +00:00
|
|
|
One(const QString &id, uint16 x, uint16 y, bool hasPostfix, bool colorizable, EmojiPtr original, const CreationTag &)
|
2017-03-22 09:24:53 +00:00
|
|
|
: _id(id)
|
|
|
|
, _x(x)
|
|
|
|
, _y(y)
|
|
|
|
, _hasPostfix(hasPostfix)
|
|
|
|
, _colorizable(colorizable)
|
|
|
|
, _original(original) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
int index() const;
|
|
|
|
QString toUrl() const {
|
|
|
|
return qsl("emoji://e.") + QString::number(index());
|
|
|
|
}
|
|
|
|
|
|
|
|
int x() const {
|
|
|
|
return _x;
|
|
|
|
}
|
|
|
|
int y() const {
|
|
|
|
return _y;
|
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;
|
|
|
|
const uint16 _x = 0;
|
|
|
|
const uint16 _y = 0;
|
|
|
|
const bool _hasPostfix = false;
|
|
|
|
const bool _colorizable = false;
|
|
|
|
const EmojiPtr _original = nullptr;
|
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-02-15 08:50:11 +00:00
|
|
|
inline int Size(int index = Index()) {
|
|
|
|
int sizes[] = { 18, 22, 27, 36, 45 };
|
|
|
|
return sizes[index];
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
inline QString Filename(int index = Index()) {
|
|
|
|
const char *EmojiNames[] = {
|
|
|
|
":/gui/art/emoji.webp",
|
|
|
|
":/gui/art/emoji_125x.webp",
|
|
|
|
":/gui/art/emoji_150x.webp",
|
|
|
|
":/gui/art/emoji_200x.webp",
|
|
|
|
":/gui/art/emoji_250x.webp",
|
|
|
|
};
|
|
|
|
return QString::fromLatin1(EmojiNames[index]);
|
2014-05-30 08:53:19 +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
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
} // namespace Emoji
|
|
|
|
} // namespace Ui
|