summaryrefslogtreecommitdiff
path: root/src/icondelegate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/icondelegate.cpp')
-rw-r--r--src/icondelegate.cpp61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp
index e502dc69..4125210a 100644
--- a/src/icondelegate.cpp
+++ b/src/icondelegate.cpp
@@ -18,50 +18,43 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "icondelegate.h"
+#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QPainter>
-#include <QDebug>
#include <QPixmapCache>
+IconDelegate::IconDelegate(QObject* parent) : QStyledItemDelegate(parent) {}
-IconDelegate::IconDelegate(QObject *parent)
- : QStyledItemDelegate(parent)
-{
-}
-
+void IconDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
+ QStyledItemDelegate::paint(painter, option, index);
-void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
-{
- QStyledItemDelegate::paint(painter, option, index);
+ QList<QString> icons = getIcons(index);
- QList<QString> icons = getIcons(index);
+ int x = 4;
+ painter->save();
- int x = 4;
- painter->save();
+ int iconWidth = icons.size() > 0 ? ((option.rect.width() / icons.size()) - 4) : 16;
+ iconWidth = std::min(16, iconWidth);
- int iconWidth = icons.size() > 0 ? ((option.rect.width() / icons.size()) - 4) : 16;
- iconWidth = std::min(16, iconWidth);
-
- painter->translate(option.rect.topLeft());
- for (const QString &iconId : icons) {
- if (iconId.isEmpty()) {
- x += iconWidth + 4;
- continue;
- }
- QPixmap icon;
- QString fullIconId = QString("%1_%2").arg(iconId).arg(iconWidth);
- if (!QPixmapCache::find(fullIconId, &icon)) {
- icon = QIcon(iconId).pixmap(iconWidth, iconWidth);
- if (icon.isNull()) {
- qWarning("failed to load icon %s", qPrintable(iconId));
- }
- QPixmapCache::insert(fullIconId, icon);
+ painter->translate(option.rect.topLeft());
+ for (const QString& iconId : icons) {
+ if (iconId.isEmpty()) {
+ x += iconWidth + 4;
+ continue;
+ }
+ QPixmap icon;
+ QString fullIconId = QString("%1_%2").arg(iconId).arg(iconWidth);
+ if (!QPixmapCache::find(fullIconId, &icon)) {
+ icon = QIcon(iconId).pixmap(iconWidth, iconWidth);
+ if (icon.isNull()) {
+ qWarning("failed to load icon %s", qPrintable(iconId));
+ }
+ QPixmapCache::insert(fullIconId, icon);
+ }
+ painter->drawPixmap(x, 2, iconWidth, iconWidth, icon);
+ x += iconWidth + 4;
}
- painter->drawPixmap(x, 2, iconWidth, iconWidth, icon);
- x += iconWidth + 4;
- }
- painter->restore();
+ painter->restore();
}
-