mirror of https://github.com/procxx/kepka.git
Show full emoji in fields in all scales.
This commit is contained in:
parent
bd7cee2252
commit
97a239a8b4
|
@ -79,7 +79,7 @@ auto TouchbarEmoji = (Instance*)nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto MainEmojiMap = std::map<int, QPixmap>();
|
auto MainEmojiMap = std::map<int, QPixmap>();
|
||||||
auto OtherEmojiMap = std::map<int, std::map<int, QPixmap>>();
|
auto OtherEmojiMap = base::flat_map<int, std::map<int, QPixmap>>();
|
||||||
|
|
||||||
int RowsCount(int index) {
|
int RowsCount(int index) {
|
||||||
if (index + 1 < SpritesCount) {
|
if (index + 1 < SpritesCount) {
|
||||||
|
@ -880,32 +880,33 @@ rpl::producer<> UpdatedRecent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const QPixmap &SinglePixmap(EmojiPtr emoji, int fontHeight) {
|
const QPixmap &SinglePixmap(EmojiPtr emoji, int fontHeight) {
|
||||||
auto &map = (fontHeight == st::msgFont->height)
|
auto &map = (fontHeight == st::msgFont->height * cIntRetinaFactor())
|
||||||
? MainEmojiMap
|
? MainEmojiMap
|
||||||
: OtherEmojiMap[fontHeight];
|
: OtherEmojiMap[fontHeight];
|
||||||
auto i = map.find(emoji->index());
|
auto i = map.find(emoji->index());
|
||||||
if (i == end(map)) {
|
if (i != end(map)) {
|
||||||
auto image = QImage(
|
return i->second;
|
||||||
SizeNormal + st::emojiPadding * cIntRetinaFactor() * 2,
|
|
||||||
fontHeight * cIntRetinaFactor(),
|
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
image.setDevicePixelRatio(cRetinaFactor());
|
|
||||||
image.fill(Qt::transparent);
|
|
||||||
{
|
|
||||||
QPainter p(&image);
|
|
||||||
PainterHighQualityEnabler hq(p);
|
|
||||||
Draw(
|
|
||||||
p,
|
|
||||||
emoji,
|
|
||||||
SizeNormal,
|
|
||||||
st::emojiPadding * cIntRetinaFactor(),
|
|
||||||
(fontHeight * cIntRetinaFactor() - SizeNormal) / 2);
|
|
||||||
}
|
|
||||||
i = map.emplace(
|
|
||||||
emoji->index(),
|
|
||||||
App::pixmapFromImageInPlace(std::move(image))).first;
|
|
||||||
}
|
}
|
||||||
return i->second;
|
auto image = QImage(
|
||||||
|
SizeNormal + st::emojiPadding * 2,
|
||||||
|
fontHeight,
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
image.setDevicePixelRatio(cRetinaFactor());
|
||||||
|
image.fill(Qt::transparent);
|
||||||
|
{
|
||||||
|
QPainter p(&image);
|
||||||
|
PainterHighQualityEnabler hq(p);
|
||||||
|
Draw(
|
||||||
|
p,
|
||||||
|
emoji,
|
||||||
|
SizeNormal,
|
||||||
|
st::emojiPadding * cIntRetinaFactor(),
|
||||||
|
(fontHeight - SizeNormal) / 2);
|
||||||
|
}
|
||||||
|
return map.emplace(
|
||||||
|
emoji->index(),
|
||||||
|
App::pixmapFromImageInPlace(std::move(image))
|
||||||
|
).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw(QPainter &p, EmojiPtr emoji, int size, int x, int y) {
|
void Draw(QPainter &p, EmojiPtr emoji, int size, int x, int y) {
|
||||||
|
|
|
@ -82,7 +82,9 @@ QVariant InputDocument::loadResource(int type, const QUrl &name) {
|
||||||
}
|
}
|
||||||
auto result = [&] {
|
auto result = [&] {
|
||||||
if (const auto emoji = Ui::Emoji::FromUrl(name.toDisplayString())) {
|
if (const auto emoji = Ui::Emoji::FromUrl(name.toDisplayString())) {
|
||||||
const auto height = _st.font->height;
|
const auto height = std::max(
|
||||||
|
_st.font->height * cIntRetinaFactor(),
|
||||||
|
Ui::Emoji::GetSizeNormal());
|
||||||
return QVariant(Ui::Emoji::SinglePixmap(emoji, height));
|
return QVariant(Ui::Emoji::SinglePixmap(emoji, height));
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -614,9 +616,9 @@ QString AccumulateText(Iterator begin, Iterator end) {
|
||||||
|
|
||||||
QTextImageFormat PrepareEmojiFormat(EmojiPtr emoji, const QFont &font) {
|
QTextImageFormat PrepareEmojiFormat(EmojiPtr emoji, const QFont &font) {
|
||||||
const auto factor = cIntRetinaFactor();
|
const auto factor = cIntRetinaFactor();
|
||||||
const auto width = Ui::Emoji::GetSizeNormal()
|
const auto size = Ui::Emoji::GetSizeNormal();
|
||||||
+ st::emojiPadding * factor * 2;
|
const auto width = size + st::emojiPadding * factor * 2;
|
||||||
const auto height = QFontMetrics(font).height() * factor;
|
const auto height = std::max(QFontMetrics(font).height() * factor, size);
|
||||||
auto result = QTextImageFormat();
|
auto result = QTextImageFormat();
|
||||||
result.setWidth(width / factor);
|
result.setWidth(width / factor);
|
||||||
result.setHeight(height / factor);
|
result.setHeight(height / factor);
|
||||||
|
@ -641,7 +643,7 @@ void RemoveDocumentTags(
|
||||||
auto cursor = QTextCursor(document->docHandle(), from);
|
auto cursor = QTextCursor(document->docHandle(), from);
|
||||||
cursor.setPosition(end, QTextCursor::KeepAnchor);
|
cursor.setPosition(end, QTextCursor::KeepAnchor);
|
||||||
|
|
||||||
QTextCharFormat format;
|
auto format = QTextCharFormat();
|
||||||
format.setProperty(kTagProperty, QString());
|
format.setProperty(kTagProperty, QString());
|
||||||
format.setProperty(kReplaceTagId, QString());
|
format.setProperty(kReplaceTagId, QString());
|
||||||
format.setForeground(st.textFg);
|
format.setForeground(st.textFg);
|
||||||
|
|
Loading…
Reference in New Issue