mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
refact struct projects
This commit is contained in:
232
InstructorsAndTrainees/settings/dialogsettings.cpp
Normal file
232
InstructorsAndTrainees/settings/dialogsettings.cpp
Normal file
@@ -0,0 +1,232 @@
|
||||
#include "dialogsettings.h"
|
||||
#include "ui_dialogsettings.h"
|
||||
#include "tools.h"
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QRegExpValidator>
|
||||
|
||||
DialogSettings::DialogSettings(ConnectorToServer* connectorToServer, bool instructorIsLogged, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogSettings),
|
||||
settings(nullptr),
|
||||
connectorToServer(nullptr),
|
||||
flSettingsServerChanged(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->btnUpdateStyle->setObjectName("btnUpdateStyle");
|
||||
ui->btnSetVersion->setObjectName("btnSetVersion");
|
||||
ui->btnSave->setObjectName("btnSave");
|
||||
ui->checkAutoStart->setObjectName("checkAutoStart");
|
||||
|
||||
#ifndef PROJECT_TYPE_DEBUG
|
||||
ui->btnUpdateStyle->setVisible(false);
|
||||
#endif
|
||||
|
||||
this->connectorToServer = connectorToServer;
|
||||
|
||||
/* Создаем строку для регулярного выражения */
|
||||
QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
|
||||
/* Создаем регулярное выражение с применением строки, как
|
||||
* повторяющегося элемента
|
||||
*/
|
||||
QRegExp ipRegex ("^" + ipRange
|
||||
+ "\\." + ipRange
|
||||
+ "\\." + ipRange
|
||||
+ "\\." + ipRange + "$");
|
||||
/* Создаем Валидатор регулярного выражения с применением
|
||||
* созданного регулярного выражения
|
||||
*/
|
||||
QRegExpValidator *ipValidator = new QRegExpValidator(ipRegex, this);
|
||||
/* Устанавливаем Валидатор на QLineEdit */
|
||||
ui->editAddress->setValidator(ipValidator);
|
||||
|
||||
settings = new ServerSettings;
|
||||
|
||||
//Задаём два пункта с текстом локалей в комбобоксе
|
||||
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->checkAutoStart->setChecked(settings->isAutoStart);
|
||||
}
|
||||
|
||||
ui->btnSetVersion->setEnabled(false);
|
||||
if(connectorToServer)
|
||||
if(connectorToServer->getIsConnected())
|
||||
{
|
||||
if(instructorIsLogged)
|
||||
ui->btnSetVersion->setEnabled(true);
|
||||
}
|
||||
|
||||
ui->label_AutoStart->setVisible(false);
|
||||
ui->checkAutoStart->setVisible(false);
|
||||
|
||||
ui->btnSave->setEnabled(false);
|
||||
flSettingsServerChanged = false;
|
||||
}
|
||||
|
||||
DialogSettings::~DialogSettings()
|
||||
{
|
||||
delete ui;
|
||||
delete settings;
|
||||
}
|
||||
|
||||
ServerSettings DialogSettings::getSettings()
|
||||
{
|
||||
return *settings;
|
||||
}
|
||||
|
||||
void DialogSettings::changeEvent(QEvent *event)
|
||||
{
|
||||
// В случае получения события изменения языка приложения
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
{// переведём окно заново
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
|
||||
void DialogSettings::on_btnUpdateStyle_clicked()
|
||||
{
|
||||
emit signal_UpdateStyleSheet();
|
||||
}
|
||||
|
||||
bool DialogSettings::loadSettings(ServerSettings *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;
|
||||
}
|
||||
|
||||
bool DialogSettings::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 DialogSettings::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();
|
||||
settings->isAutoStart = ui->checkAutoStart->isChecked();
|
||||
|
||||
saveSettings();
|
||||
|
||||
this->accept();
|
||||
}
|
||||
|
||||
void DialogSettings::on_btnSetVersion_clicked()
|
||||
{
|
||||
if(connectorToServer)
|
||||
if(connectorToServer->getIsConnected())
|
||||
connectorToServer->sendShowVersionSelect();
|
||||
}
|
||||
|
||||
void DialogSettings::on_cmbLanguage_currentIndexChanged(int index)
|
||||
{
|
||||
ui->btnSave->setEnabled(true);
|
||||
}
|
||||
|
||||
void DialogSettings::on_editAddress_textChanged(const QString &arg1)
|
||||
{
|
||||
ui->btnSave->setEnabled(true);
|
||||
flSettingsServerChanged = true;
|
||||
}
|
||||
|
||||
void DialogSettings::on_editPort_textChanged(const QString &arg1)
|
||||
{
|
||||
ui->btnSave->setEnabled(true);
|
||||
flSettingsServerChanged = true;
|
||||
}
|
||||
|
||||
void DialogSettings::on_DialogSettings_accepted()
|
||||
{
|
||||
QString language;
|
||||
|
||||
if(settings->Language == "ENG")
|
||||
language = QString("en_EN");
|
||||
else
|
||||
language = QString("ru_RU");
|
||||
|
||||
emit signal_LanguageChanged(language);
|
||||
}
|
||||
59
InstructorsAndTrainees/settings/dialogsettings.h
Normal file
59
InstructorsAndTrainees/settings/dialogsettings.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef DIALOGSETTINGS_H
|
||||
#define DIALOGSETTINGS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTranslator>
|
||||
#include <QEvent>
|
||||
#include "Datas.h"
|
||||
#include "connectortoserver.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogSettings;
|
||||
}
|
||||
|
||||
class DialogSettings : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogSettings(ConnectorToServer* connectorToServer, bool instructorIsLogged, QWidget *parent = nullptr);
|
||||
~DialogSettings();
|
||||
|
||||
ServerSettings getSettings();
|
||||
|
||||
bool settingsServerIsChanged(){ return flSettingsServerChanged;}
|
||||
|
||||
static bool loadSettings(ServerSettings *settings);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * event) override;
|
||||
|
||||
signals:
|
||||
//сигнал об изменении языка интерфейса
|
||||
void signal_LanguageChanged(QString language);
|
||||
//сигнал об изменении стиля
|
||||
void signal_UpdateStyleSheet();
|
||||
|
||||
private slots:
|
||||
void on_btnUpdateStyle_clicked();
|
||||
void on_btnSave_clicked();
|
||||
void on_btnSetVersion_clicked();
|
||||
void on_cmbLanguage_currentIndexChanged(int index);
|
||||
void on_editAddress_textChanged(const QString &arg1);
|
||||
void on_editPort_textChanged(const QString &arg1);
|
||||
void on_DialogSettings_accepted();
|
||||
|
||||
private:
|
||||
bool saveSettings();
|
||||
|
||||
private:
|
||||
Ui::DialogSettings *ui;
|
||||
QTranslator qtLanguageTranslator;
|
||||
|
||||
ServerSettings *settings;
|
||||
ConnectorToServer* connectorToServer;
|
||||
|
||||
bool flSettingsServerChanged;
|
||||
};
|
||||
|
||||
#endif // DIALOGSETTINGS_H
|
||||
376
InstructorsAndTrainees/settings/dialogsettings.ui
Normal file
376
InstructorsAndTrainees/settings/dialogsettings.ui
Normal file
@@ -0,0 +1,376 @@
|
||||
<?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>500</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/lms.png</normaloff>:/resources/icons/lms.png</iconset>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>false</bool>
|
||||
</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="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Main</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<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>
|
||||
<widget class="Line" name="line">
|
||||
<property name="lineWidth">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_Server">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Server</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_Server">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Address">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Address">
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_Address">
|
||||
<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="QLineEdit" name="editAddress">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Port">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Port">
|
||||
<property name="text">
|
||||
<string>Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_Port">
|
||||
<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="QLineEdit" name="editPort">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>70</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_AutoStart">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_AutoStart">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Auto start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_AutoStart">
|
||||
<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="QCheckBox" name="checkAutoStart">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</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="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="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>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_Additional">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Additional</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_Additional">
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnSetVersion">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>58</width>
|
||||
<height>58</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Version</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/updateVersion.png</normaloff>:/resources/icons/updateVersion.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>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnUpdateStyle">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>58</width>
|
||||
<height>58</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Style</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="InstructorsAndTrainees.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>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_Additional">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="InstructorsAndTrainees.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user