diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-06 19:43:21 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-10 10:27:22 +0100 |
| commit | 1ac3f4d8e8ee7461f047d34e196df40499e89557 (patch) | |
| tree | 803e663c2da154d0d48a4f284185b37c53e0b2f2 /src/modcontenticondelegate.cpp | |
| parent | 76796796bec37a1670cfc4e0b1e42e7b1096b237 (diff) | |
Display children contents in collapsed separator.
Diffstat (limited to 'src/modcontenticondelegate.cpp')
| -rw-r--r-- | src/modcontenticondelegate.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
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<QString> 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<QHelpEvent*>(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); + } +} |
