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

#include "openfile.h"

#include <funkce.h>
#include <my_image.h>


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


  //pripojeni signalu a slotu:

    //AUTOMAT
    connect(ui->automat,SIGNAL(RUN_Automat()),this,SLOT(auto_run()));


    //pripojeni pokud je nacten uzivatelem novy obraz
    connect(ui->show_ref,SIGNAL(new_image_load(render*)),ui->haus,SLOT(RefImageIsLoaded()));
    connect(ui->show_img,SIGNAL(new_image_load(render*)),ui->haus,SLOT(ImageIsLoaded()));

    connect(ui->show_ref,SIGNAL(new_image_load(render*)),ui->haus_m,SLOT(RefImageIsLoaded()));
    connect(ui->show_img,SIGNAL(new_image_load(render*)),ui->haus_m,SLOT(ImageIsLoaded()));

    connect(ui->show_ref,SIGNAL(new_image_load(render*)),ui->ris_cis,SLOT(RefImageIsLoaded()));
    connect(ui->show_img,SIGNAL(new_image_load(render*)),ui->ris_cis,SLOT(ImageIsLoaded()));

    connect(ui->show_ref,SIGNAL(new_image_load(render*)),ui->korl,SLOT(RefImageIsLoaded()));
    connect(ui->show_img,SIGNAL(new_image_load(render*)),ui->korl,SLOT(ImageIsLoaded()));

    //pokud nejaka z metod chce nacist obraz:
    connect(ui->haus,SIGNAL(NeedLoadRef(int)),this,SLOT(LoadingRefImage(int)));
    connect(ui->haus,SIGNAL(NeedLoadImg(int)),this,SLOT(LoadingImage(int)));

    connect(ui->haus_m,SIGNAL(NeedLoadRef(int)),this,SLOT(LoadingRefImage(int)));
    connect(ui->haus_m,SIGNAL(NeedLoadImg(int)),this,SLOT(LoadingImage(int)));

    connect(ui->ris_cis,SIGNAL(NeedLoadRef(int)),this,SLOT(LoadingRefImage(int)));
    connect(ui->ris_cis,SIGNAL(NeedLoadImg(int)),this,SLOT(LoadingImage(int)));

    connect(ui->korl,SIGNAL(NeedLoadRef(int)),this,SLOT(LoadingRefImage(int)));
    connect(ui->korl,SIGNAL(NeedLoadImg(int)),this,SLOT(LoadingImage(int)));
}

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

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

void MainWindow::LoadingRefImage(int i){
    switch (i) {
        case 1:
            //((hausdorff_setting*)sender)->load_ref_image(ui->show_ref->image);
            ui->haus->load_ref_image(ui->show_ref->image);
        break;
    case 2:
            ui->haus_m->load_ref_image(ui->show_ref->image);
        break;
    case 3:
            ui->ris_cis->load_ref_image(ui->show_ref->image);
        break;
    case 4:
        ui->korl->load_ref_image(ui->show_ref->image);
        break;
    }

}


void MainWindow::LoadingImage(int i){
    //((hausdorff_setting*)sender)->load_image(ui->show_img->image);
    switch (i) {
        case 1:
            ui->haus->load_image(ui->show_img->image);
        break;
    case 2:
        ui->haus_m->load_image(ui->show_img->image);
        break;
    case 3:
        ui->ris_cis->load_image(ui->show_img->image);
        break;
    case 4:
        ui->korl->load_image(ui->show_img->image);
        break;
    }
}
