diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/icondelegate.cpp | 21 | ||||
| -rw-r--r-- | src/modflagicondelegate.cpp | 22 | ||||
| -rw-r--r-- | src/modflagicondelegate.h | 3 | ||||
| -rw-r--r-- | src/modinfo.cpp | 12 |
4 files changed, 44 insertions, 14 deletions
diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp index 048b09f9..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) @@ -37,25 +38,33 @@ void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, 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 = icons.begin(); iter != icons.end(); ++iter) { - painter->drawPixmap(x, 2, 16, 16, iter->pixmap(QSize(16, 16))); - x += 20; + 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; } diff --git a/src/modflagicondelegate.cpp b/src/modflagicondelegate.cpp index db69eb52..914503a1 100644 --- a/src/modflagicondelegate.cpp +++ b/src/modflagicondelegate.cpp @@ -2,6 +2,11 @@ #include <QList>
+ModInfo::EFlag ModFlagIconDelegate::m_ConflictFlags[4] = { ModInfo::FLAG_CONFLICT_MIXED
+ , ModInfo::FLAG_CONFLICT_OVERWRITE
+ , ModInfo::FLAG_CONFLICT_OVERWRITTEN
+ , ModInfo::FLAG_CONFLICT_REDUNDANT };
+
ModFlagIconDelegate::ModFlagIconDelegate(QObject *parent)
: IconDelegate(parent)
{
@@ -15,6 +20,16 @@ QList<QIcon> ModFlagIconDelegate::getIcons(const QModelIndex &index) const ModInfo::Ptr info = ModInfo::getByIndex(modid.toInt());
std::vector<ModInfo::EFlag> flags = info->getFlags();
+ { // insert conflict icon first to provide nicer alignment
+ auto iter = std::find_first_of(flags.begin(), flags.end(), m_ConflictFlags, m_ConflictFlags + 4);
+ if (iter != flags.end()) {
+ result.append(getFlagIcon(*iter));
+ flags.erase(iter);
+ } else {
+ result.append(QIcon());
+ }
+ }
+
for (auto iter = flags.begin(); iter != flags.end(); ++iter) {
result.append(getFlagIcon(*iter));
}
@@ -42,7 +57,12 @@ size_t ModFlagIconDelegate::getNumIcons(const QModelIndex &index) const unsigned int modIdx = index.data(Qt::UserRole + 1).toInt();
if (modIdx < ModInfo::getNumMods()) {
ModInfo::Ptr info = ModInfo::getByIndex(modIdx);
- return info->getFlags().size();
+ std::vector<ModInfo::EFlag> flags = info->getFlags();
+ int count = flags.size();
+ if (std::find_first_of(flags.begin(), flags.end(), m_ConflictFlags, m_ConflictFlags + 4) == flags.end()) {
+ ++count;
+ }
+ return count;
} else {
return 0;
}
diff --git a/src/modflagicondelegate.h b/src/modflagicondelegate.h index 800e2741..b64ca08f 100644 --- a/src/modflagicondelegate.h +++ b/src/modflagicondelegate.h @@ -12,7 +12,8 @@ private: virtual size_t getNumIcons(const QModelIndex &index) const;
QIcon getFlagIcon(ModInfo::EFlag flag) const;
-
+private:
+ static ModInfo::EFlag m_ConflictFlags[4];
};
#endif // MODFLAGICONDELEGATE_H
diff --git a/src/modinfo.cpp b/src/modinfo.cpp index ed13deae..bd244852 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -637,12 +637,6 @@ void ModInfoRegular::ignoreUpdate(bool ignore) std::vector<ModInfo::EFlag> ModInfoRegular::getFlags() const { std::vector<ModInfo::EFlag> result; - if (!isValid()) { - result.push_back(ModInfo::FLAG_INVALID); - } - if ((m_NexusID != -1) && (endorsedState() == ENDORSED_FALSE)) { - result.push_back(ModInfo::FLAG_NOTENDORSED); - } switch (isConflicted()) { case CONFLICT_MIXED: { result.push_back(ModInfo::FLAG_CONFLICT_MIXED); @@ -658,6 +652,12 @@ std::vector<ModInfo::EFlag> ModInfoRegular::getFlags() const } break; default: { /* NOP */ } } + if ((m_NexusID != -1) && (endorsedState() == ENDORSED_FALSE)) { + result.push_back(ModInfo::FLAG_NOTENDORSED); + } + if (!isValid()) { + result.push_back(ModInfo::FLAG_INVALID); + } if (m_Notes.length() != 0) { result.push_back(ModInfo::FLAG_NOTES); } |
