diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-12-29 15:43:15 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-02 15:38:16 +0100 |
| commit | a67fca47600d9e3e6e43a93511182396c2f292d9 (patch) | |
| tree | 1309a8e22c8af61b5e10c4a3506e01e2f1d4a172 /src | |
| parent | de87a105b0cbcc73440a2613af6446d0e8819fb6 (diff) | |
Tentative fix for the indentation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 2 | ||||
| -rw-r--r-- | src/modlistview.cpp | 46 |
2 files changed, 34 insertions, 14 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3fdaa6d8..39ecfa95 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -558,8 +558,6 @@ 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))); diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 593d3772..be7471aa 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -4,18 +4,22 @@ #include <QMimeData>
#include <QProxyStyle>
+#include "modlist.h"
+#include "log.h"
+
class ModListProxyStyle : public QProxyStyle {
public:
using QProxyStyle::QProxyStyle;
- void drawPrimitive(PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
+ void drawPrimitive(PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const override
{
if (element == QStyle::PE_IndicatorItemViewItemDrop)
{
QStyleOption opt(*option);
- opt.rect.setLeft(20);
+ opt.rect.setLeft(0);
if (auto* view = qobject_cast<const QTreeView*>(widget)) {
+ opt.rect.setLeft(view->indentation());
opt.rect.setRight(widget->width());
}
QProxyStyle::drawPrimitive(element, &opt, painter, widget);
@@ -24,25 +28,43 @@ public: QProxyStyle::drawPrimitive(element, option, painter, widget);
}
}
+
+ QRect subElementRect(QStyle::SubElement element, const QStyleOption* option, const QWidget* widget) const override
+ {
+ QRect rect = QProxyStyle::subElementRect(element, option, widget);
+ switch (element) {
+ case SE_ItemViewItemCheckIndicator:
+ case SE_ItemViewItemDecoration:
+ case SE_ItemViewItemText:
+ case SE_ItemViewItemFocusRect:
+ rect.adjust(-20, 0, 0, 0);
+ break;
+ }
+ return rect;
+ }
};
class ModListStyledItemDelegated : public QStyledItemDelegate
{
+ QTreeView* m_view;
+
public:
+
+ ModListStyledItemDelegated(QTreeView* view) :
+ QStyledItemDelegate(view), m_view(view) { }
+
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);
+ if (!index.model()->hasChildren(index) && index.parent().isValid()) {
+ auto parentIndex = index.parent().data(ModList::IndexRole).toInt();
+ if (ModInfo::getByIndex(parentIndex)->isSeparator()) {
+ opt.rect.adjust(-m_view->indentation(), 0, 0, 0);
+ }
+ }
}
+ QStyledItemDelegate::paint(painter, opt, index);
}
};
@@ -54,11 +76,11 @@ ModListView::ModListView(QWidget* parent) MOBase::setCustomizableColumns(this);
setAutoExpandDelay(1000);
- setIndentation(0);
setStyle(new ModListProxyStyle(style()));
setItemDelegate(new ModListStyledItemDelegated(this));
}
+
void ModListView::setModel(QAbstractItemModel* model)
{
QTreeView::setModel(model);
|
