aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2023-05-24 20:15:34 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2023-05-24 20:15:34 -0700
commit086a7e19f099c6c9b9529afb2360300e534876bf (patch)
tree1ab5d7313e406ef8e07091a528792d17fbc7149f
parent74e7c13a177afdb503a642cb9c97d71e72249291 (diff)
downloadPrismLauncher-086a7e19f099c6c9b9529afb2360300e534876bf.tar.gz
PrismLauncher-086a7e19f099c6c9b9529afb2360300e534876bf.tar.bz2
PrismLauncher-086a7e19f099c6c9b9529afb2360300e534876bf.zip
feat: Column on left, hideable
- columns are hideable (saves to settings) - image column moved to left - datamodals can provide resize modes Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
-rw-r--r--launcher/minecraft/mod/ModFolderModel.cpp6
-rw-r--r--launcher/minecraft/mod/ModFolderModel.h4
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.cpp66
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.h12
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.cpp6
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.h4
-rw-r--r--launcher/minecraft/mod/ShaderPackFolderModel.h2
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.cpp9
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.h4
-rw-r--r--launcher/ui/pages/instance/ExternalResourcesPage.cpp15
-rw-r--r--launcher/ui/pages/instance/ExternalResourcesPage.h1
-rw-r--r--launcher/ui/widgets/ModListView.cpp9
-rw-r--r--launcher/ui/widgets/ModListView.h2
13 files changed, 131 insertions, 9 deletions
diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp
index 8843f79f..59e078f1 100644
--- a/launcher/minecraft/mod/ModFolderModel.cpp
+++ b/launcher/minecraft/mod/ModFolderModel.cpp
@@ -37,6 +37,7 @@
#include "ModFolderModel.h"
#include <FileSystem.h>
+#include <qheaderview.h>
#include <QDebug>
#include <QFileSystemWatcher>
#include <QIcon>
@@ -56,7 +57,8 @@
ModFolderModel::ModFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance, bool is_indexed, bool create_dir)
: ResourceFolderModel(QDir(dir), instance, nullptr, create_dir), m_is_indexed(is_indexed)
{
- m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER, SortType::NAME };
+ m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME , SortType::VERSION, SortType::DATE, SortType::PROVIDER};
+ m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents};
}
QVariant ModFolderModel::data(const QModelIndex &index, int role) const
@@ -143,7 +145,7 @@ QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, in
switch (section)
{
case ActiveColumn:
- return QString();
+ return tr("Enable");
case NameColumn:
return tr("Name");
case VersionColumn:
diff --git a/launcher/minecraft/mod/ModFolderModel.h b/launcher/minecraft/mod/ModFolderModel.h
index 20018e9c..c1f9a2b6 100644
--- a/launcher/minecraft/mod/ModFolderModel.h
+++ b/launcher/minecraft/mod/ModFolderModel.h
@@ -64,11 +64,11 @@ public:
enum Columns
{
ActiveColumn = 0,
+ ImageColumn,
NameColumn,
VersionColumn,
DateColumn,
ProviderColumn,
- ImageColumn,
NUM_COLUMNS
};
enum ModStatusAction {
@@ -78,6 +78,8 @@ public:
};
ModFolderModel(const QString &dir, std::shared_ptr<const BaseInstance> instance, bool is_indexed = false, bool create_dir = true);
+ virtual QString id() const override { return "mods"; }
+
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp
index e1973468..ba64497b 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourceFolderModel.cpp
@@ -8,12 +8,15 @@
#include <QStyle>
#include <QThreadPool>
#include <QUrl>
+#include <QMenu>
#include "Application.h"
#include "FileSystem.h"
+#include "QVariantUtils.h"
#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
+#include "settings/Setting.h"
#include "tasks/Task.h"
ResourceFolderModel::ResourceFolderModel(QDir dir, std::shared_ptr<const BaseInstance> instance, QObject* parent, bool create_dir)
@@ -471,6 +474,8 @@ QVariant ResourceFolderModel::headerData(int section, Qt::Orientation orientatio
switch (role) {
case Qt::DisplayRole:
switch (section) {
+ case ACTIVE_COLUMN:
+ return tr("Enable");
case NAME_COLUMN:
return tr("Name");
case DATE_COLUMN:
@@ -500,6 +505,67 @@ QVariant ResourceFolderModel::headerData(int section, Qt::Orientation orientatio
return {};
}
+void ResourceFolderModel::setupHeaderAction(QAction* act, int column)
+{
+ Q_ASSERT(act);
+
+ act->setText(headerData(column, Qt::Orientation::Horizontal).toString());
+}
+
+void ResourceFolderModel::saveHiddenColumn(int column, bool hidden)
+{
+ auto const setting_name = QString("UI/%1_Page/HiddenColumns").arg(id());
+ auto setting = (APPLICATION->settings()->contains(setting_name)) ?
+ APPLICATION->settings()->getSetting(setting_name) : APPLICATION->settings()->registerSetting(setting_name);
+
+ auto hiddenColumns = QVariantUtils::toList<int>(setting->get());
+ auto index = hiddenColumns.indexOf(column);
+ if (index >= 0 && !hidden) {
+ hiddenColumns.removeAt(index);
+ } else if ( index < 0 && hidden) {
+ hiddenColumns.append(column);
+ }
+ setting->set(QVariantUtils::fromList(hiddenColumns));
+}
+
+void ResourceFolderModel::loadHiddenColumns(QTreeView *tree)
+{
+ auto const setting_name = QString("UI/%1_Page/HiddenColumns").arg(id());
+ auto setting = (APPLICATION->settings()->contains(setting_name)) ?
+ APPLICATION->settings()->getSetting(setting_name) : APPLICATION->settings()->registerSetting(setting_name);
+
+ auto hiddenColumns = QVariantUtils::toList<int>(setting->get().toList());
+ for (auto col : hiddenColumns) {
+ tree->setColumnHidden(col, true);
+ }
+
+}
+
+std::unique_ptr<QMenu> ResourceFolderModel::createHeaderContextMenu(QWidget* parent, QTreeView* tree)
+{
+ auto menu = std::make_unique<QMenu>(parent);
+
+ menu->addSeparator()->setText(tr("Show / Hide Columns"));
+
+ for (int col = 0; col < columnCount(); ++col) {
+ auto act = new QAction();
+ setupHeaderAction(act, col);
+
+ act->setCheckable(true);
+ act->setChecked(!tree->isColumnHidden(col));
+
+ connect(act, &QAction::toggled, tree, [this, col, tree](bool toggled){
+ tree->setColumnHidden(col, !toggled);
+ saveHiddenColumn(col, !toggled);
+ });
+
+ menu->addAction(act);
+
+ }
+
+ return menu;
+}
+
QSortFilterProxyModel* ResourceFolderModel::createFilterProxyModel(QObject* parent)
{
return new ProxyModel(parent);
diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h
index fdf5f331..54627c80 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.h
+++ b/launcher/minecraft/mod/ResourceFolderModel.h
@@ -1,5 +1,8 @@
#pragma once
+#include <QHeaderView>
+#include <QAction>
+#include <QTreeView>
#include <QAbstractListModel>
#include <QDir>
#include <QFileSystemWatcher>
@@ -29,6 +32,8 @@ class ResourceFolderModel : public QAbstractListModel {
ResourceFolderModel(QDir, std::shared_ptr<const BaseInstance>, QObject* parent = nullptr, bool create_dir = true);
~ResourceFolderModel() override;
+ virtual QString id() const { return "resource"; }
+
/** Starts watching the paths for changes.
*
* Returns whether starting to watch all the paths was successful.
@@ -110,6 +115,11 @@ class ResourceFolderModel : public QAbstractListModel {
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
+ void setupHeaderAction(QAction* act, int column);
+ void saveHiddenColumn(int column, bool hidden);
+ void loadHiddenColumns(QTreeView* tree);
+ std::unique_ptr<QMenu> createHeaderContextMenu(QWidget* parent, QTreeView* tree);
+
/** This creates a proxy model to filter / sort the model for a UI.
*
* The actual comparisons and filtering are done directly by the Resource, so to modify behavior go there instead!
@@ -117,6 +127,7 @@ class ResourceFolderModel : public QAbstractListModel {
QSortFilterProxyModel* createFilterProxyModel(QObject* parent = nullptr);
[[nodiscard]] SortType columnToSortKey(size_t column) const;
+ [[nodiscard]] QList<QHeaderView::ResizeMode> columnResizeModes() const { return m_column_resize_modes; }
class ProxyModel : public QSortFilterProxyModel {
public:
@@ -187,6 +198,7 @@ class ResourceFolderModel : public QAbstractListModel {
// Represents the relationship between a column's index (represented by the list index), and it's sorting key.
// As such, the order in with they appear is very important!
QList<SortType> m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::DATE };
+ QList<QHeaderView::ResizeMode> m_column_resize_modes = { QHeaderView::Stretch, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents };
bool m_can_interact = true;
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
index b11e2262..7ec5668c 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
@@ -50,7 +50,9 @@
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance)
: ResourceFolderModel(QDir(dir), instance)
{
- m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE, SortType::NAME };
+ m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE};
+ m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents};
+
}
QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
@@ -130,7 +132,7 @@ QVariant ResourcePackFolderModel::headerData(int section, Qt::Orientation orient
case Qt::DisplayRole:
switch (section) {
case ActiveColumn:
- return QString();
+ return tr("Enable");
case NameColumn:
return tr("Name");
case PackFormatColumn:
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.h b/launcher/minecraft/mod/ResourcePackFolderModel.h
index 71532f30..bbec9619 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.h
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.h
@@ -11,15 +11,17 @@ public:
enum Columns
{
ActiveColumn = 0,
+ ImageColumn,
NameColumn,
PackFormatColumn,
DateColumn,
- ImageColumn,
NUM_COLUMNS
};
explicit ResourcePackFolderModel(const QString &dir, std::shared_ptr<const BaseInstance> instance);
+ virtual QString id() const override { return "resourcepacks"; }
+
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
diff --git a/launcher/minecraft/mod/ShaderPackFolderModel.h b/launcher/minecraft/mod/ShaderPackFolderModel.h
index 6f3f2811..e010f6ed 100644
--- a/launcher/minecraft/mod/ShaderPackFolderModel.h
+++ b/launcher/minecraft/mod/ShaderPackFolderModel.h
@@ -9,4 +9,6 @@ class ShaderPackFolderModel : public ResourceFolderModel {
explicit ShaderPackFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance)
: ResourceFolderModel(QDir(dir), instance)
{}
+
+ virtual QString id() const override { return "shaderpacks"; }
};
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp
index e115cce6..c88f8f37 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.cpp
+++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp
@@ -45,7 +45,9 @@
TexturePackFolderModel::TexturePackFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance)
: ResourceFolderModel(QDir(dir), instance)
{
- m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::DATE, SortType::NAME };
+ m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::DATE };
+ m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents};
+
}
Task* TexturePackFolderModel::createUpdateTask()
@@ -115,6 +117,8 @@ QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orienta
switch (role) {
case Qt::DisplayRole:
switch (section) {
+ case ActiveColumn:
+ return tr("Enable");
case NameColumn:
return tr("Name");
case DateColumn:
@@ -149,4 +153,5 @@ QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orienta
int TexturePackFolderModel::columnCount(const QModelIndex& parent) const
{
return parent.isValid() ? 0 : NUM_COLUMNS;
-} \ No newline at end of file
+}
+
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.h b/launcher/minecraft/mod/TexturePackFolderModel.h
index 4467691a..ce9c06c4 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.h
+++ b/launcher/minecraft/mod/TexturePackFolderModel.h
@@ -49,14 +49,16 @@ public:
enum Columns
{
ActiveColumn = 0,
+ ImageColumn,
NameColumn,
DateColumn,
- ImageColumn,
NUM_COLUMNS
};
explicit TexturePackFolderModel(const QString &dir, std::shared_ptr<const BaseInstance> instance);
+ virtual QString id() const override { return "texturepacks"; }
+
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.cpp b/launcher/ui/pages/instance/ExternalResourcesPage.cpp
index 6c11b85b..bee11d9a 100644
--- a/launcher/ui/pages/instance/ExternalResourcesPage.cpp
+++ b/launcher/ui/pages/instance/ExternalResourcesPage.cpp
@@ -24,6 +24,8 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
m_filterModel->setSourceModel(m_model.get());
m_filterModel->setFilterKeyColumn(-1);
ui->treeView->setModel(m_filterModel);
+ // must come after setModel
+ ui->treeView->setResizeModes(m_model->columnResizeModes());
ui->treeView->installEventFilter(this);
ui->treeView->sortByColumn(1, Qt::AscendingOrder);
@@ -44,6 +46,13 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
auto selection_model = ui->treeView->selectionModel();
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged);
+
+ auto viewHeader = ui->treeView->header();
+ viewHeader->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ connect(viewHeader, &QHeaderView::customContextMenuRequested, this, &ExternalResourcesPage::ShowHeaderContextMenu);
+
+ m_model->loadHiddenColumns(ui->treeView);
}
ExternalResourcesPage::~ExternalResourcesPage()
@@ -65,6 +74,12 @@ void ExternalResourcesPage::ShowContextMenu(const QPoint& pos)
delete menu;
}
+void ExternalResourcesPage::ShowHeaderContextMenu(const QPoint& pos)
+{
+ auto menu = m_model->createHeaderContextMenu(this, ui->treeView);
+ menu->exec(ui->treeView->mapToGlobal(pos));
+}
+
void ExternalResourcesPage::openedImpl()
{
m_model->startWatching();
diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.h b/launcher/ui/pages/instance/ExternalResourcesPage.h
index d17fbb7f..906e6df7 100644
--- a/launcher/ui/pages/instance/ExternalResourcesPage.h
+++ b/launcher/ui/pages/instance/ExternalResourcesPage.h
@@ -60,6 +60,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
virtual void viewConfigs();
void ShowContextMenu(const QPoint& pos);
+ void ShowHeaderContextMenu(const QPoint& pos);
protected:
BaseInstance* m_instance = nullptr;
diff --git a/launcher/ui/widgets/ModListView.cpp b/launcher/ui/widgets/ModListView.cpp
index 09b03a76..893cd120 100644
--- a/launcher/ui/widgets/ModListView.cpp
+++ b/launcher/ui/widgets/ModListView.cpp
@@ -79,3 +79,12 @@ void ModListView::setModel ( QAbstractItemModel* model )
});
}
}
+
+void ModListView::setResizeModes(const QList<QHeaderView::ResizeMode> &modes)
+{
+ auto head = header();
+ for(int i = 0; i < modes.count(); i++) {
+ head->setSectionResizeMode(i, modes[i]);
+ }
+}
+
diff --git a/launcher/ui/widgets/ModListView.h b/launcher/ui/widgets/ModListView.h
index 881e092f..3f0b3b0e 100644
--- a/launcher/ui/widgets/ModListView.h
+++ b/launcher/ui/widgets/ModListView.h
@@ -14,6 +14,7 @@
*/
#pragma once
+#include <QHeaderView>
#include <QTreeView>
class ModListView: public QTreeView
@@ -22,4 +23,5 @@ class ModListView: public QTreeView
public:
explicit ModListView ( QWidget* parent = 0 );
virtual void setModel ( QAbstractItemModel* model );
+ virtual void setResizeModes (const QList<QHeaderView::ResizeMode>& modes);
};