Settings 1

This commit is contained in:
2025-10-20 18:47:13 +03:00
parent 294a7e4a7d
commit 068a4ee14a
14 changed files with 470 additions and 43 deletions

View File

@@ -28,8 +28,7 @@ public Q_SLOTS:
private:
Ui::MainWindow *ui;
QTranslator qtLanguageTranslator;
InstructorsAndTraineesWidget* instructorsAndTraineesWidget;
QTranslator qtLanguageTranslator;
};
#endif // MAINWINDOW_H

View File

@@ -26,7 +26,7 @@
<string>Settings</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<iconset>
<normaloff>:/resources/icons/lms.png</normaloff>:/resources/icons/lms.png</iconset>
</property>
<property name="sizeGripEnabled">
@@ -232,7 +232,7 @@
<string>Save</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset>
<normaloff>:/resources/icons/circleGreen.png</normaloff>:/resources/icons/circleGreen.png</iconset>
</property>
<property name="iconSize">
@@ -291,7 +291,7 @@
<string>Version</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset>
<normaloff>:/resources/icons/updateVersion.png</normaloff>:/resources/icons/updateVersion.png</iconset>
</property>
<property name="iconSize">
@@ -323,7 +323,7 @@
<string>Style</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset>
<normaloff>:/resources/icons/style.png</normaloff>:/resources/icons/style.png</iconset>
</property>
<property name="iconSize">
@@ -359,8 +359,6 @@
</item>
</layout>
</widget>
<resources>
<include location="resources.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

View File

@@ -53,7 +53,7 @@
<string>Connection</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/connectDB.png</normaloff>:/resources/icons/connectDB.png</iconset>
</property>
<property name="iconSize">
@@ -82,7 +82,7 @@
<string>Authorization</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/login-user.png</normaloff>:/resources/icons/login-user.png</iconset>
</property>
<property name="iconSize">
@@ -111,7 +111,7 @@
<string>Trainee editor</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/DB-trainees.png</normaloff>:/resources/icons/DB-trainees.png</iconset>
</property>
<property name="iconSize">
@@ -137,7 +137,7 @@
<string>Instructor editor</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/DB-instructors.png</normaloff>:/resources/icons/DB-instructors.png</iconset>
</property>
<property name="iconSize">
@@ -163,7 +163,7 @@
<string>Personal card</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/personalCard.png</normaloff>:/resources/icons/personalCard.png</iconset>
</property>
<property name="iconSize">
@@ -202,7 +202,7 @@
<string>Settings</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/settings.png</normaloff>:/resources/icons/settings.png</iconset>
</property>
<property name="iconSize">
@@ -323,7 +323,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/resources/icons/circleGray.png</pixmap>
<pixmap resource="InstructorsAndTrainees.qrc">:/resources/icons/circleGray.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
@@ -379,7 +379,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/resources/icons/circleGray.png</pixmap>
<pixmap resource="InstructorsAndTrainees.qrc">:/resources/icons/circleGray.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
@@ -427,7 +427,7 @@
</layout>
</widget>
<resources>
<include location="resources.qrc"/>
<include location="InstructorsAndTrainees.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -7,6 +7,9 @@ add_library(ServerLMS SHARED
serverlmswidget.cpp
serverlmswidget.h
serverlmswidget.ui
dialogsettingstray.cpp
dialogsettingstray.h
dialogsettingstray.ui
clienthandler.cpp
clienthandler.h
multithreadserver.cpp

View File

@@ -14,5 +14,6 @@
<file>resources/icons/open.png</file>
<file>resources/icons/rocket.png</file>
<file>resources/icons/stop.png</file>
<file>resources/icons/settings.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,163 @@
#include "dialogsettingstray.h"
#include "ui_dialogsettingstray.h"
DialogSettingsTray::DialogSettingsTray(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogSettingsTray),
settings(nullptr),
flSettingsServerChanged(false)
{
ui->setupUi(this);
settings = new DBSettings;
//Задаём два пункта с текстом локалей в комбобоксе
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
if(loadSettings(settings))
{
if(settings->Language == "ENG")
ui->cmbLanguage->setCurrentText("English");
else
ui->cmbLanguage->setCurrentText("Русский");
//ui->editAddress->setText(settings->Address);
//ui->editPort->setText(settings->Port);
}
ui->btnSave->setEnabled(false);
flSettingsServerChanged = false;
}
DialogSettingsTray::~DialogSettingsTray()
{
delete ui;
delete settings;
}
DBSettings DialogSettingsTray::getSettings()
{
return *settings;
}
bool DialogSettingsTray::loadSettings(DBSettings *settings)
{
/*
QFile file(settingsName);
if(! file.open(QIODevice::ReadOnly))
return false;
QXmlStreamReader xmlReader(&file);
while (!xmlReader.atEnd()){
if(xmlReader.isStartElement()){
if(xmlReader.name() == "ServerSettings")
{
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes()){
QString name = attr.name().toString();
QString value = attr.value().toString();
if(name == "Address"){
settings->Address = value;
}
if(name == "Port"){
settings->Port = value;
}
if(name == "Language"){
settings->Language = value;
}
if(name == "AutoStart"){
settings->isAutoStart = value.toInt();
}
}
}
}
xmlReader.readNext();
}
file.close();
*/
return true;
}
void DialogSettingsTray::on_cmbLanguage_currentTextChanged(const QString &arg1)
{
}
void DialogSettingsTray::on_btnSave_clicked()
{
if(ui->cmbLanguage->currentText() == QStringLiteral("English"))
{
settings->Language = "ENG";
}
else
{
settings->Language = "RUS";
}
//settings->Address = ui->editAddress->text();
//settings->Port = ui->editPort->text();
saveSettings();
this->accept();
}
bool DialogSettingsTray::saveSettings()
{
/*
QFile file(settingsName);
if(! file.open(QIODevice::WriteOnly))
return false;
QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("ServerSettingsContainer");
xmlWriter.writeStartElement("ServerSettings");
xmlWriter.writeAttribute("Address", settings->Address);
xmlWriter.writeAttribute("Port", settings->Port);
xmlWriter.writeAttribute("Language", settings->Language);
xmlWriter.writeAttribute("AutoStart", QString::number(settings->isAutoStart));
xmlWriter.writeEndElement();
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
file.close();
*/
return true;
}
void DialogSettingsTray::on_cmbLanguage_currentIndexChanged(int index)
{
ui->btnSave->setEnabled(true);
}
void DialogSettingsTray::on_DialogSettingsTray_accepted()
{
QString language;
if(settings->Language == "ENG")
language = QString("en_EN");
else
language = QString("ru_RU");
emit signal_LanguageChanged(language);
}

View File

@@ -0,0 +1,56 @@
#ifndef DIALOGSETTINGSTRAY_H
#define DIALOGSETTINGSTRAY_H
#include <QDialog>
#include <QTranslator>
#include <QEvent>
class DBSettings{
public:
QString Address;
QString Port;
QString Language;
};
namespace Ui {
class DialogSettingsTray;
}
class DialogSettingsTray : public QDialog
{
Q_OBJECT
public:
explicit DialogSettingsTray(QWidget *parent = nullptr);
~DialogSettingsTray();
DBSettings getSettings();
bool settingsServerIsChanged(){ return flSettingsServerChanged;}
static bool loadSettings(DBSettings *settings);
signals:
//сигнал об изменении языка интерфейса
void signal_LanguageChanged(QString language);
private slots:
void on_cmbLanguage_currentTextChanged(const QString &arg1);
void on_btnSave_clicked();
void on_cmbLanguage_currentIndexChanged(int index);
void on_DialogSettingsTray_accepted();
private:
bool saveSettings();
private:
Ui::DialogSettingsTray *ui;
DBSettings *settings;
bool flSettingsServerChanged;
};
#endif // DIALOGSETTINGSTRAY_H

View File

@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogSettingsTray</class>
<widget class="QDialog" name="DialogSettingsTray">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_Main">
<item>
<widget class="QGroupBox" name="groupBox_Main">
<property name="title">
<string>Main</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_Main">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_Language">
<item>
<widget class="QLabel" name="label_Language">
<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>
<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_Save">
<item>
<widget class="QToolButton" name="btnSave">
<property name="minimumSize">
<size>
<width>58</width>
<height>58</height>
</size>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="icon">
<iconset resource="../InstructorsAndTrainees/InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/circleGreen.png</normaloff>:/resources/icons/circleGreen.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>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../InstructorsAndTrainees/InstructorsAndTrainees.qrc"/>
</resources>
<connections/>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -6,8 +6,12 @@
#include <QThread>
#include <QErrorMessage>
#include "serverlmswidget.h"
#include "dialogsettingstray.h"
#include "ui_serverlmswidget.h"
const QString ServerLMSWidget::languageENG = "en_EN";
const QString ServerLMSWidget::languageRUS = "ru_RU";
ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ServerLMSWidget),
@@ -17,7 +21,8 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
dataParser(nullptr),
processingSystem(nullptr),
updateController(nullptr),
providerDBLMS(nullptr)
providerDBLMS(nullptr),
language(languageENG)
{
ui->setupUi(this);
mutex = new QMutex;
@@ -145,6 +150,8 @@ void ServerLMSWidget::slot_LanguageChanged(QString language)
{
qtLanguageTranslator.load(QString("translations/ServerLMS_") + language, ".");
qApp->installTranslator(&qtLanguageTranslator);
emit signal_LanguageChanged(language);
}
void ServerLMSWidget::on_btnStartServer_clicked()
@@ -192,3 +199,44 @@ void ServerLMSWidget::changeEvent(QEvent *event)
ui->lblDBsettings->setText(strDBsettings);
}
}
void ServerLMSWidget::on_cmbLanguage_currentTextChanged(const QString &arg1)
{
}
void ServerLMSWidget::on_btnSettings_clicked()
{
DialogSettingsTray dlg(this);
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
connect(&dlg, &DialogSettingsTray::signal_LanguageChanged, this, &ServerLMSWidget::slot_LanguageChanged);
//connect(&dlg, &DialogSettingsTray::signal_UpdateStyleSheet, this, &InstructorsAndTraineesWidget::slot_UpdateStyleSheet);
switch( dlg.exec() )
{
case QDialog::Accepted:
{
language = dlg.getSettings().Language;
if(dlg.settingsServerIsChanged())
{
//SpecialMessageBox(this, SpecialMessageBox::TypeSpecMsgBox::warningClose, tr("Server settings have been changed. Please reconnect to the server.")).exec();
//flSettingsServerIsChanged = true;
//if(authorizationIsCompleted())
//deAuthorizationInstructor(loginInstructorLoggedInLocal);
//connectorToServer->StopConnectToServer();
}
break;
}
case QDialog::Rejected:
break;
default:
break;
}
}

View File

@@ -49,6 +49,10 @@ public:
explicit ServerLMSWidget(QWidget *parent = nullptr);
~ServerLMSWidget();
public:
static const QString languageENG;
static const QString languageRUS;
void setError(int code);
protected:
@@ -63,6 +67,9 @@ signals:
QTcpSocket* sigGetSocket();
//сигнал смены языка
void signal_LanguageChanged(QString language);
public slots:
void slot_LanguageChanged(QString language);
void slotUpdateListClients();
@@ -87,6 +94,10 @@ private slots:
void on_btnStartServer_clicked();
void on_btnStopServer_clicked();
void on_cmbLanguage_currentTextChanged(const QString &arg1);
void on_btnSettings_clicked();
private:
Ui::ServerLMSWidget *ui;
@@ -108,6 +119,7 @@ private:
bool first = true; // для тестов Unity
QTranslator qtLanguageTranslator;
QString language;
int errorCode;
};

View File

@@ -28,8 +28,8 @@
<widget class="QToolButton" name="btnStartServer">
<property name="minimumSize">
<size>
<width>80</width>
<height>55</height>
<width>130</width>
<height>58</height>
</size>
</property>
<property name="maximumSize">
@@ -51,7 +51,7 @@
<string>Start</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="ServerLMS.qrc">
<normaloff>:/resources/icons/rocket.png</normaloff>:/resources/icons/rocket.png</iconset>
</property>
<property name="iconSize">
@@ -69,8 +69,8 @@
<widget class="QToolButton" name="btnStopServer">
<property name="minimumSize">
<size>
<width>80</width>
<height>55</height>
<width>130</width>
<height>58</height>
</size>
</property>
<property name="maximumSize">
@@ -92,7 +92,7 @@
<string>Stop</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<iconset resource="ServerLMS.qrc">
<normaloff>:/resources/icons/stop.png</normaloff>:/resources/icons/stop.png</iconset>
</property>
<property name="iconSize">
@@ -106,6 +106,25 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblOnOff">
<property name="maximumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="ServerLMS.qrc">:/resources/icons/switchOff.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -120,21 +139,28 @@
</spacer>
</item>
<item>
<widget class="QLabel" name="lblOnOff">
<property name="maximumSize">
<widget class="QToolButton" name="btnSettings">
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
<width>130</width>
<height>58</height>
</size>
</property>
<property name="text">
<string/>
<string>Settings</string>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/resources/icons/switchOff.png</pixmap>
<property name="icon">
<iconset resource="../InstructorsAndTrainees/InstructorsAndTrainees.qrc">
<normaloff>:/resources/icons/settings.png</normaloff>:/resources/icons/settings.png</iconset>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
@@ -263,7 +289,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/resources/icons/open.png</pixmap>
<pixmap resource="ServerLMS.qrc">:/resources/icons/open.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
@@ -279,7 +305,8 @@
</layout>
</widget>
<resources>
<include location="resources.qrc"/>
<include location="../InstructorsAndTrainees/InstructorsAndTrainees.qrc"/>
<include location="ServerLMS.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -6,7 +6,7 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_serverLMSWidget(nullptr),
serverLMSWidget(nullptr),
trayIcon(nullptr),
menu(nullptr),
action_ShowWindow(nullptr),
@@ -18,11 +18,11 @@ MainWindow::MainWindow(QWidget *parent) :
//Задаём два пункта с текстом локалей в комбобоксе
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
m_serverLMSWidget = new ServerLMSWidget(this);
serverLMSWidget = new ServerLMSWidget(this);
ui->verticalLayout_1->addWidget(m_serverLMSWidget);
ui->verticalLayout_1->addWidget(serverLMSWidget);
connect(this, &MainWindow::signal_LanguageChanged, m_serverLMSWidget, &ServerLMSWidget::slot_LanguageChanged);
connect(serverLMSWidget, &ServerLMSWidget::signal_LanguageChanged, this, &MainWindow::slot_LanguageChanged);
//this->move(0, 0);
//this->showNormal();
@@ -115,7 +115,7 @@ void MainWindow::exit()
MainWindow::~MainWindow()
{
delete m_serverLMSWidget;
delete serverLMSWidget;
delete trayIcon;
delete ui;
}
@@ -146,7 +146,7 @@ void MainWindow::on_cmbLanguage_currentIndexChanged(const QString &arg1)
void MainWindow::errorCheck()
{
if(m_serverLMSWidget->hasError() == 100)
if(serverLMSWidget->hasError() == 100)
{
QMessageBox msgBox;
@@ -193,3 +193,9 @@ void MainWindow::slot_Menu_Exit()
this->hide();
this->close();
}
void MainWindow::slot_LanguageChanged(QString language)
{
qtLanguageTranslator.load(QString(QStringLiteral("translations/TrayServerLMS_")) + language, QStringLiteral("."));
qApp->installTranslator(&qtLanguageTranslator);
}

View File

@@ -36,6 +36,10 @@ protected:
*/
void closeEvent(QCloseEvent * event) override;
public slots:
//Слот обработки смены языка
void slot_LanguageChanged(QString language);
private slots:
//Слот нажатия на иконку приложения в трее
void slot_IconActivated(QSystemTrayIcon::ActivationReason reason);
@@ -60,7 +64,7 @@ private:
private:
Ui::MainWindow *ui;
ServerLMSWidget* m_serverLMSWidget;
ServerLMSWidget* serverLMSWidget;
QTranslator qtLanguageTranslator;
QSystemTrayIcon* trayIcon;