Add close button to page dialog. Add help button to page dialog.

Smile.
This commit is contained in:
Petr Mrázek 2014-06-10 00:46:05 +02:00
parent 0bccc94471
commit 9ec6deea84
15 changed files with 66 additions and 90 deletions

View File

@ -18,6 +18,7 @@
#include <QStackedLayout> #include <QStackedLayout>
#include <QPushButton> #include <QPushButton>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QUrl>
#include "MultiMC.h" #include "MultiMC.h"
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QListView> #include <QListView>
@ -25,6 +26,7 @@
#include <QLabel> #include <QLabel>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QGridLayout> #include <QGridLayout>
#include <QDesktopServices>
#include <settingsobject.h> #include <settingsobject.h>
#include "PageDialog_p.h" #include "PageDialog_p.h"
@ -127,38 +129,36 @@ void PageDialog::createUI()
m_pageStack->setMargin(0); m_pageStack->setMargin(0);
m_pageStack->addWidget(new QWidget(this)); m_pageStack->addWidget(new QWidget(this));
/*
QDialogButtonBox *buttons = QDialogButtonBox *buttons =
new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close);
QDialogButtonBox::Apply | QDialogButtonBox::Cancel); buttons->button(QDialogButtonBox::Close)->setDefault(true);
buttons->button(QDialogButtonBox::Ok)->setDefault(true); connect(buttons->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(close()));
connect(buttons->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply())); connect(buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), this, SLOT(help()));
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
*/
QGridLayout *mainGridLayout = new QGridLayout; QGridLayout *mainGridLayout = new QGridLayout;
mainGridLayout->addLayout(headerHLayout, 0, 1, 1, 1); mainGridLayout->addLayout(headerHLayout, 0, 1, 1, 1);
mainGridLayout->addWidget(m_pageList, 0, 0, 2, 1); mainGridLayout->addWidget(m_pageList, 0, 0, 2, 1);
mainGridLayout->addLayout(m_pageStack, 1, 1, 1, 1); mainGridLayout->addLayout(m_pageStack, 1, 1, 1, 1);
//mainGridLayout->addWidget(buttons, 2, 0, 1, 2); mainGridLayout->addWidget(buttons, 2, 0, 1, 2);
mainGridLayout->setColumnStretch(1, 4); mainGridLayout->setColumnStretch(1, 4);
setLayout(mainGridLayout); setLayout(mainGridLayout);
} }
void PageDialog::showPage(int row) void PageDialog::showPage(int row)
{ {
auto page = m_model->pages().at(row); if(row != -1)
m_pageStack->setCurrentIndex(page->stackIndex);
m_header->setText(page->displayName());
m_iconHeader->setIcon(page->icon());
}
void PageDialog::currentChanged(const QModelIndex &current)
{
if (current.isValid())
{ {
showPage(m_proxyModel->mapToSource(current).row()); m_currentPage = m_model->pages().at(row);
}
else
{
m_currentPage = nullptr;
}
if(m_currentPage)
{
m_pageStack->setCurrentIndex(m_currentPage->stackIndex);
m_header->setText(m_currentPage->displayName());
m_iconHeader->setIcon(m_currentPage->icon());
} }
else else
{ {
@ -168,45 +168,32 @@ void PageDialog::currentChanged(const QModelIndex &current)
} }
} }
void PageDialog::accept() void PageDialog::help()
{
if(m_currentPage)
{
QString pageId = m_currentPage->helpPage();
if(pageId.isEmpty())
return;
QDesktopServices::openUrl(QUrl("https://github.com/MultiMC/MultiMC5/wiki/" + pageId));
}
}
void PageDialog::currentChanged(const QModelIndex &current)
{
showPage(current.isValid() ? m_proxyModel->mapToSource(current).row() : -1);
}
void PageDialog::closeEvent(QCloseEvent * event)
{ {
bool accepted = true; bool accepted = true;
for(auto page: m_model->pages()) for(auto page: m_model->pages())
{ {
accepted &= page->accept(); accepted &= page->apply();
} }
if(accepted) if(accepted)
{ {
MMC->settings()->set("PagedGeometry", saveGeometry().toBase64());
QDialog::accept();
}
}
void PageDialog::reject()
{
bool rejected = true;
for(auto page: m_model->pages())
{
rejected &= page->reject();
}
if(rejected)
{
MMC->settings()->set("PagedGeometry", saveGeometry().toBase64());
QDialog::reject();
}
}
void PageDialog::apply()
{
for(auto page: m_model->pages())
{
page->apply();
}
}
void PageDialog::closeEvent(QCloseEvent * event)
{
MMC->settings()->set("PagedGeometry", saveGeometry().toBase64()); MMC->settings()->set("PagedGeometry", saveGeometry().toBase64());
QDialog::closeEvent(event); QDialog::closeEvent(event);
}
} }

View File

@ -38,14 +38,14 @@ private:
void createUI(); void createUI();
private private
slots: slots:
void apply();
virtual void reject();
virtual void accept();
void currentChanged(const QModelIndex &current); void currentChanged(const QModelIndex &current);
void showPage(int row); void showPage(int row);
void help();
virtual void closeEvent(QCloseEvent *event); virtual void closeEvent(QCloseEvent *event);
private: private:
BasePage * m_currentPage;
QSortFilterProxyModel *m_proxyModel; QSortFilterProxyModel *m_proxyModel;
PageModel *m_model; PageModel *m_model;
QStackedLayout *m_pageStack; QStackedLayout *m_pageStack;

View File

@ -25,14 +25,6 @@ public:
virtual QString id() = 0; virtual QString id() = 0;
virtual QString displayName() = 0; virtual QString displayName() = 0;
virtual QIcon icon() = 0; virtual QIcon icon() = 0;
virtual bool accept()
{
return true;
}
virtual bool reject()
{
return true;
}
virtual bool apply() virtual bool apply()
{ {
return true; return true;
@ -41,6 +33,10 @@ public:
{ {
return true; return true;
} }
virtual QString helpPage()
{
return QString();
}
int stackIndex = -1; int stackIndex = -1;
int listIndex = -1; int listIndex = -1;
}; };

View File

@ -28,10 +28,6 @@ InstanceSettingsPage::InstanceSettingsPage(SettingsObject *s, QWidget *parent)
{ {
ui->setupUi(this); ui->setupUi(this);
loadSettings(); loadSettings();
connect(ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked(bool)), this,
SLOT(applySettings()));
connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked(bool)), this,
SLOT(loadSettings()));
} }
InstanceSettingsPage::~InstanceSettingsPage() InstanceSettingsPage::~InstanceSettingsPage()
@ -42,7 +38,6 @@ InstanceSettingsPage::~InstanceSettingsPage()
bool InstanceSettingsPage::apply() bool InstanceSettingsPage::apply()
{ {
applySettings(); applySettings();
loadSettings();
return true; return true;
} }

View File

@ -38,7 +38,7 @@ public:
virtual QIcon icon() override; virtual QIcon icon() override;
virtual QString id() override; virtual QString id() override;
virtual bool apply(); virtual bool apply();
virtual QString helpPage() override { return "InstanceSettingsPage"; };
private: private:
void updateCheckboxStuff(); void updateCheckboxStuff();
private slots: private slots:

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>458</width> <width>458</width>
<height>476</height> <height>426</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -425,16 +425,6 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Reset</set>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -37,6 +37,7 @@ public:
virtual QString displayName(); virtual QString displayName();
virtual QIcon icon(); virtual QIcon icon();
virtual QString id(); virtual QString id();
virtual QString helpPage() override { return "LegacyJarModPage"; };
private private
slots: slots:

View File

@ -36,6 +36,7 @@ public:
virtual QString displayName() override; virtual QString displayName() override;
virtual QIcon icon() override; virtual QIcon icon() override;
virtual QString id() override; virtual QString id() override;
virtual QString helpPage() override { return "LegacyUpgradePage"; };
private private
slots: slots:
void on_upgradeButton_clicked(); void on_upgradeButton_clicked();

View File

@ -49,7 +49,7 @@ QString ModFolderPage::id()
} }
ModFolderPage::ModFolderPage(std::shared_ptr<ModList> mods, QString id, QString iconName, ModFolderPage::ModFolderPage(std::shared_ptr<ModList> mods, QString id, QString iconName,
QString displayName, QWidget *parent) QString displayName, QString helpPage, QWidget *parent)
: QWidget(parent), ui(new Ui::ModFolderPage) : QWidget(parent), ui(new Ui::ModFolderPage)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -57,6 +57,7 @@ ModFolderPage::ModFolderPage(std::shared_ptr<ModList> mods, QString id, QString
m_id = id; m_id = id;
m_displayName = displayName; m_displayName = displayName;
m_iconName = iconName; m_iconName = iconName;
m_helpName = helpPage;
ui->modTreeView->setModel(m_mods.get()); ui->modTreeView->setModel(m_mods.get());
ui->modTreeView->installEventFilter(this); ui->modTreeView->installEventFilter(this);
m_mods->startWatching(); m_mods->startWatching();

View File

@ -33,12 +33,12 @@ class ModFolderPage : public QWidget, public BasePage
public: public:
explicit ModFolderPage(std::shared_ptr<ModList> mods, QString id, QString iconName, explicit ModFolderPage(std::shared_ptr<ModList> mods, QString id, QString iconName,
QString displayName, QWidget *parent = 0); QString displayName, QString helpPage = "" , QWidget *parent = 0);
virtual ~ModFolderPage(); virtual ~ModFolderPage();
virtual QString displayName() override; virtual QString displayName() override;
virtual QIcon icon() override; virtual QIcon icon() override;
virtual QString id() override; virtual QString id() override;
virtual QString helpPage() override { return m_helpName; };
protected: protected:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
bool modListFilter(QKeyEvent *ev); bool modListFilter(QKeyEvent *ev);
@ -49,6 +49,7 @@ private:
QString m_iconName; QString m_iconName;
QString m_id; QString m_id;
QString m_displayName; QString m_displayName;
QString m_helpName;
public slots: public slots:
void modCurrent(const QModelIndex &current, const QModelIndex &previous); void modCurrent(const QModelIndex &current, const QModelIndex &previous);

View File

@ -6,7 +6,7 @@ class ResourcePackPage : public ModFolderPage
public: public:
explicit ResourcePackPage(BaseInstance *instance, QWidget *parent = 0) explicit ResourcePackPage(BaseInstance *instance, QWidget *parent = 0)
: ModFolderPage(instance->texturePackList(), "resourcepacks", "resourcepacks", : ModFolderPage(instance->texturePackList(), "resourcepacks", "resourcepacks",
tr("Resource packs"), parent) tr("Resource packs"), "TexturePacksPage", parent)
{ {
m_inst = instance; m_inst = instance;
} }
@ -17,7 +17,6 @@ public:
return !m_inst->traits().contains("no-texturepacks") && return !m_inst->traits().contains("no-texturepacks") &&
!m_inst->traits().contains("texturepacks"); !m_inst->traits().contains("texturepacks");
} }
private: private:
BaseInstance *m_inst; BaseInstance *m_inst;
}; };

View File

@ -6,7 +6,7 @@ class TexturePackPage : public ModFolderPage
public: public:
explicit TexturePackPage(BaseInstance *instance, QWidget *parent = 0) explicit TexturePackPage(BaseInstance *instance, QWidget *parent = 0)
: ModFolderPage(instance->texturePackList(), "texturepacks", "resourcepacks", : ModFolderPage(instance->texturePackList(), "texturepacks", "resourcepacks",
tr("Texture packs"), parent) tr("Texture packs"), "ResourcePacksPage", parent)
{ {
m_inst = instance; m_inst = instance;
} }

View File

@ -36,6 +36,7 @@ public:
virtual QString displayName() override; virtual QString displayName() override;
virtual QIcon icon() override; virtual QIcon icon() override;
virtual QString id() override; virtual QString id() override;
virtual QString helpPage() override { return "VersionPage"; };
private private
slots: slots:

View File

@ -50,8 +50,10 @@ QList<BasePage *> LegacyInstance::getPages()
QList<BasePage *> values; QList<BasePage *> values;
values.append(new LegacyUpgradePage(this)); values.append(new LegacyUpgradePage(this));
values.append(new LegacyJarModPage(this)); values.append(new LegacyJarModPage(this));
values.append(new ModFolderPage(loaderModList(), "mods", "plugin-blue", tr("Loader Mods"))); values.append(new ModFolderPage(loaderModList(), "mods", "plugin-blue", tr("Loader Mods"),
values.append(new ModFolderPage(coreModList(), "coremods", "plugin-green", tr("Core Mods"))); "LoaderModsPage"));
values.append(new ModFolderPage(coreModList(), "coremods", "plugin-green", tr("Core Mods"),
"CoreModsPage"));
values.append(new TexturePackPage(this)); values.append(new TexturePackPage(this));
values.append(new InstanceSettingsPage(&settings())); values.append(new InstanceSettingsPage(&settings()));
return values; return values;
@ -70,7 +72,7 @@ std::shared_ptr<Task> LegacyInstance::doUpdate()
return std::shared_ptr<Task>(new LegacyUpdate(this, this)); return std::shared_ptr<Task>(new LegacyUpdate(this, this));
} }
bool LegacyInstance::prepareForLaunch(AuthSessionPtr account, QString & launchScript) bool LegacyInstance::prepareForLaunch(AuthSessionPtr account, QString &launchScript)
{ {
QIcon icon = MMC->icons()->getIcon(iconKey()); QIcon icon = MMC->icons()->getIcon(iconKey());
auto pixmap = icon.pixmap(128, 128); auto pixmap = icon.pixmap(128, 128);

View File

@ -61,8 +61,10 @@ QList<BasePage *> OneSixInstance::getPages()
{ {
QList<BasePage *> values; QList<BasePage *> values;
values.append(new VersionPage(this)); values.append(new VersionPage(this));
values.append(new ModFolderPage(loaderModList(), "mods", "plugin-blue", tr("Loader Mods"))); values.append(new ModFolderPage(loaderModList(), "mods", "plugin-blue", tr("Loader Mods"),
values.append(new ModFolderPage(coreModList(), "coremods", "plugin-green", tr("Core Mods"))); "LoaderModsPage"));
values.append(new ModFolderPage(coreModList(), "coremods", "plugin-green", tr("Core Mods"),
"CoreModsPage"));
values.append(new ResourcePackPage(this)); values.append(new ResourcePackPage(this));
values.append(new TexturePackPage(this)); values.append(new TexturePackPage(this));
values.append(new InstanceSettingsPage(&settings())); values.append(new InstanceSettingsPage(&settings()));