Merge pull request #583 from PhenomRetroShare/Add_GroupedEmoticons

Add grouped emoticons.
This commit is contained in:
defnax 2016-11-24 08:04:00 +01:00 committed by GitHub
commit cf270d73c0
4 changed files with 440 additions and 387 deletions

View File

@ -19,194 +19,243 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QHash>
#include <QFile>
#include <QApplication>
#include <QWidget>
#include <QFile>
#include <QIcon>
#include <QDesktopWidget>
#include <QFile>
#include <QGridLayout>
#include <QHash>
#include <QIcon>
#include <QPushButton>
#include <QTabWidget>
#include <QWidget>
#include <iostream>
#include <math.h>
#include "Emoticons.h"
#include "util/HandleRichText.h"
static QHash<QString, QString> Smileys;
static QVector<QString> order;
static QHash<QString, QPair<QVector<QString>, QHash<QString, QString> > > Smileys;
static QVector<QString> grpOrdered;
void Emoticons::load()
{
QString sm_codes;
bool internalEmoticons = true;
QString sm_AllLines;
bool internalFiles = true;
#if defined(Q_OS_WIN)
// first try external emoticons
QFile sm_file(QApplication::applicationDirPath() + "/emoticons/emotes.acs");
if(sm_file.open(QIODevice::ReadOnly))
{
internalEmoticons = false;
} else {
// then embedded emotions
sm_file.setFileName(":/emojione/emotes.acs");
if(!sm_file.open(QIODevice::ReadOnly))
{
std::cout << "error opening ressource file" << std::endl ;
return ;
}
}
#else
QFile sm_file(QString(":/emojione/emotes.acs"));
if(!sm_file.open(QIODevice::ReadOnly))
{
std::cout << "error opening ressource file" << std::endl ;
return ;
}
#endif
// First try external emoticons
QFile sm_File(QApplication::applicationDirPath() + "/emoticons/emotes.acs");
if(sm_File.open(QIODevice::ReadOnly))
internalFiles = false;
else
{
// Then embedded emotions
sm_File.setFileName(":/emojione/emotes.acs");
if(!sm_File.open(QIODevice::ReadOnly))
{
std::cout << "error opening ressource file" << std::endl;
return;
}
}
sm_codes = sm_file.readAll();
sm_file.close();
sm_AllLines = sm_File.readAll();
sm_File.close();
sm_codes.remove("\n");
sm_codes.remove("\r");
sm_AllLines.remove("\n");
sm_AllLines.remove("\r");
int i = 0;
QString smcode;
QString smfile;
while(i < sm_codes.length() && sm_codes[i] != '{')
{
++i;
}
while (i < sm_codes.length()-2)
{
smcode = "";
smfile = "";
int i = 0 ;
QString smGroup;
QString smCode;
QString smFile;
while(i < sm_AllLines.length() && sm_AllLines[i] != '{')
++i ;//Ignore text before {
while(sm_codes[i] != '\"')
{
++i;
}
++i;
while (sm_codes[i] != '\"')
{
smcode += sm_codes[i];
++i;
}
++i;
while (i < sm_AllLines.length()-2)
{
// Type of lines:
// "Group"|":code:":"emojione/file.png";
smGroup = "";
smCode = "";
smFile = "";
while(sm_codes[i] != '\"')
{
++i;
}
++i;
while(sm_codes[i] != '\"' && sm_codes[i+1] != ';')
{
smfile += sm_codes[i];
++i;
}
++i;
if(!smcode.isEmpty() && !smfile.isEmpty()) {
while (smcode.right(1) == "|") {
smcode.remove(smcode.length() - 1, 1);
}
//Reading Groupe (First into "")
while(sm_AllLines[i] != '\"')
++i; //Ignore text outside ""
if (internalEmoticons) {
Smileys.insert(smcode, ":/"+smfile);
} else {
Smileys.insert(smcode, smfile);
}
order.append(smcode);
}
}
++i; //'"'
while (sm_AllLines[i] != '\"')
smGroup += sm_AllLines[i++]; //Get group char by char
// init <img> embedder
RsHtml::initEmoticons(Smileys);
++i; //'"'
if (sm_AllLines[i] == '|')
{
//File in new format with group
++i; //'|'
//Reading Code (Second into "")
while(sm_AllLines[i] != '\"')
++i; //Ignore text outside ""
++i; //'"'
while (sm_AllLines[i] != '\"')
smCode += sm_AllLines[i++]; //Get code char by char
++i; //'"'
} else {
//Old file without group
++i; //':'
smCode = smGroup;
smGroup = "NULL";
}
//Reading File (Third into "")
while(sm_AllLines[i] != '\"')
++i; //Ignore text outside ""
++i; //'"'
while(sm_AllLines[i] != '\"' && sm_AllLines[i+1] != ';')
smFile += sm_AllLines[i++]; //Get file char by char
++i; //'"'
++i; //';'
if(!smGroup.isEmpty() && !smCode.isEmpty() && !smFile.isEmpty())
{
while (smCode.right(1) == "|")
smCode.remove(smCode.length() - 1, 1);
if (internalFiles)
{
smFile = ":/" + smFile;
if (smGroup.right(4).toLower() == ".png")
smGroup = ":/" + smGroup;
}
QVector<QString> ordered;
if (Smileys.contains(smGroup)) ordered = Smileys[smGroup].first;
ordered.append(smCode);
Smileys[smGroup].first = ordered;
Smileys[smGroup].second.insert(smCode, smFile);
if (!grpOrdered.contains(smGroup)) grpOrdered.append(smGroup);
}
}
// init <img> embedder
RsHtml::initEmoticons(Smileys);
}
void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above)
{
QWidget *smWidget = new QWidget(parent, Qt::Popup);
QWidget *smWidget = new QWidget(parent, Qt::Popup) ;
smWidget->setAttribute(Qt::WA_DeleteOnClose) ;
smWidget->setWindowTitle("Emoticons") ;
const int buttonWidth = 26;
const int buttonHeight = 26;
//QTabWidget::setTabBarAutoHide(true) is from QT5.4, no way to hide TabBar before.
bool bOnlyOneGroup = (Smileys.count() == 1);
int rowCount = (int)sqrt((double)Smileys.size());
int countPerLine = (Smileys.size()/rowCount) + ((Smileys.size() % rowCount) ? 1 : 0);
QTabWidget *smTab = NULL;
if (! bOnlyOneGroup)
{
smTab = new QTabWidget(smWidget);
QGridLayout *smGLayout = new QGridLayout(smWidget);
smGLayout->setContentsMargins(0,0,0,0);
smGLayout->addWidget(smTab);
}
smWidget->setAttribute( Qt::WA_DeleteOnClose);
smWidget->setWindowTitle("Emoticons");
smWidget->setBaseSize(countPerLine*buttonWidth, rowCount*buttonHeight);
const int buttonWidth = QFontMetricsF(smWidget->font()).height()*2;
const int buttonHeight = QFontMetricsF(smWidget->font()).height()*2;
int maxRowCount = 0;
int maxCountPerLine = 0;
//Warning: this part of code was taken from kadu instant messenger;
// It was EmoticonSelector::alignTo(QWidget* w) function there
// comments are Polish, I dont' know how does it work...
// oblicz pozycj<63> widgetu do kt<6B>rego r<>wnamy
// oblicz rozmiar selektora
QPoint pos = button->mapToGlobal(QPoint(0,0));
QSize e_size = smWidget->sizeHint();
// oblicz rozmiar pulpitu
QSize s_size = QApplication::desktop()->size();
// oblicz dystanse od widgetu do lewego brzegu i do prawego
int l_dist = pos.x();
int r_dist = s_size.width() - (pos.x() + button->width());
// oblicz pozycj<63> w zale<6C>no<6E>ci od tego czy po lewej stronie
// jest wi<77>cej miejsca czy po prawej
int x;
if (l_dist >= r_dist)
x = pos.x() - e_size.width();
else
x = pos.x() + button->width();
// oblicz pozycj<63> y - centrujemy w pionie
int y = pos.y() + button->height()/2 - e_size.height()/2;
// je<6A>li wychodzi poza doln<6C> kraw<61>d<EFBFBD> to r<>wnamy do niej
if (y + e_size.height() > s_size.height())
y = s_size.height() - e_size.height();
QVectorIterator<QString> grp(grpOrdered);
while(grp.hasNext())
{
QString groupName = grp.next();
QHash<QString,QString> group = Smileys.value(groupName).second;
if (above) {
y -= rowCount*buttonHeight;
}
QWidget *tabGrpWidget = NULL;
if (! bOnlyOneGroup)
{
tabGrpWidget = new QWidget(smTab);
if (groupName.right(4).toLower() == ".png")
smTab->addTab( tabGrpWidget, QIcon(groupName), "");
else
smTab->addTab( tabGrpWidget, groupName);
} else {
tabGrpWidget = smWidget;
}
// je<6A>li wychodzi poza g<>rn<72> kraw<61>d<EFBFBD> to r<>wnamy do niej
if (y < 0)
y = 0;
// ustawiamy selektor na wyliczonej pozycji
smWidget->move(x, y);
QGridLayout *tabGLayout = new QGridLayout(tabGrpWidget);
tabGLayout->setContentsMargins(0,0,0,0);
tabGLayout->setSpacing(0);
x = 0;
y = 0;
int rowCount = (int)sqrt((double)group.size());
int countPerLine = (group.size()/rowCount) + ((group.size() % rowCount) ? 1 : 0);
maxRowCount = qMax(maxRowCount, rowCount);
maxCountPerLine = qMax(maxCountPerLine, countPerLine);
QVectorIterator<QString> i(order);
while(i.hasNext())
{
QString key = i.next();
QPushButton *smButton = new QPushButton("", smWidget);
smButton->setGeometry(x*buttonWidth, y*buttonHeight, buttonWidth, buttonHeight);
smButton->setIconSize(QSize(buttonWidth, buttonHeight));
smButton->setIcon(QPixmap(Smileys.value(key)));
smButton->setToolTip(key);
smButton->setStyleSheet("QPushButton:hover {border: 3px solid white; border-radius: 2px;}");
smButton->setFlat(true);
++x;
if(x >= countPerLine)
{
x = 0;
++y;
}
QObject::connect(smButton, SIGNAL(clicked()), parent, slotAddMethod);
QObject::connect(smButton, SIGNAL(clicked()), smWidget, SLOT(close()));
}
int lin = 0;
int col = 0;
QVector<QString> ordered = Smileys.value(groupName).first;
QVectorIterator<QString> it(ordered);
while(it.hasNext())
{
smWidget->show();
QString key = it.next();
QPushButton *button = new QPushButton("", tabGrpWidget);
button->setIconSize(QSize(buttonWidth, buttonHeight));
button->setFixedSize(QSize(buttonWidth, buttonHeight));
button->setIcon(QPixmap(group.value(key)));
button->setToolTip(key);
button->setStyleSheet("QPushButton:hover {border: 3px solid white; border-radius: 2px;}");
button->setFlat(true);
tabGLayout->addWidget(button,col,lin);
++lin;
if(lin >= countPerLine)
{
lin = 0;
++col;
}
QObject::connect(button, SIGNAL(clicked()), parent, slotAddMethod);
QObject::connect(button, SIGNAL(clicked()), smWidget, SLOT(close()));
}
}
//Get left up pos of button
QPoint butTopLeft = button->mapToGlobal(QPoint(0,0));
//Get widget's size
QSize sizeWidget = smWidget->sizeHint();
//Get screen's size
QSize sizeScreen = QApplication::desktop()->size();
//Calculate left distance to screen start
int distToScreenLeft = butTopLeft.x();
//Calculate right distance to screen end
int distToRightScreen = sizeScreen.width() - (butTopLeft.x() + button->width());
//Calculate left position
int x;
if (distToScreenLeft >= distToRightScreen) //More distance in left than right in screen
x = butTopLeft.x() - sizeWidget.width(); //Place widget on left of button
else
x = butTopLeft.x() + button->width(); //Place widget on right of button
//Calculate top position
int y;
if (above) //Widget must be above the button
y = butTopLeft.y() + button->height() - sizeWidget.height();
else
y = butTopLeft.y() + button->height()/2 - sizeWidget.height()/2; //Centered on button height
if (y + sizeWidget.height() > sizeScreen.height()) //Widget will be too low
y = sizeScreen.height() - sizeWidget.height(); //Place widget bottom at screen bottom
if (y < 0) //Widget will be too high
y = 0; //Place widget top at screen top
smWidget->move(x, y) ;
smWidget->show() ;
}
//void Emoticons::formatText(QString &text)
//{
// QHashIterator<QString, QString> i(Smileys);
// while(i.hasNext()) {
// i.next();
// foreach (QString code, i.key().split("|")) {
// text.replace(code, "<img src=\"" + i.value() + "\">");
// }
// }
//}

View File

@ -1,201 +1,201 @@
{
":grinning:":"emojione/1F600.png";
":grin:":"emojione/1F601.png";
":joy:|:')|:'-)":"emojione/1F602.png";
":smile:|:-DD|:DD":"emojione/1F604.png";
":smiley:|:-D|:D":"emojione/1F603.png";
":sweat_smile:|':)|':-)|'=)|':D|':-D|'=D":"emojione/1F605.png";
":laughing:|:satisfied":"emojione/1F606.png";
":innocent:|O:-)|0:-3|0:3|0:-)|0:)":"emojione/1F607.png";
":smiling_imp:":"emojione/1F608.png";
":imp:":"emojione/1F47F.png";
":wink:|;-)|;)":"emojione/1F609.png";
":blush:":"emojione/1F60A.png";
":relaxed:":"emojione/263A.png";
":yum:":"emojione/1F60B.png";
":relieved:":"emojione/1F60C.png";
":heart_eyes:":"emojione/1F60D.png";
":sunglasses:|B-)|B)|8)|8-)|B-D|8-D":"emojione/1F60E.png";
":smirk:":"emojione/1F60F.png";
":neutral_face:":"emojione/1F610.png";
":expressionless:|-_-":"emojione/1F611.png";
":unamused:":"emojione/1F612.png";
":sweat:|':(|':-(|'=(":"emojione/1F613.png";
":pensive:":"emojione/1F614.png";
":confused:|:-/|:-.|:\|=/|=\|:L|=L":"emojione/1F615.png";
":confounded:":"emojione/1F616.png";
":kissing:":"emojione/1F617.png";
":kissing_heart:|:*|:-*|=*":"emojione/1F618.png";
":kissing_smiling_eyes:":"emojione/1F619.png";
":kissing_closed_eyes:":"emojione/1F61A.png";
":stuck_out_tongue:|:-P|:P|:p|:-p":"emojione/1F61B.png";
":stuck_out_tongue_winking_eye:":"emojione/1F61C.png";
":stuck_out_tongue_closed_eyes:":"emojione/1F61D.png";
":disappointed:|:-(|:(":"emojione/1F61E.png";
":worried:":"emojione/1F61F.png";
":angry:|:@":"emojione/1F620.png";
":rage:":"emojione/1F621.png";
":cry:|:'(|:'-(|;(|;-(":"emojione/1F622.png";
":persevere:":"emojione/1F623.png";
":triumph:":"emojione/1F624.png";
":disappointed_relieved:":"emojione/1F625.png";
":frowning:":"emojione/1F626.png";
":anguished:":"emojione/1F627.png";
":fearful:":"emojione/1F628.png";
":weary:":"emojione/1F629.png";
":sleepy:":"emojione/1F62A.png";
":tired_face:":"emojione/1F62B.png";
":grimacing:":"emojione/1F62C.png";
":sob:":"emojione/1F62D.png";
":open_mouth:|:-O|:O":"emojione/1F62E.png";
":hushed:":"emojione/1F62F.png";
":cold_sweat:":"emojione/1F630.png";
":scream:":"emojione/1F631.png";
":astonished:":"emojione/1F632.png";
":flushed:|=$|:$|:-$":"emojione/1F633.png";
":sleeping:":"emojione/1F634.png";
":bulb:":"emojione/1F4A1.png";
":zzz:":"emojione/1F4A4.png";
":fire:|:flame:":"emojione/1F525.png";
":stars:":"emojione/1F320.png";
":star:":"emojione/2B50.png";
":dizzy:":"emojione/1F4AB.png";
":boom:":"emojione/1F4A5.png";
":anger:":"emojione/1F4A2.png";
":bomb:":"emojione/1F4A3.png";
":sweat_drops:":"emojione/1F4A6.png";
":droplet:":"emojione/1F4A7.png";
":dash:":"emojione/1F4A8.png";
":poop:|:shit:|:hankey:|:poo:":"emojione/1F4A9.png";
":dizzy_face:|#-)|#)|%-)|%)|X)|X-)":"emojione/1F635.png";
":no_mouth:|:-X|:X:|-#|:#|=X|=x|:x|:-x|=#":"emojione/1F636.png";
":mask:":"emojione/1F637.png";
":slight_frown:|:slightly_frowning_face:":"emojione/1F641.png";
":slight_smile:|:)|:-)|:slightly_smiling_face:":"emojione/1F642.png";
":smile_cat:|(@)":"emojione/1F638.png";
":joy_cat:":"emojione/1F639.png";
":smiley_cat:":"emojione/1F63A.png";
":heart_eyes_cat:":"emojione/1F63B.png";
":smirk_cat:":"emojione/1F63C.png";
":kissing_cat:":"emojione/1F63D.png";
":pouting_cat:":"emojione/1F63E.png";
":crying_cat_face:":"emojione/1F63F.png";
":scream_cat:":"emojione/1F640.png";
":footprints:":"emojione/1F463.png";
":bust_in_silhouette:":"emojione/1F464.png";
":busts_in_silhouette:":"emojione/1F465.png";
":levitate:|:man_in_business_suit_levitating:":"emojione/1F574.png";
":spy:|:sleuth_or_spy:":"emojione/1F575.png";
":baby:":"emojione/1F476.png";
":boy:":"emojione/1F466.png";
":girl:":"emojione/1F467.png";
":man:":"emojione/1F468.png";
":woman:":"emojione/1F469.png";
":family:":"emojione/1F46A.png";
":couple:":"emojione/1F46B.png";
":dancers:":"emojione/1F46F.png";
":bride_with_veil:":"emojione/1F470.png";
":person_with_blond_hair:":"emojione/1F471.png";
":man_with_gua_pi_mao:":"emojione/1F472.png";
":man_with_turban:":"emojione/1F473.png";
":older_man:":"emojione/1F474.png";
":older_woman:":"emojione/1F475.png";
":cop:":"emojione/1F46E.png";
":construction_worker:":"emojione/1F477.png";
":princess:":"emojione/1F478.png";
":guardsman:":"emojione/1F482.png";
":angel:":"emojione/1F47C.png";
":santa:":"emojione/1F385.png";
":ghost:":"emojione/1F47B.png";
":skull:|:skeleton:":"emojione/1F480.png";
":alien:":"emojione/1F47D.png";
":space_invader:":"emojione/1F47E.png";
":japanese_ogre:":"emojione/1F479.png";
":japanese_goblin:":"emojione/1F47A.png";
":bow:":"emojione/1F647.png";
":information_desk_person:":"emojione/1F481.png";
":raised_hands:":"emojione/1F64C.png";
":clap:":"emojione/1F44F.png";
":ear:":"emojione/1F442.png";
":eye:":"emojione/1F441.png";
":eyes:":"emojione/1F440.png";
":nose:":"emojione/1F443.png";
":lips:":"emojione/1F444.png";
":lips2:":"emojione/1F5E2.png";
":kiss:":"emojione/1F48B.png";
":tongue:":"emojione/1F445.png";
":nail_care:":"emojione/1F485.png";
":wave:":"emojione/1F44B.png";
":thumbsup:|:+1:|(y)|(Y)":"emojione/1F44D.png";
":thumbsdown:|:-1:|(N)|(n)":"emojione/1F44E.png";
":muscle:":"emojione/1F4AA.png";
":middle_finger:|":"emojione/1F595.png";
":finger_pointing_down:":"emojione/1F597.png";
":finger_pointing_left:":"emojione/1F598.png";
":finger_pointing_right:":"emojione/1F599.png";
":finger_pointing_up:":"emojione/1F59E.png";
":coffee:|(C)|(c)":"emojione/2615.png";
":sake:":"emojione/1F376.png";
":tea:":"emojione/1F375.png";
":cake:":"emojione/1F370.png";
":egg:":"emojione/1F373.png";
":hamburger:":"emojione/1F354.png";
":doughnut:":"emojione/1F369.png";
":wine_glass:":"emojione/1F377.png";
":cocktail:":"emojione/1F378.png";
":tropical_drink:":"emojione/1F379.png";
":beer:|(B)|(b)":"emojione/1F37A.png";
":beers:":"emojione/1F37B.png";
":watch:":"emojione/231A.png";
":iphone:":"emojione/1F4F1.png";
":monkey:":"emojione/1F412.png";
":see_no_evil:":"emojione/1F648.png";
":hear_no_evil:":"emojione/1F649.png";
":speak_no_evil:":"emojione/1F64A.png";
":turtle:":"emojione/1F422.png";
":frog:":"emojione/1F438.png";
":airplane:":"emojione/2708.png";
":heart:|<3":"emojione/2764.png";
":broken_heart:|</3":"emojione/1F494.png";
":love_letter:":"emojione/1F48C.png";
":two_hearts:":"emojione/1F495.png";
":revolving_hearts:":"emojione/1F49E.png";
":heartbeat:":"emojione/1F493.png";
":heartpulse:":"emojione/1F497.png";
":sparkling_heart:":"emojione/1F496.png";
":cupid:":"emojione/1F498.png";
":gift_heart:":"emojione/1F49D.png";
":birthday:":"emojione/1F382.png";
":gift:":"emojione/1F381.png";
":christmas_tree:":"emojione/1F384.png";
":penguin:":"emojione/1F427.png";
":sunny:":"emojione/2600.png";
":partly_sunny:":"emojione/26C5.png";
":cloud:":"emojione/2601.png";
":cloud_rain:":"emojione/1F327.png";
":cloud_snow:":"emojione/1F328.png";
":cloud_lightning:":"emojione/1F329.png";
":cloud_tornado:":"emojione/1F32A.png";
":crescent_moon:":"emojione/1F319.png";
":umbrella:":"emojione/2614.png";
":snowflake:":"emojione/2744.png";
":fist:":"emojione/270A.png";
":v:":"emojione/270C.png";
":raised_hand:":"emojione/270B.png";
":point_up:":"emojione/261D.png";
":pizza:":"emojione/1F355.png";
":cookie:":"emojione/1F36A.png";
":ok_hand:":"emojione/1F44C.png";
":four_leaf_clover:":"emojione/1F340.png";
":jack_o_lantern:":"emojione/1F383.png";
":bouquet:":"emojione/1F490.png";
":vulcan:":"emojione/1F596.png";
":zipper_mouth_face:":"emojione/1f910.png";
":money_mouth_face:":"emojione/1f911.png";
":face_with_thermometer:":"emojione/1f912.png";
":nerd_face:":"emojione/1f913.png";
":thinking_face:":"emojione/1f914.png";
":head_bandage:":"emojione/1f915.png";
":robot_face:":"emojione/1f916.png";
":updside_down_face:":"emojione/1f643.png";
"emojione/1F600.png"|":grinning:":"emojione/1F600.png";
"emojione/1F600.png"|":grin:":"emojione/1F601.png";
"emojione/1F600.png"|":joy:|:')|:'-)":"emojione/1F602.png";
"emojione/1F600.png"|":smile:|:-DD|:DD":"emojione/1F604.png";
"emojione/1F600.png"|":smiley:|:-D|:D":"emojione/1F603.png";
"emojione/1F600.png"|":sweat_smile:|':)|':-)|'=)|':D|':-D|'=D":"emojione/1F605.png";
"emojione/1F600.png"|":laughing:|:satisfied":"emojione/1F606.png";
"emojione/1F600.png"|":innocent:|O:-)|0:-3|0:3|0:-)|0:)":"emojione/1F607.png";
"emojione/1F600.png"|":smiling_imp:":"emojione/1F608.png";
"emojione/1F600.png"|":imp:":"emojione/1F47F.png";
"emojione/1F600.png"|":wink:|;-)|;)":"emojione/1F609.png";
"emojione/1F600.png"|":blush:":"emojione/1F60A.png";
"emojione/1F600.png"|":relaxed:":"emojione/263A.png";
"emojione/1F600.png"|":yum:":"emojione/1F60B.png";
"emojione/1F600.png"|":relieved:":"emojione/1F60C.png";
"emojione/1F600.png"|":heart_eyes:":"emojione/1F60D.png";
"emojione/1F600.png"|":sunglasses:|B-)|B)|8)|8-)|B-D|8-D":"emojione/1F60E.png";
"emojione/1F600.png"|":smirk:":"emojione/1F60F.png";
"emojione/1F600.png"|":neutral_face:":"emojione/1F610.png";
"emojione/1F600.png"|":expressionless:|-_-":"emojione/1F611.png";
"emojione/1F600.png"|":unamused:":"emojione/1F612.png";
"emojione/1F600.png"|":sweat:|':(|':-(|'=(":"emojione/1F613.png";
"emojione/1F600.png"|":pensive:":"emojione/1F614.png";
"emojione/1F600.png"|":confused:|:-/|:-.|:\|=/|=\|:L|=L":"emojione/1F615.png";
"emojione/1F600.png"|":confounded:":"emojione/1F616.png";
"emojione/1F600.png"|":kissing:":"emojione/1F617.png";
"emojione/1F600.png"|":kissing_heart:|:*|:-*|=*":"emojione/1F618.png";
"emojione/1F600.png"|":kissing_smiling_eyes:":"emojione/1F619.png";
"emojione/1F600.png"|":kissing_closed_eyes:":"emojione/1F61A.png";
"emojione/1F600.png"|":stuck_out_tongue:|:-P|:P|:p|:-p":"emojione/1F61B.png";
"emojione/1F600.png"|":stuck_out_tongue_winking_eye:":"emojione/1F61C.png";
"emojione/1F600.png"|":stuck_out_tongue_closed_eyes:":"emojione/1F61D.png";
"emojione/1F600.png"|":disappointed:|:-(|:(":"emojione/1F61E.png";
"emojione/1F600.png"|":worried:":"emojione/1F61F.png";
"emojione/1F600.png"|":angry:|:@":"emojione/1F620.png";
"emojione/1F600.png"|":rage:":"emojione/1F621.png";
"emojione/1F600.png"|":cry:|:'(|:'-(|;(|;-(":"emojione/1F622.png";
"emojione/1F600.png"|":persevere:":"emojione/1F623.png";
"emojione/1F600.png"|":triumph:":"emojione/1F624.png";
"emojione/1F600.png"|":disappointed_relieved:":"emojione/1F625.png";
"emojione/1F600.png"|":frowning:":"emojione/1F626.png";
"emojione/1F600.png"|":anguished:":"emojione/1F627.png";
"emojione/1F600.png"|":fearful:":"emojione/1F628.png";
"emojione/1F600.png"|":weary:":"emojione/1F629.png";
"emojione/1F600.png"|":sleepy:":"emojione/1F62A.png";
"emojione/1F600.png"|":tired_face:":"emojione/1F62B.png";
"emojione/1F600.png"|":grimacing:":"emojione/1F62C.png";
"emojione/1F600.png"|":sob:":"emojione/1F62D.png";
"emojione/1F600.png"|":open_mouth:|:-O|:O":"emojione/1F62E.png";
"emojione/1F600.png"|":hushed:":"emojione/1F62F.png";
"emojione/1F600.png"|":cold_sweat:":"emojione/1F630.png";
"emojione/1F600.png"|":scream:":"emojione/1F631.png";
"emojione/1F600.png"|":astonished:":"emojione/1F632.png";
"emojione/1F600.png"|":flushed:|=$|:$|:-$":"emojione/1F633.png";
"emojione/1F600.png"|":sleeping:":"emojione/1F634.png";
"emojione/1F4A1.png"|":bulb:":"emojione/1F4A1.png";
"emojione/1F4A1.png"|":zzz:":"emojione/1F4A4.png";
"emojione/1F4A1.png"|":fire:|:flame:":"emojione/1F525.png";
"emojione/1F4A1.png"|":stars:":"emojione/1F320.png";
"emojione/1F4A1.png"|":star:":"emojione/2B50.png";
"emojione/1F4A1.png"|":dizzy:":"emojione/1F4AB.png";
"emojione/1F4A1.png"|":boom:":"emojione/1F4A5.png";
"emojione/1F4A1.png"|":anger:":"emojione/1F4A2.png";
"emojione/1F4A1.png"|":bomb:":"emojione/1F4A3.png";
"emojione/1F4A1.png"|":sweat_drops:":"emojione/1F4A6.png";
"emojione/1F4A1.png"|":droplet:":"emojione/1F4A7.png";
"emojione/1F4A1.png"|":dash:":"emojione/1F4A8.png";
"emojione/1F4A1.png"|":poop:|:shit:|:hankey:|:poo:":"emojione/1F4A9.png";
"emojione/1F600.png"|":dizzy_face:|#-)|#)|%-)|%)|X)|X-)":"emojione/1F635.png";
"emojione/1F600.png"|":no_mouth:|:-X|:X:|-#|:#|=X|=x|:x|:-x|=#":"emojione/1F636.png";
"emojione/1F600.png"|":mask:":"emojione/1F637.png";
"emojione/1F600.png"|":slight_frown:|:slightly_frowning_face:":"emojione/1F641.png";
"emojione/1F600.png"|":slight_smile:|:)|:-)|:slightly_smiling_face:":"emojione/1F642.png";
"emojione/1F638.png"|":smile_cat:|(@)":"emojione/1F638.png";
"emojione/1F638.png"|":joy_cat:":"emojione/1F639.png";
"emojione/1F638.png"|":smiley_cat:":"emojione/1F63A.png";
"emojione/1F638.png"|":heart_eyes_cat:":"emojione/1F63B.png";
"emojione/1F638.png"|":smirk_cat:":"emojione/1F63C.png";
"emojione/1F638.png"|":kissing_cat:":"emojione/1F63D.png";
"emojione/1F638.png"|":pouting_cat:":"emojione/1F63E.png";
"emojione/1F638.png"|":crying_cat_face:":"emojione/1F63F.png";
"emojione/1F638.png"|":scream_cat:":"emojione/1F640.png";
"?"|":footprints:":"emojione/1F463.png";
"?"|":bust_in_silhouette:":"emojione/1F464.png";
"?"|":busts_in_silhouette:":"emojione/1F465.png";
"emojione/1F46A.png"|":levitate:|:man_in_business_suit_levitating:":"emojione/1F574.png";
"emojione/1F46A.png"|":spy:|:sleuth_or_spy:":"emojione/1F575.png";
"emojione/1F46A.png"|":baby:":"emojione/1F476.png";
"emojione/1F46A.png"|":boy:":"emojione/1F466.png";
"emojione/1F46A.png"|":girl:":"emojione/1F467.png";
"emojione/1F46A.png"|":man:":"emojione/1F468.png";
"emojione/1F46A.png"|":woman:":"emojione/1F469.png";
"emojione/1F46A.png"|":family:":"emojione/1F46A.png";
"emojione/1F46A.png"|":couple:":"emojione/1F46B.png";
"emojione/1F46A.png"|":dancers:":"emojione/1F46F.png";
"emojione/1F46A.png"|":bride_with_veil:":"emojione/1F470.png";
"emojione/1F46A.png"|":person_with_blond_hair:":"emojione/1F471.png";
"emojione/1F46A.png"|":man_with_gua_pi_mao:":"emojione/1F472.png";
"emojione/1F46A.png"|":man_with_turban:":"emojione/1F473.png";
"emojione/1F46A.png"|":older_man:":"emojione/1F474.png";
"emojione/1F46A.png"|":older_woman:":"emojione/1F475.png";
"emojione/1F46A.png"|":cop:":"emojione/1F46E.png";
"emojione/1F46A.png"|":construction_worker:":"emojione/1F477.png";
"emojione/1F46A.png"|":princess:":"emojione/1F478.png";
"emojione/1F46A.png"|":guardsman:":"emojione/1F482.png";
"emojione/1F46A.png"|":angel:":"emojione/1F47C.png";
"emojione/1F46A.png"|":santa:":"emojione/1F385.png";
"emojione/1F46A.png"|":ghost:":"emojione/1F47B.png";
"emojione/1F46A.png"|":skull:|:skeleton:":"emojione/1F480.png";
"emojione/1F46A.png"|":alien:":"emojione/1F47D.png";
"emojione/1F46A.png"|":space_invader:":"emojione/1F47E.png";
"emojione/1F46A.png"|":japanese_ogre:":"emojione/1F479.png";
"emojione/1F46A.png"|":japanese_goblin:":"emojione/1F47A.png";
"emojione/1F46A.png"|":bow:":"emojione/1F647.png";
"emojione/1F46A.png"|":information_desk_person:":"emojione/1F481.png";
"emojione/1F44D.png"|":raised_hands:":"emojione/1F64C.png";
"emojione/1F44D.png"|":clap:":"emojione/1F44F.png";
"emojione/1F442.png"|":ear:":"emojione/1F442.png";
"emojione/1F442.png"|":eye:":"emojione/1F441.png";
"emojione/1F442.png"|":eyes:":"emojione/1F440.png";
"emojione/1F442.png"|":nose:":"emojione/1F443.png";
"emojione/1F442.png"|":lips:":"emojione/1F444.png";
"emojione/1F442.png"|":lips2:":"emojione/1F5E2.png";
"emojione/1F442.png"|":kiss:":"emojione/1F48B.png";
"emojione/1F442.png"|":tongue:":"emojione/1F445.png";
"emojione/1F442.png"|":nail_care:":"emojione/1F485.png";
"emojione/1F44D.png"|":wave:":"emojione/1F44B.png";
"emojione/1F44D.png"|":thumbsup:|:+1:|(y)|(Y)":"emojione/1F44D.png";
"emojione/1F44D.png"|":thumbsdown:|:-1:|(N)|(n)":"emojione/1F44E.png";
"emojione/1F44D.png"|":muscle:":"emojione/1F4AA.png";
"emojione/1F44D.png"|":middle_finger:|":"emojione/1F595.png";
"emojione/1F44D.png"|":finger_pointing_down:":"emojione/1F597.png";
"emojione/1F44D.png"|":finger_pointing_left:":"emojione/1F598.png";
"emojione/1F44D.png"|":finger_pointing_right:":"emojione/1F599.png";
"emojione/1F44D.png"|":finger_pointing_up:":"emojione/1F59E.png";
"emojione/1F370.png"|":coffee:|(C)|(c)":"emojione/2615.png";
"emojione/1F370.png"|":sake:":"emojione/1F376.png";
"emojione/1F370.png"|":tea:":"emojione/1F375.png";
"emojione/1F370.png"|":cake:":"emojione/1F370.png";
"emojione/1F370.png"|":egg:":"emojione/1F373.png";
"emojione/1F370.png"|":hamburger:":"emojione/1F354.png";
"emojione/1F370.png"|":doughnut:":"emojione/1F369.png";
"emojione/1F370.png"|":wine_glass:":"emojione/1F377.png";
"emojione/1F370.png"|":cocktail:":"emojione/1F378.png";
"emojione/1F370.png"|":tropical_drink:":"emojione/1F379.png";
"emojione/1F370.png"|":beer:|(B)|(b)":"emojione/1F37A.png";
"emojione/1F370.png"|":beers:":"emojione/1F37B.png";
"?"|":watch:":"emojione/231A.png";
"?"|":iphone:":"emojione/1F4F1.png";
"?"|":monkey:":"emojione/1F412.png";
"?"|":see_no_evil:":"emojione/1F648.png";
"?"|":hear_no_evil:":"emojione/1F649.png";
"?"|":speak_no_evil:":"emojione/1F64A.png";
"?"|":turtle:":"emojione/1F422.png";
"?"|":frog:":"emojione/1F438.png";
"?"|":airplane:":"emojione/2708.png";
"?"|":heart:|<3":"emojione/2764.png";
"?"|":broken_heart:|</3":"emojione/1F494.png";
"?"|":love_letter:":"emojione/1F48C.png";
"?"|":two_hearts:":"emojione/1F495.png";
"?"|":revolving_hearts:":"emojione/1F49E.png";
"?"|":heartbeat:":"emojione/1F493.png";
"?"|":heartpulse:":"emojione/1F497.png";
"?"|":sparkling_heart:":"emojione/1F496.png";
"?"|":cupid:":"emojione/1F498.png";
"?"|":gift_heart:":"emojione/1F49D.png";
"?"|":birthday:":"emojione/1F382.png";
"?"|":gift:":"emojione/1F381.png";
"?"|":christmas_tree:":"emojione/1F384.png";
"?"|":penguin:":"emojione/1F427.png";
"?"|":sunny:":"emojione/2600.png";
"?"|":partly_sunny:":"emojione/26C5.png";
"?"|":cloud:":"emojione/2601.png";
"?"|":cloud_rain:":"emojione/1F327.png";
"?"|":cloud_snow:":"emojione/1F328.png";
"?"|":cloud_lightning:":"emojione/1F329.png";
"?"|":cloud_tornado:":"emojione/1F32A.png";
"?"|":crescent_moon:":"emojione/1F319.png";
"?"|":umbrella:":"emojione/2614.png";
"?"|":snowflake:":"emojione/2744.png";
"emojione/1F44D.png"|":fist:":"emojione/270A.png";
"emojione/1F44D.png"|":v:":"emojione/270C.png";
"emojione/1F44D.png"|":raised_hand:":"emojione/270B.png";
"emojione/1F44D.png"|":point_up:":"emojione/261D.png";
"emojione/1F370.png"|":pizza:":"emojione/1F355.png";
"emojione/1F370.png"|":cookie:":"emojione/1F36A.png";
"emojione/1F44D.png"|":ok_hand:":"emojione/1F44C.png";
"?"|":four_leaf_clover:":"emojione/1F340.png";
"?"|":jack_o_lantern:":"emojione/1F383.png";
"?"|":bouquet:":"emojione/1F490.png";
"emojione/1F44D.png"|":vulcan:":"emojione/1F596.png";
"emojione/1F600.png"|":zipper_mouth_face:":"emojione/1f910.png";
"emojione/1F600.png"|":money_mouth_face:":"emojione/1f911.png";
"emojione/1F600.png"|":face_with_thermometer:":"emojione/1f912.png";
"emojione/1F600.png"|":nerd_face:":"emojione/1f913.png";
"emojione/1F600.png"|":thinking_face:":"emojione/1f914.png";
"emojione/1F600.png"|":head_bandage:":"emojione/1f915.png";
"emojione/1F600.png"|":robot_face:":"emojione/1f916.png";
"emojione/1F600.png"|":updside_down_face:":"emojione/1f643.png";
}

View File

@ -166,43 +166,47 @@ RsHtml::RsHtml()
{
}
void RsHtml::initEmoticons(const QHash< QString, QString >& hash)
void RsHtml::initEmoticons(const QHash<QString, QPair<QVector<QString>, QHash<QString, QString> > >& hash)
{
QString newRE;
for(QHash<QString,QString>::const_iterator it = hash.begin(); it != hash.end(); ++it)
foreach(QString smile, it.key().split("|")) {
if (smile.isEmpty()) {
continue;
}
defEmbedImg.smileys.insert(smile, it.value());
// add space around smileys
newRE += "(?:^|\\s)(" + QRegExp::escape(smile) + ")(?:$|\\s)|";
// explanations:
// (?:^|\s)(*smiley*)(?:$|\s)
//
// (?:^|\s) Non-capturing group
// 1st Alternative: ^
// ^ assert position at start of the string
// 2nd Alternative: \s
// \s match any white space character [\r\n\t\f ]
//
// 1st Capturing group (*smiley*)
// *smiley* matches the characters *smiley* literally (case sensitive)
//
// (?:$|\s) Non-capturing group
// 1st Alternative: $
// $ assert position at end of the string
// 2nd Alternative: \s
// \s match any white space character [\r\n\t\f ]
for(QHash<QString, QPair<QVector<QString>, QHash<QString, QString> > >::const_iterator groupit = hash.begin(); groupit != hash.end(); ++groupit) {
QHash<QString,QString> group = groupit.value().second;
for(QHash<QString,QString>::const_iterator it = group.begin(); it != group.end(); ++it)
foreach(QString smile, it.key().split("|")) {
if (smile.isEmpty()) {
continue;
}
defEmbedImg.smileys.insert(smile, it.value());
// add space around smileys
newRE += "(?:^|\\s)(" + QRegExp::escape(smile) + ")(?:$|\\s)|";
// explanations:
// (?:^|\s)(*smiley*)(?:$|\s)
//
// (?:^|\s) Non-capturing group
// 1st Alternative: ^
// ^ assert position at start of the string
// 2nd Alternative: \s
// \s match any white space character [\r\n\t\f ]
//
// 1st Capturing group (*smiley*)
// *smiley* matches the characters *smiley* literally (case sensitive)
//
// (?:$|\s) Non-capturing group
// 1st Alternative: $
// $ assert position at end of the string
// 2nd Alternative: \s
// \s match any white space character [\r\n\t\f ]
/*
/*
* TODO
* a better version is:
* (?<=^|\s)(*smile*)(?=$|\s) using the lookbehind/lookahead operator instead of non-capturing groups.
* This solves the problem that spaces are matched, too (see workaround in RsHtml::embedHtml)
* This is not supported by Qt4!
*/
}
}
}
newRE.chop(1); // remove last |
defEmbedImg.myREs.append(QRegExp(newRE));
}

View File

@ -60,7 +60,7 @@ class RsHtml
public:
RsHtml();
static void initEmoticons(const QHash< QString, QString >& hash);
static void initEmoticons(const QHash<QString, QPair<QVector<QString>, QHash<QString, QString> > > &hash);
QString formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0, int desiredMinimumFontSize = 10);
static bool findAnchors(const QString &text, QStringList& urls);