#include "ris_form.h"
#include "ui_ris_form.h"

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

    img=NULL;

    connect(ui->number,SIGNAL(valueChanged(int)),this,SLOT(ChangeNumber()));
    connect(ui->Check_Edge,SIGNAL(toggled(bool)),this,SLOT(Check_Edege()));
    connect(ui->Btn_OK,SIGNAL(clicked()),this,SLOT(Btn_OK()));
    connect(ui->Btn_Show,SIGNAL(clicked()),this,SLOT(Show_image()));

}

ris_form::~ris_form()
{
    if(this->img!=NULL)
        delete img;
    delete ui;
}

my_image * ris_form::apply_filt(my_image *new_image){
    my_image *ret=new my_image(new_image);
    my_image *pom;

    if(ui->Check_Edge->checkState()){
        double p1=ui->Text_Edge_prah1->text().toDouble();
        double p2=ui->Text_Edge_prah2->text().toDouble();
        int s=ui->Text_Edge_size->text().toInt();
        if(!(s==1||s==3||s==5||s==7||s==9||s==11)){
            s=1;
            ui->Text_Edge_size->setText(QString::number(s));
        }
        pom=edge(ret,p1,p2,s);
        delete ret;
        ret=pom;
    }
    return ret;
}


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


void ris_form::load_image(my_image *image){
    if(img!=NULL)
        delete img;
    img=new my_image(image);
}




//sloty:

void ris_form::ChangeNumber(){
    Count_Number=ui->number->value();

    Count_Cis2Ris_CIS=ui->number_CIS2RIS->value();
    Count_Cis2Ris_pocet=ui->number_CIS2RIS_pocet->value();
    Count_Cis2Ris_delka=ui->number_CIS2RIS_delka->value();

    Count_Ris_pocet=ui->number_RIS_pocet->value();
    Count_Ris_delka=ui->number_RIS_delka->value();

    Count_Cis_pocet=ui->number_CIS_pocet->value();
    Count_Cis_dif=ui->number_CIS_dif->value();
}


void ris_form::Check_Edege(){
    this->Show_image();
}

void ris_form::Btn_OK(){
    this->ChangeNumber();
    this->close();
    emit this->Form_Close();
}

void ris_form::Show_image(){
    if(img==NULL)
        return;

    my_image * newImage=this->apply_filt(img);
    show_image(newImage,-1);
    delete newImage;
}





