pollymc/launcher/ui/pages/instance/ExternalResourcesPage.h
flow 97a74d5c1f
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>
2022-08-20 10:47:58 -03:00

75 lines
2.0 KiB
C++

#pragma once
#include <QMainWindow>
#include <QSortFilterProxyModel>
#include "Application.h"
#include "minecraft/MinecraftInstance.h"
#include "ui/pages/BasePage.h"
class ResourceFolderModel;
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:
explicit ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> 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:
bool current(const QModelIndex& current, const QModelIndex& previous);
virtual bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous);
protected slots:
virtual void itemActivated(const QModelIndex& index) {};
void filterTextChanged(const QString& newContents);
virtual 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<ResourceFolderModel> m_model;
QSortFilterProxyModel* m_filterModel = nullptr;
QString m_fileSelectionFilter;
QString m_viewFilter;
bool m_controlsEnabled = true;
};