mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 17:40:39 +00:00
Move branch colouring to RDTreeView
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <QPainter>
|
||||
#include <QProxyStyle>
|
||||
#include <QScrollBar>
|
||||
#include <QStack>
|
||||
#include <QStylePainter>
|
||||
#include <QToolTip>
|
||||
#include <QWheelEvent>
|
||||
@@ -88,6 +89,12 @@ RDTreeViewDelegate::RDTreeViewDelegate(RDTreeView *view) : ForwardingDelegate(vi
|
||||
{
|
||||
}
|
||||
|
||||
void RDTreeViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
return ForwardingDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
||||
QSize RDTreeViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QSize ret = ForwardingDelegate::sizeHint(option, index);
|
||||
@@ -538,8 +545,32 @@ void RDTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &options,
|
||||
}
|
||||
}
|
||||
|
||||
void RDTreeView::fillBranchesRect(QPainter *painter, const QRect &rect, const QModelIndex &index) const
|
||||
void RDTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
|
||||
{
|
||||
// we do our own custom branch rendering to ensure the backgrounds for the +/- markers are filled
|
||||
// (as otherwise they don't show up well over selection or background fills) as well as to draw
|
||||
// any vertical branch colors.
|
||||
|
||||
// start at the left-most side of the rect
|
||||
QRect branchRect(rect.left(), rect.top(), indentation(), rect.height());
|
||||
|
||||
// first draw the coloured lines - we're only interested in parents for this, so push all the
|
||||
// parents onto a stack
|
||||
QStack<QModelIndex> parents;
|
||||
|
||||
QModelIndex parent = index.parent();
|
||||
|
||||
while(parent.isValid())
|
||||
{
|
||||
parents.push(parent);
|
||||
parent = parent.parent();
|
||||
}
|
||||
|
||||
// fill in the background behind the lines for the whole row, since by default it doesn't show up
|
||||
// behind the tree lines.
|
||||
|
||||
QRect allLinesRect(rect.left(), rect.top(), (parents.count() + 1) * indentation(), rect.height());
|
||||
|
||||
QStyleOptionViewItem opt;
|
||||
opt.initFrom(this);
|
||||
if(selectionModel()->isSelected(index))
|
||||
@@ -566,12 +597,13 @@ void RDTreeView::fillBranchesRect(QPainter *painter, const QRect &rect, const QM
|
||||
opt.rect.setWidth(depth * indentation());
|
||||
opt.showDecorationSelected = true;
|
||||
style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, this);
|
||||
}
|
||||
|
||||
void RDTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
|
||||
{
|
||||
if(m_fillBranchRect)
|
||||
fillBranchesRect(painter, rect, index);
|
||||
QBrush back = index.data(Qt::BackgroundRole).value<QBrush>();
|
||||
|
||||
if(!selectionModel()->isSelected(index) && back.style() != Qt::NoBrush)
|
||||
{
|
||||
painter->fillRect(allLinesRect, back);
|
||||
}
|
||||
|
||||
if(m_VisibleBranches)
|
||||
{
|
||||
@@ -590,19 +622,46 @@ void RDTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModel
|
||||
if(model()->rowCount(index) == 0)
|
||||
return;
|
||||
|
||||
QStyleOptionViewItem opt = viewOptions();
|
||||
QStyleOptionViewItem branchopt = viewOptions();
|
||||
|
||||
opt.rect = primitive;
|
||||
branchopt.rect = primitive;
|
||||
|
||||
// unfortunately QStyle::State_Children doesn't render ONLY the
|
||||
// open-toggle-button, but the vertical line upwards to a previous sibling.
|
||||
// For consistency, draw one downwards too.
|
||||
opt.state = QStyle::State_Children | QStyle::State_Sibling;
|
||||
branchopt.state = QStyle::State_Children | QStyle::State_Sibling;
|
||||
if(isExpanded(index))
|
||||
opt.state |= QStyle::State_Open;
|
||||
branchopt.state |= QStyle::State_Open;
|
||||
|
||||
style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this);
|
||||
style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchopt, painter, this);
|
||||
}
|
||||
|
||||
// we now iterate from the top-most parent down, moving in from the left
|
||||
// we draw this after calling into drawBranches() so we paint on top of the built-in lines
|
||||
QPen oldPen = painter->pen();
|
||||
while(!parents.isEmpty())
|
||||
{
|
||||
parent = parents.pop();
|
||||
|
||||
back = parent.data(RDTreeView::TreeLineColorRole).value<QBrush>();
|
||||
|
||||
if(back.style() != Qt::NoBrush)
|
||||
{
|
||||
// draw a centred pen vertically down the middle of branchRect
|
||||
painter->setPen(QPen(QBrush(back), m_treeColorLineWidth));
|
||||
|
||||
QPoint topCentre = QRect(branchRect).center();
|
||||
QPoint bottomCentre = topCentre;
|
||||
|
||||
topCentre.setY(branchRect.top());
|
||||
bottomCentre.setY(branchRect.bottom());
|
||||
|
||||
painter->drawLine(topCentre, bottomCentre);
|
||||
}
|
||||
|
||||
branchRect.moveLeft(branchRect.left() + indentation());
|
||||
}
|
||||
painter->setPen(oldPen);
|
||||
}
|
||||
|
||||
QModelIndex RDTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
|
||||
|
||||
@@ -42,6 +42,8 @@ private:
|
||||
|
||||
public:
|
||||
RDTreeViewDelegate(RDTreeView *view);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
@@ -78,6 +80,8 @@ public:
|
||||
explicit RDTreeView(QWidget *parent = 0);
|
||||
virtual ~RDTreeView();
|
||||
|
||||
static const int TreeLineColorRole = Qt::UserRole + 1000000;
|
||||
|
||||
void showBranches() { m_VisibleBranches = true; }
|
||||
void hideBranches() { m_VisibleBranches = false; }
|
||||
void showGridLines() { m_VisibleGridLines = true; }
|
||||
@@ -88,6 +92,8 @@ public:
|
||||
void setItemVerticalMargin(int vertical) { m_VertMargin = vertical; }
|
||||
int verticalItemMargin() { return m_VertMargin; }
|
||||
void setIgnoreIconSize(bool ignore) { m_IgnoreIconSize = ignore; }
|
||||
void setIgnoreBackgroundColors(bool ignore) { m_IgnoreBackgroundColors = ignore; }
|
||||
void setColoredTreeLineWidth(float w) { m_treeColorLineWidth = w; }
|
||||
bool ignoreIconSize() { return m_IgnoreIconSize; }
|
||||
bool customCopyPasteHandler() { return m_customCopyPaste; }
|
||||
void setCustomCopyPasteHandler(bool custom) { m_customCopyPaste = custom; }
|
||||
@@ -150,8 +156,6 @@ protected:
|
||||
|
||||
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
|
||||
|
||||
void fillBranchesRect(QPainter *painter, const QRect &rect, const QModelIndex &index) const;
|
||||
void enableBranchRectFill(bool fill) { m_fillBranchRect = fill; }
|
||||
QModelIndex m_currentHoverIndex;
|
||||
|
||||
private slots:
|
||||
@@ -178,5 +182,7 @@ private:
|
||||
int m_VertMargin = 6;
|
||||
bool m_IgnoreIconSize = false;
|
||||
|
||||
bool m_fillBranchRect = true;
|
||||
bool m_IgnoreBackgroundColors = false;
|
||||
|
||||
float m_treeColorLineWidth = 1.0f;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QStack>
|
||||
#include <QToolTip>
|
||||
#include "Code/Interface/QRDInterface.h"
|
||||
#include "Code/QRDUtils.h"
|
||||
@@ -201,8 +200,7 @@ public:
|
||||
}
|
||||
else if(role == Qt::BackgroundRole)
|
||||
{
|
||||
// item's background color takes priority but only if not selected
|
||||
if(item->m_back != QBrush() && !widget->selectionModel()->isSelected(index))
|
||||
if(item->m_back.style() != Qt::NoBrush)
|
||||
return item->m_back;
|
||||
|
||||
// otherwise if we're hover-highlighting, use the highlight color at 20% opacity
|
||||
@@ -216,6 +214,11 @@ public:
|
||||
// otherwise, no special background
|
||||
return QVariant();
|
||||
}
|
||||
else if(role == RDTreeView::TreeLineColorRole)
|
||||
{
|
||||
if(item->m_treeCol.isValid())
|
||||
return QBrush(item->m_treeCol);
|
||||
}
|
||||
|
||||
return item->data(index.column(), role);
|
||||
}
|
||||
@@ -570,9 +573,6 @@ RDTreeWidgetItemIterator &RDTreeWidgetItemIterator::operator++()
|
||||
|
||||
RDTreeWidget::RDTreeWidget(QWidget *parent) : RDTreeView(parent)
|
||||
{
|
||||
// we'll call this ourselves in drawBranches()
|
||||
RDTreeView::enableBranchRectFill(false);
|
||||
|
||||
m_delegate = new RichTextViewDelegate(this);
|
||||
RDTreeView::setItemDelegate(m_delegate);
|
||||
|
||||
@@ -843,74 +843,6 @@ void RDTreeWidget::focusOutEvent(QFocusEvent *event)
|
||||
RDTreeView::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void RDTreeWidget::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
|
||||
{
|
||||
// we do our own custom branch rendering to ensure the backgrounds for the +/- markers are
|
||||
// filled
|
||||
// (as otherwise they don't show up well over selection or background fills) as well as to draw
|
||||
// any vertical branch colors.
|
||||
|
||||
// start at the left-most side of the rect
|
||||
QRect branchRect(rect.left(), rect.top(), indentation(), rect.height());
|
||||
|
||||
RDTreeWidgetItem *item = m_model->itemForIndex(index);
|
||||
|
||||
// first draw the coloured lines - we're only interested in parents for this, so push all the
|
||||
// parents onto a stack
|
||||
QStack<RDTreeWidgetItem *> parents;
|
||||
|
||||
RDTreeWidgetItem *parent = item->parent();
|
||||
|
||||
while(parent && parent != m_root)
|
||||
{
|
||||
parents.push(parent);
|
||||
parent = parent->parent();
|
||||
}
|
||||
|
||||
// fill in the background behind the lines for the whole row, since by default it doesn't show
|
||||
// up
|
||||
// behind the tree lines.
|
||||
|
||||
QRect allLinesRect(rect.left(), rect.top(), (parents.count() + 1) * indentation(), rect.height());
|
||||
|
||||
// calling this manually here means it won't be called later in RDTreeView::drawBranches, and
|
||||
// allows us to overwrite it with our background filling if we want to.
|
||||
RDTreeWidget::fillBranchesRect(painter, rect, index);
|
||||
|
||||
if(!selectionModel()->isSelected(index) && item->m_back != QBrush())
|
||||
{
|
||||
painter->fillRect(allLinesRect, item->m_back);
|
||||
}
|
||||
|
||||
RDTreeView::drawBranches(painter, rect, index);
|
||||
|
||||
// we now iterate from the top-most parent down, moving in from the left
|
||||
// we draw this after calling into drawBranches() so we paint on top of the built-in lines
|
||||
QPen oldPen = painter->pen();
|
||||
while(!parents.isEmpty())
|
||||
{
|
||||
parent = parents.pop();
|
||||
|
||||
if(parent->m_treeCol.isValid())
|
||||
{
|
||||
// draw a centred pen vertically down the middle of branchRect
|
||||
|
||||
painter->setPen(QPen(QBrush(parent->m_treeCol), parent->m_treeColWidth));
|
||||
|
||||
QPoint topCentre = QRect(branchRect).center();
|
||||
QPoint bottomCentre = topCentre;
|
||||
|
||||
topCentre.setY(branchRect.top());
|
||||
bottomCentre.setY(branchRect.bottom());
|
||||
|
||||
painter->drawLine(topCentre, bottomCentre);
|
||||
}
|
||||
|
||||
branchRect.moveLeft(branchRect.left() + indentation());
|
||||
}
|
||||
painter->setPen(oldPen);
|
||||
}
|
||||
|
||||
void RDTreeWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||
{
|
||||
emit itemSelectionChanged();
|
||||
|
||||
@@ -78,11 +78,7 @@ public:
|
||||
m_italic = italic;
|
||||
dataChanged(0, Qt::FontRole);
|
||||
}
|
||||
inline void setTreeColor(QColor col, float pixels)
|
||||
{
|
||||
m_treeCol = col;
|
||||
m_treeColWidth = pixels;
|
||||
}
|
||||
inline void setTreeColor(QColor col) { m_treeCol = col; }
|
||||
inline void setBackgroundColor(QColor background) { setBackground(QBrush(background)); }
|
||||
inline void setForegroundColor(QColor foreground) { setForeground(QBrush(foreground)); }
|
||||
inline void setBackground(QBrush background)
|
||||
@@ -174,7 +170,6 @@ private:
|
||||
bool m_bold = false;
|
||||
bool m_italic = false;
|
||||
QColor m_treeCol;
|
||||
float m_treeColWidth = 0.0f;
|
||||
QBrush m_back;
|
||||
QBrush m_fore;
|
||||
QVariant m_tag;
|
||||
@@ -282,7 +277,6 @@ private:
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void leaveEvent(QEvent *e) override;
|
||||
void focusOutEvent(QFocusEvent *event) override;
|
||||
void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override;
|
||||
|
||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
|
||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
||||
|
||||
@@ -114,6 +114,8 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent)
|
||||
ui->events->setItemVerticalMargin(0);
|
||||
ui->events->setIgnoreIconSize(true);
|
||||
|
||||
ui->events->setColoredTreeLineWidth(3.0f);
|
||||
|
||||
// set up default section layout. This will be overridden in restoreState()
|
||||
ui->events->header()->resizeSection(COL_EID, 80);
|
||||
ui->events->header()->resizeSection(COL_DRAW, 60);
|
||||
@@ -238,6 +240,8 @@ EventBrowser::~EventBrowser()
|
||||
|
||||
void EventBrowser::OnCaptureLoaded()
|
||||
{
|
||||
ui->events->setIgnoreBackgroundColors(!m_Ctx.Config().EventBrowser_ColorEventRow);
|
||||
|
||||
uint32_t frameNumber = m_Ctx.FrameInfo().frameNumber;
|
||||
|
||||
QString rootName =
|
||||
@@ -393,7 +397,7 @@ QPair<uint32_t, uint32_t> EventBrowser::AddDrawcalls(RDTreeWidgetItem *parent,
|
||||
QColor col = QColor::fromRgb(
|
||||
qRgb(d.markerColor.x * 255.0f, d.markerColor.y * 255.0f, d.markerColor.z * 255.0f));
|
||||
|
||||
child->setTreeColor(col, 3.0f);
|
||||
child->setTreeColor(col);
|
||||
|
||||
if(m_Ctx.Config().EventBrowser_ColorEventRow)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user