summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/modlistversiondelegate.cpp60
-rw-r--r--src/modlistversiondelegate.h21
-rw-r--r--src/modlistview.cpp2
4 files changed, 84 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c274f989..d1092637 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -151,6 +151,7 @@ add_filter(NAME src/modlist/view GROUPS
modflagicondelegate
modcontenticondelegate
modconflicticondelegate
+ modlistversiondelegate
)
add_filter(NAME src/plugins GROUPS
diff --git a/src/modlistversiondelegate.cpp b/src/modlistversiondelegate.cpp
new file mode 100644
index 00000000..f60edcf8
--- /dev/null
+++ b/src/modlistversiondelegate.cpp
@@ -0,0 +1,60 @@
+#include "modlistversiondelegate.h"
+
+#include "modlistview.h"
+#include "log.h"
+
+ModListVersionDelegate::ModListVersionDelegate(ModListView* view) :
+ QItemDelegate(view), m_view(view) { }
+
+
+void ModListVersionDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+ m_view->itemDelegate()->paint(painter, option, index);
+
+ if (m_view->hasCollapsibleSeparators()
+ && m_view->model()->hasChildren(index)
+ && !m_view->isExpanded(index.sibling(index.row(), 0))) {
+ auto* model = m_view->model();
+
+ bool downgrade = false, upgrade = false;
+
+ for (int i = 0; i < model->rowCount(index); ++i) {
+ const auto mIndex = model->index(i, index.column(), index).data(ModList::IndexRole);
+ if (mIndex.isValid()) {
+ auto info = ModInfo::getByIndex(mIndex.toInt());
+ downgrade = downgrade || info->downgradeAvailable();
+ upgrade = upgrade || info->updateAvailable();
+ }
+ }
+
+ const int margin = m_view->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, m_view) + 1;
+
+ QStyleOptionViewItem opt(option);
+ const int sz = m_view->style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, m_view);
+ opt.decorationSize = QSize(sz, sz);
+ opt.decorationAlignment = Qt::AlignCenter;
+
+ if (upgrade) {
+ QIcon icon(":/MO/gui/update_available");
+ QPixmap pixmap = decoration(opt, icon);
+
+ QSize pm = icon.actualSize(opt.decorationSize);
+ pm.rwidth() += 2 * margin;
+ opt.rect.setRect(opt.rect.x(), opt.rect.y(), pm.width(), opt.rect.height());
+
+ drawDecoration(painter, opt, opt.rect, pixmap);
+ }
+
+ if (downgrade) {
+ QIcon icon(":/MO/gui/warning");
+ QPixmap pixmap = decoration(opt, icon);
+
+ QSize pm = icon.actualSize(opt.decorationSize);
+ pm.rwidth() += 2 * margin;
+ opt.rect.setRect(opt.rect.x() + opt.decorationSize.width() + margin, opt.rect.y(), pm.width(), opt.rect.height());
+
+ drawDecoration(painter, opt, opt.rect, pixmap);
+
+ }
+ }
+}
diff --git a/src/modlistversiondelegate.h b/src/modlistversiondelegate.h
new file mode 100644
index 00000000..8a51e9b4
--- /dev/null
+++ b/src/modlistversiondelegate.h
@@ -0,0 +1,21 @@
+#ifndef MODLISTVERSIONDELEGATE_H
+#define MODLISTVERSIONDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+class ModListView;
+
+class ModListVersionDelegate : public QItemDelegate
+{
+public:
+ ModListVersionDelegate(ModListView* view);
+
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
+
+
+private:
+
+ ModListView* m_view;
+};
+
+#endif
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index f4f045c6..c23cd34b 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -19,6 +19,7 @@
#include "modflagicondelegate.h"
#include "modconflicticondelegate.h"
#include "modcontenticondelegate.h"
+#include "modlistversiondelegate.h"
#include "modlistviewactions.h"
#include "modlistdropinfo.h"
#include "modlistcontextmenu.h"
@@ -776,6 +777,7 @@ void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindo
setItemDelegateForColumn(ModList::COL_FLAGS, new ModFlagIconDelegate(this, ModList::COL_FLAGS, 120));
setItemDelegateForColumn(ModList::COL_CONFLICTFLAGS, new ModConflictIconDelegate(this, ModList::COL_CONFLICTFLAGS, 80));
setItemDelegateForColumn(ModList::COL_CONTENT, new ModContentIconDelegate(this, ModList::COL_CONTENT, 150));
+ setItemDelegateForColumn(ModList::COL_VERSION, new ModListVersionDelegate(this));
if (m_core->settings().geometry().restoreState(header())) {
// hack: force the resize-signal to be triggered because restoreState doesn't seem to do that