summaryrefslogtreecommitdiffstats
path: root/application/pages
diff options
context:
space:
mode:
Diffstat (limited to 'application/pages')
-rw-r--r--application/pages/WorldListPage.cpp94
-rw-r--r--application/pages/WorldListPage.h69
-rw-r--r--application/pages/WorldListPage.ui94
3 files changed, 257 insertions, 0 deletions
diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp
new file mode 100644
index 00000000..662b7452
--- /dev/null
+++ b/application/pages/WorldListPage.cpp
@@ -0,0 +1,94 @@
+//
+// Created by robotbrain on 8/18/15.
+//
+
+#include "WorldListPage.h"
+#include "ui_WorldListPage.h"
+#include "minecraft/WorldList.h"
+#include "dialogs/ModEditDialogCommon.h"
+#include <QEvent>
+#include <QKeyEvent>
+
+WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
+ QString iconName, QString displayName, QString helpPage,
+ QWidget *parent)
+ : QWidget(parent), ui(new Ui::WorldListPage)
+{
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
+ m_inst = inst;
+ m_worlds = worlds;
+ m_id = id;
+ m_displayName = displayName;
+ m_iconName = iconName;
+ m_helpName = helpPage;
+ ui->worldTreeView->setModel(m_worlds.get());
+ ui->worldTreeView->installEventFilter(this);
+ auto smodel = ui->worldTreeView->selectionModel();
+ connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ SLOT(modCurrent(QModelIndex, QModelIndex)));
+}
+
+void WorldListPage::opened()
+{
+ m_worlds->startWatching();
+}
+
+void WorldListPage::closed()
+{
+ m_worlds->stopWatching();
+}
+
+WorldListPage::~WorldListPage()
+{
+ m_worlds->stopWatching();
+ delete ui;
+}
+
+bool WorldListPage::shouldDisplay() const
+{
+ if (m_inst)
+ return !m_inst->isRunning();
+ return true;
+}
+
+bool WorldListPage::worldListFilter(QKeyEvent *keyEvent)
+{
+ switch (keyEvent->key())
+ {
+ case Qt::Key_Delete:
+ on_rmWorldBtn_clicked();
+ return true;
+ default:
+ break;
+ }
+ return QWidget::eventFilter(ui->worldTreeView, keyEvent);
+}
+
+bool WorldListPage::eventFilter(QObject *obj, QEvent *ev)
+{
+ if (ev->type() != QEvent::KeyPress)
+ {
+ return QWidget::eventFilter(obj, ev);
+ }
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
+ if (obj == ui->worldTreeView)
+ return worldListFilter(keyEvent);
+ return QWidget::eventFilter(obj, ev);
+}
+void WorldListPage::on_rmWorldBtn_clicked()
+{
+ int first, last;
+ auto list = ui->worldTreeView->selectionModel()->selectedRows();
+
+ if (!lastfirst(list, first, last))
+ return;
+ m_worlds->stopWatching();
+ m_worlds->deleteWorlds(first, last);
+ m_worlds->startWatching();
+}
+
+void WorldListPage::on_viewFolderBtn_clicked()
+{
+ openDirInDefaultProgram(m_worlds->dir().absolutePath(), true);
+}
diff --git a/application/pages/WorldListPage.h b/application/pages/WorldListPage.h
new file mode 100644
index 00000000..f55f2999
--- /dev/null
+++ b/application/pages/WorldListPage.h
@@ -0,0 +1,69 @@
+//
+// Created by robotbrain on 8/18/15.
+//
+
+#pragma once
+
+#include <QWidget>
+
+#include "minecraft/OneSixInstance.h"
+#include "BasePage.h"
+#include <MultiMC.h>
+#include <pathutils.h>
+
+class WorldList;
+namespace Ui
+{
+class WorldListPage;
+}
+
+class WorldListPage : public QWidget, public BasePage
+{
+ Q_OBJECT
+
+public:
+ explicit WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
+ QString iconName, QString displayName, QString helpPage = "",
+ QWidget *parent = 0);
+ virtual ~WorldListPage();
+
+ virtual QString displayName() const override
+ {
+ return m_displayName;
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon(m_iconName);
+ }
+ virtual QString id() const override
+ {
+ return m_id;
+ }
+ virtual QString helpPage() const override
+ {
+ return m_helpName;
+ }
+ virtual bool shouldDisplay() const;
+
+ virtual void opened();
+ virtual void closed();
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *ev);
+ bool worldListFilter(QKeyEvent *ev);
+
+protected:
+ BaseInstance *m_inst;
+
+private:
+ Ui::WorldListPage *ui;
+ std::shared_ptr<WorldList> m_worlds;
+ QString m_iconName;
+ QString m_id;
+ QString m_displayName;
+ QString m_helpName;
+
+private slots:
+ void on_rmWorldBtn_clicked();
+ void on_viewFolderBtn_clicked();
+};
diff --git a/application/pages/WorldListPage.ui b/application/pages/WorldListPage.ui
new file mode 100644
index 00000000..b8100acd
--- /dev/null
+++ b/application/pages/WorldListPage.ui
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WorldListPage</class>
+ <widget class="QWidget" name="WorldListPage">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>723</width>
+ <height>532</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Mods</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Tab 1</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QTreeView" name="worldTreeView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::DropOnly</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QPushButton" name="rmWorldBtn">
+ <property name="text">
+ <string>&amp;Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="viewFolderBtn">
+ <property name="text">
+ <string>&amp;View Folder</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>