#include "limitssettings.h"
#include "ui_limitssettings.h"

LimitsSettings::LimitsSettings(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LimitsSettings)
{
    ui->setupUi(this);

    connect(ui->btn_cancel, SIGNAL(clicked()), this, SLOT(deleteLater()));
    connect(ui->btn_ok, SIGNAL(clicked()), this->parent(), SLOT(slot_MainWindow_set_limits_ok()));
    connect(ui->sldr_max_lim, SIGNAL(valueChanged(int)), this, SLOT(slot_LimitsSettings_show_max_lim(int)));
    connect(ui->sldr_min_lim, SIGNAL(valueChanged(int)), this, SLOT(slot_LimitsSettings_show_min_lim(int)));
}

LimitsSettings::~LimitsSettings()
{
    delete ui;
}

void LimitsSettings::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type())
    {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void LimitsSettings::updateWidgets(LbtSettings &s)//předání starého nastavení a inicializace widgetů
{
    new_settings = s;
    ui->sldr_max_lim->setSliderPosition(s.max_limit);
    ui->max_lim_label->setNum(s.max_limit);
    ui->sldr_min_lim->setSliderPosition(s.min_limit);
    ui->min_lim_label->setNum(s.min_limit);
}

void LimitsSettings::slot_LimitsSettings_show_max_lim(int max_lim)
{
    new_settings.max_limit = max_lim;
    ui->max_lim_label->setNum(max_lim);
}

void LimitsSettings::slot_LimitsSettings_show_min_lim(int min_lim)
{
    new_settings.min_limit = min_lim;
    ui->min_lim_label->setNum(min_lim);
}
