#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <Controller/mainwindowcontroller.h>
#include <QGridLayout>
#include <QMessageBox>
#include <QPushButton>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    controller = new MainWindowController(this);
    this->setWindowTitle(tr("Hello"));
    ui->retranslateUi(this);    
}

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

void MainWindow::showError(int numErrors, QString errors)
{
    QMessageBox errorMessage(this);
    errorMessage.setWindowTitle(tr("Ups!, algo inesperado ha ocurrido"));
    errorMessage.setIconPixmap(QPixmap(":/resources/icon/error.png").scaled(40,40,Qt::KeepAspectRatio, Qt::SmoothTransformation));
    errorMessage.setText(QString(tr("Se han encontrado %1 error(es)")).arg(numErrors));
    errorMessage.setDetailedText(errors);
    errorMessage.setFixedSize(500,500);
    errorMessage.exec();
}

void MainWindow::on_menuBtn_clicked()
{
    controller->createMenuScreen();
}

void MainWindow::on_infoBtn_clicked()
{
    controller->createInformationScreen();
}

void MainWindow::on_inkBtn_clicked()
{
    controller->createInkScreen();
}

void MainWindow::on_editBtn_clicked()
{

    controller->edit();
}

void MainWindow::on_settingsBtn_clicked()
{
    controller->settingsOption();
}

void MainWindow::on_helpBtn_clicked()
{    
    controller->helpOption();
}

void MainWindow::moveEvent(QMoveEvent *event)
{
    currentPosition = event->pos();
}

QPoint MainWindow::getCurrentPosition() const
{
    return currentPosition;
}


void MainWindow::on_editBtnUp_clicked()
{
    controller->edit();
}

void MainWindow::on_editBtnDown_clicked()
{
    controller->edit();
}

void MainWindow::on_infoBtnUp_clicked()
{
    controller->createInformationScreen();
}

void MainWindow::on_infoBtnDown_clicked()
{
    controller->createInformationScreen();
}

void MainWindow::on_menuBtnUp_clicked()
{
    controller->createMenuScreen();
}

void MainWindow::on_menuBtnDown_clicked()
{
    controller->createMenuScreen();
}

void MainWindow::on_inkBtnUp_clicked()
{
    controller->createInkScreen();
}

void MainWindow::on_inkBtnDown_clicked()
{
    controller->createInkScreen();
}

void MainWindow::on_startBtn_clicked()
{
    setEnabled(true);
}

void MainWindow::closeEvent(QCloseEvent *e)
{
    foreach(QWidget *w, qApp->topLevelWidgets()) {
        if(QString::compare(w->metaObject()->className(), "BeforeStart") == 0 ||
           QString::compare(w->metaObject()->className(), "EditScreen") == 0 )
        {
            w->close();
            break;
        }
    }
}
