summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-12-29 14:24:33 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:16 +0100
commitde87a105b0cbcc73440a2613af6446d0e8819fb6 (patch)
treecf034331ec4d716916c9b567dc174e868fef19ef /src
parent4ee3d2848e0fc2f32543f7d2aeaed22d77d937bd (diff)
Fix indentation and drop indicator.
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp11
-rw-r--r--src/modlistview.cpp47
-rw-r--r--src/modlistview.h3
3 files changed, 58 insertions, 3 deletions
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<QString, int> IDs;
ModInfo::Ptr info = ModInfo::getByIndex(index);
IDs.insert(std::make_pair<QString, int>(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 <widgetutility.h>
#include <QUrl>
#include <QMimeData>
+#include <QProxyStyle>
+
+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<const QTreeView*>(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 <QDragEnterEvent>
#include "viewmarkingscrollbar.h"
+namespace Ui { class MainWindow; }
+class OrganizerCore;
+
class ModListView : public QTreeView
{
Q_OBJECT