/* NAME: Kirill Vasil'evich Timofeev, 322
 * ASGN: N1
 */
#include <QtGui>

#include "View.h"
#include "Controller.h"

View::View()
{
}

View::~View()
{
}

MainWindow::MainWindow()
{
    window = new QWidget;
    mainLayout= new QVBoxLayout;
    labelIm = new QLabel;
    layout1 = new QHBoxLayout;
    layout2 = new QHBoxLayout;
    button1 = new QPushButton("&Train");
    button2 = new QPushButton("&Searching in the directory");
    button3 = new QPushButton("&Searching in an image");
    button4 = new QPushButton("&Exit");
    button6 = new QPushButton("&Precision and Recall");
    image = new QPixmap;


    layout2->addWidget(button1, 8);
    layout2->addWidget(button2, 8);
    layout2->addWidget(button3, 8);
    layout2->addWidget(button6, 8);
    layout2->addWidget(button4, 8);
    layout1->addWidget(labelIm);
    mainLayout->addLayout(layout2);
    mainLayout->addLayout(layout1);
    window->setLayout(mainLayout);
    setCentralWidget(window);

    statusBar()->showMessage(tr("Ready"));
    setWindowTitle("Claasif");
    show();
}

MainWindow::~MainWindow()
{
    delete PRAct;
    delete trainAct;
    delete serDirAct;
    delete serImAct;
    delete exitAct;

    delete image;
    delete button1;
    delete button2;
    delete button3;
    delete button4;
    delete button6;
    delete labelIm;
    delete layout1;
    delete layout2;
    delete mainLayout;
    delete window;

}

void MainWindow::mesBox(char *temp)
{
    QMessageBox msgBox;
    msgBox.setWindowTitle("Message");
    msgBox.setText(temp);
    msgBox.exec();
}

QString MainWindow::message(QString msg, bool fil)
{
    QMessageBox msgBox;
    msgBox.setWindowTitle("Message");
    msgBox.setText(msg);
    msgBox.exec();
    QString newStr;
    do
    {
        if (fil) newStr = QFileDialog::getOpenFileName(this);
        else newStr = QFileDialog::getExistingDirectory(this);
    }
    while (newStr.isEmpty());

    return newStr;
}

void MainWindow::showMessage(const QString msg, const bool b, QImage* temp)
{
    statusBar()->showMessage(msg, 2000);
    if (b)
    {
        image->convertFromImage(*temp);
        labelIm->setPixmap(*image);
    }

}

void MainWindow::exit()
{
    QMessageBox msgBox;
    msgBox.setWindowTitle("Exit");
    msgBox.setText("Thank you for using my Program)) Goodbye!!");
    msgBox.exec();
    close();
}

void MainWindow::controlActions(Controller *t, char* temp)
{

    PRAct = new QAction(tr("&Count Precision and Recall..."), this);
    PRAct->setStatusTip(tr("Count Precision and Recall"));
    connect(button6, SIGNAL(pressed()), t, SLOT(PRcount()));

    trainAct = new QAction(tr("&train..."), this);
    trainAct->setStatusTip(tr("train"));
    connect(button1, SIGNAL(pressed()), t, SLOT(training()));

    serDirAct = new QAction(tr("&tra..."), this);
    serDirAct->setStatusTip(tr("tra"));
    connect(button2, SIGNAL(pressed()), t, SLOT(serDir()));

    serImAct = new QAction(tr("&tr..."), this);
    serImAct->setStatusTip(tr("tr"));
    connect(button3, SIGNAL(pressed()), t, SLOT(serIn()));

    exitAct = new QAction(tr("&in..."), this);
    exitAct->setStatusTip(tr("in"));
    connect(button4, SIGNAL(pressed()), t, SLOT(exit()));
}
