#include "korel_form.h"
#include "ui_korel_form.h"

korel_form::korel_form(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::korel_form)
{
    ui->setupUi(this);
    img=NULL;


    //connecty:
    connect(ui->Btn_OK,SIGNAL(clicked()),this,SLOT(Btn_OK()));
    connect(ui->Btn_Show,SIGNAL(clicked()),this,SLOT(Btn_Show()));
    connect(ui->Btn_Show_2,SIGNAL(clicked()),this,SLOT(Btn_Show()));

    connect(ui->Check_Edge,SIGNAL(stateChanged(int)),this,SLOT(CheckBox_Change(int)));
    connect(ui->Check_Gaus,SIGNAL(stateChanged(int)),this,SLOT(CheckBox_Change(int)));

}

korel_form::~korel_form()
{
    delete ui;
    delete img;
}


void korel_form::load_img(my_image * new_img){
    if(img!=NULL)
        delete img;
    img=new my_image(new_img);

}

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


my_image * korel_form::apply_filt(my_image *new_image){

my_image* ret=new my_image(new_image);
my_image* pom;


if(ui->Check_Gaus->checkState()){
    int maska= ui->Text_Gaus_size->text().toInt();
    if(!(maska==1||maska==3||maska==5||maska==7||maska==9||maska==11)){
        maska=1;
        ui->Text_Gaus_size->setText(QString::number(maska));
    }
    pom= gauss_smooth(ret,maska);
    delete ret;
    ret=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;
}


        //signaly:::
void korel_form::Btn_OK(){
    this->close();
    emit this->Form_Close();
}


void korel_form::Btn_Show(){
    if(img==NULL)
        return;

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


void korel_form::CheckBox_Change(int state){
    this->Btn_Show();
    if(state)
        std::cout<<std::endl;
}







