diff options
| author | Sandro Jäckel <sandro.jaeckel@gmail.com> | 2018-02-22 16:54:34 +0100 |
|---|---|---|
| committer | Sandro Jäckel <sandro.jaeckel@gmail.com> | 2018-02-22 16:54:34 +0100 |
| commit | 5e5c9c07291f6b09623d31c92b1fb61c4ede576e (patch) | |
| tree | 0684c123db375336e0e03f0240155a12e744db16 /src/icondelegate.cpp | |
| parent | 5ad912e1934061b38825801a27f7c12933878005 (diff) | |
Applied clang-format on source
Diffstat (limited to 'src/icondelegate.cpp')
| -rw-r--r-- | src/icondelegate.cpp | 61 |
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();
}
-
|
