refactor: adapt rest of the codebase to the new resource model
In order to access the ModFolderModel from the ModFolderPage, i created a new m_model for the correct type, shadowing the m_model of type ResourceFolderModel. This creates two shared_ptr references to the same object, but since they will have the same lifetime, it doesn't generate a memory leak. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
256f8094f5
commit
97a74d5c1f
@ -326,6 +326,7 @@ set(MINECRAFT_SOURCES
|
|||||||
minecraft/mod/ResourcePackFolderModel.cpp
|
minecraft/mod/ResourcePackFolderModel.cpp
|
||||||
minecraft/mod/TexturePackFolderModel.h
|
minecraft/mod/TexturePackFolderModel.h
|
||||||
minecraft/mod/TexturePackFolderModel.cpp
|
minecraft/mod/TexturePackFolderModel.cpp
|
||||||
|
minecraft/mod/ShaderPackFolderModel.h
|
||||||
minecraft/mod/tasks/BasicFolderLoadTask.h
|
minecraft/mod/tasks/BasicFolderLoadTask.h
|
||||||
minecraft/mod/tasks/ModFolderLoadTask.h
|
minecraft/mod/tasks/ModFolderLoadTask.h
|
||||||
minecraft/mod/tasks/ModFolderLoadTask.cpp
|
minecraft/mod/tasks/ModFolderLoadTask.cpp
|
||||||
@ -884,8 +885,8 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/widgets/LineSeparator.h
|
ui/widgets/LineSeparator.h
|
||||||
ui/widgets/LogView.cpp
|
ui/widgets/LogView.cpp
|
||||||
ui/widgets/LogView.h
|
ui/widgets/LogView.h
|
||||||
ui/widgets/MCModInfoFrame.cpp
|
ui/widgets/InfoFrame.cpp
|
||||||
ui/widgets/MCModInfoFrame.h
|
ui/widgets/InfoFrame.h
|
||||||
ui/widgets/ModFilterWidget.cpp
|
ui/widgets/ModFilterWidget.cpp
|
||||||
ui/widgets/ModFilterWidget.h
|
ui/widgets/ModFilterWidget.h
|
||||||
ui/widgets/ModListView.cpp
|
ui/widgets/ModListView.cpp
|
||||||
@ -947,7 +948,7 @@ qt_wrap_ui(LAUNCHER_UI
|
|||||||
ui/pages/modplatform/technic/TechnicPage.ui
|
ui/pages/modplatform/technic/TechnicPage.ui
|
||||||
ui/widgets/InstanceCardWidget.ui
|
ui/widgets/InstanceCardWidget.ui
|
||||||
ui/widgets/CustomCommands.ui
|
ui/widgets/CustomCommands.ui
|
||||||
ui/widgets/MCModInfoFrame.ui
|
ui/widgets/InfoFrame.ui
|
||||||
ui/widgets/ModFilterWidget.ui
|
ui/widgets/ModFilterWidget.ui
|
||||||
ui/dialogs/CopyInstanceDialog.ui
|
ui/dialogs/CopyInstanceDialog.ui
|
||||||
ui/dialogs/ProfileSetupDialog.ui
|
ui/dialogs/ProfileSetupDialog.ui
|
||||||
|
@ -37,9 +37,9 @@ public:
|
|||||||
modsPage->setFilter("%1 (*.zip *.jar *.litemod)");
|
modsPage->setFilter("%1 (*.zip *.jar *.litemod)");
|
||||||
values.append(modsPage);
|
values.append(modsPage);
|
||||||
values.append(new CoreModFolderPage(onesix.get(), onesix->coreModList()));
|
values.append(new CoreModFolderPage(onesix.get(), onesix->coreModList()));
|
||||||
values.append(new ResourcePackPage(onesix.get()));
|
values.append(new ResourcePackPage(onesix.get(), onesix->resourcePackList()));
|
||||||
values.append(new TexturePackPage(onesix.get()));
|
values.append(new TexturePackPage(onesix.get(), onesix->texturePackList()));
|
||||||
values.append(new ShaderPackPage(onesix.get()));
|
values.append(new ShaderPackPage(onesix.get(), onesix->shaderPackList()));
|
||||||
values.append(new NotesPage(onesix.get()));
|
values.append(new NotesPage(onesix.get()));
|
||||||
values.append(new WorldListPage(onesix.get(), onesix->worldList()));
|
values.append(new WorldListPage(onesix.get(), onesix->worldList()));
|
||||||
values.append(new ServersPage(onesix));
|
values.append(new ServersPage(onesix));
|
||||||
|
@ -76,6 +76,7 @@
|
|||||||
|
|
||||||
#include "mod/ModFolderModel.h"
|
#include "mod/ModFolderModel.h"
|
||||||
#include "mod/ResourcePackFolderModel.h"
|
#include "mod/ResourcePackFolderModel.h"
|
||||||
|
#include "mod/ShaderPackFolderModel.h"
|
||||||
#include "mod/TexturePackFolderModel.h"
|
#include "mod/TexturePackFolderModel.h"
|
||||||
|
|
||||||
#include "WorldList.h"
|
#include "WorldList.h"
|
||||||
@ -1092,18 +1093,18 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList() const
|
|||||||
return m_core_mod_list;
|
return m_core_mod_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ModFolderModel> MinecraftInstance::resourcePackList() const
|
std::shared_ptr<ResourcePackFolderModel> MinecraftInstance::resourcePackList() const
|
||||||
{
|
{
|
||||||
if (!m_resource_pack_list)
|
if (!m_resource_pack_list)
|
||||||
{
|
{
|
||||||
m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir()));
|
m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir()));
|
||||||
m_resource_pack_list->disableInteraction(isRunning());
|
m_resource_pack_list->enableInteraction(!isRunning());
|
||||||
connect(this, &BaseInstance::runningStatusChanged, m_resource_pack_list.get(), &ModFolderModel::disableInteraction);
|
connect(this, &BaseInstance::runningStatusChanged, m_resource_pack_list.get(), &ResourcePackFolderModel::disableInteraction);
|
||||||
}
|
}
|
||||||
return m_resource_pack_list;
|
return m_resource_pack_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ModFolderModel> MinecraftInstance::texturePackList() const
|
std::shared_ptr<TexturePackFolderModel> MinecraftInstance::texturePackList() const
|
||||||
{
|
{
|
||||||
if (!m_texture_pack_list)
|
if (!m_texture_pack_list)
|
||||||
{
|
{
|
||||||
@ -1114,11 +1115,11 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::texturePackList() const
|
|||||||
return m_texture_pack_list;
|
return m_texture_pack_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ModFolderModel> MinecraftInstance::shaderPackList() const
|
std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList() const
|
||||||
{
|
{
|
||||||
if (!m_shader_pack_list)
|
if (!m_shader_pack_list)
|
||||||
{
|
{
|
||||||
m_shader_pack_list.reset(new ResourcePackFolderModel(shaderPacksDir()));
|
m_shader_pack_list.reset(new ShaderPackFolderModel(shaderPacksDir()));
|
||||||
m_shader_pack_list->disableInteraction(isRunning());
|
m_shader_pack_list->disableInteraction(isRunning());
|
||||||
connect(this, &BaseInstance::runningStatusChanged, m_shader_pack_list.get(), &ModFolderModel::disableInteraction);
|
connect(this, &BaseInstance::runningStatusChanged, m_shader_pack_list.get(), &ModFolderModel::disableInteraction);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
#include "minecraft/launch/MinecraftServerTarget.h"
|
#include "minecraft/launch/MinecraftServerTarget.h"
|
||||||
|
|
||||||
class ModFolderModel;
|
class ModFolderModel;
|
||||||
|
class ResourceFolderModel;
|
||||||
|
class ResourcePackFolderModel;
|
||||||
|
class ShaderPackFolderModel;
|
||||||
|
class TexturePackFolderModel;
|
||||||
class WorldList;
|
class WorldList;
|
||||||
class GameOptions;
|
class GameOptions;
|
||||||
class LaunchStep;
|
class LaunchStep;
|
||||||
@ -72,9 +76,9 @@ public:
|
|||||||
////// Mod Lists //////
|
////// Mod Lists //////
|
||||||
std::shared_ptr<ModFolderModel> loaderModList() const;
|
std::shared_ptr<ModFolderModel> loaderModList() const;
|
||||||
std::shared_ptr<ModFolderModel> coreModList() const;
|
std::shared_ptr<ModFolderModel> coreModList() const;
|
||||||
std::shared_ptr<ModFolderModel> resourcePackList() const;
|
std::shared_ptr<ResourcePackFolderModel> resourcePackList() const;
|
||||||
std::shared_ptr<ModFolderModel> texturePackList() const;
|
std::shared_ptr<TexturePackFolderModel> texturePackList() const;
|
||||||
std::shared_ptr<ModFolderModel> shaderPackList() const;
|
std::shared_ptr<ShaderPackFolderModel> shaderPackList() const;
|
||||||
std::shared_ptr<WorldList> worldList() const;
|
std::shared_ptr<WorldList> worldList() const;
|
||||||
std::shared_ptr<GameOptions> gameOptionsModel() const;
|
std::shared_ptr<GameOptions> gameOptionsModel() const;
|
||||||
|
|
||||||
@ -125,9 +129,9 @@ protected: // data
|
|||||||
std::shared_ptr<PackProfile> m_components;
|
std::shared_ptr<PackProfile> m_components;
|
||||||
mutable std::shared_ptr<ModFolderModel> m_loader_mod_list;
|
mutable std::shared_ptr<ModFolderModel> m_loader_mod_list;
|
||||||
mutable std::shared_ptr<ModFolderModel> m_core_mod_list;
|
mutable std::shared_ptr<ModFolderModel> m_core_mod_list;
|
||||||
mutable std::shared_ptr<ModFolderModel> m_resource_pack_list;
|
mutable std::shared_ptr<ResourcePackFolderModel> m_resource_pack_list;
|
||||||
mutable std::shared_ptr<ModFolderModel> m_shader_pack_list;
|
mutable std::shared_ptr<ShaderPackFolderModel> m_shader_pack_list;
|
||||||
mutable std::shared_ptr<ModFolderModel> m_texture_pack_list;
|
mutable std::shared_ptr<TexturePackFolderModel> m_texture_pack_list;
|
||||||
mutable std::shared_ptr<WorldList> m_world_list;
|
mutable std::shared_ptr<WorldList> m_world_list;
|
||||||
mutable std::shared_ptr<GameOptions> m_game_options;
|
mutable std::shared_ptr<GameOptions> m_game_options;
|
||||||
};
|
};
|
||||||
|
@ -50,7 +50,8 @@ public:
|
|||||||
|
|
||||||
Mod() = default;
|
Mod() = default;
|
||||||
Mod(const QFileInfo &file);
|
Mod(const QFileInfo &file);
|
||||||
explicit Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata);
|
Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata);
|
||||||
|
Mod(QString file_path) : Mod(QFileInfo(file_path)) {}
|
||||||
|
|
||||||
auto enabled() const -> bool { return m_enabled; }
|
auto enabled() const -> bool { return m_enabled; }
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
#include "minecraft/mod/tasks/LocalModParseTask.h"
|
#include "minecraft/mod/tasks/LocalModParseTask.h"
|
||||||
#include "minecraft/mod/tasks/ModFolderLoadTask.h"
|
#include "minecraft/mod/tasks/ModFolderLoadTask.h"
|
||||||
|
|
||||||
ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(dir), m_is_indexed(is_indexed)
|
ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(QDir(dir)), m_is_indexed(is_indexed)
|
||||||
{
|
{
|
||||||
FS::ensureFolderPathExists(m_dir.absolutePath());
|
FS::ensureFolderPathExists(m_dir.absolutePath());
|
||||||
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE };
|
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE };
|
||||||
|
@ -34,6 +34,8 @@ class Resource : public QObject {
|
|||||||
|
|
||||||
Resource(QObject* parent = nullptr);
|
Resource(QObject* parent = nullptr);
|
||||||
Resource(QFileInfo file_info);
|
Resource(QFileInfo file_info);
|
||||||
|
Resource(QString file_path) : Resource(QFileInfo(file_path)) {}
|
||||||
|
|
||||||
~Resource() override = default;
|
~Resource() override = default;
|
||||||
|
|
||||||
void setFile(QFileInfo file_info);
|
void setFile(QFileInfo file_info);
|
||||||
|
@ -261,6 +261,9 @@ void ResourceFolderModel::applyUpdates(QSet<QString>& current_set, QSet<QString>
|
|||||||
|
|
||||||
std::sort(removed_rows.begin(), removed_rows.end());
|
std::sort(removed_rows.begin(), removed_rows.end());
|
||||||
|
|
||||||
|
for (int i = 0; i < removed_rows.size(); i++)
|
||||||
|
removed_rows[i] -= i;
|
||||||
|
|
||||||
for (auto& removed_index : removed_rows) {
|
for (auto& removed_index : removed_rows) {
|
||||||
beginRemoveRows(QModelIndex(), removed_index, removed_index);
|
beginRemoveRows(QModelIndex(), removed_index, removed_index);
|
||||||
|
|
||||||
|
13
launcher/minecraft/mod/ResourcePack.h
Normal file
13
launcher/minecraft/mod/ResourcePack.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Resource.h"
|
||||||
|
|
||||||
|
class ResourcePack : public Resource {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
using Ptr = shared_qobject_ptr<Resource>;
|
||||||
|
|
||||||
|
ResourcePack(QObject* parent = nullptr) : Resource(parent) {}
|
||||||
|
ResourcePack(QFileInfo file_info) : Resource(file_info) {}
|
||||||
|
|
||||||
|
};
|
@ -35,5 +35,4 @@
|
|||||||
|
|
||||||
#include "ResourcePackFolderModel.h"
|
#include "ResourcePackFolderModel.h"
|
||||||
|
|
||||||
ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ResourceFolderModel(dir) {
|
ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ResourceFolderModel(QDir(dir)) {}
|
||||||
}
|
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
#include "ResourceFolderModel.h"
|
#include "ResourceFolderModel.h"
|
||||||
|
|
||||||
|
#include "ResourcePack.h"
|
||||||
|
|
||||||
class ResourcePackFolderModel : public ResourceFolderModel
|
class ResourcePackFolderModel : public ResourceFolderModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ResourcePackFolderModel(const QString &dir);
|
explicit ResourcePackFolderModel(const QString &dir);
|
||||||
|
|
||||||
|
RESOURCE_HELPERS(ResourcePack)
|
||||||
};
|
};
|
||||||
|
10
launcher/minecraft/mod/ShaderPackFolderModel.h
Normal file
10
launcher/minecraft/mod/ShaderPackFolderModel.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ResourceFolderModel.h"
|
||||||
|
|
||||||
|
class ShaderPackFolderModel : public ResourceFolderModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ShaderPackFolderModel(const QString& dir) : ResourceFolderModel(QDir(dir)) {}
|
||||||
|
};
|
@ -35,24 +35,4 @@
|
|||||||
|
|
||||||
#include "TexturePackFolderModel.h"
|
#include "TexturePackFolderModel.h"
|
||||||
|
|
||||||
TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ModFolderModel(dir) {
|
TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ResourceFolderModel(QDir(dir)) {}
|
||||||
}
|
|
||||||
|
|
||||||
QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
|
||||||
if (role == Qt::ToolTipRole) {
|
|
||||||
switch (section) {
|
|
||||||
case ActiveColumn:
|
|
||||||
return tr("Is the texture pack enabled?");
|
|
||||||
case NameColumn:
|
|
||||||
return tr("The name of the texture pack.");
|
|
||||||
case VersionColumn:
|
|
||||||
return tr("The version of the texture pack.");
|
|
||||||
case DateColumn:
|
|
||||||
return tr("The date and time this texture pack was last changed (or added).");
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ModFolderModel::headerData(section, orientation, role);
|
|
||||||
}
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ModFolderModel.h"
|
#include "ResourceFolderModel.h"
|
||||||
|
|
||||||
class TexturePackFolderModel : public ModFolderModel
|
class TexturePackFolderModel : public ResourceFolderModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TexturePackFolderModel(const QString &dir);
|
explicit TexturePackFolderModel(const QString &dir);
|
||||||
|
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
||||||
};
|
};
|
||||||
|
@ -3,100 +3,13 @@
|
|||||||
|
|
||||||
#include "DesktopServices.h"
|
#include "DesktopServices.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ResourceFolderModel.h"
|
||||||
#include "ui/GuiUtil.h"
|
#include "ui/GuiUtil.h"
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
namespace {
|
ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent)
|
||||||
// FIXME: wasteful
|
|
||||||
void RemoveThePrefix(QString& string)
|
|
||||||
{
|
|
||||||
QRegularExpression regex(QStringLiteral("^(?:the|teh) +"), QRegularExpression::CaseInsensitiveOption);
|
|
||||||
string.remove(regex);
|
|
||||||
string = string.trimmed();
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
class SortProxy : public QSortFilterProxyModel {
|
|
||||||
public:
|
|
||||||
explicit SortProxy(QObject* parent = nullptr) : QSortFilterProxyModel(parent) {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
|
|
||||||
{
|
|
||||||
ModFolderModel* model = qobject_cast<ModFolderModel*>(sourceModel());
|
|
||||||
if (!model)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const auto& mod = model->at(source_row);
|
|
||||||
|
|
||||||
if (filterRegularExpression().match(mod->name()).hasMatch())
|
|
||||||
return true;
|
|
||||||
if (filterRegularExpression().match(mod->description()).hasMatch())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (auto& author : mod->authors()) {
|
|
||||||
if (filterRegularExpression().match(author).hasMatch()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override
|
|
||||||
{
|
|
||||||
ModFolderModel* model = qobject_cast<ModFolderModel*>(sourceModel());
|
|
||||||
if (!model || !source_left.isValid() || !source_right.isValid() || source_left.column() != source_right.column()) {
|
|
||||||
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
|
||||||
}
|
|
||||||
|
|
||||||
// we are now guaranteed to have two valid indexes in the same column... we love the provided invariants unconditionally and
|
|
||||||
// proceed.
|
|
||||||
|
|
||||||
auto column = (ModFolderModel::Columns) source_left.column();
|
|
||||||
bool invert = false;
|
|
||||||
switch (column) {
|
|
||||||
// GH-2550 - sort by enabled/disabled
|
|
||||||
case ModFolderModel::ActiveColumn: {
|
|
||||||
auto dataL = source_left.data(Qt::CheckStateRole).toBool();
|
|
||||||
auto dataR = source_right.data(Qt::CheckStateRole).toBool();
|
|
||||||
if (dataL != dataR)
|
|
||||||
return dataL > dataR;
|
|
||||||
|
|
||||||
// fallthrough
|
|
||||||
invert = sortOrder() == Qt::DescendingOrder;
|
|
||||||
}
|
|
||||||
// GH-2722 - sort mod names in a way that discards "The" prefixes
|
|
||||||
case ModFolderModel::NameColumn: {
|
|
||||||
auto dataL = model->data(model->index(source_left.row(), ModFolderModel::NameColumn)).toString();
|
|
||||||
RemoveThePrefix(dataL);
|
|
||||||
auto dataR = model->data(model->index(source_right.row(), ModFolderModel::NameColumn)).toString();
|
|
||||||
RemoveThePrefix(dataR);
|
|
||||||
|
|
||||||
auto less = dataL.compare(dataR, sortCaseSensitivity());
|
|
||||||
if (less != 0)
|
|
||||||
return invert ? (less > 0) : (less < 0);
|
|
||||||
|
|
||||||
// fallthrough
|
|
||||||
invert = sortOrder() == Qt::DescendingOrder;
|
|
||||||
}
|
|
||||||
// GH-2762 - sort versions by parsing them as versions
|
|
||||||
case ModFolderModel::VersionColumn: {
|
|
||||||
auto dataL = Version(model->data(model->index(source_left.row(), ModFolderModel::VersionColumn)).toString());
|
|
||||||
auto dataR = Version(model->data(model->index(source_right.row(), ModFolderModel::VersionColumn)).toString());
|
|
||||||
return invert ? (dataL > dataR) : (dataL < dataR);
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ModFolderModel> model, QWidget* parent)
|
|
||||||
: QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model)
|
: QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -105,7 +18,7 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
|
|||||||
|
|
||||||
ui->actionsToolbar->insertSpacer(ui->actionViewConfigs);
|
ui->actionsToolbar->insertSpacer(ui->actionViewConfigs);
|
||||||
|
|
||||||
m_filterModel = new SortProxy(this);
|
m_filterModel = model->createFilterProxyModel(this);
|
||||||
m_filterModel->setDynamicSortFilter(true);
|
m_filterModel->setDynamicSortFilter(true);
|
||||||
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
@ -127,7 +40,6 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
|
|||||||
connect(ui->actionViewFolder, &QAction::triggered, this, &ExternalResourcesPage::viewFolder);
|
connect(ui->actionViewFolder, &QAction::triggered, this, &ExternalResourcesPage::viewFolder);
|
||||||
|
|
||||||
connect(ui->treeView, &ModListView::customContextMenuRequested, this, &ExternalResourcesPage::ShowContextMenu);
|
connect(ui->treeView, &ModListView::customContextMenuRequested, this, &ExternalResourcesPage::ShowContextMenu);
|
||||||
connect(ui->treeView, &ModListView::activated, this, &ExternalResourcesPage::itemActivated);
|
|
||||||
|
|
||||||
auto selection_model = ui->treeView->selectionModel();
|
auto selection_model = ui->treeView->selectionModel();
|
||||||
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
|
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
|
||||||
@ -137,19 +49,9 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
|
|||||||
|
|
||||||
ExternalResourcesPage::~ExternalResourcesPage()
|
ExternalResourcesPage::~ExternalResourcesPage()
|
||||||
{
|
{
|
||||||
m_model->stopWatching();
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalResourcesPage::itemActivated(const QModelIndex&)
|
|
||||||
{
|
|
||||||
if (!m_controlsEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
|
||||||
m_model->setModStatus(selection.indexes(), ModFolderModel::Toggle);
|
|
||||||
}
|
|
||||||
|
|
||||||
QMenu* ExternalResourcesPage::createPopupMenu()
|
QMenu* ExternalResourcesPage::createPopupMenu()
|
||||||
{
|
{
|
||||||
QMenu* filteredMenu = QMainWindow::createPopupMenu();
|
QMenu* filteredMenu = QMainWindow::createPopupMenu();
|
||||||
@ -241,7 +143,7 @@ void ExternalResourcesPage::addItem()
|
|||||||
|
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
for (auto filename : list) {
|
for (auto filename : list) {
|
||||||
m_model->installMod(filename);
|
m_model->installResource(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,25 +154,7 @@ void ExternalResourcesPage::removeItem()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
||||||
m_model->deleteMods(selection.indexes());
|
m_model->deleteResources(selection.indexes());
|
||||||
}
|
|
||||||
|
|
||||||
void ExternalResourcesPage::enableItem()
|
|
||||||
{
|
|
||||||
if (!m_controlsEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
|
||||||
m_model->setModStatus(selection.indexes(), ModFolderModel::Enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExternalResourcesPage::disableItem()
|
|
||||||
{
|
|
||||||
if (!m_controlsEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
|
||||||
m_model->setModStatus(selection.indexes(), ModFolderModel::Disable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalResourcesPage::viewConfigs()
|
void ExternalResourcesPage::viewConfigs()
|
||||||
@ -283,15 +167,23 @@ void ExternalResourcesPage::viewFolder()
|
|||||||
DesktopServices::openDirectory(m_model->dir().absolutePath(), true);
|
DesktopServices::openDirectory(m_model->dir().absolutePath(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalResourcesPage::current(const QModelIndex& current, const QModelIndex& previous)
|
bool ExternalResourcesPage::current(const QModelIndex& current, const QModelIndex& previous)
|
||||||
{
|
{
|
||||||
if (!current.isValid()) {
|
if (!current.isValid()) {
|
||||||
ui->frame->clear();
|
ui->frame->clear();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return onSelectionChanged(current, previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||||
|
{
|
||||||
auto sourceCurrent = m_filterModel->mapToSource(current);
|
auto sourceCurrent = m_filterModel->mapToSource(current);
|
||||||
int row = sourceCurrent.row();
|
int row = sourceCurrent.row();
|
||||||
Mod& m = *m_model->operator[](row);
|
Resource const& resource = m_model->at(row);
|
||||||
ui->frame->updateWithMod(m);
|
ui->frame->updateWithResource(resource);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "ui/pages/BasePage.h"
|
#include "ui/pages/BasePage.h"
|
||||||
|
|
||||||
class ModFolderModel;
|
class ResourceFolderModel;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ExternalResourcesPage;
|
class ExternalResourcesPage;
|
||||||
@ -19,8 +19,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// FIXME: Switch to different model (or change the name of this one)
|
explicit ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent = nullptr);
|
||||||
explicit ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ModFolderModel> model, QWidget* parent = nullptr);
|
|
||||||
virtual ~ExternalResourcesPage();
|
virtual ~ExternalResourcesPage();
|
||||||
|
|
||||||
virtual QString displayName() const override = 0;
|
virtual QString displayName() const override = 0;
|
||||||
@ -41,18 +40,20 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
|
|||||||
QMenu* createPopupMenu() override;
|
QMenu* createPopupMenu() override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void current(const QModelIndex& current, const QModelIndex& previous);
|
bool current(const QModelIndex& current, const QModelIndex& previous);
|
||||||
|
|
||||||
|
virtual bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void itemActivated(const QModelIndex& index);
|
virtual void itemActivated(const QModelIndex& index) {};
|
||||||
void filterTextChanged(const QString& newContents);
|
void filterTextChanged(const QString& newContents);
|
||||||
virtual void runningStateChanged(bool running);
|
virtual void runningStateChanged(bool running);
|
||||||
|
|
||||||
virtual void addItem();
|
virtual void addItem();
|
||||||
virtual void removeItem();
|
virtual void removeItem();
|
||||||
|
|
||||||
virtual void enableItem();
|
virtual void enableItem() {};
|
||||||
virtual void disableItem();
|
virtual void disableItem() {};
|
||||||
|
|
||||||
virtual void viewFolder();
|
virtual void viewFolder();
|
||||||
virtual void viewConfigs();
|
virtual void viewConfigs();
|
||||||
@ -63,7 +64,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
|
|||||||
BaseInstance* m_instance = nullptr;
|
BaseInstance* m_instance = nullptr;
|
||||||
|
|
||||||
Ui::ExternalResourcesPage* ui = nullptr;
|
Ui::ExternalResourcesPage* ui = nullptr;
|
||||||
std::shared_ptr<ModFolderModel> m_model;
|
std::shared_ptr<ResourceFolderModel> m_model;
|
||||||
QSortFilterProxyModel* m_filterModel = nullptr;
|
QSortFilterProxyModel* m_filterModel = nullptr;
|
||||||
|
|
||||||
QString m_fileSelectionFilter;
|
QString m_fileSelectionFilter;
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1" colspan="3">
|
<item row="2" column="1" colspan="3">
|
||||||
<widget class="MCModInfoFrame" name="frame">
|
<widget class="InfoFrame" name="frame">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -166,9 +166,9 @@
|
|||||||
<header>ui/widgets/ModListView.h</header>
|
<header>ui/widgets/ModListView.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>MCModInfoFrame</class>
|
<class>InfoFrame</class>
|
||||||
<extends>QFrame</extends>
|
<extends>QFrame</extends>
|
||||||
<header>ui/widgets/MCModInfoFrame.h</header>
|
<header>ui/widgets/InfoFrame.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
#include "ui/dialogs/ProgressDialog.h"
|
#include "ui/dialogs/ProgressDialog.h"
|
||||||
|
|
||||||
ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel> mods, QWidget* parent)
|
ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel> mods, QWidget* parent)
|
||||||
: ExternalResourcesPage(inst, mods, parent)
|
: ExternalResourcesPage(inst, mods, parent), m_model(mods)
|
||||||
{
|
{
|
||||||
// This is structured like that so that these changes
|
// This is structured like that so that these changes
|
||||||
// do not affect the Resource pack and Shader pack tabs
|
// do not affect the Resource pack and Shader pack tabs
|
||||||
@ -110,6 +110,8 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
|
|||||||
|
|
||||||
ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning());
|
ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(ui->treeView, &ModListView::activated, this, &ModFolderPage::itemActivated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModFolderPage::runningStateChanged(bool running)
|
void ModFolderPage::runningStateChanged(bool running)
|
||||||
@ -124,6 +126,44 @@ bool ModFolderPage::shouldDisplay() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModFolderPage::itemActivated(const QModelIndex&)
|
||||||
|
{
|
||||||
|
if (!m_controlsEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
||||||
|
m_model->setModStatus(selection.indexes(), ModFolderModel::Toggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModFolderPage::enableItem()
|
||||||
|
{
|
||||||
|
if (!m_controlsEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
||||||
|
m_model->setModStatus(selection.indexes(), ModFolderModel::Enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModFolderPage::disableItem()
|
||||||
|
{
|
||||||
|
if (!m_controlsEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
||||||
|
m_model->setModStatus(selection.indexes(), ModFolderModel::Disable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModFolderPage::onSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||||
|
{
|
||||||
|
auto sourceCurrent = m_filterModel->mapToSource(current);
|
||||||
|
int row = sourceCurrent.row();
|
||||||
|
Mod const* m = m_model->at(row);
|
||||||
|
if (m)
|
||||||
|
ui->frame->updateWithMod(*m);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ModFolderPage::installMods()
|
void ModFolderPage::installMods()
|
||||||
{
|
{
|
||||||
if (!m_controlsEnabled)
|
if (!m_controlsEnabled)
|
||||||
|
@ -55,9 +55,20 @@ class ModFolderPage : public ExternalResourcesPage {
|
|||||||
virtual bool shouldDisplay() const override;
|
virtual bool shouldDisplay() const override;
|
||||||
void runningStateChanged(bool running) override;
|
void runningStateChanged(bool running) override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous) override;
|
||||||
|
|
||||||
|
void itemActivated(const QModelIndex& index) override;
|
||||||
|
|
||||||
|
void enableItem() override;
|
||||||
|
void disableItem() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void installMods();
|
void installMods();
|
||||||
void updateMods();
|
void updateMods();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<ModFolderModel> m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CoreModFolderPage : public ModFolderPage {
|
class CoreModFolderPage : public ModFolderPage {
|
||||||
|
@ -38,12 +38,14 @@
|
|||||||
#include "ExternalResourcesPage.h"
|
#include "ExternalResourcesPage.h"
|
||||||
#include "ui_ExternalResourcesPage.h"
|
#include "ui_ExternalResourcesPage.h"
|
||||||
|
|
||||||
|
#include "minecraft/mod/ResourcePackFolderModel.h"
|
||||||
|
|
||||||
class ResourcePackPage : public ExternalResourcesPage
|
class ResourcePackPage : public ExternalResourcesPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ResourcePackPage(MinecraftInstance *instance, QWidget *parent = 0)
|
explicit ResourcePackPage(MinecraftInstance *instance, std::shared_ptr<ResourcePackFolderModel> model, QWidget *parent = 0)
|
||||||
: ExternalResourcesPage(instance, instance->resourcePackList(), parent)
|
: ExternalResourcesPage(instance, model, parent)
|
||||||
{
|
{
|
||||||
ui->actionViewConfigs->setVisible(false);
|
ui->actionViewConfigs->setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,14 @@
|
|||||||
#include "ExternalResourcesPage.h"
|
#include "ExternalResourcesPage.h"
|
||||||
#include "ui_ExternalResourcesPage.h"
|
#include "ui_ExternalResourcesPage.h"
|
||||||
|
|
||||||
|
#include "minecraft/mod/ShaderPackFolderModel.h"
|
||||||
|
|
||||||
class ShaderPackPage : public ExternalResourcesPage
|
class ShaderPackPage : public ExternalResourcesPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ShaderPackPage(MinecraftInstance *instance, QWidget *parent = 0)
|
explicit ShaderPackPage(MinecraftInstance *instance, std::shared_ptr<ShaderPackFolderModel> model, QWidget *parent = 0)
|
||||||
: ExternalResourcesPage(instance, instance->shaderPackList(), parent)
|
: ExternalResourcesPage(instance, model, parent)
|
||||||
{
|
{
|
||||||
ui->actionViewConfigs->setVisible(false);
|
ui->actionViewConfigs->setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,14 @@
|
|||||||
#include "ExternalResourcesPage.h"
|
#include "ExternalResourcesPage.h"
|
||||||
#include "ui_ExternalResourcesPage.h"
|
#include "ui_ExternalResourcesPage.h"
|
||||||
|
|
||||||
|
#include "minecraft/mod/TexturePackFolderModel.h"
|
||||||
|
|
||||||
class TexturePackPage : public ExternalResourcesPage
|
class TexturePackPage : public ExternalResourcesPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit TexturePackPage(MinecraftInstance *instance, QWidget *parent = 0)
|
explicit TexturePackPage(MinecraftInstance *instance, std::shared_ptr<TexturePackFolderModel> model, QWidget *parent = 0)
|
||||||
: ExternalResourcesPage(instance, instance->texturePackList(), parent)
|
: ExternalResourcesPage(instance, model, parent)
|
||||||
{
|
{
|
||||||
ui->actionViewConfigs->setVisible(false);
|
ui->actionViewConfigs->setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -196,10 +196,10 @@ void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &
|
|||||||
switch(severity)
|
switch(severity)
|
||||||
{
|
{
|
||||||
case ProblemSeverity::Warning:
|
case ProblemSeverity::Warning:
|
||||||
ui->frame->setModText(tr("%1 possibly has issues.").arg(patch->getName()));
|
ui->frame->setName(tr("%1 possibly has issues.").arg(patch->getName()));
|
||||||
break;
|
break;
|
||||||
case ProblemSeverity::Error:
|
case ProblemSeverity::Error:
|
||||||
ui->frame->setModText(tr("%1 has issues!").arg(patch->getName()));
|
ui->frame->setName(tr("%1 has issues!").arg(patch->getName()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case ProblemSeverity::None:
|
case ProblemSeverity::None:
|
||||||
@ -222,7 +222,7 @@ void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &
|
|||||||
problemOut += problem.m_description;
|
problemOut += problem.m_description;
|
||||||
problemOut += "\n";
|
problemOut += "\n";
|
||||||
}
|
}
|
||||||
ui->frame->setModDescription(problemOut);
|
ui->frame->setDescription(problemOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VersionPage::updateRunningStatus(bool running)
|
void VersionPage::updateRunningStatus(bool running)
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="MCModInfoFrame" name="frame">
|
<widget class="InfoFrame" name="frame">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -278,9 +278,9 @@
|
|||||||
<header>ui/widgets/ModListView.h</header>
|
<header>ui/widgets/ModListView.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>MCModInfoFrame</class>
|
<class>InfoFrame</class>
|
||||||
<extends>QFrame</extends>
|
<extends>QFrame</extends>
|
||||||
<header>ui/widgets/MCModInfoFrame.h</header>
|
<header>ui/widgets/InfoFrame.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -14,14 +14,28 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QtGui>
|
|
||||||
|
|
||||||
#include "MCModInfoFrame.h"
|
#include "InfoFrame.h"
|
||||||
#include "ui_MCModInfoFrame.h"
|
#include "ui_InfoFrame.h"
|
||||||
|
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
|
|
||||||
void MCModInfoFrame::updateWithMod(Mod &m)
|
InfoFrame::InfoFrame(QWidget *parent) :
|
||||||
|
QFrame(parent),
|
||||||
|
ui(new Ui::InfoFrame)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->descriptionLabel->setHidden(true);
|
||||||
|
ui->nameLabel->setHidden(true);
|
||||||
|
updateHiddenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoFrame::~InfoFrame()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InfoFrame::updateWithMod(Mod const& m)
|
||||||
{
|
{
|
||||||
if (m.type() == ResourceType::FOLDER)
|
if (m.type() == ResourceType::FOLDER)
|
||||||
{
|
{
|
||||||
@ -43,42 +57,32 @@ void MCModInfoFrame::updateWithMod(Mod &m)
|
|||||||
if (!m.authors().isEmpty())
|
if (!m.authors().isEmpty())
|
||||||
text += " by " + m.authors().join(", ");
|
text += " by " + m.authors().join(", ");
|
||||||
|
|
||||||
setModText(text);
|
setName(text);
|
||||||
|
|
||||||
if (m.description().isEmpty())
|
if (m.description().isEmpty())
|
||||||
{
|
{
|
||||||
setModDescription(QString());
|
setDescription(QString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setModDescription(m.description());
|
setDescription(m.description());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCModInfoFrame::clear()
|
void InfoFrame::updateWithResource(const Resource& resource)
|
||||||
{
|
{
|
||||||
setModText(QString());
|
setName(resource.name());
|
||||||
setModDescription(QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MCModInfoFrame::MCModInfoFrame(QWidget *parent) :
|
void InfoFrame::clear()
|
||||||
QFrame(parent),
|
|
||||||
ui(new Ui::MCModInfoFrame)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
setName();
|
||||||
ui->label_ModDescription->setHidden(true);
|
setDescription();
|
||||||
ui->label_ModText->setHidden(true);
|
|
||||||
updateHiddenState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MCModInfoFrame::~MCModInfoFrame()
|
void InfoFrame::updateHiddenState()
|
||||||
{
|
{
|
||||||
delete ui;
|
if(ui->descriptionLabel->isHidden() && ui->nameLabel->isHidden())
|
||||||
}
|
|
||||||
|
|
||||||
void MCModInfoFrame::updateHiddenState()
|
|
||||||
{
|
|
||||||
if(ui->label_ModDescription->isHidden() && ui->label_ModText->isHidden())
|
|
||||||
{
|
{
|
||||||
setHidden(true);
|
setHidden(true);
|
||||||
}
|
}
|
||||||
@ -88,34 +92,34 @@ void MCModInfoFrame::updateHiddenState()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCModInfoFrame::setModText(QString text)
|
void InfoFrame::setName(QString text)
|
||||||
{
|
{
|
||||||
if(text.isEmpty())
|
if(text.isEmpty())
|
||||||
{
|
{
|
||||||
ui->label_ModText->setHidden(true);
|
ui->nameLabel->setHidden(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->label_ModText->setText(text);
|
ui->nameLabel->setText(text);
|
||||||
ui->label_ModText->setHidden(false);
|
ui->nameLabel->setHidden(false);
|
||||||
}
|
}
|
||||||
updateHiddenState();
|
updateHiddenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCModInfoFrame::setModDescription(QString text)
|
void InfoFrame::setDescription(QString text)
|
||||||
{
|
{
|
||||||
if(text.isEmpty())
|
if(text.isEmpty())
|
||||||
{
|
{
|
||||||
ui->label_ModDescription->setHidden(true);
|
ui->descriptionLabel->setHidden(true);
|
||||||
updateHiddenState();
|
updateHiddenState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->label_ModDescription->setHidden(false);
|
ui->descriptionLabel->setHidden(false);
|
||||||
updateHiddenState();
|
updateHiddenState();
|
||||||
}
|
}
|
||||||
ui->label_ModDescription->setToolTip("");
|
ui->descriptionLabel->setToolTip("");
|
||||||
QString intermediatetext = text.trimmed();
|
QString intermediatetext = text.trimmed();
|
||||||
bool prev(false);
|
bool prev(false);
|
||||||
QChar rem('\n');
|
QChar rem('\n');
|
||||||
@ -133,36 +137,36 @@ void MCModInfoFrame::setModDescription(QString text)
|
|||||||
labeltext.reserve(300);
|
labeltext.reserve(300);
|
||||||
if(finaltext.length() > 290)
|
if(finaltext.length() > 290)
|
||||||
{
|
{
|
||||||
ui->label_ModDescription->setOpenExternalLinks(false);
|
ui->descriptionLabel->setOpenExternalLinks(false);
|
||||||
ui->label_ModDescription->setTextFormat(Qt::TextFormat::RichText);
|
ui->descriptionLabel->setTextFormat(Qt::TextFormat::RichText);
|
||||||
desc = text;
|
m_description = text;
|
||||||
// This allows injecting HTML here.
|
// This allows injecting HTML here.
|
||||||
labeltext.append("<html><body>" + finaltext.left(287) + "<a href=\"#mod_desc\">...</a></body></html>");
|
labeltext.append("<html><body>" + finaltext.left(287) + "<a href=\"#mod_desc\">...</a></body></html>");
|
||||||
QObject::connect(ui->label_ModDescription, &QLabel::linkActivated, this, &MCModInfoFrame::modDescEllipsisHandler);
|
QObject::connect(ui->descriptionLabel, &QLabel::linkActivated, this, &InfoFrame::descriptionEllipsisHandler);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->label_ModDescription->setTextFormat(Qt::TextFormat::PlainText);
|
ui->descriptionLabel->setTextFormat(Qt::TextFormat::PlainText);
|
||||||
labeltext.append(finaltext);
|
labeltext.append(finaltext);
|
||||||
}
|
}
|
||||||
ui->label_ModDescription->setText(labeltext);
|
ui->descriptionLabel->setText(labeltext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCModInfoFrame::modDescEllipsisHandler(const QString &link)
|
void InfoFrame::descriptionEllipsisHandler(QString link)
|
||||||
{
|
{
|
||||||
if(!currentBox)
|
if(!m_current_box)
|
||||||
{
|
{
|
||||||
currentBox = CustomMessageBox::selectable(this, QString(), desc);
|
m_current_box = CustomMessageBox::selectable(this, "", m_description);
|
||||||
connect(currentBox, &QMessageBox::finished, this, &MCModInfoFrame::boxClosed);
|
connect(m_current_box, &QMessageBox::finished, this, &InfoFrame::boxClosed);
|
||||||
currentBox->show();
|
m_current_box->show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentBox->setText(desc);
|
m_current_box->setText(m_description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCModInfoFrame::boxClosed(int result)
|
void InfoFrame::boxClosed(int result)
|
||||||
{
|
{
|
||||||
currentBox = nullptr;
|
m_current_box = nullptr;
|
||||||
}
|
}
|
@ -16,37 +16,39 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
|
||||||
#include "minecraft/mod/Mod.h"
|
#include "minecraft/mod/Mod.h"
|
||||||
|
#include "minecraft/mod/ResourcePack.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class MCModInfoFrame;
|
class InfoFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MCModInfoFrame : public QFrame
|
class InfoFrame : public QFrame {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MCModInfoFrame(QWidget *parent = 0);
|
InfoFrame(QWidget* parent = nullptr);
|
||||||
~MCModInfoFrame();
|
~InfoFrame() override;
|
||||||
|
|
||||||
void setModText(QString text);
|
void setName(QString text = {});
|
||||||
void setModDescription(QString text);
|
void setDescription(QString text = {});
|
||||||
|
|
||||||
void updateWithMod(Mod &m);
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
void updateWithMod(Mod const& m);
|
||||||
|
void updateWithResource(Resource const& resource);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void modDescEllipsisHandler(const QString& link );
|
void descriptionEllipsisHandler(QString link);
|
||||||
void boxClosed(int result);
|
void boxClosed(int result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateHiddenState();
|
void updateHiddenState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MCModInfoFrame *ui;
|
Ui::InfoFrame* ui;
|
||||||
QString desc;
|
QString m_description;
|
||||||
class QMessageBox * currentBox = nullptr;
|
class QMessageBox* m_current_box = nullptr;
|
||||||
};
|
};
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>MCModInfoFrame</class>
|
<class>InfoFrame</class>
|
||||||
<widget class="QFrame" name="MCModInfoFrame">
|
<widget class="QFrame" name="InfoFrame">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
@ -39,7 +39,7 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_ModText">
|
<widget class="QLabel" name="nameLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
||||||
@ -61,7 +61,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_ModDescription">
|
<widget class="QLabel" name="descriptionLabel">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
Loading…
Reference in New Issue
Block a user