From cc4dcf617fbad6783b74b4df0963911a149ffaf1 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 31 Dec 2020 17:53:45 +0100 Subject: Move modlistview proxy style to moapplication. --- src/moapplication.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/moapplication.cpp') diff --git a/src/moapplication.cpp b/src/moapplication.cpp index fb6a7121..9b261a45 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -65,6 +65,13 @@ public: void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if(element == QStyle::PE_IndicatorItemViewItemDrop) { + + QRect rect(option->rect); + if (auto* view = qobject_cast(widget)) { + rect.setLeft(view->indentation()); + rect.setRight(widget->width()); + } + painter->setRenderHint(QPainter::Antialiasing, true); QColor col(option->palette.windowText().color()); @@ -75,16 +82,16 @@ public: painter->setPen(pen); painter->setBrush(brush); - if(option->rect.height() == 0) { + if(rect.height() == 0) { QPoint tri[3] = { - option->rect.topLeft(), - option->rect.topLeft() + QPoint(-5, 5), - option->rect.topLeft() + QPoint(-5, -5) + rect.topLeft(), + rect.topLeft() + QPoint(-5, 5), + rect.topLeft() + QPoint(-5, -5) }; painter->drawPolygon(tri, 3); - painter->drawLine(QPoint(option->rect.topLeft().x(), option->rect.topLeft().y()), option->rect.topRight()); + painter->drawLine(QPoint(rect.topLeft().x(), rect.topLeft().y()), rect.topRight()); } else { - painter->drawRoundedRect(option->rect, 5, 5); + painter->drawRoundedRect(rect, 5, 5); } } else { QProxyStyle::drawPrimitive(element, option, painter, widget); -- cgit v1.3.1 From e420b8fc265f2635334530742d32fcc5e49d88b2 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 31 Dec 2020 18:02:17 +0100 Subject: ProxyStyle documentation. --- src/moapplication.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/moapplication.cpp') diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 9b261a45..15fbdb3c 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -56,6 +56,8 @@ along with Mod Organizer. If not, see . using namespace MOBase; using namespace MOShared; +// style proxy that changes the appearance of drop indicators +// class ProxyStyle : public QProxyStyle { public: ProxyStyle(QStyle *baseStyle = 0) @@ -66,22 +68,23 @@ public: 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); if (auto* view = qobject_cast(widget)) { rect.setLeft(view->indentation()); rect.setRight(widget->width()); } + // 2. stylish drop indicator painter->setRenderHint(QPainter::Antialiasing, true); QColor col(option->palette.windowText().color()); QPen pen(col); pen.setWidth(2); col.setAlpha(50); - QBrush brush(col); painter->setPen(pen); - painter->setBrush(brush); + painter->setBrush(QBrush(col)); if(rect.height() == 0) { QPoint tri[3] = { rect.topLeft(), -- cgit v1.3.1 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/moapplication.cpp') 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