From d911c9908c11c42144084c862c64b740cfb0c02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 18 Jun 2014 01:15:01 +0200 Subject: Replace notes dialog with a page. --- gui/MainWindow.cpp | 50 ++++++++++---------------- gui/dialogs/EditNotesDialog.cpp | 43 ----------------------- gui/dialogs/EditNotesDialog.h | 38 -------------------- gui/dialogs/EditNotesDialog.ui | 77 ----------------------------------------- gui/pages/NotesPage.cpp | 35 +++++++++++++++++++ gui/pages/NotesPage.h | 45 ++++++++++++++++++++++++ gui/pages/NotesPage.ui | 46 ++++++++++++++++++++++++ 7 files changed, 145 insertions(+), 189 deletions(-) delete mode 100644 gui/dialogs/EditNotesDialog.cpp delete mode 100644 gui/dialogs/EditNotesDialog.h delete mode 100644 gui/dialogs/EditNotesDialog.ui create mode 100644 gui/pages/NotesPage.cpp create mode 100644 gui/pages/NotesPage.h create mode 100644 gui/pages/NotesPage.ui (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index e9cfd361..35ac541d 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -57,7 +57,6 @@ #include "gui/dialogs/CustomMessageBox.h" #include "gui/dialogs/LwjglSelectDialog.h" #include "gui/dialogs/IconPickerDialog.h" -#include "gui/dialogs/EditNotesDialog.h" #include "gui/dialogs/CopyInstanceDialog.h" #include "gui/dialogs/AccountListDialog.h" #include "gui/dialogs/AccountSelectDialog.h" @@ -941,17 +940,31 @@ void MainWindow::on_actionSettings_triggered() updateToolsMenu(); } -void MainWindow::on_actionInstanceSettings_triggered() +template +void ShowPageDialog(T raw_provider, QWidget * parent, QString open_page = QString()) { - if (!m_selectedInstance) - return; - auto provider = std::dynamic_pointer_cast(m_selectedInstance); + auto provider = std::dynamic_pointer_cast(raw_provider); if(!provider) return; - PageDialog dlg(provider, "settings" , this); + PageDialog dlg(provider, open_page, parent); dlg.exec(); } +void MainWindow::on_actionInstanceSettings_triggered() +{ + ShowPageDialog(m_selectedInstance, this, "settings"); +} + +void MainWindow::on_actionEditInstNotes_triggered() +{ + ShowPageDialog(m_selectedInstance, this, "notes"); +} + +void MainWindow::on_actionEditInstance_triggered() +{ + ShowPageDialog(m_selectedInstance, this); +} + void MainWindow::on_actionManageAccounts_triggered() { AccountListDialog dialog(this); @@ -1040,17 +1053,6 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered() } } -void MainWindow::on_actionEditInstance_triggered() -{ - if (!m_selectedInstance) - return; - auto provider = std::dynamic_pointer_cast(m_selectedInstance); - if(!provider) - return; - PageDialog dlg(provider, "" , this); - dlg.exec(); -} - void MainWindow::closeEvent(QCloseEvent *event) { // Save the window state and geometry. @@ -1398,20 +1400,6 @@ void MainWindow::selectionBad() setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString()); } -void MainWindow::on_actionEditInstNotes_triggered() -{ - if (!m_selectedInstance) - return; - - EditNotesDialog noteedit(m_selectedInstance->notes(), m_selectedInstance->name(), this); - noteedit.exec(); - if (noteedit.result() == QDialog::Accepted) - { - - m_selectedInstance->setNotes(noteedit.getText()); - } -} - void MainWindow::instanceEnded() { this->show(); diff --git a/gui/dialogs/EditNotesDialog.cpp b/gui/dialogs/EditNotesDialog.cpp deleted file mode 100644 index f2aa029f..00000000 --- a/gui/dialogs/EditNotesDialog.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "EditNotesDialog.h" -#include "ui_EditNotesDialog.h" -#include "gui/Platform.h" - -#include -#include - -EditNotesDialog::EditNotesDialog(QString notes, QString name, QWidget *parent) - : QDialog(parent), ui(new Ui::EditNotesDialog), m_instance_name(name), - m_instance_notes(notes) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - ui->noteEditor->setText(notes); - setWindowTitle(tr("Edit notes of %1").arg(m_instance_name)); - // connect(ui->closeButton, SIGNAL(clicked()), SLOT(close())); -} - -EditNotesDialog::~EditNotesDialog() -{ - delete ui; -} - -QString EditNotesDialog::getText() -{ - QString test = ui->noteEditor->toPlainText(); - return test; -} diff --git a/gui/dialogs/EditNotesDialog.h b/gui/dialogs/EditNotesDialog.h deleted file mode 100644 index b74558c4..00000000 --- a/gui/dialogs/EditNotesDialog.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace Ui -{ -class EditNotesDialog; -} - -class EditNotesDialog : public QDialog -{ - Q_OBJECT - -public: - explicit EditNotesDialog(QString notes, QString name, QWidget *parent = 0); - ~EditNotesDialog(); - QString getText(); - -private: - Ui::EditNotesDialog *ui; - QString m_instance_name; - QString m_instance_notes; -}; diff --git a/gui/dialogs/EditNotesDialog.ui b/gui/dialogs/EditNotesDialog.ui deleted file mode 100644 index 487dfb84..00000000 --- a/gui/dialogs/EditNotesDialog.ui +++ /dev/null @@ -1,77 +0,0 @@ - - - EditNotesDialog - - - - 0 - 0 - 459 - 399 - - - - Edit Notes - - - - - - Qt::ScrollBarAlwaysOn - - - false - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - EditNotesDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - EditNotesDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/gui/pages/NotesPage.cpp b/gui/pages/NotesPage.cpp new file mode 100644 index 00000000..b4746a77 --- /dev/null +++ b/gui/pages/NotesPage.cpp @@ -0,0 +1,35 @@ +#include "NotesPage.h" +#include "ui_NotesPage.h" + +QString NotesPage::displayName() +{ + return tr("Notes"); +} + +QIcon NotesPage::icon() +{ + return QIcon::fromTheme("news"); +} + +QString NotesPage::id() +{ + return "notes"; +} + +NotesPage::NotesPage(BaseInstance *inst, QWidget *parent) + : QWidget(parent), ui(new Ui::NotesPage), m_inst(inst) +{ + ui->setupUi(this); + ui->noteEditor->setText(m_inst->notes()); +} + +NotesPage::~NotesPage() +{ + delete ui; +} + +bool NotesPage::apply() +{ + m_inst->setNotes(ui->noteEditor->toPlainText()); + return true; +} diff --git a/gui/pages/NotesPage.h b/gui/pages/NotesPage.h new file mode 100644 index 00000000..fe916f21 --- /dev/null +++ b/gui/pages/NotesPage.h @@ -0,0 +1,45 @@ +/* Copyright 2014 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +#include +#include +#include "BasePage.h" + +class EnabledItemFilter; +namespace Ui +{ +class NotesPage; +} + +class NotesPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit NotesPage(BaseInstance *inst, QWidget *parent = 0); + virtual ~NotesPage(); + virtual QString displayName() override; + virtual QIcon icon() override; + virtual QString id() override; + virtual bool apply(); + virtual QString helpPage() override { return "Notes"; }; + +private: + Ui::NotesPage *ui; + BaseInstance *m_inst; +}; diff --git a/gui/pages/NotesPage.ui b/gui/pages/NotesPage.ui new file mode 100644 index 00000000..ab33ffd3 --- /dev/null +++ b/gui/pages/NotesPage.ui @@ -0,0 +1,46 @@ + + + NotesPage + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::ScrollBarAlwaysOn + + + false + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + -- cgit v1.2.3