Skip to content

Commit

Permalink
MainWindow: add rasterized pixmaps to QIcon instead of loading the SV…
Browse files Browse the repository at this point in the history
…G file directly
  • Loading branch information
davidebeatrici committed Mar 5, 2018
1 parent 412f197 commit 65a33a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
37 changes: 13 additions & 24 deletions src/mumble/MainWindow.cpp
Expand Up @@ -45,6 +45,7 @@
#include "Settings.h"
#include "Themes.h"
#include "SSLCipherInfo.h"
#include "SvgIcon.h"

#ifdef Q_OS_WIN
#include "TaskList.h"
Expand All @@ -63,37 +64,25 @@ OpenURLEvent::OpenURLEvent(QUrl u) : QEvent(static_cast<QEvent::Type>(OU_QEVENT)
}

MainWindow::MainWindow(QWidget *p) : QMainWindow(p) {
qiIconMuteSelf.addFile(QLatin1String("skin:muted_self.svg"));
qiIconMuteServer.addFile(QLatin1String("skin:muted_server.svg"));
qiIconMuteSuppressed.addFile(QLatin1String("skin:muted_suppressed.svg"));
qiIconMutePushToMute.addFile(QLatin1String("skin:muted_pushtomute.svg"));
qiIconDeafSelf.addFile(QLatin1String("skin:deafened_self.svg"));
qiIconDeafServer.addFile(QLatin1String("skin:deafened_server.svg"));
qiTalkingOff.addFile(QLatin1String("skin:talking_off.svg"));
qiTalkingOn.addFile(QLatin1String("skin:talking_on.svg"));
qiTalkingShout.addFile(QLatin1String("skin:talking_alt.svg"));
qiTalkingWhisper.addFile(QLatin1String("skin:talking_whisper.svg"));
SvgIcon::addSvgPixmapsToIcon(qiIconMuteSelf, QLatin1String("skin:muted_self.svg"));
SvgIcon::addSvgPixmapsToIcon(qiIconMuteServer, QLatin1String("skin:muted_server.svg"));
SvgIcon::addSvgPixmapsToIcon(qiIconMuteSuppressed, QLatin1String("skin:muted_suppressed.svg"));
SvgIcon::addSvgPixmapsToIcon(qiIconMutePushToMute, QLatin1String("skin:muted_pushtomute.svg"));
SvgIcon::addSvgPixmapsToIcon(qiIconDeafSelf, QLatin1String("skin:deafened_self.svg"));
SvgIcon::addSvgPixmapsToIcon(qiIconDeafServer, QLatin1String("skin:deafened_server.svg"));
SvgIcon::addSvgPixmapsToIcon(qiTalkingOff, QLatin1String("skin:talking_off.svg"));
SvgIcon::addSvgPixmapsToIcon(qiTalkingOn, QLatin1String("skin:talking_on.svg"));
SvgIcon::addSvgPixmapsToIcon(qiTalkingShout, QLatin1String("skin:talking_alt.svg"));
SvgIcon::addSvgPixmapsToIcon(qiTalkingWhisper, QLatin1String("skin:talking_whisper.svg"));

#ifdef Q_OS_MAC
if (QFile::exists(QLatin1String("skin:mumble.icns")))
qiIcon.addFile(QLatin1String("skin:mumble.icns"));
else
qiIcon.addFile(QLatin1String("skin:mumble.svg"));
SvgIcon::addSvgPixmapsToIcon(qiIcon, QLatin1String("skin:mumble.svg"));
#else
{
QSvgRenderer svg(QLatin1String("skin:mumble.svg"));
QPixmap original(512,512);
original.fill(Qt::transparent);

QPainter painter(&original);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
svg.render(&painter);

for (int sz=8;sz<=256;sz+=8)
qiIcon.addPixmap(original.scaled(sz,sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
SvgIcon::addSvgPixmapsToIcon(qiIcon, QLatin1String("skin:mumble.svg"));
}

// Set application icon except on MacOSX, where the window-icon
Expand Down
2 changes: 1 addition & 1 deletion src/mumble/SvgIcon.h
Expand Up @@ -14,7 +14,7 @@ class SvgIcon
/// addSvgPixmapsToIcon renders the SVG file at |fn| in various
/// sizes from 8x8 up to 512x512 and adds the resulting rasterized
/// pixmaps to |icon|.
void addSvgPixmapsToIcon(QIcon &icon, QString fn);
static void addSvgPixmapsToIcon(QIcon &icon, QString fn);
};

#endif

0 comments on commit 65a33a7

Please sign in to comment.