#include <QHBoxLayout>
#include <QMessageBox>

#include "mainwindow.h"
#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
      ui(new Ui::MainWindow),
      instructorsAndTraineesWidget(nullptr)
{
    ui->setupUi(this);

    instructorsAndTraineesWidget = new InstructorsAndTraineesWidget(this);

    connect(instructorsAndTraineesWidget, &InstructorsAndTraineesWidget::signal_LanguageChanged, this, &MainWindow::slot_LanguageChanged);

    ui->horizontalLayout->addWidget(instructorsAndTraineesWidget);

    this->move(0, 0);
    //this->showNormal();
    this->showMaximized();

    qtLanguageTranslator.load(QString("translations/GUIdataBaseLMS_") + instructorsAndTraineesWidget->getLanguage(), ".");
    qApp->installTranslator(&qtLanguageTranslator);
}

MainWindow::~MainWindow()
{
    delete instructorsAndTraineesWidget;
    delete ui;
}

void MainWindow::changeEvent(QEvent *event)
{
    // В случае получения события изменения языка приложения
    if (event->type() == QEvent::LanguageChange)
    {// переведём окно заново
        ui->retranslateUi(this);
    }
}

void MainWindow::slot_LanguageChanged(QString language)
{
    qtLanguageTranslator.load(QString(QStringLiteral("translations/GUIdataBaseLMS_")) + language, QStringLiteral("."));
    qApp->installTranslator(&qtLanguageTranslator);
}
