From 9ec6deea848f8cdbebeb5c6be8b042c754ad9de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 10 Jun 2014 00:46:05 +0200 Subject: [PATCH] Add close button to page dialog. Add help button to page dialog. Smile. --- gui/pagedialog/PageDialog.cpp | 89 +++++++++++++----------------- gui/pagedialog/PageDialog.h | 6 +- gui/pages/BasePage.h | 12 ++-- gui/pages/InstanceSettingsPage.cpp | 5 -- gui/pages/InstanceSettingsPage.h | 2 +- gui/pages/InstanceSettingsPage.ui | 12 +--- gui/pages/LegacyJarModPage.h | 1 + gui/pages/LegacyUpgradePage.h | 1 + gui/pages/ModFolderPage.cpp | 3 +- gui/pages/ModFolderPage.h | 5 +- gui/pages/ResourcePackPage.h | 3 +- gui/pages/TexturePackPage.h | 2 +- gui/pages/VersionPage.h | 1 + logic/LegacyInstance.cpp | 8 ++- logic/OneSixInstance.cpp | 6 +- 15 files changed, 66 insertions(+), 90 deletions(-) diff --git a/gui/pagedialog/PageDialog.cpp b/gui/pagedialog/PageDialog.cpp index 450f2b08..4db5cd28 100644 --- a/gui/pagedialog/PageDialog.cpp +++ b/gui/pagedialog/PageDialog.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "MultiMC.h" #include #include @@ -25,6 +26,7 @@ #include #include #include +#include #include #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 ¤t) -{ - 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 ¤t) } } -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 ¤t) +{ + 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(); + QDialog::closeEvent(event); } } - -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); -} diff --git a/gui/pagedialog/PageDialog.h b/gui/pagedialog/PageDialog.h index bb31a607..88926ef1 100644 --- a/gui/pagedialog/PageDialog.h +++ b/gui/pagedialog/PageDialog.h @@ -38,14 +38,14 @@ private: void createUI(); private slots: - void apply(); - virtual void reject(); - virtual void accept(); void currentChanged(const QModelIndex ¤t); void showPage(int row); + void help(); virtual void closeEvent(QCloseEvent *event); + private: + BasePage * m_currentPage; QSortFilterProxyModel *m_proxyModel; PageModel *m_model; QStackedLayout *m_pageStack; diff --git a/gui/pages/BasePage.h b/gui/pages/BasePage.h index feb19a79..93ce3f35 100644 --- a/gui/pages/BasePage.h +++ b/gui/pages/BasePage.h @@ -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; }; diff --git a/gui/pages/InstanceSettingsPage.cpp b/gui/pages/InstanceSettingsPage.cpp index 0bcfc7f2..b4a6405f 100644 --- a/gui/pages/InstanceSettingsPage.cpp +++ b/gui/pages/InstanceSettingsPage.cpp @@ -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; } diff --git a/gui/pages/InstanceSettingsPage.h b/gui/pages/InstanceSettingsPage.h index 7b736b0b..583cab0e 100644 --- a/gui/pages/InstanceSettingsPage.h +++ b/gui/pages/InstanceSettingsPage.h @@ -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: diff --git a/gui/pages/InstanceSettingsPage.ui b/gui/pages/InstanceSettingsPage.ui index 3c76d94b..b8af6c60 100644 --- a/gui/pages/InstanceSettingsPage.ui +++ b/gui/pages/InstanceSettingsPage.ui @@ -7,7 +7,7 @@ 0 0 458 - 476 + 426 @@ -425,16 +425,6 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Apply|QDialogButtonBox::Reset - - - diff --git a/gui/pages/LegacyJarModPage.h b/gui/pages/LegacyJarModPage.h index a2a7f74e..5bbd7cde 100644 --- a/gui/pages/LegacyJarModPage.h +++ b/gui/pages/LegacyJarModPage.h @@ -37,6 +37,7 @@ public: virtual QString displayName(); virtual QIcon icon(); virtual QString id(); + virtual QString helpPage() override { return "LegacyJarModPage"; }; private slots: diff --git a/gui/pages/LegacyUpgradePage.h b/gui/pages/LegacyUpgradePage.h index 549c8bf3..7f533310 100644 --- a/gui/pages/LegacyUpgradePage.h +++ b/gui/pages/LegacyUpgradePage.h @@ -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(); diff --git a/gui/pages/ModFolderPage.cpp b/gui/pages/ModFolderPage.cpp index de51edfa..6d5c6226 100644 --- a/gui/pages/ModFolderPage.cpp +++ b/gui/pages/ModFolderPage.cpp @@ -49,7 +49,7 @@ QString ModFolderPage::id() } ModFolderPage::ModFolderPage(std::shared_ptr 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 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(); diff --git a/gui/pages/ModFolderPage.h b/gui/pages/ModFolderPage.h index 276e23d5..b4e05928 100644 --- a/gui/pages/ModFolderPage.h +++ b/gui/pages/ModFolderPage.h @@ -33,12 +33,12 @@ class ModFolderPage : public QWidget, public BasePage public: explicit ModFolderPage(std::shared_ptr 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 ¤t, const QModelIndex &previous); diff --git a/gui/pages/ResourcePackPage.h b/gui/pages/ResourcePackPage.h index 14321b9b..0c239bf1 100644 --- a/gui/pages/ResourcePackPage.h +++ b/gui/pages/ResourcePackPage.h @@ -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; }; diff --git a/gui/pages/TexturePackPage.h b/gui/pages/TexturePackPage.h index ddb1fa49..f807bea5 100644 --- a/gui/pages/TexturePackPage.h +++ b/gui/pages/TexturePackPage.h @@ -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; } diff --git a/gui/pages/VersionPage.h b/gui/pages/VersionPage.h index 55e244b3..be271074 100644 --- a/gui/pages/VersionPage.h +++ b/gui/pages/VersionPage.h @@ -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: diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index 5096d50d..0bd1bda8 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -50,8 +50,10 @@ QList LegacyInstance::getPages() QList 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 LegacyInstance::doUpdate() return std::shared_ptr(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); diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 1033c624..c1d5f2b1 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -61,8 +61,10 @@ QList OneSixInstance::getPages() { QList 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()));