kcontrol: load preview icons in SVG/SVGZ format as any other format

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-02-01 18:11:59 +02:00
parent 9fcbe100a1
commit 21d5aaf376
2 changed files with 5 additions and 16 deletions

View file

@ -12,7 +12,7 @@ set(kcm_icons_PART_SRCS
kde4_add_plugin(kcm_icons ${kcm_icons_PART_SRCS}) kde4_add_plugin(kcm_icons ${kcm_icons_PART_SRCS})
target_link_libraries(kcm_icons ${KDE4_KIO_LIBS} ${QT_QTSVG_LIBRARY}) target_link_libraries(kcm_icons ${KDE4_KIO_LIBS} ${QT_QTGUI_LIBRARY})
########### install files ############### ########### install files ###############

View file

@ -30,8 +30,6 @@
#include <QFrame> #include <QFrame>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QTreeWidget> #include <QTreeWidget>
#include <QPainter>
#include <QSvgRenderer>
#include <kdebug.h> #include <kdebug.h>
#include <kapplication.h> #include <kapplication.h>
@ -109,7 +107,7 @@ IconThemesConfig::IconThemesConfig(const KComponentData &inst, QWidget *parent)
connect(m_removeButton,SIGNAL(clicked()),SLOT(removeSelectedTheme())); connect(m_removeButton,SIGNAL(clicked()),SLOT(removeSelectedTheme()));
topLayout->addWidget( topLayout->addWidget(
new QLabel(i18n("Select the icon theme you want to use:"), this)); new QLabel(i18n("Select the icon theme you want to use:"), this));
topLayout->addWidget(m_preview); topLayout->addWidget(m_preview);
topLayout->addWidget(m_iconThemes); topLayout->addWidget(m_iconThemes);
QHBoxLayout *lg = new QHBoxLayout(); QHBoxLayout *lg = new QHBoxLayout();
@ -370,7 +368,6 @@ void IconThemesConfig::updateRemoveButton()
void loadPreview(QLabel *label, KIconTheme& icontheme, const QStringList& iconnames) void loadPreview(QLabel *label, KIconTheme& icontheme, const QStringList& iconnames)
{ {
const int size = qMin(48, icontheme.defaultSize(KIconLoader::Desktop)); const int size = qMin(48, icontheme.defaultSize(KIconLoader::Desktop));
QSvgRenderer renderer;
foreach(const QString &iconthemename, QStringList() << icontheme.internalName() << icontheme.inherits()) { foreach(const QString &iconthemename, QStringList() << icontheme.internalName() << icontheme.inherits()) {
foreach(const QString &name, iconnames) { foreach(const QString &name, iconnames) {
K3Icon icon = KIconTheme(iconthemename).iconPath(QString("%1.png").arg(name), size, KIconLoader::MatchBest); K3Icon icon = KIconTheme(iconthemename).iconPath(QString("%1.png").arg(name), size, KIconLoader::MatchBest);
@ -379,19 +376,11 @@ void loadPreview(QLabel *label, KIconTheme& icontheme, const QStringList& iconna
return; return;
} }
icon = KIconTheme(iconthemename).iconPath(QString("%1.svg").arg(name), size, KIconLoader::MatchBest); icon = KIconTheme(iconthemename).iconPath(QString("%1.svg").arg(name), size, KIconLoader::MatchBest);
if( ! icon.isValid() ) { if(!icon.isValid() ) {
icon = KIconTheme(iconthemename).iconPath(QString("%1.svgz").arg(name), size, KIconLoader::MatchBest); icon = KIconTheme(iconthemename).iconPath(QString("%1.svgz").arg(name), size, KIconLoader::MatchBest);
if( ! icon.isValid() ) {
continue;
}
} }
if (renderer.load(icon.path)) { if (icon.isValid()) {
QPixmap pix(size, size); label->setPixmap(QPixmap(icon.path).scaled(size, size));
pix.fill(label->palette().color(QPalette::Background));
QPainter p(&pix);
p.setViewport(0, 0, size, size);
renderer.render(&p);
label->setPixmap(pix.scaled(size, size));
return; return;
} }
} }