From 8d52157b41d62eedee2c21357defd67f6819ffc0 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 19 Oct 2021 14:43:20 +0300 Subject: [PATCH] Help user to select default GUI language. --- ChangeLog.txt | 1 + src/app/puzzle/vpmainwindow.cpp | 29 ++++++ src/app/puzzle/vpmainwindow.h | 2 + src/app/tape/tmainwindow.cpp | 28 ++++++ src/app/tape/tmainwindow.h | 2 + src/app/valentina/mainwindow.cpp | 27 ++++++ src/app/valentina/mainwindow.h | 2 + .../vmisc/dialogs/dialogselectlanguage.cpp | 52 +++++++++++ src/libs/vmisc/dialogs/dialogselectlanguage.h | 53 +++++++++++ .../vmisc/dialogs/dialogselectlanguage.ui | 91 +++++++++++++++++++ src/libs/vmisc/vcommonsettings.cpp | 9 ++ src/libs/vmisc/vcommonsettings.h | 1 + src/libs/vmisc/vmisc.pri | 9 +- 13 files changed, 303 insertions(+), 3 deletions(-) create mode 100644 src/libs/vmisc/dialogs/dialogselectlanguage.cpp create mode 100644 src/libs/vmisc/dialogs/dialogselectlanguage.h create mode 100644 src/libs/vmisc/dialogs/dialogselectlanguage.ui diff --git a/ChangeLog.txt b/ChangeLog.txt index db0ae0100..3f15da862 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -15,6 +15,7 @@ - Fix reading tiled page margins in console mode. - Fix handling numeric values passed in console mode. - Add Don't ask again for Stale layout question dialog. +- Help user to select default GUI language. # Valentina 0.7.49 July 1, 2021 - Fix crash. diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index ceea637fd..1d4e507dc 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "ui_vpmainwindow.h" #include "dialogs/vpdialogabout.h" @@ -59,6 +60,7 @@ #include "undocommands/vpundopiecemove.h" #include "dialogs/dialogsavemanuallayout.h" #include "../vdxf/libdxfrw/drw_base.h" +#include "../vmisc/dialogs/dialogselectlanguage.h" #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) #include "../vmisc/backport/qscopeguard.h" @@ -383,6 +385,11 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : }); m_graphicsView->RefreshLayout(); + + if (m_cmd->IsGuiEnabled()) + { + QTimer::singleShot(1000, this, &VPMainWindow::SetDefaultGUILanguage); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -4513,6 +4520,28 @@ void VPMainWindow::RemoveWatermark() } } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::SetDefaultGUILanguage() +{ + if (m_cmd->IsGuiEnabled()) + { + auto *settings = VPApplication::VApp()->PuzzleSettings(); + if (not settings->IsLocaleSelected()) + { + QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + DialogSelectLanguage dialog(this); + QGuiApplication::restoreOverrideCursor(); + dialog.setWindowModality(Qt::WindowModal); + if (dialog.exec() == QDialog::Accepted) + { + QString locale = dialog.Locale(); + settings->SetLocale(locale); + VAbstractApplication::VApp()->LoadTranslation(locale); + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- #if defined(Q_OS_MAC) void VPMainWindow::AboutToShowDockMenu() diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index c83ccbe9c..039dbcc01 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -289,6 +289,8 @@ private slots: void AboutToShowDockMenu(); #endif //defined(Q_OS_MAC) + void SetDefaultGUILanguage(); + private: Q_DISABLE_COPY(VPMainWindow) Ui::VPMainWindow *ui; diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 14d2ea115..221e15325 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -52,6 +52,7 @@ #include "../qmuparser/qmudef.h" #include "../vtools/dialogs/support/dialogeditwrongformula.h" #include "version.h" +#include "../vmisc/dialogs/dialogselectlanguage.h" #include "mapplication.h" // Should be last because of definning qApp #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) @@ -148,6 +149,11 @@ TMainWindow::TMainWindow(QWidget *parent) AboutToShowDockMenu(); menu->setAsDockMenu(); #endif //defined(Q_OS_MAC) + + if (MApplication::VApp()->IsAppInGUIMode()) + { + QTimer::singleShot(1000, this, &TMainWindow::SetDefaultGUILanguage); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -2307,6 +2313,28 @@ void TMainWindow::EditDimensionLabels() InitDimensionControls(); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SetDefaultGUILanguage() +{ + if (MApplication::VApp()->IsAppInGUIMode()) + { + VTapeSettings *settings = MApplication::VApp()->TapeSettings(); + if (not settings->IsLocaleSelected()) + { + QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + DialogSelectLanguage dialog(this); + QGuiApplication::restoreOverrideCursor(); + dialog.setWindowModality(Qt::WindowModal); + if (dialog.exec() == QDialog::Accepted) + { + QString locale = dialog.Locale(); + settings->SetLocale(locale); + VAbstractApplication::VApp()->LoadTranslation(locale); + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetupMenu() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 2bb9436e1..b50e1d21c 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -145,6 +145,8 @@ private slots: void EditDimensionLabels(); + void SetDefaultGUILanguage(); + private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 71382c2e9..8631e090f 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -70,6 +70,7 @@ #include "../vlayout/vlayoutexporter.h" #include "../vwidgets/vgraphicssimpletextitem.h" #include "../vlayout/dialogs/dialoglayoutscale.h" +#include "../vmisc/dialogs/dialogselectlanguage.h" #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) #include "../vmisc/backport/qscopeguard.h" @@ -376,6 +377,11 @@ MainWindow::MainWindow(QWidget *parent) ClearPatternMessages(); } }); + + if (VApplication::VApp()->IsGUIMode()) + { + QTimer::singleShot(1000, this, &MainWindow::SetDefaultGUILanguage); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -4162,6 +4168,27 @@ void MainWindow::ClearPatternMessages() } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::SetDefaultGUILanguage() +{ + if (VApplication::VApp()->IsGUIMode()) + { + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); + if (not settings->IsLocaleSelected()) + { + QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + DialogSelectLanguage dialog(this); + QGuiApplication::restoreOverrideCursor(); + if (dialog.exec() == QDialog::Accepted) + { + QString locale = dialog.Locale(); + settings->SetLocale(locale); + VAbstractApplication::VApp()->LoadTranslation(locale); + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::InitDimensionControls() { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index f456b7e07..17637bcec 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -224,6 +224,8 @@ private slots: void ShowProgress(); void ClearPatternMessages(); + void SetDefaultGUILanguage(); + private: Q_DISABLE_COPY(MainWindow) /** @brief ui keeps information about user interface */ diff --git a/src/libs/vmisc/dialogs/dialogselectlanguage.cpp b/src/libs/vmisc/dialogs/dialogselectlanguage.cpp new file mode 100644 index 000000000..80e8deb36 --- /dev/null +++ b/src/libs/vmisc/dialogs/dialogselectlanguage.cpp @@ -0,0 +1,52 @@ +/************************************************************************ + ** + ** @file dialogselectlanguage.cpp + ** @author Roman Telezhynskyi + ** @date 19 10, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "dialogselectlanguage.h" +#include "ui_dialogselectlanguage.h" +#include "../vmisc/def.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogSelectLanguage::DialogSelectLanguage(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogSelectLanguage) +{ + ui->setupUi(this); + + InitLanguages(ui->comboBoxLanguage); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogSelectLanguage::~DialogSelectLanguage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogSelectLanguage::Locale() const +{ + return qvariant_cast(ui->comboBoxLanguage->currentData()); +} diff --git a/src/libs/vmisc/dialogs/dialogselectlanguage.h b/src/libs/vmisc/dialogs/dialogselectlanguage.h new file mode 100644 index 000000000..c3593ce9c --- /dev/null +++ b/src/libs/vmisc/dialogs/dialogselectlanguage.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file dialogselectlanguage.h + ** @author Roman Telezhynskyi + ** @date 19 10, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef DIALOGSELECTLANGUAGE_H +#define DIALOGSELECTLANGUAGE_H + +#include + +namespace Ui +{ +class DialogSelectLanguage; +} + +class DialogSelectLanguage : public QDialog +{ + Q_OBJECT + +public: + explicit DialogSelectLanguage(QWidget *parent = nullptr); + ~DialogSelectLanguage(); + + QString Locale() const; + +private: + Q_DISABLE_COPY(DialogSelectLanguage) + Ui::DialogSelectLanguage *ui; +}; + +#endif // DIALOGSELECTLANGUAGE_H diff --git a/src/libs/vmisc/dialogs/dialogselectlanguage.ui b/src/libs/vmisc/dialogs/dialogselectlanguage.ui new file mode 100644 index 000000000..7ed475193 --- /dev/null +++ b/src/libs/vmisc/dialogs/dialogselectlanguage.ui @@ -0,0 +1,91 @@ + + + DialogSelectLanguage + + + + 0 + 0 + 224 + 99 + + + + Select language + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + Select user interface language + + + + + + + + + Language: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogSelectLanguage + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogSelectLanguage + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 5b0706ea0..a293912c0 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -534,6 +534,15 @@ void VCommonSettings::SetAutosaveTime(const int &value) setValue(*settingConfigurationAutosaveTime, value); } +//--------------------------------------------------------------------------------------------------------------------- +auto VCommonSettings::IsLocaleSelected() const -> bool +{ + const QString fakeLocale = QStringLiteral("Fake"); + QString locale = value(*settingConfigurationLocale, fakeLocale).toString(); + + return locale != fakeLocale; +} + //--------------------------------------------------------------------------------------------------------------------- QString VCommonSettings::GetLocale() const { diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index 4f3e2e2aa..902599ea5 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -93,6 +93,7 @@ public: int GetAutosaveTime() const; void SetAutosaveTime(const int &value); + bool IsLocaleSelected() const; QString GetLocale() const; void SetLocale(const QString &value); diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index 3e7edd1c9..a326e8aa3 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -14,7 +14,8 @@ SOURCES += \ $$PWD/vtablesearch.cpp \ $$PWD/dialogs/dialogexporttocsv.cpp \ $$PWD/literals.cpp \ - $$PWD/vmodifierkey.cpp + $$PWD/vmodifierkey.cpp \ + $$PWD/dialogs/dialogselectlanguage.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -52,7 +53,8 @@ HEADERS += \ $$PWD/vdatastreamenum.h \ $$PWD/vmodifierkey.h \ $$PWD/typedef.h \ - $$PWD/backport/qscopeguard.h + $$PWD/backport/qscopeguard.h \ + $$PWD/dialogs/dialogselectlanguage.h contains(DEFINES, APPIMAGE) { SOURCES += \ @@ -72,4 +74,5 @@ contains(QT_VERSION, ^5\\.[0-2]\\.[0-2]$) { # Since Qt 5.3.0 } FORMS += \ - $$PWD/dialogs/dialogexporttocsv.ui + $$PWD/dialogs/dialogexporttocsv.ui \ + $$PWD/dialogs/dialogselectlanguage.ui