From e96a1f3ced974b5d1b02907bf9feabca97d2baa9 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 3 Jan 2021 01:44:39 +0100 Subject: Fix indentation of indicators branches when using collapsible separators. --- src/moapplication.cpp | 17 ++++++++++------- src/modlist.cpp | 2 -- src/modlist.h | 10 ++++------ src/modlistview.cpp | 9 +++++++++ src/modlistview.h | 2 ++ 5 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 15fbdb3c..709bcbda 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -60,13 +60,13 @@ using namespace MOShared; // class ProxyStyle : public QProxyStyle { public: - ProxyStyle(QStyle *baseStyle = 0) + ProxyStyle(QStyle* baseStyle = 0) : QProxyStyle(baseStyle) { } - void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { - if(element == QStyle::PE_IndicatorItemViewItemDrop) { + void drawPrimitive(PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const { + if (element == QStyle::PE_IndicatorItemViewItemDrop) { // 1. full-width drop indicator QRect rect(option->rect); @@ -85,7 +85,7 @@ public: painter->setPen(pen); painter->setBrush(QBrush(col)); - if(rect.height() == 0) { + if (rect.height() == 0) { QPoint tri[3] = { rect.topLeft(), rect.topLeft() + QPoint(-5, 5), @@ -93,13 +93,16 @@ public: }; painter->drawPolygon(tri, 3); painter->drawLine(QPoint(rect.topLeft().x(), rect.topLeft().y()), rect.topRight()); - } else { + } + else { painter->drawRoundedRect(rect, 5, 5); } - } else { + } + else { QProxyStyle::drawPrimitive(element, option, painter, widget); } } + }; @@ -535,8 +538,8 @@ bool MOApplication::notify(QObject* receiver, QEvent* event) void MOApplication::updateStyle(const QString& fileName) { if (QStyleFactory::keys().contains(fileName)) { - setStyle(QStyleFactory::create(fileName)); setStyleSheet(""); + setStyle(new ProxyStyle(QStyleFactory::create(fileName))); } else { setStyle(new ProxyStyle(QStyleFactory::create(m_DefaultStyle))); if (QFile::exists(fileName)) { diff --git a/src/modlist.cpp b/src/modlist.cpp index c89e53d5..e541ff71 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -61,8 +61,6 @@ along with Mod Organizer. If not, see . using namespace MOBase; -const int ModList::ModUserRole = Qt::UserRole + QMetaEnum::fromType().keyCount(); - ModList::ModList(PluginContainer *pluginContainer, OrganizerCore *organizer) : QAbstractItemModel(organizer) , m_Organizer(organizer) diff --git a/src/modlist.h b/src/modlist.h index 9c963119..279ef71a 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -78,13 +78,11 @@ public: PriorityRole = Qt::UserRole + 5, // marking role for the scrollbar - ScrollMarkRole = Qt::UserRole + 6 - }; - - Q_ENUM(ModListRole) + ScrollMarkRole = Qt::UserRole + 6, - // this is the first available role - static const int ModUserRole; + // this is the first available role + ModUserRole = Qt::UserRole + 7 + }; enum EColumn { COL_NAME, diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 778b228d..c2942717 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -853,6 +853,15 @@ QRect ModListView::visualRect(const QModelIndex& index) const return rect; } +void ModListView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const +{ + QRect r(rect); + if (hasCollapsibleSeparators() && index.parent().isValid()) { + r.adjust(-indentation(), 0, 0 -indentation(), 0); + } + QTreeView::drawBranches(painter, r, index); +} + QModelIndexList ModListView::selectedIndexes() const { // during drag&drop events, we fake the return value of selectedIndexes() diff --git a/src/modlistview.h b/src/modlistview.h index c11c4fbf..b7d641ea 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -155,6 +155,8 @@ protected: bool toggleSelectionState(); bool copySelection(); + void drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const override; + void timerEvent(QTimerEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; void dragMoveEvent(QDragMoveEvent* event) override; -- cgit v1.3.1