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 <QPushButton>
#include <QSortFilterProxyModel>
#include <QUrl>
#include "MultiMC.h"
#include <QStyledItemDelegate>
#include <QListView>
@ -25,6 +26,7 @@
#include <QLabel>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QDesktopServices>
#include <settingsobject.h>
#include "PageDialog_p.h"
@ -127,38 +129,36 @@ void PageDialog::createUI()
m_pageStack->setMargin(0);
m_pageStack->addWidget(new QWidget(this));
/*
QDialogButtonBox *buttons =
new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok |
QDialogButtonBox::Apply | QDialogButtonBox::Cancel);
buttons->button(QDialogButtonBox::Ok)->setDefault(true);
connect(buttons->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
*/
new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close);
buttons->button(QDialogButtonBox::Close)->setDefault(true);
connect(buttons->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(close()));
connect(buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), this, SLOT(help()));
QGridLayout *mainGridLayout = new QGridLayout;
mainGridLayout->addLayout(headerHLayout, 0, 1, 1, 1);
mainGridLayout->addWidget(m_pageList, 0, 0, 2, 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);
setLayout(mainGridLayout);
}
void PageDialog::showPage(int row)
{
auto page = m_model->pages().at(row);
m_pageStack->setCurrentIndex(page->stackIndex);
m_header->setText(page->displayName());
m_iconHeader->setIcon(page->icon());
}
void PageDialog::currentChanged(const QModelIndex &current)
{
if (current.isValid())
if(row != -1)
{
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
{
@ -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;
for(auto page: m_model->pages())
{
accepted &= page->accept();
accepted &= page->apply();
}
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());
QDialog::closeEvent(event);
}
}

View File

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

View File

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

View File

@ -28,10 +28,6 @@ InstanceSettingsPage::InstanceSettingsPage(SettingsObject *s, QWidget *parent)
{
ui->setupUi(this);
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()
@ -42,7 +38,6 @@ InstanceSettingsPage::~InstanceSettingsPage()
bool InstanceSettingsPage::apply()
{
applySettings();
loadSettings();
return true;
}

View File

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

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>458</width>
<height>476</height>
<height>426</height>
</rect>
</property>
<property name="windowTitle">
@ -425,16 +425,6 @@
</widget>
</widget>
</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>
</widget>
<resources/>

View File

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

View File

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

View File

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

View File

@ -33,12 +33,12 @@ class ModFolderPage : public QWidget, public BasePage
public:
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 QString displayName() override;
virtual QIcon icon() override;
virtual QString id() override;
virtual QString helpPage() override { return m_helpName; };
protected:
bool eventFilter(QObject *obj, QEvent *ev);
bool modListFilter(QKeyEvent *ev);
@ -49,6 +49,7 @@ private:
QString m_iconName;
QString m_id;
QString m_displayName;
QString m_helpName;
public slots:
void modCurrent(const QModelIndex &current, const QModelIndex &previous);

View File

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

View File

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

View File

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

View File

@ -50,8 +50,10 @@ QList<BasePage *> LegacyInstance::getPages()
QList<BasePage *> values;
values.append(new LegacyUpgradePage(this));
values.append(new LegacyJarModPage(this));
values.append(new ModFolderPage(loaderModList(), "mods", "plugin-blue", tr("Loader Mods")));
values.append(new ModFolderPage(coreModList(), "coremods", "plugin-green", tr("Core Mods")));
values.append(new ModFolderPage(loaderModList(), "mods", "plugin-blue", tr("Loader Mods"),
"LoaderModsPage"));
values.append(new ModFolderPage(coreModList(), "coremods", "plugin-green", tr("Core Mods"),
"CoreModsPage"));
values.append(new TexturePackPage(this));
values.append(new InstanceSettingsPage(&settings()));
return values;
@ -70,7 +72,7 @@ std::shared_ptr<Task> LegacyInstance::doUpdate()
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());
auto pixmap = icon.pixmap(128, 128);

View File

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