Added buddy stars to chat

This commit is contained in:
Matt Lowe 2015-01-23 02:09:01 +01:00
parent b06b81895b
commit d5c8f45ab9
5 changed files with 85 additions and 0 deletions

View file

@ -54,6 +54,8 @@
<file>resources/genders/male.svg</file>
<file>resources/genders/female.svg</file>
<file>resources/genders/unknown.svg</file>
<file>resources/buddy_icon.svg</file>
<file>resources/countries/ar.svg</file>
<file>resources/countries/at.svg</file>

View file

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
viewBox="0 0 64 64"
enable-background="new 0 0 64 64"
id="svg2"
version="1.1"
inkscape:version="0.48.5 r10040"
width="100%"
height="100%"
sodipodi:docname="buddy_icon.svg">
<metadata
id="metadata12">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs10" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1028"
id="namedview8"
showgrid="false"
inkscape:zoom="7.375"
inkscape:cx="27.318536"
inkscape:cy="23.31428"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<path
d="M 60.456025,23.062583 38.036064,22.95865 31.209111,0.27044038 24.381168,22.95865 1.9602161,23.062586 20.162454,37.54598 10.959875,62.252482 31.209111,46.553559 51.468243,62.252482 42.254777,37.54598 z"
id="path4"
style="fill:#9600ec;fill-opacity:1"
inkscape:connector-curvature="0" />
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -133,6 +133,9 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
if (!sender.isEmpty()) {
const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel));
QMap<QString, UserListTWI *> buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers();
if (buddyList.contains(sender))
cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/buddy_icon.svg").toImage());
cursor.insertText(" ");
}
cursor.setCharFormat(senderFormat);

View file

@ -160,4 +160,20 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user
return pixmap;
}
QMap<QString, QPixmap> PixmapGenerator::pmCache;
QPixmap PixmapGenerator::generatePixmap(int height, QString resourceName) {
if (pmCache.contains(resourceName))
return pmCache.value(resourceName);
QSvgRenderer svg(resourceName);
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
QPixmap pixmap(width, height);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
svg.render(&painter, QRectF(0, 0, width, height));
pmCache.insert(resourceName, pixmap);
return pixmap;
}
QMap<int, QPixmap> UserLevelPixmapGenerator::pmCache;

View file

@ -54,4 +54,12 @@ public:
static void clear() { pmCache.clear(); }
};
class PixmapGenerator {
private:
static QMap<QString, QPixmap> pmCache;
public:
static QPixmap generatePixmap(int height, QString resourceName);
static void clear() { pmCache.clear(); }
};
#endif