diff options
author | Thanos Doukoudakis <thanos.doukoudakis@isode.com> | 2018-04-16 09:59:34 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2018-05-10 08:13:57 (GMT) |
commit | 4663da31954d989f8535b94c4a78a0f4515542a4 (patch) | |
tree | aa6cf7a359ed0e61e038f3f518581bc9351d52f9 /Swift/QtUI | |
parent | 8fab33012e5ac7c03ab00ec30118dcb2c5218051 (diff) | |
download | swift-4663da31954d989f8535b94c4a78a0f4515542a4.zip swift-4663da31954d989f8535b94c4a78a0f4515542a4.tar.bz2 |
Enable Emojis on Windows and Linux
This patch enables emojis for Linux and Windows. In windows, currently the
emojis are only black and white, due to some inconsistencies in the UI.
For Linux the Noto Colour Emoji font (https://www.google.com/get/noto/) is
used.
The client must be build with Qt 5.6 or newer to support the emoji
characters.
Test-Information:
Tested the changes with Qt 5.8 on Windows 10 and Linux Ubuntu 17.10.
Built and tested the appimage on Ubuntu 17.10 and Ubuntu 16.04.
Change-Id: I6d0f2842349eae789d773c33d1a93ad33304df3e
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 12 | ||||
-rw-r--r-- | Swift/QtUI/QtEmojiCell.cpp | 15 | ||||
-rw-r--r-- | Swift/QtUI/QtEmojisSelector.cpp | 9 | ||||
-rw-r--r-- | Swift/QtUI/QtSwift.cpp | 9 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 3 |
5 files changed, 34 insertions, 14 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 231a9b9..cbdab48 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -155,11 +155,15 @@ QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventSt connect(input_, SIGNAL(lostFocus()), this, SLOT(handleTextInputLostFocus())); connect(input_, SIGNAL(itemDropped(QDropEvent*)), this, SLOT(dropEvent(QDropEvent*))); QPushButton* emojisButton_ = new QPushButton(this); - -#ifdef SWIFTEN_PLATFORM_MACOSX emojisButton_->setText("\xF0\x9F\x98\x83"); -#else - emojisButton_->setIcon(QIcon(":/emoticons/smile.png")); + +#if defined(SWIFTEN_PLATFORM_WINDOWS) || defined(SWIFTEN_PLATFORM_LINUX) + //Using a emoji glyph instead of an image makes the button sizes inequal in windows & linux, + //so we set fixed size for both buttons, the one that is hinted for actionButton_ + emojisButton_->setMaximumWidth(actionButton_->sizeHint().width()); + emojisButton_->setMaximumHeight(actionButton_->sizeHint().height()); + actionButton_->setMaximumWidth(actionButton_->sizeHint().width()); + actionButton_->setMaximumHeight(actionButton_->sizeHint().height()); #endif connect(emojisButton_, SIGNAL(clicked()), this, SLOT(handleEmojisButtonClicked())); diff --git a/Swift/QtUI/QtEmojiCell.cpp b/Swift/QtUI/QtEmojiCell.cpp index 865f1f6..106e968 100644 --- a/Swift/QtUI/QtEmojiCell.cpp +++ b/Swift/QtUI/QtEmojiCell.cpp @@ -1,11 +1,13 @@ /* - * Copyright (c) 2016-2017 Isode Limited. + * Copyright (c) 2016-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/QtUI/QtEmojiCell.h> +#include <Swiften/Base/Platform.h> + #include <QFont> #include <QFontMetrics> #include <QPushButton> @@ -17,13 +19,20 @@ namespace Swift { QtEmojiCell::QtEmojiCell(QString shortname, QString text, QWidget* parent) : QPushButton(parent) { setText(text); QFont font = this->font(); +#ifdef SWIFTEN_PLATFORM_WINDOWS + //Windows emoji font miscalculates the bounding rectangular that surrounds the emoji. We set a multiplier value to make it look consistent with linux & Mac + const float sizeMultiplier = 1.3; + font.setPointSize(18); +#else font.setPointSize(22); + const float sizeMultiplier = 1; +#endif font.setBold(true); setFont(font); const auto boundingRect = fontMetrics().boundingRect("\xF0\x9F\x98\x83"); - setFixedWidth(qMax(boundingRect.width(), boundingRect.height())); - setFixedHeight(qMax(boundingRect.width(), boundingRect.height())); + setFixedWidth(qMax(sizeMultiplier*boundingRect.width(), sizeMultiplier*boundingRect.height())); + setFixedHeight(qMax(sizeMultiplier*boundingRect.width(), sizeMultiplier*boundingRect.height())); setFlat(true); setToolTip(shortname); diff --git a/Swift/QtUI/QtEmojisSelector.cpp b/Swift/QtUI/QtEmojisSelector.cpp index 62ed862..fe2f235 100644 --- a/Swift/QtUI/QtEmojisSelector.cpp +++ b/Swift/QtUI/QtEmojisSelector.cpp @@ -24,7 +24,6 @@ namespace Swift { QtEmojisSelector::QtEmojisSelector(QSettings* settings, const std::map<std::string, std::string>& emoticonsMap, QWidget* parent) : QTabWidget(parent), settings_(settings), emoticonsMap_(emoticonsMap) { -#ifdef SWIFTEN_PLATFORM_MACOSX recentEmojisGrid_ = addRecentTab(); connect(recentEmojisGrid_, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString))); @@ -34,17 +33,13 @@ namespace Swift { connect(grid, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString))); } } - loadSettings(); -#else - setupEmoticonsTab(); -#endif + //The size of an emoji cell varies depending the OS, 42 is the ceil value. + setFixedSize(QSize(EmojiMapper::emojisInCategory.size() * 42, 300)); } QtEmojisSelector::~QtEmojisSelector() { -#ifdef SWIFTEN_PLATFORM_MACOSX writeSettings(); -#endif } QtRecentEmojisGrid* QtEmojisSelector::addRecentTab() { diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 76e3583..2d75565 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -233,6 +233,15 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa SWIFT_LOG_ASSERT(error != -1, error) << "Failed to load font " << fontPath << std::endl; } +#ifdef SWIFTEN_PLATFORM_LINUX + std::string fontPath = std::string(":/themes/Default/Noto/NotoColorEmoji.ttf"); + int error = QFontDatabase::addApplicationFont(P2QSTRING(fontPath)); + SWIFT_LOG_ASSERT(error != -1, error) << "Failed to load font " << fontPath << std::endl; + QFont::insertSubstitution(QApplication::font().family(),"NotoColorEmoji"); +#endif +#ifdef SWIFTEN_PLATFORM_WINDOWS + QFont::insertSubstitution(QApplication::font().family(), "Segoe UI Emoji"); +#endif bool enableAdHocCommandOnJID = options.count("enable-jid-adhocs") > 0; tabs_ = nullptr; if (options.count("no-tabs") && !splitter_) { diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index b8ec3ba..09860ed 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -7,6 +7,9 @@ def generateQRCTheme(dir, prefix) : result += "<RCC version =\"1.0\">" result += "<qresource prefix=\"/themes/" + prefix + "\">" for (path, dirs, files) in os.walk(sourceDir) : + #skip the Noto emoji fonts in Windows. No need to package them since they aren't used + if "Noto" in path and not env["PLATFORM"] == "linux" : + continue for file in files : filePath = os.path.join(path,file) result += "<file alias=\"%(alias)s\">%(path)s</file>" % { |