mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
make use of EmojiFontPointSize (fix #1026)
This commit is contained in:
parent
a558733507
commit
f509e07c45
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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("<img title=\"%1\" src=\"key:%1\"\\>").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()
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QPixmap>
|
||||
#include <QIcon>
|
||||
|
||||
#define SMILEYPACK_SEARCH_PATHS \
|
||||
{ \
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
QString smileyfied(QString msg);
|
||||
QList<QStringList> 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<QString, QString> filenameTable; // matches an emoticon to its corresponding smiley ie. ":)" -> "happy.png"
|
||||
QHash<QString, QPixmap> pixmapCache; // (scaled) representation of a smiley ie. "happy.png" -> data
|
||||
QHash<QString, QIcon> iconCache; // representation of a smiley ie. "happy.png" -> data
|
||||
QList<QStringList> emoticons; // {{ ":)", ":-)" }, {":(", ...}, ... }
|
||||
QString path; // directory containing the cfg and image files
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user