NOISSUE Add world icons and world icon reset button
This commit is contained in:
@ -31,6 +31,33 @@
|
||||
#include <QProcess>
|
||||
#include <FileSystem.h>
|
||||
|
||||
class WorldListProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WorldListProxyModel(QObject *parent) : QSortFilterProxyModel(parent) {}
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
|
||||
{
|
||||
QModelIndex sourceIndex = mapToSource(index);
|
||||
|
||||
if (index.column() == 0 && role == Qt::DecorationRole)
|
||||
{
|
||||
WorldList *worlds = qobject_cast<WorldList *>(sourceModel());
|
||||
auto iconFile = worlds->data(sourceIndex, WorldList::IconFileRole).toString();
|
||||
if(iconFile.isNull()) {
|
||||
// NOTE: Minecraft uses the same placeholder for servers AND worlds
|
||||
return MMC->getThemedIcon("unknown_server");
|
||||
}
|
||||
return QIcon(iconFile);
|
||||
}
|
||||
|
||||
return sourceIndex.data(role);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QWidget *parent)
|
||||
: QMainWindow(parent), m_inst(inst), ui(new Ui::WorldListPage), m_worlds(worlds)
|
||||
{
|
||||
@ -38,13 +65,14 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worl
|
||||
|
||||
ui->toolBar->insertSpacer(ui->actionRefresh);
|
||||
|
||||
QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this);
|
||||
WorldListProxyModel * proxy = new WorldListProxyModel(this);
|
||||
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
proxy->setSourceModel(m_worlds.get());
|
||||
ui->worldTreeView->setSortingEnabled(true);
|
||||
ui->worldTreeView->setModel(proxy);
|
||||
ui->worldTreeView->installEventFilter(this);
|
||||
ui->worldTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
ui->worldTreeView->setIconSize(QSize(64,64));
|
||||
connect(ui->worldTreeView, &QTreeView::customContextMenuRequested, this, &WorldListPage::ShowContextMenu);
|
||||
|
||||
auto head = ui->worldTreeView->header();
|
||||
@ -142,6 +170,19 @@ void WorldListPage::on_actionView_Folder_triggered()
|
||||
DesktopServices::openDirectory(m_worlds->dir().absolutePath(), true);
|
||||
}
|
||||
|
||||
void WorldListPage::on_actionReset_Icon_triggered()
|
||||
{
|
||||
auto proxiedIndex = getSelectedWorld();
|
||||
|
||||
if(!proxiedIndex.isValid())
|
||||
return;
|
||||
|
||||
if(m_worlds->resetIcon(proxiedIndex.row())) {
|
||||
ui->actionReset_Icon->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QModelIndex WorldListPage::getSelectedWorld()
|
||||
{
|
||||
auto index = ui->worldTreeView->selectionModel()->currentIndex();
|
||||
@ -255,6 +296,8 @@ void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex &
|
||||
ui->actionRemove->setEnabled(enable);
|
||||
ui->actionCopy->setEnabled(enable);
|
||||
ui->actionRename->setEnabled(enable);
|
||||
bool hasIcon = !index.data(WorldList::IconFileRole).isNull();
|
||||
ui->actionReset_Icon->setEnabled(enable && hasIcon);
|
||||
}
|
||||
|
||||
void WorldListPage::on_actionAdd_triggered()
|
||||
@ -342,3 +385,5 @@ void WorldListPage::on_actionRefresh_triggered()
|
||||
{
|
||||
m_worlds->update();
|
||||
}
|
||||
|
||||
#include "WorldListPage.moc"
|
||||
|
@ -90,6 +90,7 @@ private slots:
|
||||
void on_actionRename_triggered();
|
||||
void on_actionRefresh_triggered();
|
||||
void on_actionView_Folder_triggered();
|
||||
void on_actionReset_Icon_triggered();
|
||||
void worldChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void mceditState(LoggedProcess::State state);
|
||||
|
||||
|
@ -41,6 +41,12 @@
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -79,6 +85,7 @@
|
||||
<addaction name="actionCopy"/>
|
||||
<addaction name="actionRemove"/>
|
||||
<addaction name="actionMCEdit"/>
|
||||
<addaction name="actionReset_Icon"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionCopy_Seed"/>
|
||||
<addaction name="actionRefresh"/>
|
||||
@ -124,6 +131,14 @@
|
||||
<string>View Folder</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionReset_Icon">
|
||||
<property name="text">
|
||||
<string>Reset Icon</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Remove world icon to make the game re-generate it on next load.</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
Reference in New Issue
Block a user