Expand RDTreeWidget to allow per-item go column

* This lets us use the existing logic for hovering columns, to get things like
  the hand cursor, while still only showing it for resource entries.
This commit is contained in:
baldurk
2026-01-23 14:14:31 +00:00
parent 2dd3df5aa1
commit 58eb49ce5b
4 changed files with 22 additions and 30 deletions
+6 -21
View File
@@ -33,6 +33,8 @@
#include "Code/Resources.h"
#include "Extended/RDHeaderView.h"
const int HoverRole = Qt::UserRole;
AnnotationDisplay::AnnotationDisplay(ICaptureContext &ctx, bool standalone, QWidget *parent)
: QFrame(parent), m_Ctx(ctx), m_Standalone(standalone)
{
@@ -63,11 +65,9 @@ AnnotationDisplay::AnnotationDisplay(ICaptureContext &ctx, bool standalone, QWid
QObject::connect(m_Tree, &RDTreeWidget::customContextMenu, this,
&AnnotationDisplay::customContextMenu);
QObject::connect(m_Tree, &RDTreeWidget::itemClicked, this, &AnnotationDisplay::itemClicked);
QObject::connect(m_Tree, &RDTreeWidget::hoverItemChanged, this,
&AnnotationDisplay::hoverItemChanged);
m_Tree->viewport()->setAttribute(Qt::WA_Hover);
m_Tree->setMouseTracking(true);
m_Tree->setHoverIconColumn(2, Icons::action(), Icons::action_hover());
m_Tree->setHoverRole(HoverRole);
if(m_Standalone)
m_Ctx.AddCaptureViewer(this);
@@ -204,6 +204,8 @@ void AnnotationDisplay::addStructuredChildren(RDTreeWidgetItem *parent, const SD
item->setTag(QVariant::fromValue(tag));
item->setData(2, HoverRole, true);
if(m_HasGoColumn)
item->setIcon(2, Icons::action());
}
@@ -251,7 +253,6 @@ void AnnotationDisplay::setAnnotationObject(const SDObject *annotation)
m_Annotation = annotation;
m_Items.clear();
m_HoveredItem = NULL;
m_Tree->invisibleRootItem()->clear();
// Check if we have any buffer annotations to determine columns
@@ -360,19 +361,3 @@ void AnnotationDisplay::itemClicked(RDTreeWidgetItem *item, int column)
});
}
}
void AnnotationDisplay::hoverItemChanged(RDTreeWidgetItem *item)
{
// Restore normal icon for previously hovered resource item with a Go button
if(m_HoveredItem)
{
m_HoveredItem->setIcon(2, Icons::action());
}
// Set hover icon for newly hovered resource item, if it has a valid tag
if(item && item->tag().canConvert<AnnotationResourceTag>() && m_HasGoColumn)
{
m_HoveredItem = item;
m_HoveredItem->setIcon(2, Icons::action_hover());
}
}
-4
View File
@@ -67,7 +67,6 @@ public:
private slots:
void customContextMenu(QModelIndex index, QMenu *menu);
void itemClicked(RDTreeWidgetItem *item, int column);
void hoverItemChanged(RDTreeWidgetItem *item);
protected:
@@ -85,9 +84,6 @@ private:
// whether the Go column is present
bool m_HasGoColumn = false;
// track hovered item for icon changes
RDTreeWidgetItem *m_HoveredItem = NULL;
QMap<const SDObject *, RDTreeWidgetItem *> m_Items;
void addStructuredChildren(RDTreeWidgetItem *parent, const SDObject &parentObj);
+13 -5
View File
@@ -193,7 +193,8 @@ public:
}
else if(role == Qt::DecorationRole)
{
if(widget->m_hoverColumn == index.column())
if(widget->m_hoverColumn == index.column() &&
(widget->m_hoverRole < 0 || item->data(widget->m_hoverColumn, widget->m_hoverRole).toBool()))
{
if(itemForIndex(widget->m_currentHoverIndex) == item)
return widget->m_activeHoverIcon;
@@ -803,12 +804,19 @@ void RDTreeWidget::mouseMoveEvent(QMouseEvent *e)
RDTreeWidgetItem *newHover = m_model->itemForIndex(m_currentHoverIndex);
if(m_currentHoverIndex.column() == m_hoverColumn && m_hoverHandCursor)
if(m_hoverRole < 0 || newHover->data(m_hoverColumn, m_hoverRole).toBool())
{
setCursor(QCursor(Qt::PointingHandCursor));
if(m_currentHoverIndex.column() == m_hoverColumn && m_hoverHandCursor)
{
setCursor(QCursor(Qt::PointingHandCursor));
}
else if(oldHoverIndex.column() == m_hoverColumn &&
m_currentHoverIndex.column() != m_hoverColumn && m_hoverHandCursor)
{
unsetCursor();
}
}
else if(oldHoverIndex.column() == m_hoverColumn &&
m_currentHoverIndex.column() != m_hoverColumn && m_hoverHandCursor)
else
{
unsetCursor();
}
@@ -233,7 +233,9 @@ public:
m_activeHoverIcon = hover;
m_hoverHandCursor = true;
m_activateOnClick = true;
m_hoverRole = -1;
}
void setHoverRole(int role) { m_hoverRole = role; }
void setHoverHandCursor(bool hand) { m_hoverHandCursor = hand; }
void setHoverClickActivate(bool click) { m_activateOnClick = click; }
void setClearSelectionOnFocusLoss(bool clear) { m_clearSelectionOnFocusLoss = clear; }
@@ -327,6 +329,7 @@ private:
QVector<Qt::Alignment> m_alignments;
int m_hoverColumn = -1;
int m_hoverRole = -1;
QIcon m_normalHoverIcon;
QIcon m_activeHoverIcon;
bool m_hoverHandCursor = false;