From 0f3c01425daf9d4449854f34d8921e9032edc35d Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 20 Jan 2020 19:55:28 -0500 Subject: font, tooltip and foreground --- src/filetreemodel.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'src/filetreemodel.cpp') diff --git a/src/filetreemodel.cpp b/src/filetreemodel.cpp index 87de1d45..dd79f941 100644 --- a/src/filetreemodel.cpp +++ b/src/filetreemodel.cpp @@ -263,6 +263,48 @@ QVariant FileTreeModel::data(const QModelIndex& index, int role) const break; } + + case Qt::FontRole: + { + if (auto* item=itemFromIndex(index)) { + return item->font(); + } + + break; + } + + case Qt::ToolTipRole: + { + if (auto* item=itemFromIndex(index)) { + return makeTooltip(*item); + } + + return {}; + } + + case Qt::ForegroundRole: + { + if (index.column() == 1) { + if (auto* item=itemFromIndex(index)) { + if (item->isConflicted()) { + return QBrush(Qt::red); + } + } + } + + break; + } + + case Qt::DecorationRole: + { + if (index.column() == 0) { + if (auto* item=itemFromIndex(index)) { + return makeIcon(*item, index); + } + } + + break; + } } return {}; @@ -634,3 +676,77 @@ std::wstring FileTreeModel::makeModName( return name; } + +QString FileTreeModel::makeTooltip(const FileTreeItem& item) const +{ + auto nowrap = [&](auto&& s) { + return "
" + s + "
"; + }; + + auto line = [&](auto&& caption, auto&& value) { + if (value.isEmpty()) { + return nowrap("" + caption + ":\n"); + } else { + return nowrap("" + caption + ": " + value.toHtmlEscaped()) + "\n"; + } + }; + + + if (item.isDirectory()) { + return + line(tr("Directory"), item.filename()) + + line(tr("Virtual path"), item.virtualPath()); + } + + + static const QString ListStart = + "