Skip to content

Commit

Permalink
Highlight mods that contain selected files in datatab
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanFeenstra committed Dec 24, 2024
1 parent 91912f5 commit 09d6a9a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/colortable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ void ColorTable::load(Settings& s)
});

addColor(
QObject::tr("Mod contains selected plugin"), QColor(0, 0, 255, 64),
QObject::tr("Mod contains selected file"), QColor(0, 0, 255, 64),
[this] {
return m_settings->colors().modlistContainsPlugin();
return m_settings->colors().modlistContainsFile();
},
[this](auto&& v) {
m_settings->colors().setModlistContainsPlugin(v);
m_settings->colors().setModlistContainsFile(v);
});

addColor(
Expand Down
13 changes: 13 additions & 0 deletions src/datatab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "filetree.h"
#include "filetreemodel.h"
#include "messagedialog.h"
#include "modelutils.h"
#include "organizercore.h"
#include "settings.h"
#include "ui_mainwindow.h"
Expand Down Expand Up @@ -57,6 +58,18 @@ DataTab::DataTab(OrganizerCore& core, PluginContainer& pc, QWidget* parent,
onHiddenFiles();
});

connect(ui.tree->selectionModel(), &QItemSelectionModel::selectionChanged,
[=](auto&& selected) {
const auto* fileTreeModel = m_filetree->model();
const auto& selectedIndexList = MOShared::indexViewToModel(
ui.tree->selectionModel()->selectedRows(), fileTreeModel);
std::set<QString> mods;
for (auto& idx : selectedIndexList) {
mods.insert(fileTreeModel->itemFromIndex(idx)->mod());
}
mwui->modList->setHighlightedMods(mods);
});

connect(m_filetree.get(), &FileTree::executablesChanged, this,
&DataTab::executablesChanged);

Expand Down
16 changes: 15 additions & 1 deletion src/modlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,20 @@ void ModListView::setHighlightedMods(const std::vector<unsigned int>& pluginIndi
verticalScrollBar()->repaint();
}

void ModListView::setHighlightedMods(const std::set<QString>& modNames)
{
m_markers.highlight.clear();
for (const auto& modName : modNames) {
const auto index = ModInfo::getIndex(modName);
if (index != UINT_MAX) {
m_markers.highlight.insert(index);
}
}
dataChanged(model()->index(0, 0),
model()->index(model()->rowCount(), model()->columnCount()));
verticalScrollBar()->repaint();
}

QColor ModListView::markerColor(const QModelIndex& index) const
{
unsigned int modIndex = index.data(ModList::IndexRole).toInt();
Expand All @@ -1150,7 +1164,7 @@ QColor ModListView::markerColor(const QModelIndex& index) const
m_markers.archiveLooseOverwritten.end();

if (highligth) {
return Settings::instance().colors().modlistContainsPlugin();
return Settings::instance().colors().modlistContainsFile();
} else if (overwritten || archiveLooseOverwritten) {
return Settings::instance().colors().modlistOverwritingLoose();
} else if (overwrite || archiveLooseOverwrite) {
Expand Down
1 change: 1 addition & 0 deletions src/modlistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public slots:
// set highligth markers
//
void setHighlightedMods(const std::vector<unsigned int>& pluginIndices);
void setHighlightedMods(const std::set<QString>& modNames);

protected:
// map from/to the view indexes to the model
Expand Down
8 changes: 4 additions & 4 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,15 +1265,15 @@ void ColorSettings::setModlistOverwritingArchive(const QColor& c)
set(m_Settings, "Settings", "overwritingArchiveFilesColor", c);
}

QColor ColorSettings::modlistContainsPlugin() const
QColor ColorSettings::modlistContainsFile() const
{
return get<QColor>(m_Settings, "Settings", "containsPluginColor",
return get<QColor>(m_Settings, "Settings", "containsFileColor",
QColor(0, 0, 255, 64));
}

void ColorSettings::setModlistContainsPlugin(const QColor& c)
void ColorSettings::setModlistContainsFile(const QColor& c)
{
set(m_Settings, "Settings", "containsPluginColor", c);
set(m_Settings, "Settings", "containsFileColor", c);
}

QColor ColorSettings::pluginListContained() const
Expand Down
4 changes: 2 additions & 2 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ class ColorSettings
QColor modlistOverwritingArchive() const;
void setModlistOverwritingArchive(const QColor& c);

QColor modlistContainsPlugin() const;
void setModlistContainsPlugin(const QColor& c);
QColor modlistContainsFile() const;
void setModlistContainsFile(const QColor& c);

QColor pluginListContained() const;
void setPluginListContained(const QColor& c);
Expand Down

0 comments on commit 09d6a9a

Please sign in to comment.