1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

revert: "fix(icons): Removed unnecessary icon preparation."

This reverts commit fac0021a47.
This commit is contained in:
DX37 2017-03-03 10:48:11 +07:00
parent db2e2d7ab7
commit 8174a4173d
2 changed files with 38 additions and 6 deletions

View File

@ -118,27 +118,28 @@ void Widget::init()
actionShow = new QAction(this);
connect(actionShow, &QAction::triggered, this, &Widget::forceShow);
//Preparing icons and set their size
statusOnline = new QAction(this);
statusOnline->setIcon(QIcon(getStatusIconPath(Status::Online)));
statusOnline->setIcon(prepareIcon(getStatusIconPath(Status::Online), icon_size, icon_size));
connect(statusOnline, &QAction::triggered, this, &Widget::setStatusOnline);
statusAway = new QAction(this);
statusAway->setIcon(QIcon(getStatusIconPath(Status::Away)));
statusAway->setIcon(prepareIcon(getStatusIconPath(Status::Away), icon_size, icon_size));
connect(statusAway, &QAction::triggered, this, &Widget::setStatusAway);
statusBusy = new QAction(this);
statusBusy->setIcon(QIcon(getStatusIconPath(Status::Busy)));
statusBusy->setIcon(prepareIcon(getStatusIconPath(Status::Busy), icon_size, icon_size));
connect(statusBusy, &QAction::triggered, this, &Widget::setStatusBusy);
actionLogout = new QAction(this);
actionLogout->setIcon(QIcon(":/img/others/logout-icon.svg"));
actionLogout->setIcon(prepareIcon(":/img/others/logout-icon.svg", icon_size, icon_size));
actionQuit = new QAction(this);
#ifndef Q_OS_OSX
actionQuit->setMenuRole(QAction::QuitRole);
#endif
actionQuit->setIcon(QIcon(":/ui/rejectCall/rejectCall.svg"));
actionQuit->setIcon(prepareIcon(":/ui/rejectCall/rejectCall.svg", icon_size, icon_size));
connect(actionQuit, &QAction::triggered, qApp, &QApplication::quit);
layout()->setContentsMargins(0, 0, 0, 0);
@ -631,7 +632,7 @@ void Widget::onBadProxyCore()
void Widget::onStatusSet(Status status)
{
ui->statusButton->setProperty("status", getStatusTitle(status));
ui->statusButton->setIcon(QIcon(getStatusIconPath(status)));
ui->statusButton->setIcon(prepareIcon(getStatusIconPath(status), icon_size, icon_size));
updateIcons();
}
@ -2064,6 +2065,36 @@ QString Widget::getStatusIconPath(Status status)
}
}
//Preparing needed to set correct size of icons for GTK tray backend
inline QIcon Widget::prepareIcon(QString path, int w, int h)
{
#ifdef Q_OS_LINUX
QString desktop = getenv("XDG_CURRENT_DESKTOP");
if (desktop.isEmpty())
{
desktop = getenv("DESKTOP_SESSION");
}
desktop = desktop.toLower();
if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate" || desktop == "x-cinnamon")
{
if (w > 0 && h > 0)
{
QSvgRenderer renderer(path);
QPixmap pm(w, h);
pm.fill(Qt::transparent);
QPainter painter(&pm);
renderer.render(&painter, pm.rect());
return QIcon(pm);
}
}
#endif
return QIcon(path);
}
QPixmap Widget::getStatusIconPixmap(QString path, uint32_t w, uint32_t h)
{
QPixmap pix(w, h);

View File

@ -122,6 +122,7 @@ public:
void reloadTheme();
static QString getStatusIconPath(Status status);
static inline QIcon prepareIcon(QString path, int w = 0, int h = 0);
static QPixmap getStatusIconPixmap(QString path, uint32_t w, uint32_t h);
static QString getStatusTitle(Status status);
static Status getStatusFromString(QString status);