Move size delegate into item margins implemented by RDTreeView

This commit is contained in:
baldurk
2017-06-01 14:17:00 +01:00
parent a30c704e46
commit 3076b4337b
5 changed files with 46 additions and 25 deletions
-18
View File
@@ -870,24 +870,6 @@ struct RDDialog
QFileDialog::Options options = QFileDialog::Options());
};
// useful delegate for enforcing a given size
#include <QItemDelegate>
class SizeDelegate : public QItemDelegate
{
private:
Q_OBJECT
QSize m_Size;
public:
SizeDelegate(QSize size) : m_Size(size) {}
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return m_Size;
}
};
class QGridLayout;
void addGridLines(QGridLayout *grid);
@@ -25,8 +25,26 @@
#include "RDTreeView.h"
#include <QPainter>
RDTreeViewDelegate::RDTreeViewDelegate(RDTreeView *view) : QStyledItemDelegate(view), m_View(view)
{
}
QSize RDTreeViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize ret = QStyledItemDelegate::sizeHint(option, index);
// expand by the margins
ret.setWidth(ret.width() + m_View->m_HorizMargin);
ret.setHeight(ret.height() + m_View->m_VertMargin);
return ret;
}
RDTreeView::RDTreeView(QWidget *parent) : QTreeView(NULL)
{
setItemDelegate(new RDTreeViewDelegate(this));
}
}
void RDTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
+28 -1
View File
@@ -24,8 +24,23 @@
#pragma once
#include <QStyledItemDelegate>
#include <QTreeView>
class RDTreeView;
class RDTreeViewDelegate : public QStyledItemDelegate
{
private:
Q_OBJECT
RDTreeView *m_View;
public:
RDTreeViewDelegate(RDTreeView *view);
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
class RDTreeView : public QTreeView
{
Q_OBJECT
@@ -33,8 +48,20 @@ public:
explicit RDTreeView(QWidget *parent = 0);
void setDrawBranches(bool draw) { m_DrawBranches = draw; }
private:
void setItemMargins(int horizontal, int vertical)
{
m_HorizMargin = horizontal;
m_VertMargin = vertical;
}
int horizontalItemMargin() { return m_HorizMargin; }
int verticalItemMargin() { return m_VertMargin; }
protected:
void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override;
private:
bool m_DrawBranches = true;
int m_HorizMargin = 3, m_VertMargin = 3;
friend class RDTreeViewDelegate;
};
-4
View File
@@ -85,9 +85,6 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent)
// becomes quickly infuriating to rearrange, just disable until that can be fixed.
ui->events->header()->setSectionsMovable(false);
m_SizeDelegate = new SizeDelegate(QSize(0, 16));
ui->events->setItemDelegate(m_SizeDelegate);
UpdateDurationColumn();
m_FindHighlight = new QTimer(this);
@@ -141,7 +138,6 @@ EventBrowser::~EventBrowser()
m_Ctx.BuiltinWindowClosed(this);
m_Ctx.RemoveLogViewer(this);
delete ui;
delete m_SizeDelegate;
}
void EventBrowser::OnLogfileLoaded()
-2
View File
@@ -39,7 +39,6 @@ class RDTreeWidgetItem;
class QTimer;
class QTextStream;
class FlowLayout;
class SizeDelegate;
struct EventItemTag;
class EventBrowser : public QFrame, public IEventBrowser, public ILogViewer
@@ -123,7 +122,6 @@ private:
rdctype::array<CounterResult> m_Times;
SizeDelegate *m_SizeDelegate;
QTimer *m_FindHighlight;
FlowLayout *m_BookmarkStripLayout;