Вынес настройки ГУИ в отдельную кнопку

This commit is contained in:
2025-05-27 17:54:07 +03:00
parent d76bb562d9
commit 5191e12389
17 changed files with 302 additions and 78 deletions

View File

@@ -12,20 +12,18 @@ MainWindow::MainWindow(QWidget *parent)
{
ui->setupUi(this);
this->setWindowTitle(tr("Learning management system (LMS)"));
//Задаём два пункта с текстом локалей в комбобоксе
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
m_instructorsAndTraineesWidget = new InstructorsAndTraineesWidget(this);
ui->horizontalLayout->addWidget(m_instructorsAndTraineesWidget);
connect(m_instructorsAndTraineesWidget,&InstructorsAndTraineesWidget::signal_LanguageChanged,this,&MainWindow::slot_LanguageChanged);
connect(this, &MainWindow::signal_LanguageChanged, m_instructorsAndTraineesWidget, &InstructorsAndTraineesWidget::slot_LanguageChanged);
ui->horizontalLayout->addWidget(m_instructorsAndTraineesWidget);
//this->move(0, 0);
//this->showNormal();
this->showMaximized();
qtLanguageTranslator.load(QString("translations/GUIdataBaseLMS_") + "en_EN", ".");
qApp->installTranslator(&qtLanguageTranslator);
}
MainWindow::~MainWindow()
@@ -43,17 +41,8 @@ void MainWindow::changeEvent(QEvent *event)
}
}
void MainWindow::on_cmbLanguage_currentIndexChanged(const QString &arg1)
void MainWindow::slot_LanguageChanged(QString language)
{
QString language;
if(arg1 == QStringLiteral("English"))
language = QString("en_EN");
else
language = QString("ru_RU");
qtLanguageTranslator.load(QString("translations/testDBpgSQL_") + language, ".");
qtLanguageTranslator.load(QString(QStringLiteral("translations/GUIdataBaseLMS_")) + language, QStringLiteral("."));
qApp->installTranslator(&qtLanguageTranslator);
emit signal_LanguageChanged(language);
}

View File

@@ -22,12 +22,9 @@ public:
protected:
void changeEvent(QEvent * event) override;
signals:
//сигнал об изменении языка интерфейса
void signal_LanguageChanged(QString language);
private slots:
void on_cmbLanguage_currentIndexChanged(const QString &arg1);
public Q_SLOTS:
//Слот обработки смены языка
void slot_LanguageChanged(QString language);
private:
Ui::MainWindow *ui;

View File

@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>Learning management system (LMS)</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
@@ -20,40 +20,6 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbLanguage">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>

Binary file not shown.

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="ru_RU">
<context>
<name>MainWindow</name>
<message>
<location filename="../mainwindow.ui" line="14"/>
<source>Learning management system (LMS)</source>
<translation>Система управления обучением (СУО)</translation>
</message>
</context>
</TS>

View File

@@ -7,6 +7,9 @@ add_library(InstructorsAndTrainees SHARED
instructorsandtraineeswidget.cpp
instructorsandtraineeswidget.h
instructorsandtraineeswidget.ui
dialogsettings.cpp
dialogsettings.h
dialogsettings.ui
commonview.cpp
commonview.h

View File

@@ -0,0 +1,45 @@
#include "dialogsettings.h"
#include "ui_dialogsettings.h"
DialogSettings::DialogSettings(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogSettings)
{
ui->setupUi(this);
ui->btnUpdateStyle->setObjectName("btnUpdateStyle");
//Задаём два пункта с текстом локалей в комбобоксе
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
}
DialogSettings::~DialogSettings()
{
delete ui;
}
void DialogSettings::changeEvent(QEvent *event)
{
// В случае получения события изменения языка приложения
if (event->type() == QEvent::LanguageChange)
{// переведём окно заново
ui->retranslateUi(this);
}
}
void DialogSettings::on_cmbLanguage_currentIndexChanged(const QString &arg1)
{
QString language;
if(arg1 == QStringLiteral("English"))
language = QString("en_EN");
else
language = QString("ru_RU");
emit signal_LanguageChanged(language);
}
void DialogSettings::on_btnUpdateStyle_clicked()
{
emit signal_UpdateStyleSheet();
}

View File

@@ -0,0 +1,39 @@
#ifndef DIALOGSETTINGS_H
#define DIALOGSETTINGS_H
#include <QDialog>
#include <QTranslator>
#include <QEvent>
namespace Ui {
class DialogSettings;
}
class DialogSettings : public QDialog
{
Q_OBJECT
public:
explicit DialogSettings(QWidget *parent = nullptr);
~DialogSettings();
protected:
void changeEvent(QEvent * event) override;
signals:
//сигнал об изменении языка интерфейса
void signal_LanguageChanged(QString language);
//сигнал об изменении стиля
void signal_UpdateStyleSheet();
private slots:
void on_cmbLanguage_currentIndexChanged(const QString &arg1);
void on_btnUpdateStyle_clicked();
private:
Ui::DialogSettings *ui;
QTranslator qtLanguageTranslator;
};
#endif // DIALOGSETTINGS_H

View File

@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogSettings</class>
<widget class="QDialog" name="DialogSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_1">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="cmbLanguage"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="btnUpdateStyle">
<property name="minimumSize">
<size>
<width>58</width>
<height>58</height>
</size>
</property>
<property name="text">
<string>Update style</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/resources/icons/style.png</normaloff>:/resources/icons/style.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -3,6 +3,7 @@
#include "instructorsandtraineeswidget.h"
#include "ui_instructorsandtraineeswidget.h"
#include "dialogauthorizationinstructor.h"
#include "dialogsettings.h"
InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
QWidget(parent),
@@ -19,7 +20,7 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
{
ui->setupUi(this);
ui->btnUpdateStyleSheet->setObjectName("btnUpdateStyleSheet");
ui->btnSettings->setObjectName("btnSettings");
#ifndef PROJECT_TYPE_DEBUG
ui->btnUpdateStyleSheet->setVisible(false);
#endif
@@ -182,7 +183,12 @@ void InstructorsAndTraineesWidget::slot_LanguageChanged(QString language)
qtLanguageTranslator.load(QString(QStringLiteral("translations/InstructorsAndTraineesWidget_")) + language, QStringLiteral("."));
qApp->installTranslator(&qtLanguageTranslator);
Q_EMIT signal_LanguageChanged(language);
emit signal_LanguageChanged(language);
}
void InstructorsAndTraineesWidget::slot_UpdateStyleSheet()
{
updateMyStyleSheet();
}
void InstructorsAndTraineesWidget::checkLoginResult(ServerAuthorization *serverAuth)
@@ -408,11 +414,6 @@ void InstructorsAndTraineesWidget::updateLabelLoggedInInstructor(QString login,
}
}
void InstructorsAndTraineesWidget::on_btnUpdateStyleSheet_clicked()
{
updateMyStyleSheet();
}
void InstructorsAndTraineesWidget::on_btnSetVersion_clicked()
{
connectorToServer->showVersionSelect();
@@ -445,3 +446,24 @@ void InstructorsAndTraineesWidget::on_tabWidget_currentChanged(int index)
ui->btnAssignTask->setEnabled(false);
}
}
void InstructorsAndTraineesWidget::on_btnSettings_clicked()
{
DialogSettings dlg(this);
connect(&dlg, &DialogSettings::signal_LanguageChanged, this, &InstructorsAndTraineesWidget::slot_LanguageChanged);
connect(&dlg, &DialogSettings::signal_UpdateStyleSheet, this, &InstructorsAndTraineesWidget::slot_UpdateStyleSheet);
switch( dlg.exec() )
{
case QDialog::Accepted:
{
break;
}
case QDialog::Rejected:
break;
default:
break;
}
}

View File

@@ -45,6 +45,10 @@ private:
public Q_SLOTS:
//Слот обработки смены языка
void slot_LanguageChanged(QString language);
//Слот обработки смены стиля
void slot_UpdateStyleSheet();
//Слот обработки результата авторизации
void checkLoginResult(ServerAuthorization * serverAuth);
//Слот обработки результата деавторизации
@@ -54,7 +58,7 @@ public Q_SLOTS:
void slot_currentItemChanged();
Q_SIGNALS:
//сигнал об изменении языка интерфейса
//Слот смены языка
void signal_LanguageChanged(QString language);
//сигнал о необходимости обновления интерфейса
void signal_NeedUpdateUI(bool treeInstructor, bool treeTrainee);
@@ -67,7 +71,6 @@ Q_SIGNALS:
private Q_SLOTS:
void on_btnConnectionToServer_clicked();
void on_btnAuthorizationInstructor_clicked();
void on_btnUpdateStyleSheet_clicked();
void on_btnSetVersion_clicked();
@@ -75,6 +78,8 @@ private Q_SLOTS:
void on_tabWidget_currentChanged(int index);
void on_btnSettings_clicked();
private:
//Авторизация инструктора локальная
bool authorizationInstructorDialog(QWidget* parent = nullptr);

View File

@@ -217,7 +217,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="btnUpdateStyleSheet">
<widget class="QToolButton" name="btnSettings">
<property name="minimumSize">
<size>
<width>58</width>
@@ -225,7 +225,20 @@
</size>
</property>
<property name="text">
<string>Update StyleSheet</string>
<string>Settings</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/resources/icons/settings.png</normaloff>:/resources/icons/settings.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>

View File

@@ -47,5 +47,7 @@
<file>resources/icons/check.png</file>
<file>resources/icons/circleRed.png</file>
<file>resources/icons/circleYellow.png</file>
<file>resources/icons/settings.png</file>
<file>resources/icons/style.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -232,6 +232,19 @@ The status will be set: &apos;completed&apos;</source>
<translation>Залогирован</translation>
</message>
</context>
<context>
<name>DialogSettings</name>
<message>
<location filename="../dialogsettings.ui" line="14"/>
<source>Settings</source>
<translation>Настройки</translation>
</message>
<message>
<location filename="../dialogsettings.ui" line="24"/>
<source>Language</source>
<translation>Язык</translation>
</message>
</context>
<context>
<name>EditorInstructors</name>
<message>
@@ -613,28 +626,33 @@ Delete it anyway?</source>
<translation>Обновить стиль</translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.ui" line="242"/>
<location filename="../instructorsandtraineeswidget.ui" line="241"/>
<source>Settings</source>
<translation>Настройки</translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.ui" line="268"/>
<source>Tasks</source>
<translation>Задачи</translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.ui" line="254"/>
<location filename="../instructorsandtraineeswidget.ui" line="280"/>
<source>AMM</source>
<translation></translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.ui" line="264"/>
<location filename="../instructorsandtraineeswidget.ui" line="290"/>
<source>FIM</source>
<translation></translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.ui" line="279"/>
<location filename="../instructorsandtraineeswidget.ui" line="305"/>
<source>Assign task</source>
<translation>Назначить задачу</translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.ui" line="116"/>
<location filename="../instructorsandtraineeswidget.cpp" line="139"/>
<location filename="../instructorsandtraineeswidget.cpp" line="141"/>
<location filename="../instructorsandtraineeswidget.cpp" line="239"/>
<location filename="../instructorsandtraineeswidget.cpp" line="264"/>
<source>Authorization Instructor</source>
@@ -647,18 +665,18 @@ Delete it anyway?</source>
<translation>нет</translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.cpp" line="137"/>
<location filename="../instructorsandtraineeswidget.cpp" line="139"/>
<location filename="../instructorsandtraineeswidget.cpp" line="207"/>
<source>Deauthorization Instructor</source>
<translation>Деавторизация инструктора</translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.cpp" line="167"/>
<location filename="../instructorsandtraineeswidget.cpp" line="169"/>
<source>Attention!</source>
<translation>Внимание!</translation>
</message>
<message>
<location filename="../instructorsandtraineeswidget.cpp" line="167"/>
<location filename="../instructorsandtraineeswidget.cpp" line="169"/>
<source>The file could not be opened </source>
<translation>Файл не может быть открыт </translation>
</message>