From de87a105b0cbcc73440a2613af6446d0e8819fb6 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Tue, 29 Dec 2020 14:24:33 +0100 Subject: Fix indentation and drop indicator. --- src/mainwindow.cpp | 11 ++++++++--- src/modlistview.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/modlistview.h | 3 +++ 3 files changed, 58 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3ab61f98..3fdaa6d8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -558,6 +558,8 @@ void MainWindow::updateModListByPriorityProxy() void MainWindow::setupModList() { + ui->modList->setIndentation(0); + m_ModListByPriorityProxy = new ModListByPriorityProxy(m_OrganizerCore.currentProfile(), &m_OrganizerCore); connect(ui->modList, SIGNAL(expanded(QModelIndex)), m_ModListByPriorityProxy, SLOT(expanded(QModelIndex))); connect(ui->modList, SIGNAL(collapsed(QModelIndex)), m_ModListByPriorityProxy, SLOT(collapsed(QModelIndex))); @@ -2521,15 +2523,18 @@ void MainWindow::modInstalled(const QString &modName) ui->modList->expand(m_ModListSortProxy->mapFromSource(qIndex)); } - ui->modList->setCurrentIndex(m_ModListSortProxy->mapFromSource(qIndex)); - ui->modList->scrollTo(m_ModListSortProxy->mapFromSource(qIndex)); - ui->modList->setFocus(Qt::OtherFocusReason); + qIndex = m_ModListSortProxy->mapFromSource(qIndex); // force an update to happen std::multimap IDs; ModInfo::Ptr info = ModInfo::getByIndex(index); IDs.insert(std::make_pair(info->gameName(), info->nexusId())); modUpdateCheck(IDs); + + ui->modList->setFocus(Qt::OtherFocusReason); + ui->modList->scrollTo(qIndex); + // ui->modList->setCurrentIndex(qIndex); + ui->modList->selectionModel()->select(qIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows); } void MainWindow::showMessage(const QString &message) diff --git a/src/modlistview.cpp b/src/modlistview.cpp index bfc8e385..593d3772 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -2,6 +2,49 @@ #include #include #include +#include + +class ModListProxyStyle : public QProxyStyle { +public: + + using QProxyStyle::QProxyStyle; + + void drawPrimitive(PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const + { + if (element == QStyle::PE_IndicatorItemViewItemDrop) + { + QStyleOption opt(*option); + opt.rect.setLeft(20); + if (auto* view = qobject_cast(widget)) { + opt.rect.setRight(widget->width()); + } + QProxyStyle::drawPrimitive(element, &opt, painter, widget); + } + else { + QProxyStyle::drawPrimitive(element, option, painter, widget); + } + } +}; + +class ModListStyledItemDelegated : public QStyledItemDelegate +{ +public: + using QStyledItemDelegate::QStyledItemDelegate; + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override { + QStyleOptionViewItem opt(option); + if (index.column() == 0) + opt.rect.adjust(opt.rect.height(), 0, 0, 0); + QStyledItemDelegate::paint(painter, opt, index); + if (index.column() == 0) { + QStyleOptionViewItem branch; + branch.rect = QRect(0, opt.rect.y(), opt.rect.height(), opt.rect.height()); + branch.state = option.state; + const QWidget* widget = option.widget; + QStyle* style = widget ? widget->style() : QApplication::style(); + style->drawPrimitive(QStyle::PE_IndicatorBranch, &branch, painter, widget); + } + } +}; ModListView::ModListView(QWidget* parent) : QTreeView(parent) @@ -10,6 +53,10 @@ ModListView::ModListView(QWidget* parent) setVerticalScrollBar(m_scrollbar); MOBase::setCustomizableColumns(this); setAutoExpandDelay(1000); + + setIndentation(0); + setStyle(new ModListProxyStyle(style())); + setItemDelegate(new ModListStyledItemDelegated(this)); } void ModListView::setModel(QAbstractItemModel* model) diff --git a/src/modlistview.h b/src/modlistview.h index 0ded8f1d..438ed8a4 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -5,6 +5,9 @@ #include #include "viewmarkingscrollbar.h" +namespace Ui { class MainWindow; } +class OrganizerCore; + class ModListView : public QTreeView { Q_OBJECT -- cgit v1.3.1