Add initial read-only emoji support

This commit is contained in:
Konstantinos Sideris 2017-04-19 19:38:39 +03:00
parent e680865593
commit f046dc8ac6
18 changed files with 41 additions and 12 deletions

View File

@ -63,6 +63,11 @@ Here is a screen shot to get a feel for the UI, but things will probably change.
![nheko](https://dl.dropboxusercontent.com/s/fw94dkpmr7azvmm/nheko.png)
### Third party
- [Emoji One](http://emojione.com)
- [Open Sans](https://fonts.google.com/specimen/Open+Sans)
### License

View File

@ -42,6 +42,8 @@ private:
void generateBody(const QString &userid, const QString &color, const QString &body);
void generateTimestamp(const QDateTime &time);
QString replaceEmoji(const QString &body);
void setupLayout();
QHBoxLayout *top_layout_;

Binary file not shown.

View File

@ -14,15 +14,17 @@
</qresource>
<qresource prefix="/fonts">
<file>fonts/OpenSans-Light.ttf</file>
<file>fonts/OpenSans-LightItalic.ttf</file>
<file>fonts/OpenSans-Regular.ttf</file>
<file>fonts/OpenSans-Italic.ttf</file>
<file>fonts/OpenSans-Bold.ttf</file>
<file>fonts/OpenSans-BoldItalic.ttf</file>
<file>fonts/OpenSans-Semibold.ttf</file>
<file>fonts/OpenSans-SemiboldItalic.ttf</file>
<file>fonts/OpenSans-ExtraBold.ttf</file>
<file>fonts/OpenSans-ExtraBoldItalic.ttf</file>
<file>fonts/OpenSans/OpenSans-Light.ttf</file>
<file>fonts/OpenSans/OpenSans-LightItalic.ttf</file>
<file>fonts/OpenSans/OpenSans-Regular.ttf</file>
<file>fonts/OpenSans/OpenSans-Italic.ttf</file>
<file>fonts/OpenSans/OpenSans-Bold.ttf</file>
<file>fonts/OpenSans/OpenSans-BoldItalic.ttf</file>
<file>fonts/OpenSans/OpenSans-Semibold.ttf</file>
<file>fonts/OpenSans/OpenSans-SemiboldItalic.ttf</file>
<file>fonts/OpenSans/OpenSans-ExtraBold.ttf</file>
<file>fonts/OpenSans/OpenSans-ExtraBoldItalic.ttf</file>
<file>fonts/EmojiOne/emojione-android.ttf</file>
</qresource>
</RCC>

View File

@ -70,7 +70,7 @@ void HistoryViewItem::generateBody(const QString &body)
" </span>"
"</body>"
"</html>");
content_label_->setText(content.arg(body));
content_label_->setText(content.arg(replaceEmoji(body)));
content_label_->setTextInteractionFlags(Qt::TextSelectableByMouse);
}
@ -94,7 +94,7 @@ void HistoryViewItem::generateBody(const QString &userid, const QString &color,
" </span>"
"</body>"
"</html>");
content_label_->setText(content.arg(color).arg(sender).arg(body));
content_label_->setText(content.arg(color).arg(sender).arg(replaceEmoji(body)));
content_label_->setTextInteractionFlags(Qt::TextSelectableByMouse);
}
@ -137,6 +137,23 @@ void HistoryViewItem::setupLayout()
setLayout(top_layout_);
}
QString HistoryViewItem::replaceEmoji(const QString &body)
{
QString fmtBody = "";
for (auto &c : body) {
auto code = c.unicode();
// TODO: A map should be used with the unicode codes supported by emoji one
if (code > 127)
fmtBody += "<span style=\"font-family: Emoji One; font-size: 16px\">" + QString(c) + "</span>";
else
fmtBody += c;
}
return fmtBody;
}
HistoryViewItem::~HistoryViewItem()
{
}

View File

@ -24,6 +24,8 @@
TextInputWidget::TextInputWidget(QWidget *parent)
: QWidget(parent)
{
setFont(QFont("Emoji One"));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setCursor(Qt::ArrowCursor);
setStyleSheet("background-color: #f8fbfe; height: 45px;");

View File

@ -36,6 +36,7 @@ int main(int argc, char *argv[])
QFontDatabase::addApplicationFont(":/fonts/OpenSans-SemiboldItalic.ttf");
QFontDatabase::addApplicationFont(":/fonts/OpenSans-ExtraBold.ttf");
QFontDatabase::addApplicationFont(":/fonts/OpenSans-ExtraBoldItalic.ttf");
QFontDatabase::addApplicationFont(":/fonts/emojione-android.ttf");
QApplication app(argc, argv);