Browse Source

Refactor GuiIconProvider::generateDifferentSizes()

adaptive-webui-19844
Chocobo1 6 years ago
parent
commit
e1727c9a6a
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 12
      src/gui/guiiconprovider.cpp

12
src/gui/guiiconprovider.cpp

@ -30,6 +30,7 @@
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include <QIcon> #include <QIcon>
#include <QVector>
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
@ -99,16 +100,15 @@ QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon) const
return icon; return icon;
QIcon newIcon; QIcon newIcon;
QList<QSize> requiredSizes; const QVector<QSize> requiredSizes {{16, 16}, {24, 24}, {32, 32}};
requiredSizes << QSize(16, 16) << QSize(24, 24) << QSize(32, 32); const QVector<QIcon::Mode> modes {QIcon::Normal, QIcon::Active, QIcon::Selected, QIcon::Disabled};
QList<QIcon::Mode> modes; for (const QSize &size : requiredSizes) {
modes << QIcon::Normal << QIcon::Active << QIcon::Selected << QIcon::Disabled; for (const QIcon::Mode mode : modes) {
foreach (const QSize &size, requiredSizes) {
foreach (QIcon::Mode mode, modes) {
QPixmap pixoff = icon.pixmap(size, mode, QIcon::Off); QPixmap pixoff = icon.pixmap(size, mode, QIcon::Off);
if (pixoff.height() > size.height()) if (pixoff.height() > size.height())
pixoff = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); pixoff = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
newIcon.addPixmap(pixoff, mode, QIcon::Off); newIcon.addPixmap(pixoff, mode, QIcon::Off);
QPixmap pixon = icon.pixmap(size, mode, QIcon::On); QPixmap pixon = icon.pixmap(size, mode, QIcon::On);
if (pixon.height() > size.height()) if (pixon.height() > size.height())
pixon = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); pixon = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);

Loading…
Cancel
Save