Handle richtext delegate in RDTreeView instead of widget

This commit is contained in:
baldurk
2021-05-19 15:57:34 +01:00
parent b591b12eac
commit a1a0dee085
4 changed files with 21 additions and 34 deletions
+17 -3
View File
@@ -85,19 +85,19 @@ static bool CompareModelIndex(const QModelIndex &a, const QModelIndex &b)
return CompareModelIndex(ap, bp);
}
RDTreeViewDelegate::RDTreeViewDelegate(RDTreeView *view) : ForwardingDelegate(view), m_View(view)
RDTreeViewDelegate::RDTreeViewDelegate(RDTreeView *view) : RichTextViewDelegate(view), m_View(view)
{
}
void RDTreeViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
return ForwardingDelegate::paint(painter, option, index);
return RichTextViewDelegate::paint(painter, option, index);
}
QSize RDTreeViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize ret = ForwardingDelegate::sizeHint(option, index);
QSize ret = RichTextViewDelegate::sizeHint(option, index);
if(m_View->ignoreIconSize())
ret.setHeight(qMax(option.decorationSize.height() + 2, ret.height()));
@@ -228,6 +228,20 @@ void RDTreeView::mouseMoveEvent(QMouseEvent *e)
m_currentHoverIndex = indexAt(e->pos());
if(m_delegate->linkHover(e, font(), m_currentHoverIndex))
{
if(cursor().shape() != Qt::PointingHandCursor)
{
viewport()->update(visualRect(m_currentHoverIndex));
setCursor(QCursor(Qt::PointingHandCursor));
}
}
else if(cursor().shape() == Qt::PointingHandCursor)
{
viewport()->update(visualRect(m_currentHoverIndex));
unsetCursor();
}
if(oldHoverIndex != m_currentHoverIndex)
{
if(m_instantTooltips)
+1 -1
View File
@@ -33,7 +33,7 @@ class RDTreeView;
typedef QSet<uint> RDTreeViewExpansionState;
class RDTreeViewDelegate : public ForwardingDelegate
class RDTreeViewDelegate : public RichTextViewDelegate
{
private:
Q_OBJECT
+3 -20
View File
@@ -604,9 +604,6 @@ RDTreeWidgetItemIterator &RDTreeWidgetItemIterator::operator++()
RDTreeWidget::RDTreeWidget(QWidget *parent) : RDTreeView(parent)
{
m_delegate = new RichTextViewDelegate(this);
RDTreeView::setItemDelegate(m_delegate);
header()->setSectionsMovable(false);
m_root = new RDTreeWidgetItem;
@@ -689,17 +686,6 @@ void RDTreeWidget::setColumnAlignment(int column, Qt::Alignment align)
m_alignments[column] = align;
}
void RDTreeWidget::setItemDelegate(QAbstractItemDelegate *delegate)
{
m_userDelegate = delegate;
m_delegate->setForwardDelegate(m_userDelegate);
}
QAbstractItemDelegate *RDTreeWidget::itemDelegate() const
{
return m_userDelegate;
}
RDTreeWidgetItem *RDTreeWidget::itemForIndex(QModelIndex idx) const
{
if(idx.model() == m_model)
@@ -794,6 +780,7 @@ void RDTreeWidget::clear()
void RDTreeWidget::mouseMoveEvent(QMouseEvent *e)
{
RDTreeWidgetItem *oldHover = m_model->itemForIndex(m_currentHoverIndex);
QModelIndex oldHoverIndex = m_currentHoverIndex;
RDTreeView::mouseMoveEvent(e);
@@ -803,12 +790,8 @@ void RDTreeWidget::mouseMoveEvent(QMouseEvent *e)
{
setCursor(QCursor(Qt::PointingHandCursor));
}
else if(m_delegate->linkHover(e, font(), m_currentHoverIndex))
{
m_model->itemChanged(m_model->itemForIndex(m_currentHoverIndex), {Qt::DecorationRole});
setCursor(QCursor(Qt::PointingHandCursor));
}
else
else if(oldHoverIndex.column() == m_hoverColumn &&
m_currentHoverIndex.column() != m_hoverColumn && m_hoverHandCursor)
{
unsetCursor();
}
@@ -140,7 +140,6 @@ private:
friend class RDTreeWidget;
friend class RDTreeWidgetModel;
friend class RDTreeWidgetDelegate;
void setWidget(RDTreeWidget *widget);
RDTreeWidget *m_widget = NULL;
@@ -204,8 +203,6 @@ private:
RDTreeWidgetItem *m_Current;
};
class RichTextViewDelegate;
class RDTreeWidget : public RDTreeView
{
Q_OBJECT
@@ -235,9 +232,6 @@ public:
void endUpdate();
void setColumnAlignment(int column, Qt::Alignment align);
void setItemDelegate(QAbstractItemDelegate *delegate);
QAbstractItemDelegate *itemDelegate() const;
RDTreeWidgetItem *itemForIndex(QModelIndex idx) const;
void copyItem(QPoint pos, RDTreeWidgetItem *item);
@@ -289,16 +283,12 @@ private:
friend class RDTreeWidgetModel;
friend class RDTreeWidgetItem;
friend class RDTreeWidgetDelegate;
// invisible root item, used to simplify recursion by even top-level items having a parent
RDTreeWidgetItem *m_root;
RDTreeWidgetModel *m_model;
QAbstractItemDelegate *m_userDelegate = NULL;
RichTextViewDelegate *m_delegate;
bool m_clearing = false;
QStringList m_headers;