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
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/emoji_box.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-08 14:43:10 +00:00
|
|
|
#include "lang.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
struct EmojiReplace {
|
|
|
|
uint32 code;
|
|
|
|
const char *replace;
|
|
|
|
};
|
|
|
|
|
|
|
|
// copied from codegen_emoji
|
|
|
|
EmojiReplace Replaces[] = {
|
|
|
|
{ 0xD83DDE0AU, ":-)" },
|
|
|
|
{ 0xD83DDE0DU, "8-)" },
|
|
|
|
{ 0x2764U, "<3" },
|
|
|
|
{ 0xD83DDC8BU, ":kiss:" },
|
|
|
|
{ 0xD83DDE01U, ":grin:" },
|
|
|
|
{ 0xD83DDE02U, ":joy:" },
|
|
|
|
{ 0xD83DDE1AU, ":-*" },
|
|
|
|
{ 0xD83DDE06U, "xD" },
|
|
|
|
{ 0xD83DDC4DU, ":like:" },
|
|
|
|
{ 0xD83DDC4EU, ":dislike:" },
|
|
|
|
{ 0x261DU, ":up:" },
|
|
|
|
{ 0x270CU, ":v:" },
|
|
|
|
{ 0xD83DDC4CU, ":ok:" },
|
|
|
|
{ 0xD83DDE0EU, "B-)" },
|
|
|
|
{ 0xD83DDE03U, ":-D" },
|
|
|
|
{ 0xD83DDE09U, ";-)" },
|
|
|
|
{ 0xD83DDE1CU, ";-P" },
|
|
|
|
{ 0xD83DDE0BU, ":-p" },
|
|
|
|
{ 0xD83DDE14U, "3(" },
|
|
|
|
{ 0xD83DDE1EU, ":-(" },
|
|
|
|
{ 0xD83DDE0FU, ":]" },
|
|
|
|
{ 0xD83DDE22U, ":'(" },
|
|
|
|
{ 0xD83DDE2DU, ":_(" },
|
|
|
|
{ 0xD83DDE29U, ":((" },
|
|
|
|
{ 0xD83DDE28U, ":o" },
|
|
|
|
{ 0xD83DDE10U, ":|" },
|
|
|
|
{ 0xD83DDE0CU, "3-)" },
|
|
|
|
{ 0xD83DDE20U, ">(" },
|
|
|
|
{ 0xD83DDE21U, ">((" },
|
|
|
|
{ 0xD83DDE07U, "O:)" },
|
|
|
|
{ 0xD83DDE30U, ";o" },
|
|
|
|
{ 0xD83DDE33U, "8|" },
|
|
|
|
{ 0xD83DDE32U, "8o" },
|
|
|
|
{ 0xD83DDE37U, ":X" },
|
|
|
|
{ 0xD83DDE08U, "}:)" },
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr auto kReplacesCount = base::array_size(Replaces);
|
|
|
|
constexpr auto kReplacesInRow = 7;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
EmojiBox::EmojiBox(QWidget*) : _esize(Ui::Emoji::Size(Ui::Emoji::Index() + 1)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void EmojiBox::prepare() {
|
|
|
|
setTitle(lang(lng_settings_emoji_list));
|
2014-05-30 08:53:19 +00:00
|
|
|
fillBlocks();
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
addButton(lang(lng_close), [this] { closeBox(); });
|
2016-10-31 12:29:26 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_blockHeight = st::emojiReplaceInnerHeight;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(_blocks[0].size() * st::emojiReplaceWidth + 2 * st::emojiReplacePadding, st::emojiReplacePadding + _blocks.size() * st::emojiReplaceHeight + (st::emojiReplaceHeight - _blockHeight) + st::emojiReplacePadding);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiBox::fillBlocks() {
|
|
|
|
BlockRow currentRow;
|
2017-02-15 08:50:11 +00:00
|
|
|
currentRow.reserve(kReplacesInRow);
|
|
|
|
for (uint32 i = 0; i < kReplacesCount; ++i) {
|
|
|
|
auto emoji = Ui::Emoji::FromOldKey(Replaces[i].code);
|
|
|
|
if (!emoji) continue;
|
|
|
|
|
|
|
|
if (emoji->hasVariants()) {
|
|
|
|
auto it = cEmojiVariants().constFind(emoji->nonColoredId());
|
2015-05-12 15:01:49 +00:00
|
|
|
if (it != cEmojiVariants().cend()) {
|
2017-02-15 08:50:11 +00:00
|
|
|
emoji = emoji->variant(it.value());
|
2015-05-12 15:01:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
Block block(emoji, QString::fromUtf8(Replaces[i].replace));
|
2014-05-30 08:53:19 +00:00
|
|
|
currentRow.push_back(block);
|
2017-02-15 08:50:11 +00:00
|
|
|
if (uint32(currentRow.size()) == kReplacesInRow) {
|
2014-05-30 08:53:19 +00:00
|
|
|
_blocks.push_back(currentRow);
|
|
|
|
currentRow.resize(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentRow.size()) {
|
|
|
|
_blocks.push_back(currentRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::emojiTextFont);
|
|
|
|
p.setPen(st::boxTextFg);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto top = st::emojiReplacePadding + (st::emojiReplaceHeight - _blockHeight) / 2;
|
2015-04-02 10:33:19 +00:00
|
|
|
for (Blocks::const_iterator i = _blocks.cbegin(), e = _blocks.cend(); i != e; ++i) {
|
|
|
|
int32 rowSize = i->size(), left = (width() - rowSize * st::emojiReplaceWidth) / 2;
|
|
|
|
for (BlockRow::const_iterator j = i->cbegin(), en = i->cend(); j != en; ++j) {
|
|
|
|
if (j->emoji) {
|
2017-02-15 08:50:11 +00:00
|
|
|
p.drawPixmap(QPoint(left + (st::emojiReplaceWidth - (_esize / cIntRetinaFactor())) / 2, top + (st::emojiReplaceHeight - _blockHeight) / 2), App::emojiLarge(), QRect(j->emoji->x() * _esize, j->emoji->y() * _esize, _esize, _esize));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
QRect trect(left, top + (st::emojiReplaceHeight + _blockHeight) / 2 - st::emojiTextFont->height, st::emojiReplaceWidth, st::emojiTextFont->height);
|
|
|
|
p.drawText(trect, j->text, QTextOption(Qt::AlignHCenter | Qt::AlignTop));
|
|
|
|
left += st::emojiReplaceWidth;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
top += st::emojiReplaceHeight;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|