diff options
| author | Tannin <devnull@localhost> | 2014-04-05 15:36:42 +0200 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2014-04-05 15:36:42 +0200 |
| commit | cabed9b268c9f095d5e3b98a6797b0bcdcd38b1f (patch) | |
| tree | 454b03b0c5664e90fe586e7b39603e34a526d35b /src/icondelegate.cpp | |
| parent | 98e5e57a845541acddf519a81957261f58008cb9 (diff) | |
| parent | c017f4a0d50b67a44e276bd5ae8929ed3990c62c (diff) | |
Merge with branch1.1
Diffstat (limited to 'src/icondelegate.cpp')
| -rw-r--r-- | src/icondelegate.cpp | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp index 2540e1d5..a0993add 100644 --- a/src/icondelegate.cpp +++ b/src/icondelegate.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QHBoxLayout> #include <QLabel> #include <QPainter> +#include <QDebug> IconDelegate::IconDelegate(QObject *parent) @@ -29,53 +30,41 @@ IconDelegate::IconDelegate(QObject *parent) } -QIcon IconDelegate::getFlagIcon(ModInfo::EFlag flag) const -{ - switch (flag) { - case ModInfo::FLAG_BACKUP: return QIcon(":/MO/gui/emblem_backup"); - case ModInfo::FLAG_INVALID: return QIcon(":/MO/gui/emblem_problem"); - case ModInfo::FLAG_NOTENDORSED: return QIcon(":/MO/gui/emblem_notendorsed"); - case ModInfo::FLAG_NOTES: return QIcon(":/MO/gui/emblem_notes"); - case ModInfo::FLAG_CONFLICT_OVERWRITE: return QIcon(":/MO/gui/emblem_conflict_overwrite"); - case ModInfo::FLAG_CONFLICT_OVERWRITTEN: return QIcon(":/MO/gui/emblem_conflict_overwritten"); - case ModInfo::FLAG_CONFLICT_MIXED: return QIcon(":/MO/gui/emblem_conflict_mixed"); - case ModInfo::FLAG_CONFLICT_REDUNDANT: return QIcon(":MO/gui/emblem_conflict_redundant"); - default: return QIcon(); - } -} - - void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyledItemDelegate::paint(painter, option, index); - QVariant modid = index.data(Qt::UserRole + 1); - if (!modid.isValid()) { - return; - } - ModInfo::Ptr info = ModInfo::getByIndex(modid.toInt()); - std::vector<ModInfo::EFlag> flags = info->getFlags(); + + QList<QIcon> icons = getIcons(index); int x = 4; painter->save(); + + int iconWidth = icons.size() > 0 ? ((option.rect.width() / icons.size()) - 4) : 16; + iconWidth = std::min(16, iconWidth); + painter->translate(option.rect.topLeft()); - for (auto iter = flags.begin(); iter != flags.end(); ++iter) { - QIcon temp = getFlagIcon(*iter); - painter->drawPixmap(x, 2, 16, 16, temp.pixmap(QSize(16, 16))); - x += 20; + for (auto iter = icons.begin(); iter != icons.end(); ++iter) { + painter->drawPixmap(x, 2, iconWidth, iconWidth, iter->pixmap(QSize(iconWidth, iconWidth))); + x += iconWidth + 4; } painter->restore(); } -QSize IconDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex &modelIndex) const +QSize IconDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &modelIndex) const { + int count = getNumIcons(modelIndex); unsigned int index = modelIndex.data(Qt::UserRole + 1).toInt(); + QSize result; if (index < ModInfo::getNumMods()) { - ModInfo::Ptr info = ModInfo::getByIndex(index); - return QSize(info->getFlags().size() * 20, 20); + result = QSize(count * 40, 20); } else { - return QSize(1, 20); + result = QSize(1, 20); + } + if (option.rect.width() > 0) { + result.setWidth(std::min(option.rect.width(), result.width())); } + return result; } |
