Example #1
0
void InputField::insertEmoji(EmojiPtr emoji, QTextCursor c) {
	QTextImageFormat imageFormat;
	int32 ew = ESize + st::emojiPadding * cIntRetinaFactor() * 2, eh = _st->font->height * cIntRetinaFactor();
	imageFormat.setWidth(ew / cIntRetinaFactor());
	imageFormat.setHeight(eh / cIntRetinaFactor());
	imageFormat.setName(qsl("emoji://e.") + QString::number(emojiKey(emoji), 16));
	imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline);

	static QString objectReplacement(QChar::ObjectReplacementCharacter);
	c.insertText(objectReplacement, imageFormat);
}
Example #2
0
void FlatTextarea::insertEmoji(EmojiPtr emoji, QTextCursor c) {
	c.removeSelectedText();

	QPixmap img(App::emojiSingle(emoji, _st.font->height));
	QString url = qsl("emoji://e.") + QString::number(emojiKey(emoji), 16);
	document()->addResource(QTextDocument::ImageResource, QUrl(url), QVariant(img));
	QTextImageFormat imageFormat;
	imageFormat.setWidth(img.width() / cIntRetinaFactor());
	imageFormat.setHeight(img.height() / cIntRetinaFactor());
	imageFormat.setName(url);
	imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline);
	c.insertImage(imageFormat);
}