From 1ac3f4d8e8ee7461f047d34e196df40499e89557 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Wed, 6 Jan 2021 19:43:21 +0100 Subject: Display children contents in collapsed separator. --- src/modcontenticondelegate.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/modcontenticondelegate.cpp (limited to 'src/modcontenticondelegate.cpp') diff --git a/src/modcontenticondelegate.cpp b/src/modcontenticondelegate.cpp new file mode 100644 index 00000000..57a4dc6d --- /dev/null +++ b/src/modcontenticondelegate.cpp @@ -0,0 +1,57 @@ +#include "modcontenticondelegate.h" + +#include "modlistview.h" + +ModContentIconDelegate::ModContentIconDelegate(ModListView* view, int column, int compactSize) + : IconDelegate(view, column, compactSize), m_view(view) +{ +} + +QList ModContentIconDelegate::getIcons(const QModelIndex& index) const +{ + QVariant modIndex = index.data(ModList::IndexRole); + + if (!modIndex.isValid()) { + return {}; + } + + bool compact; + auto icons = m_view->contentsIcons(index, &compact); + + if (compact || this->compact()) { + icons.removeAll(QString()); + } + + return icons; +} + +size_t ModContentIconDelegate::getNumIcons(const QModelIndex& index) const +{ + return getIcons(index).size(); +} + +bool ModContentIconDelegate::helpEvent( + QHelpEvent* event, QAbstractItemView* view, const QStyleOptionViewItem& option, const QModelIndex& index) +{ + if (!event || !view) { + return false; + } + if (event->type() == QEvent::ToolTip) { + // this code is from QAbstractItemDelegate::helpEvent, only the the way + // text is retrieved has been changed + QHelpEvent* he = static_cast(event); + const int precision = inherits("QItemDelegate") ? 10 : 6; // keep in sync with DBL_DIG in qitemdelegate.cpp + const QString tooltip = index.isValid() ? m_view->contentsTooltip(index) : QString(); + QRect rect; + if (index.isValid()) { + const QRect r = view->visualRect(index); + rect = QRect(view->mapToGlobal(r.topLeft()), r.size()); + } + QToolTip::showText(he->globalPos(), tooltip, view, rect); + event->setAccepted(!tooltip.isEmpty()); + return true; + } + else { + return IconDelegate::helpEvent(event, view, option, index); + } +} -- cgit v1.3.1