From c08053d8b87de4d0fd4f9ac51021e03dfd851420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 9 Jan 2019 04:38:35 +0100 Subject: NOISSUE split out language selection widget, use it in settings --- application/CMakeLists.txt | 4 + application/MultiMC.cpp | 2 + application/pages/global/LanguagePage.cpp | 51 ++++++++++ application/pages/global/LanguagePage.h | 60 ++++++++++++ application/resources/OSX/OSX.qrc | 1 + application/resources/OSX/scalable/language.svg | 40 ++++++++ application/resources/flat/flat.qrc | 1 + application/resources/flat/scalable/language.svg | 103 +++++++++++++++++++ application/resources/iOS/iOS.qrc | 1 + application/resources/iOS/scalable/language.svg | 32 ++++++ application/resources/multimc/multimc.qrc | 3 + .../resources/multimc/scalable/language.svg | 109 +++++++++++++++++++++ application/resources/pe_blue/pe_blue.qrc | 1 + .../resources/pe_blue/scalable/language.svg | 46 +++++++++ application/resources/pe_colored/pe_colored.qrc | 1 + .../resources/pe_colored/scalable/language.svg | 44 +++++++++ application/resources/pe_dark/pe_dark.qrc | 1 + .../resources/pe_dark/scalable/language.svg | 45 +++++++++ application/resources/pe_light/pe_light.qrc | 1 + .../resources/pe_light/scalable/language.svg | 80 +++++++++++++++ application/setupwizard/LanguageWizardPage.cpp | 55 ++--------- application/setupwizard/LanguageWizardPage.h | 11 +-- application/widgets/LanguageSelectionWidget.cpp | 67 +++++++++++++ application/widgets/LanguageSelectionWidget.h | 41 ++++++++ 24 files changed, 744 insertions(+), 56 deletions(-) create mode 100644 application/pages/global/LanguagePage.cpp create mode 100644 application/pages/global/LanguagePage.h create mode 100644 application/resources/OSX/scalable/language.svg create mode 100644 application/resources/flat/scalable/language.svg create mode 100644 application/resources/iOS/scalable/language.svg create mode 100644 application/resources/multimc/scalable/language.svg create mode 100644 application/resources/pe_blue/scalable/language.svg create mode 100644 application/resources/pe_colored/scalable/language.svg create mode 100644 application/resources/pe_dark/scalable/language.svg create mode 100644 application/resources/pe_light/scalable/language.svg create mode 100644 application/widgets/LanguageSelectionWidget.cpp create mode 100644 application/widgets/LanguageSelectionWidget.h diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 30fa8464..30ef7268 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -116,6 +116,8 @@ SET(MULTIMC_SOURCES pages/global/ExternalToolsPage.h pages/global/JavaPage.cpp pages/global/JavaPage.h + pages/global/LanguagePage.cpp + pages/global/LanguagePage.h pages/global/MinecraftPage.cpp pages/global/MinecraftPage.h pages/global/MultiMCPage.cpp @@ -191,6 +193,8 @@ SET(MULTIMC_SOURCES widgets/JavaSettingsWidget.h widgets/LabeledToolButton.cpp widgets/LabeledToolButton.h + widgets/LanguageSelectionWidget.cpp + widgets/LanguageSelectionWidget.h widgets/LineSeparator.cpp widgets/LineSeparator.h widgets/LogView.cpp diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 3a9c281e..88e516af 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -6,6 +6,7 @@ #include "pages/global/MultiMCPage.h" #include "pages/global/MinecraftPage.h" #include "pages/global/JavaPage.h" +#include "pages/global/LanguagePage.h" #include "pages/global/ProxyPage.h" #include "pages/global/ExternalToolsPage.h" #include "pages/global/AccountListPage.h" @@ -517,6 +518,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); // m_globalSettingsProvider->addPage(); diff --git a/application/pages/global/LanguagePage.cpp b/application/pages/global/LanguagePage.cpp new file mode 100644 index 00000000..ae3168cc --- /dev/null +++ b/application/pages/global/LanguagePage.cpp @@ -0,0 +1,51 @@ +#include "LanguagePage.h" + +#include "widgets/LanguageSelectionWidget.h" +#include + +LanguagePage::LanguagePage(QWidget* parent) : + QWidget(parent) +{ + setObjectName(QStringLiteral("languagePage")); + auto layout = new QVBoxLayout(this); + mainWidget = new LanguageSelectionWidget(this); + layout->setContentsMargins(0,0,0,0); + layout->addWidget(mainWidget); + retranslate(); +} + +LanguagePage::~LanguagePage() +{ +} + +bool LanguagePage::apply() +{ + applySettings(); + return true; +} + +void LanguagePage::applySettings() +{ + auto settings = MMC->settings(); + QString key = mainWidget->getSelectedLanguageKey(); + settings->set("Language", key); +} + +void LanguagePage::loadSettings() +{ + // NIL +} + +void LanguagePage::retranslate() +{ + mainWidget->retranslate(); +} + +void LanguagePage::changeEvent(QEvent* event) +{ + if (event->type() == QEvent::LanguageChange) + { + retranslate(); + } + QWidget::changeEvent(event); +} diff --git a/application/pages/global/LanguagePage.h b/application/pages/global/LanguagePage.h new file mode 100644 index 00000000..c4df2ea9 --- /dev/null +++ b/application/pages/global/LanguagePage.h @@ -0,0 +1,60 @@ +/* Copyright 2013-2019 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 "pages/BasePage.h" +#include +#include + +class LanguageSelectionWidget; + +class LanguagePage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit LanguagePage(QWidget *parent = 0); + virtual ~LanguagePage(); + + QString displayName() const override + { + return tr("Language"); + } + QIcon icon() const override + { + return MMC->getThemedIcon("language"); + } + QString id() const override + { + return "language-settings"; + } + QString helpPage() const override + { + return "Language-settings"; + } + bool apply() override; + + void changeEvent(QEvent * ) override; + +private: + void applySettings(); + void loadSettings(); + void retranslate(); + +private: + LanguageSelectionWidget *mainWidget; +}; diff --git a/application/resources/OSX/OSX.qrc b/application/resources/OSX/OSX.qrc index a5c40894..19fd4b6a 100644 --- a/application/resources/OSX/OSX.qrc +++ b/application/resources/OSX/OSX.qrc @@ -14,6 +14,7 @@ scalable/instance-settings.svg scalable/jarmods.svg scalable/java.svg + scalable/language.svg scalable/loadermods.svg scalable/log.svg scalable/minecraft.svg diff --git a/application/resources/OSX/scalable/language.svg b/application/resources/OSX/scalable/language.svg new file mode 100644 index 00000000..4f7d002a --- /dev/null +++ b/application/resources/OSX/scalable/language.svg @@ -0,0 +1,40 @@ + +image/svg+xml \ No newline at end of file diff --git a/application/resources/flat/flat.qrc b/application/resources/flat/flat.qrc index 67c8d291..b6e2ee38 100644 --- a/application/resources/flat/flat.qrc +++ b/application/resources/flat/flat.qrc @@ -16,6 +16,7 @@ scalable/instance-settings.svg scalable/jarmods.svg scalable/java.svg + scalable/language.svg scalable/loadermods.svg scalable/log.svg scalable/minecraft.svg diff --git a/application/resources/flat/scalable/language.svg b/application/resources/flat/scalable/language.svg new file mode 100644 index 00000000..f4d3f2f4 --- /dev/null +++ b/application/resources/flat/scalable/language.svg @@ -0,0 +1,103 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/application/resources/iOS/iOS.qrc b/application/resources/iOS/iOS.qrc index 7212ce77..511e390b 100644 --- a/application/resources/iOS/iOS.qrc +++ b/application/resources/iOS/iOS.qrc @@ -14,6 +14,7 @@ scalable/instance-settings.svg scalable/jarmods.svg scalable/java.svg + scalable/language.svg scalable/loadermods.svg scalable/log.svg scalable/minecraft.svg diff --git a/application/resources/iOS/scalable/language.svg b/application/resources/iOS/scalable/language.svg new file mode 100644 index 00000000..fcc3436e --- /dev/null +++ b/application/resources/iOS/scalable/language.svg @@ -0,0 +1,32 @@ + +image/svg+xml + + + + + \ No newline at end of file diff --git a/application/resources/multimc/multimc.qrc b/application/resources/multimc/multimc.qrc index f99cfca2..7feaaaef 100644 --- a/application/resources/multimc/multimc.qrc +++ b/application/resources/multimc/multimc.qrc @@ -20,6 +20,9 @@ scalable/proxy.svg + + scalable/language.svg + scalable/java.svg diff --git a/application/resources/multimc/scalable/language.svg b/application/resources/multimc/scalable/language.svg new file mode 100644 index 00000000..968e3538 --- /dev/null +++ b/application/resources/multimc/scalable/language.svg @@ -0,0 +1,109 @@ + +image/svg+xml \ No newline at end of file diff --git a/application/resources/pe_blue/pe_blue.qrc b/application/resources/pe_blue/pe_blue.qrc index 7d28d3d7..98445d88 100644 --- a/application/resources/pe_blue/pe_blue.qrc +++ b/application/resources/pe_blue/pe_blue.qrc @@ -14,6 +14,7 @@ scalable/instance-settings.svg scalable/jarmods.svg scalable/java.svg + scalable/language.svg scalable/loadermods.svg scalable/log.svg scalable/minecraft.svg diff --git a/application/resources/pe_blue/scalable/language.svg b/application/resources/pe_blue/scalable/language.svg new file mode 100644 index 00000000..92868516 --- /dev/null +++ b/application/resources/pe_blue/scalable/language.svg @@ -0,0 +1,46 @@ + +image/svg+xml \ No newline at end of file diff --git a/application/resources/pe_colored/pe_colored.qrc b/application/resources/pe_colored/pe_colored.qrc index 9a7a89cc..fbaaf9e4 100644 --- a/application/resources/pe_colored/pe_colored.qrc +++ b/application/resources/pe_colored/pe_colored.qrc @@ -14,6 +14,7 @@ scalable/instance-settings.svg scalable/jarmods.svg scalable/java.svg + scalable/language.svg scalable/loadermods.svg scalable/log.svg scalable/minecraft.svg diff --git a/application/resources/pe_colored/scalable/language.svg b/application/resources/pe_colored/scalable/language.svg new file mode 100644 index 00000000..80c1dcad --- /dev/null +++ b/application/resources/pe_colored/scalable/language.svg @@ -0,0 +1,44 @@ + +image/svg+xml + + + + + + + + \ No newline at end of file diff --git a/application/resources/pe_dark/pe_dark.qrc b/application/resources/pe_dark/pe_dark.qrc index 0a49b0bb..a57b6a14 100644 --- a/application/resources/pe_dark/pe_dark.qrc +++ b/application/resources/pe_dark/pe_dark.qrc @@ -14,6 +14,7 @@ scalable/instance-settings.svg scalable/jarmods.svg scalable/java.svg + scalable/language.svg scalable/loadermods.svg scalable/log.svg scalable/minecraft.svg diff --git a/application/resources/pe_dark/scalable/language.svg b/application/resources/pe_dark/scalable/language.svg new file mode 100644 index 00000000..1a9b4c5c --- /dev/null +++ b/application/resources/pe_dark/scalable/language.svg @@ -0,0 +1,45 @@ + +image/svg+xml \ No newline at end of file diff --git a/application/resources/pe_light/pe_light.qrc b/application/resources/pe_light/pe_light.qrc index 98c29e9e..6d77c835 100644 --- a/application/resources/pe_light/pe_light.qrc +++ b/application/resources/pe_light/pe_light.qrc @@ -14,6 +14,7 @@ scalable/instance-settings.svg scalable/jarmods.svg scalable/java.svg + scalable/language.svg scalable/loadermods.svg scalable/log.svg scalable/minecraft.svg diff --git a/application/resources/pe_light/scalable/language.svg b/application/resources/pe_light/scalable/language.svg new file mode 100644 index 00000000..57d5e3de --- /dev/null +++ b/application/resources/pe_light/scalable/language.svg @@ -0,0 +1,80 @@ + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/setupwizard/LanguageWizardPage.cpp b/application/setupwizard/LanguageWizardPage.cpp index 9a8fd37f..ca93c6f5 100644 --- a/application/setupwizard/LanguageWizardPage.cpp +++ b/application/setupwizard/LanguageWizardPage.cpp @@ -2,41 +2,19 @@ #include #include +#include "widgets/LanguageSelectionWidget.h" #include -#include -#include -#include LanguageWizardPage::LanguageWizardPage(QWidget *parent) : BaseWizardPage(parent) { setObjectName(QStringLiteral("languagePage")); - verticalLayout = new QVBoxLayout(this); - verticalLayout->setObjectName(QStringLiteral("verticalLayout")); - languageView = new QTreeView(this); - languageView->setObjectName(QStringLiteral("languageView")); - languageView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - languageView->setAlternatingRowColors(true); - languageView->setRootIsDecorated(false); - languageView->setItemsExpandable(false); - languageView->setWordWrap(true); - languageView->header()->setCascadingSectionResizes(true); - languageView->header()->setStretchLastSection(false); - verticalLayout->addWidget(languageView); - helpUsLabel = new QLabel(this); - helpUsLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse); - helpUsLabel->setOpenExternalLinks(true); - helpUsLabel->setWordWrap(true); - verticalLayout->addWidget(helpUsLabel); - retranslate(); + auto layout = new QVBoxLayout(this); + mainWidget = new LanguageSelectionWidget(this); + layout->setContentsMargins(0,0,0,0); + layout->addWidget(mainWidget); - auto translations = MMC->translations(); - auto index = translations->selectedIndex(); - languageView->setModel(translations.get()); - languageView->setCurrentIndex(index); - languageView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); - languageView->header()->setSectionResizeMode(0, QHeaderView::Stretch); - connect(languageView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &LanguageWizardPage::languageRowChanged); + retranslate(); } LanguageWizardPage::~LanguageWizardPage() @@ -57,8 +35,7 @@ void LanguageWizardPage::refresh() bool LanguageWizardPage::validatePage() { auto settings = MMC->settings(); - auto translations = MMC->translations(); - QString key = translations->data(languageView->currentIndex(), Qt::UserRole).toString(); + QString key = mainWidget->getSelectedLanguageKey(); settings->set("Language", key); return true; } @@ -67,21 +44,5 @@ void LanguageWizardPage::retranslate() { setTitle(tr("Language")); setSubTitle(tr("Select the language to use in MultiMC")); - QString text = - tr("Don't see your language or the quality is poor?") + - "
" + - QString("%1").arg("Help us with translations!"); - helpUsLabel->setText(text); -} - -void LanguageWizardPage::languageRowChanged(const QModelIndex ¤t, const QModelIndex &previous) -{ - if (current == previous) - { - return; - } - auto translations = MMC->translations(); - QString key = translations->data(current, Qt::UserRole).toString(); - translations->selectLanguage(key); - translations->updateLanguage(key); + mainWidget->retranslate(); } diff --git a/application/setupwizard/LanguageWizardPage.h b/application/setupwizard/LanguageWizardPage.h index bfc02c95..45a0e5c0 100644 --- a/application/setupwizard/LanguageWizardPage.h +++ b/application/setupwizard/LanguageWizardPage.h @@ -2,9 +2,7 @@ #include "BaseWizardPage.h" -class QVBoxLayout; -class QTreeView; -class QLabel; +class LanguageSelectionWidget; class LanguageWizardPage : public BaseWizardPage { @@ -23,11 +21,6 @@ public: protected: void retranslate() override; -protected slots: - void languageRowChanged(const QModelIndex ¤t, const QModelIndex &previous); - private: - QVBoxLayout *verticalLayout = nullptr; - QTreeView *languageView = nullptr; - QLabel *helpUsLabel = nullptr; + LanguageSelectionWidget *mainWidget = nullptr; }; diff --git a/application/widgets/LanguageSelectionWidget.cpp b/application/widgets/LanguageSelectionWidget.cpp new file mode 100644 index 00000000..38ac5afa --- /dev/null +++ b/application/widgets/LanguageSelectionWidget.cpp @@ -0,0 +1,67 @@ +#include "LanguageSelectionWidget.h" + +#include +#include +#include +#include +#include "MultiMC.h" +#include "translations/TranslationsModel.h" + +LanguageSelectionWidget::LanguageSelectionWidget(QWidget *parent) : + QWidget(parent) +{ + verticalLayout = new QVBoxLayout(this); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + languageView = new QTreeView(this); + languageView->setObjectName(QStringLiteral("languageView")); + languageView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + languageView->setAlternatingRowColors(true); + languageView->setRootIsDecorated(false); + languageView->setItemsExpandable(false); + languageView->setWordWrap(true); + languageView->header()->setCascadingSectionResizes(true); + languageView->header()->setStretchLastSection(false); + verticalLayout->addWidget(languageView); + helpUsLabel = new QLabel(this); + helpUsLabel->setObjectName(QStringLiteral("helpUsLabel")); + helpUsLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse); + helpUsLabel->setOpenExternalLinks(true); + helpUsLabel->setWordWrap(true); + verticalLayout->addWidget(helpUsLabel); + + auto translations = MMC->translations(); + auto index = translations->selectedIndex(); + languageView->setModel(translations.get()); + languageView->setCurrentIndex(index); + languageView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + languageView->header()->setSectionResizeMode(0, QHeaderView::Stretch); + connect(languageView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &LanguageSelectionWidget::languageRowChanged); +} + +QString LanguageSelectionWidget::getSelectedLanguageKey() const +{ + auto translations = MMC->translations(); + return translations->data(languageView->currentIndex(), Qt::UserRole).toString(); +} + +void LanguageSelectionWidget::retranslate() +{ + QString text = + tr("Don't see your language or the quality is poor?") + + "
" + + QString("%1").arg("Help us with translations!"); + helpUsLabel->setText(text); + +} + +void LanguageSelectionWidget::languageRowChanged(const QModelIndex& current, const QModelIndex& previous) +{ + if (current == previous) + { + return; + } + auto translations = MMC->translations(); + QString key = translations->data(current, Qt::UserRole).toString(); + translations->selectLanguage(key); + translations->updateLanguage(key); +} diff --git a/application/widgets/LanguageSelectionWidget.h b/application/widgets/LanguageSelectionWidget.h new file mode 100644 index 00000000..03e29bd8 --- /dev/null +++ b/application/widgets/LanguageSelectionWidget.h @@ -0,0 +1,41 @@ +/* Copyright 2013-2019 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 + +class QVBoxLayout; +class QTreeView; +class QLabel; + +class LanguageSelectionWidget: public QWidget +{ + Q_OBJECT +public: + explicit LanguageSelectionWidget(QWidget *parent = 0); + virtual ~LanguageSelectionWidget() { }; + + QString getSelectedLanguageKey() const; + void retranslate(); + +protected slots: + void languageRowChanged(const QModelIndex ¤t, const QModelIndex &previous); + +private: + QVBoxLayout *verticalLayout = nullptr; + QTreeView *languageView = nullptr; + QLabel *helpUsLabel = nullptr; +}; -- cgit v1.2.3