diff --git a/src/chatlog/customtextdocument.cpp b/src/chatlog/customtextdocument.cpp
index c1dd1b96c..b4a4507ad 100644
--- a/src/chatlog/customtextdocument.cpp
+++ b/src/chatlog/customtextdocument.cpp
@@ -15,6 +15,7 @@
*/
#include "customtextdocument.h"
+#include "../misc/settings.h"
#include "../misc/smileypack.h"
#include "../misc/style.h"
@@ -34,7 +35,10 @@ CustomTextDocument::CustomTextDocument(QObject *parent)
QVariant CustomTextDocument::loadResource(int type, const QUrl &name)
{
if (type == QTextDocument::ImageResource && name.scheme() == "key")
- return SmileyPack::getInstance().getAsPixmap(name.fileName());
+ {
+ QSize size = QSize(Settings::getInstance().getEmojiFontPointSize(),Settings::getInstance().getEmojiFontPointSize());
+ return SmileyPack::getInstance().getAsIcon(name.fileName()).pixmap(size);
+ }
return QTextDocument::loadResource(type, name);
}
diff --git a/src/misc/smileypack.cpp b/src/misc/smileypack.cpp
index ac8e1115b..258b3ae9c 100644
--- a/src/misc/smileypack.cpp
+++ b/src/misc/smileypack.cpp
@@ -91,7 +91,7 @@ bool SmileyPack::load(const QString& filename)
{
// discard old data
filenameTable.clear();
- pixmapCache.clear();
+ iconCache.clear();
emoticons.clear();
path.clear();
@@ -135,7 +135,7 @@ bool SmileyPack::load(const QString& filename)
cacheSmiley(file); // preload all smileys
- if(!getCachedSmiley(emoticon).size().isEmpty())
+ if(!getCachedSmiley(emoticon).isNull())
emoticonSet.push_back(emoticon);
stringElement = stringElement.nextSibling().toElement();
@@ -183,28 +183,21 @@ QString SmileyPack::getAsRichText(const QString &key)
return QString("").arg(key);
}
-QPixmap SmileyPack::getAsPixmap(const QString &key)
+QIcon SmileyPack::getAsIcon(const QString &key)
{
return getCachedSmiley(key);
}
void SmileyPack::cacheSmiley(const QString &name)
{
- // The -1 is to avoid having the space for descenders under images move the text down
- // We can't remove it because Qt doesn't support CSS display or vertical-align
- //TODO: int fontHeight = QFontInfo(Style::getFont(Style::Big)).pixelSize() - 1;
- QSize size(16, 16);
QString filename = QDir(path).filePath(name);
- QImage img(filename);
- if (!img.isNull())
- {
- QImage scaledImg = img.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
- pixmapCache.insert(name, QPixmap::fromImage(scaledImg));
- }
+ QIcon icon;
+ icon.addFile(filename);
+ iconCache.insert(name, icon);
}
-QPixmap SmileyPack::getCachedSmiley(const QString &key)
+QIcon SmileyPack::getCachedSmiley(const QString &key)
{
// valid key?
if (!filenameTable.contains(key))
@@ -212,11 +205,11 @@ QPixmap SmileyPack::getCachedSmiley(const QString &key)
// cache it if needed
QString file = filenameTable.value(key);
- if (!pixmapCache.contains(file)) {
+ if (!iconCache.contains(file)) {
cacheSmiley(file);
}
- return pixmapCache.value(file);
+ return iconCache.value(file);
}
void SmileyPack::onSmileyPackChanged()
diff --git a/src/misc/smileypack.h b/src/misc/smileypack.h
index b88c33503..bbe3ed46e 100644
--- a/src/misc/smileypack.h
+++ b/src/misc/smileypack.h
@@ -21,7 +21,7 @@
#include
#include
#include
-#include
+#include
#define SMILEYPACK_SEARCH_PATHS \
{ \
@@ -41,7 +41,7 @@ public:
QString smileyfied(QString msg);
QList getEmoticons() const;
QString getAsRichText(const QString& key);
- QPixmap getAsPixmap(const QString& key);
+ QIcon getAsIcon(const QString& key);
private slots:
void onSmileyPackChanged();
@@ -52,10 +52,10 @@ private:
SmileyPack& operator=(const SmileyPack&) = delete;
void cacheSmiley(const QString& name);
- QPixmap getCachedSmiley(const QString& key);
+ QIcon getCachedSmiley(const QString& key);
QHash filenameTable; // matches an emoticon to its corresponding smiley ie. ":)" -> "happy.png"
- QHash pixmapCache; // (scaled) representation of a smiley ie. "happy.png" -> data
+ QHash iconCache; // representation of a smiley ie. "happy.png" -> data
QList emoticons; // {{ ":)", ":-)" }, {":(", ...}, ... }
QString path; // directory containing the cfg and image files
};
diff --git a/src/widget/emoticonswidget.cpp b/src/widget/emoticonswidget.cpp
index 55558945a..c067c5232 100644
--- a/src/widget/emoticonswidget.cpp
+++ b/src/widget/emoticonswidget.cpp
@@ -81,7 +81,7 @@ EmoticonsWidget::EmoticonsWidget(QWidget *parent) :
for (const QStringList& set : emoticons)
{
QPushButton* button = new QPushButton;
- button->setIcon(SmileyPack::getInstance().getAsPixmap(set[0]));
+ button->setIcon(SmileyPack::getInstance().getAsIcon(set[0]).pixmap(QSize(18,18)));
button->setToolTip(set.join(" "));
button->setProperty("sequence", set[0]);
button->setCursor(Qt::PointingHandCursor);
diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp
index 732e00a00..726406fb9 100644
--- a/src/widget/form/settings/generalform.cpp
+++ b/src/widget/form/settings/generalform.cpp
@@ -311,11 +311,12 @@ void GeneralForm::reloadSmiles()
for (int i = 0; i < emoticons.size(); i++)
smiles.push_front(emoticons.at(i).first());
- bodyUI->smile1->setPixmap(SmileyPack::getInstance().getAsPixmap(smiles[0]));
- bodyUI->smile2->setPixmap(SmileyPack::getInstance().getAsPixmap(smiles[1]));
- bodyUI->smile3->setPixmap(SmileyPack::getInstance().getAsPixmap(smiles[2]));
- bodyUI->smile4->setPixmap(SmileyPack::getInstance().getAsPixmap(smiles[3]));
- bodyUI->smile5->setPixmap(SmileyPack::getInstance().getAsPixmap(smiles[4]));
+ const QSize size(18,18);
+ bodyUI->smile1->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[0]).pixmap(size));
+ bodyUI->smile2->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[1]).pixmap(size));
+ bodyUI->smile3->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[2]).pixmap(size));
+ bodyUI->smile4->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[3]).pixmap(size));
+ bodyUI->smile5->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[4]).pixmap(size));
bodyUI->smile1->setToolTip(smiles[0]);
bodyUI->smile2->setToolTip(smiles[1]);