Changeset View
Changeset View
Standalone View
Standalone View
kcms/icons/iconthemes.cpp
Show First 20 Lines • Show All 390 Lines • ▼ Show 20 Line(s) | 390 | if (selectedtheme == KIconTheme::current() || | |||
---|---|---|---|---|---|
391 | selectedtheme == KIconTheme::defaultThemeName()) | 391 | selectedtheme == KIconTheme::defaultThemeName()) | ||
392 | enabled = false; | 392 | enabled = false; | ||
393 | } | 393 | } | ||
394 | m_removeButton->setEnabled(enabled); | 394 | m_removeButton->setEnabled(enabled); | ||
395 | } | 395 | } | ||
396 | 396 | | |||
397 | void loadPreview(QLabel *label, KIconTheme& icontheme, const QStringList& iconnames) | 397 | void loadPreview(QLabel *label, KIconTheme& icontheme, const QStringList& iconnames) | ||
398 | { | 398 | { | ||
399 | const qreal dpr = label->devicePixelRatioF(); | ||||
400 | | ||||
399 | //Given the icontheme loads a preview of an icon (several names are allowed for old theme standards) into the pixmap of the given label | 401 | //Given the icontheme loads a preview of an icon (several names are allowed for old theme standards) into the pixmap of the given label | ||
400 | const int size = qMin(48, icontheme.defaultSize(KIconLoader::Desktop)); | 402 | const int size = qMin(48, icontheme.defaultSize(KIconLoader::Desktop)) * dpr; | ||
401 | QSvgRenderer renderer; | 403 | QSvgRenderer renderer; | ||
402 | foreach(const QString &iconthemename, QStringList() << icontheme.internalName() << icontheme.inherits()) { | 404 | foreach(const QString &iconthemename, QStringList() << icontheme.internalName() << icontheme.inherits()) { | ||
403 | foreach(const QString &name, iconnames) { | 405 | foreach(const QString &name, iconnames) { | ||
404 | //load the icon image | 406 | //load the icon image | ||
405 | QString path = KIconTheme(iconthemename).iconPath(QStringLiteral("%1.png").arg(name), size, KIconLoader::MatchBest); | 407 | QString path = KIconTheme(iconthemename).iconPath(QStringLiteral("%1.png").arg(name), size, KIconLoader::MatchBest); | ||
406 | if (path != QString()) { | 408 | if (path != QString()) { | ||
407 | label->setPixmap(QPixmap(path).scaled(size, size)); | 409 | QPixmap pixmap(path); | ||
410 | pixmap.setDevicePixelRatio(dpr); | ||||
411 | label->setPixmap(pixmap.scaled(size, size)); | ||||
408 | return; | 412 | return; | ||
409 | } | 413 | } | ||
410 | //could not find the .png, try loading the .svg or .svgz | 414 | //could not find the .png, try loading the .svg or .svgz | ||
411 | path = KIconTheme(iconthemename).iconPath(QStringLiteral("%1.svg").arg(name), size, KIconLoader::MatchBest); | 415 | path = KIconTheme(iconthemename).iconPath(QStringLiteral("%1.svg").arg(name), size, KIconLoader::MatchBest); | ||
412 | if( path == QString() ) { | 416 | if( path == QString() ) { | ||
413 | path = KIconTheme(iconthemename).iconPath(QStringLiteral("%1.svgz").arg(name), size, KIconLoader::MatchBest); | 417 | path = KIconTheme(iconthemename).iconPath(QStringLiteral("%1.svgz").arg(name), size, KIconLoader::MatchBest); | ||
414 | if( path == QString() ) { | 418 | if( path == QString() ) { | ||
415 | continue; | 419 | continue; | ||
416 | } | 420 | } | ||
417 | } | 421 | } | ||
418 | if (renderer.load(path)) { | 422 | if (renderer.load(path)) { | ||
419 | QPixmap pix(size, size); | 423 | QPixmap pix(size * dpr, size * dpr); | ||
420 | pix.fill(label->palette().color(QPalette::Background)); | 424 | pix.setDevicePixelRatio(dpr); | ||
425 | pix.fill(QColor(Qt::transparent)); | ||||
421 | QPainter p(&pix); | 426 | QPainter p(&pix); | ||
422 | p.setViewport(0, 0, size, size); | 427 | p.setViewport(0, 0, size, size); | ||
423 | renderer.render(&p); | 428 | renderer.render(&p); | ||
424 | label->setPixmap(pix.scaled(size, size)); | 429 | label->setPixmap(pix.scaled(size, size)); | ||
425 | return; | 430 | return; | ||
426 | } | 431 | } | ||
427 | } | 432 | } | ||
428 | } | 433 | } | ||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |