Help user to select default GUI language.

This commit is contained in:
Roman Telezhynskyi 2021-10-19 14:43:20 +03:00
parent 4b3b7a8987
commit 8d52157b41
13 changed files with 303 additions and 3 deletions

View File

@ -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.

View File

@ -37,6 +37,7 @@
#include <QPrinterInfo>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include <QTimer>
#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()

View File

@ -289,6 +289,8 @@ private slots:
void AboutToShowDockMenu();
#endif //defined(Q_OS_MAC)
void SetDefaultGUILanguage();
private:
Q_DISABLE_COPY(VPMainWindow)
Ui::VPMainWindow *ui;

View File

@ -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()
{

View File

@ -145,6 +145,8 @@ private slots:
void EditDimensionLabels();
void SetDefaultGUILanguage();
private:
Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui;

View File

@ -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()
{

View File

@ -224,6 +224,8 @@ private slots:
void ShowProgress();
void ClearPatternMessages();
void SetDefaultGUILanguage();
private:
Q_DISABLE_COPY(MainWindow)
/** @brief ui keeps information about user interface */

View File

@ -0,0 +1,52 @@
/************************************************************************
**
** @file dialogselectlanguage.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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<QString>(ui->comboBoxLanguage->currentData());
}

View File

@ -0,0 +1,53 @@
/************************************************************************
**
** @file dialogselectlanguage.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef DIALOGSELECTLANGUAGE_H
#define DIALOGSELECTLANGUAGE_H
#include <QDialog>
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

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogSelectLanguage</class>
<widget class="QDialog" name="DialogSelectLanguage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>224</width>
<height>99</height>
</rect>
</property>
<property name="windowTitle">
<string>Select language</string>
</property>
<property name="windowIcon">
<iconset resource="../share/resources/icon.qrc">
<normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select user interface language</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLanguage"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../share/resources/icon.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogSelectLanguage</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogSelectLanguage</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -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
{

View File

@ -93,6 +93,7 @@ public:
int GetAutosaveTime() const;
void SetAutosaveTime(const int &value);
bool IsLocaleSelected() const;
QString GetLocale() const;
void SetLocale(const QString &value);

View File

@ -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