diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-01-20 19:55:28 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-02-04 03:33:20 -0500 |
| commit | 0f3c01425daf9d4449854f34d8921e9032edc35d (patch) | |
| tree | 4ff9d76a052c3b91f89cd54bdeb3f0ceeb1bac03 /src/filetreemodel.cpp | |
| parent | 3bc1a4a06730640baee2f17f0fae152af6bd4a3d (diff) | |
font, tooltip and foreground
Diffstat (limited to 'src/filetreemodel.cpp')
| -rw-r--r-- | src/filetreemodel.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
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 "<p style=\"white-space: pre; margin: 0; padding: 0;\">" + s + "</p>"; + }; + + auto line = [&](auto&& caption, auto&& value) { + if (value.isEmpty()) { + return nowrap("<b>" + caption + ":</b>\n"); + } else { + return nowrap("<b>" + caption + ":</b> " + value.toHtmlEscaped()) + "\n"; + } + }; + + + if (item.isDirectory()) { + return + line(tr("Directory"), item.filename()) + + line(tr("Virtual path"), item.virtualPath()); + } + + + static const QString ListStart = + "<ul style=\"" + "margin-left: 20px; " + "margin-top: 0; " + "margin-bottom: 0; " + "padding: 0; " + "-qt-list-indent: 0;" + "\">"; + + static const QString ListEnd = "</ul>"; + + + QString s = + line(tr("Virtual path"), item.virtualPath()) + + line(tr("Real path"), item.realPath()) + + line(tr("From"), item.mod()); + + + const auto file = m_core.directoryStructure()->searchFile( + item.dataRelativeFilePath().toStdWString(), nullptr); + + if (file) { + const auto alternatives = file->getAlternatives(); + QStringList list; + + for (auto&& alt : file->getAlternatives()) { + const auto& origin = m_core.directoryStructure()->getOriginByID(alt.first); + list.push_back(QString::fromStdWString(origin.getName())); + } + + if (list.size() == 1) { + s += line(tr("Also in"), list[0]); + } else if (list.size() >= 2) { + s += line(tr("Also in"), QString()) + ListStart; + + for (auto&& alt : list) { + s += "<li>" + alt +"</li>"; + } + + s += ListEnd; + } + } + + return s; +} + +QVariant FileTreeModel::makeIcon( + const FileTreeItem& item, const QModelIndex& index) const +{ + return {}; +} |
