pollymc/launcher/ui/pages/instance/ExternalResourcesPage.h
flow d394235ee0
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.

Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.

This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-06-14 07:04:31 -03:00

74 lines
2.0 KiB
C++

#pragma once
#include <QMainWindow>
#include <QSortFilterProxyModel>
#include "Application.h"
#include "minecraft/MinecraftInstance.h"
#include "ui/pages/BasePage.h"
class ModFolderModel;
namespace Ui {
class ExternalResourcesPage;
}
/* This page is used as a base for pages in which the user can manage external resources
* related to the game, such as mods, shaders or resource packs. */
class ExternalResourcesPage : public QMainWindow, public BasePage {
Q_OBJECT
public:
// FIXME: Switch to different model (or change the name of this one)
explicit ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ModFolderModel> model, QWidget* parent = nullptr);
virtual ~ExternalResourcesPage();
virtual QString displayName() const override = 0;
virtual QIcon icon() const override = 0;
virtual QString id() const override = 0;
virtual QString helpPage() const override = 0;
virtual bool shouldDisplay() const override = 0;
void openedImpl() override;
void closedImpl() override;
void retranslate() override;
protected:
bool eventFilter(QObject* obj, QEvent* ev) override;
bool listFilter(QKeyEvent* ev);
QMenu* createPopupMenu() override;
public slots:
void current(const QModelIndex& current, const QModelIndex& previous);
protected slots:
void itemActivated(const QModelIndex& index);
void filterTextChanged(const QString& newContents);
void runningStateChanged(bool running);
virtual void addItem();
virtual void removeItem();
virtual void enableItem();
virtual void disableItem();
virtual void viewFolder();
virtual void viewConfigs();
void ShowContextMenu(const QPoint& pos);
protected:
BaseInstance* m_instance = nullptr;
Ui::ExternalResourcesPage* ui = nullptr;
std::shared_ptr<ModFolderModel> m_model;
QSortFilterProxyModel* m_filterModel = nullptr;
QString m_fileSelectionFilter;
QString m_viewFilter;
bool m_controlsEnabled = true;
};