#include "view.h"
#include <QIntValidator>
#include <Controller/controller.h>
#include <QFileDialog>
#include <QMouseEvent>
#include <QTextBrowser>
#include <Common/constants.h>
#include <QCoreApplication>

View::View(QWidget *parent) :
    QMainWindow(parent)
{
    setAttribute(Qt::WA_DeleteOnClose);
}

void View::show(QPoint position, QSize size)
{
    resize(size);
    move(position);
    QMainWindow::show();
}

void View::setIntValidators(QLineEdit *input,int min, int max)
{
    input->setValidator(new QIntValidator(min, max, this));
    input->setText(QString::number(min));
}

QString View::selectImage()
{   
    QString path = QFileDialog::getOpenFileName(this,tr("Seleccione una imagen"), ".", "Images (*.png *.jpg *.jpeg)", nullptr, QFileDialog::DontUseNativeDialog );
    QFileInfo file(path);

    if(!file.exists()) return QString("");
    return path;
}

int View::checkNumberElements(int numberOfElements)
{
    if(numberOfElements < Constants::General::MIN_NUM_ELEMENTS)
    {
        return Constants::General::MIN_NUM_ELEMENTS;
    }else if(numberOfElements > Constants::General::MAX_NUM_ELEMENTS)
    {
        return Constants::General::MAX_NUM_ELEMENTS;
    }

    return numberOfElements;

}

QString View::getRootHelpPath()
{
    return QCoreApplication:: applicationDirPath();
}

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