Browse Source

Fix icon size issues

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
55aa6c36ee
  1. 32
      src/iconprovider.cpp
  2. 3
      src/iconprovider.h

32
src/iconprovider.cpp

@ -58,8 +58,11 @@ void IconProvider::drop() @@ -58,8 +58,11 @@ void IconProvider::drop()
QIcon IconProvider::getIcon(const QString &iconId)
{
#if defined(Q_WS_X11) && (QT_VERSION >= QT_VERSION_CHECK(4,6,0))
if(m_useSystemTheme)
return QIcon::fromTheme(iconId, QIcon(":/Icons/oxygen/"+iconId+".png"));
if(m_useSystemTheme) {
QIcon icon = QIcon::fromTheme(iconId, QIcon(":/Icons/oxygen/"+iconId+".png"));
icon = generateDifferentSizes(icon);
return icon;
}
#endif
return QIcon(":/Icons/oxygen/"+iconId+".png");
}
@ -69,6 +72,31 @@ void IconProvider::useSystemIconTheme(bool enable) @@ -69,6 +72,31 @@ void IconProvider::useSystemIconTheme(bool enable)
{
m_useSystemTheme = enable;
}
QIcon IconProvider::generateDifferentSizes(const QIcon &icon)
{
QIcon new_icon;
QList<QSize> required_sizes;
required_sizes << QSize(16, 16) << QSize(24, 24);
QList<QIcon::Mode> modes;
modes << QIcon::Normal << QIcon::Active << QIcon::Selected << QIcon::Disabled;
foreach(const QSize& size, required_sizes) {
foreach(QIcon::Mode mode, modes) {
QPixmap pixoff = icon.pixmap(size, mode, QIcon::Off);
if(pixoff.height() > size.height())
pixoff = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
new_icon.addPixmap(pixoff, mode, QIcon::Off);
Q_ASSERT(pixoff.height() <= size.height());
QPixmap pixon = icon.pixmap(size, mode, QIcon::On);
if(pixon.height() > size.height())
pixon = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
new_icon.addPixmap(pixon, mode, QIcon::On);
Q_ASSERT(pixon.height() <= size.height());
}
Q_ASSERT(new_icon.availableSizes().contains(size));
}
return new_icon;
}
#endif
QString IconProvider::getIconPath(const QString &iconId)

3
src/iconprovider.h

@ -52,6 +52,9 @@ public: @@ -52,6 +52,9 @@ public:
public:
void useSystemIconTheme(bool enable);
private:
QIcon generateDifferentSizes(const QIcon& icon);
private:
bool m_useSystemTheme;
#endif

Loading…
Cancel
Save