summaryrefslogtreecommitdiff
path: root/src/icondelegate.cpp
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2021-01-11 12:49:42 +0100
committerGitHub <noreply@github.com>2021-01-11 12:49:42 +0100
commit1dc2b225485a073d82e08a9820493086b2dda8b8 (patch)
tree5a4e5478d577f065c7282cb62992c2b6c735e13f /src/icondelegate.cpp
parenta680dfa3e94b34bf6b0ebd65d29d7a9799e3183f (diff)
parent05efc74e402ca3770d9fdaa2557f4030c31ee198 (diff)
Merge pull request #1350 from Holt59/collapsible-separators
Collapsible separators - Fix & Improvements.
Diffstat (limited to 'src/icondelegate.cpp')
-rw-r--r--src/icondelegate.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp
index 901b5731..7205ba62 100644
--- a/src/icondelegate.cpp
+++ b/src/icondelegate.cpp
@@ -27,9 +27,16 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
using namespace MOBase;
-IconDelegate::IconDelegate(QObject* parent)
- : QStyledItemDelegate(parent)
+IconDelegate::IconDelegate(QTreeView* view, int column, int compactSize) :
+ QStyledItemDelegate(view), m_column(column), m_compactSize(compactSize), m_compact(false)
{
+ if (view) {
+ connect(view->header(), &QHeaderView::sectionResized, [=](int column, int, int size) {
+ if (column == m_column) {
+ m_compact = size < m_compactSize;
+ }
+ });
+ }
}
void IconDelegate::paintIcons(
@@ -42,6 +49,8 @@ void IconDelegate::paintIcons(
int iconWidth = icons.size() > 0 ? ((option.rect.width() / icons.size()) - 4) : 16;
iconWidth = std::min(16, iconWidth);
+ const int margin = (option.rect.height() - iconWidth) / 2;
+
painter->translate(option.rect.topLeft());
for (const QString &iconId : icons) {
if (iconId.isEmpty()) {
@@ -57,7 +66,7 @@ void IconDelegate::paintIcons(
}
QPixmapCache::insert(fullIconId, icon);
}
- painter->drawPixmap(x, 2, iconWidth, iconWidth, icon);
+ painter->drawPixmap(x, margin, iconWidth, iconWidth, icon);
x += iconWidth + 4;
}
@@ -72,6 +81,7 @@ void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
else {
QStyledItemDelegate::paint(painter, option, index);
}
+
paintIcons(painter, option, index, getIcons(index));
}