Commit 49928cdb authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Use QIcon instead of QPixmap where possible

This avoids having to specify a size in some places.

There is a behavior change. The code clearly intends to fall back to
specific icons when the requested name is not available. However this
does not work since the first call to QIcon::fromTheme will always give
a non-null pixmap since it has a builtin fallback. The new code
correctly makes use of the fallback icons.
parent 292b2bd2
...@@ -28,21 +28,12 @@ KWalletFolderItem::KWalletFolderItem(KWallet::Wallet *w, QTreeWidget *parent, co ...@@ -28,21 +28,12 @@ KWalletFolderItem::KWalletFolderItem(KWallet::Wallet *w, QTreeWidget *parent, co
{ {
setText(0, QStringLiteral("%1 (%2)").arg(_name).arg(_entries)); setText(0, QStringLiteral("%1 (%2)").arg(_name).arg(_entries));
setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled); setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled);
setIcon(0, getFolderIcon(KIconLoader::Small)); setIcon(0, getFolderIcon());
} }
QPixmap KWalletFolderItem::getFolderIcon(KIconLoader::Group group) QIcon KWalletFolderItem::getFolderIcon()
{ {
const auto iconSize = KIconLoader::global()->currentSize(group); return QIcon::fromTheme(_name, QIcon::fromTheme(_name.toLower(), QIcon::fromTheme(QStringLiteral("folder-red"))));
QPixmap pix = QIcon::fromTheme(_name).pixmap(iconSize);
if (pix.isNull()) {
pix = QIcon::fromTheme(_name.toLower()).pixmap(iconSize);
if (pix.isNull())
pix = QIcon::fromTheme(QStringLiteral("folder-red")).pixmap(iconSize);
}
return pix;
} }
void KWalletFolderItem::refresh() void KWalletFolderItem::refresh()
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#define ALLYOURBASE_H #define ALLYOURBASE_H
#include <KWallet> #include <KWallet>
#include <KIconLoader>
#include <KIconTheme>
#include <QListWidget> #include <QListWidget>
#include <QPixmap> #include <QPixmap>
...@@ -77,7 +75,7 @@ public: ...@@ -77,7 +75,7 @@ public:
QString name() const; QString name() const;
void refresh(); void refresh();
KWalletContainerItem *getContainer(KWallet::Wallet::EntryType type); KWalletContainerItem *getContainer(KWallet::Wallet::EntryType type);
QPixmap getFolderIcon(KIconLoader::Group group); QIcon getFolderIcon();
bool contains(const QString &itemKey); bool contains(const QString &itemKey);
QTreeWidgetItem *getItem(const QString &itemKey); QTreeWidgetItem *getItem(const QString &itemKey);
void refreshItemsCount(); void refreshItemsCount();
......
...@@ -619,7 +619,7 @@ void KWalletEditor::entrySelectionChanged(QTreeWidgetItem *item) ...@@ -619,7 +619,7 @@ void KWalletEditor::entrySelectionChanged(QTreeWidgetItem *item)
if (fi) { if (fi) {
_currentFolder = fi->name(); _currentFolder = fi->name();
_entryTitle->setText(QStringLiteral("<font size=\"+1\">%1</font>").arg(fi->text(0))); _entryTitle->setText(QStringLiteral("<font size=\"+1\">%1</font>").arg(fi->text(0)));
_iconTitle->setPixmap(fi->getFolderIcon(KIconLoader::Toolbar)); _iconTitle->setPixmap(fi->getFolderIcon().pixmap(KIconLoader::global()->currentSize(KIconLoader::Toolbar)));
} }
_displayedItem = item; _displayedItem = item;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment