summaryrefslogtreecommitdiffstats
path: root/application/pages/instance/WorldListPage.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-07-17 02:01:29 +0200
committerPetr Mrázek <peterix@gmail.com>2019-07-17 02:01:29 +0200
commit95febe543615c16d5b97cdd6f379c9a62102321d (patch)
tree60c3cf31de93e0be96e28c85297e3440b1325e4c /application/pages/instance/WorldListPage.cpp
parent5b153a516566446b88cca73afac34f9abfdd82e2 (diff)
downloadMultiMC-95febe543615c16d5b97cdd6f379c9a62102321d.tar
MultiMC-95febe543615c16d5b97cdd6f379c9a62102321d.tar.gz
MultiMC-95febe543615c16d5b97cdd6f379c9a62102321d.tar.lz
MultiMC-95febe543615c16d5b97cdd6f379c9a62102321d.tar.xz
MultiMC-95febe543615c16d5b97cdd6f379c9a62102321d.zip
NOISSUE convert rest of the instance pages to use toolbars for side menus
Diffstat (limited to 'application/pages/instance/WorldListPage.cpp')
-rw-r--r--application/pages/instance/WorldListPage.cpp57
1 files changed, 33 insertions, 24 deletions
diff --git a/application/pages/instance/WorldListPage.cpp b/application/pages/instance/WorldListPage.cpp
index be72af22..bd559991 100644
--- a/application/pages/instance/WorldListPage.cpp
+++ b/application/pages/instance/WorldListPage.cpp
@@ -19,6 +19,7 @@
#include <DesktopServices.h>
#include "dialogs/ModEditDialogCommon.h"
#include <QEvent>
+#include <QMenu>
#include <QKeyEvent>
#include <QClipboard>
#include <QMessageBox>
@@ -31,13 +32,16 @@
#include <QProcess>
#include <FileSystem.h>
-WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
- QString iconName, QString displayName, QString helpPage,
- QWidget *parent)
- : QWidget(parent), m_inst(inst), ui(new Ui::WorldListPage), m_worlds(worlds), m_iconName(iconName), m_id(id), m_displayName(displayName), m_helpName(helpPage)
+WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QWidget *parent)
+ : QMainWindow(parent), m_inst(inst), ui(new Ui::WorldListPage), m_worlds(worlds)
{
ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
+
+ QWidget* spacer = new QWidget();
+ spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ // toolBar is a pointer to an existing toolbar
+ ui->toolBar->insertWidget(ui->actionRefresh, spacer);
+
QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this);
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
proxy->setSourceModel(m_worlds.get());
@@ -46,12 +50,10 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worl
ui->worldTreeView->installEventFilter(this);
auto head = ui->worldTreeView->header();
-
head->setSectionResizeMode(0, QHeaderView::Stretch);
head->setSectionResizeMode(1, QHeaderView::ResizeToContents);
- connect(ui->worldTreeView->selectionModel(),
- SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this,
- SLOT(worldChanged(const QModelIndex &, const QModelIndex &)));
+
+ connect(ui->worldTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WorldListPage::worldChanged);
worldChanged(QModelIndex(), QModelIndex());
}
@@ -71,6 +73,13 @@ WorldListPage::~WorldListPage()
delete ui;
}
+QMenu * WorldListPage::createPopupMenu()
+{
+ QMenu* filteredMenu = QMainWindow::createPopupMenu();
+ filteredMenu->removeAction( ui->toolBar->toggleViewAction() );
+ return filteredMenu;
+}
+
bool WorldListPage::shouldDisplay() const
{
return true;
@@ -81,7 +90,7 @@ bool WorldListPage::worldListFilter(QKeyEvent *keyEvent)
switch (keyEvent->key())
{
case Qt::Key_Delete:
- on_rmWorldBtn_clicked();
+ on_actionRemove_triggered();
return true;
default:
break;
@@ -101,7 +110,7 @@ bool WorldListPage::eventFilter(QObject *obj, QEvent *ev)
return QWidget::eventFilter(obj, ev);
}
-void WorldListPage::on_rmWorldBtn_clicked()
+void WorldListPage::on_actionRemove_triggered()
{
auto proxiedIndex = getSelectedWorld();
@@ -123,7 +132,7 @@ void WorldListPage::on_rmWorldBtn_clicked()
m_worlds->startWatching();
}
-void WorldListPage::on_viewFolderBtn_clicked()
+void WorldListPage::on_actionView_Folder_triggered()
{
DesktopServices::openDirectory(m_worlds->dir().absolutePath(), true);
}
@@ -136,7 +145,7 @@ QModelIndex WorldListPage::getSelectedWorld()
return proxy->mapToSource(index);
}
-void WorldListPage::on_copySeedBtn_clicked()
+void WorldListPage::on_actionCopy_Seed_triggered()
{
QModelIndex index = getSelectedWorld();
@@ -148,7 +157,7 @@ void WorldListPage::on_copySeedBtn_clicked()
MMC->clipboard()->setText(QString::number(seed));
}
-void WorldListPage::on_mcEditBtn_clicked()
+void WorldListPage::on_actionMCEdit_triggered()
{
if(m_mceditStarting)
return;
@@ -236,17 +245,17 @@ void WorldListPage::worldChanged(const QModelIndex &current, const QModelIndex &
{
QModelIndex index = getSelectedWorld();
bool enable = index.isValid();
- ui->copySeedBtn->setEnabled(enable);
- ui->mcEditBtn->setEnabled(enable);
- ui->rmWorldBtn->setEnabled(enable);
- ui->copyBtn->setEnabled(enable);
- ui->renameBtn->setEnabled(enable);
+ ui->actionCopy_Seed->setEnabled(enable);
+ ui->actionMCEdit->setEnabled(enable);
+ ui->actionRemove->setEnabled(enable);
+ ui->actionCopy->setEnabled(enable);
+ ui->actionRename->setEnabled(enable);
}
-void WorldListPage::on_addBtn_clicked()
+void WorldListPage::on_actionAdd_triggered()
{
auto list = GuiUtil::BrowseForFiles(
- m_helpName,
+ displayName(),
tr("Select a Minecraft world zip"),
tr("Minecraft World Zip File (*.zip)"), QString(), this->parentWidget());
if (!list.empty())
@@ -279,7 +288,7 @@ bool WorldListPage::worldSafetyNagQuestion()
}
-void WorldListPage::on_copyBtn_clicked()
+void WorldListPage::on_actionCopy_triggered()
{
QModelIndex index = getSelectedWorld();
if (!index.isValid())
@@ -301,7 +310,7 @@ void WorldListPage::on_copyBtn_clicked()
}
}
-void WorldListPage::on_renameBtn_clicked()
+void WorldListPage::on_actionRename_triggered()
{
QModelIndex index = getSelectedWorld();
if (!index.isValid())
@@ -324,7 +333,7 @@ void WorldListPage::on_renameBtn_clicked()
}
}
-void WorldListPage::on_refreshBtn_clicked()
+void WorldListPage::on_actionRefresh_triggered()
{
m_worlds->update();
}