#include <QApplication>
#include <QColor>
#include <QFileInfo>
#include <QPalette>
#include "MainWindow.h"
#include "ui_MainWindow.h"

#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);
	QColor bgColor = palette().color(QPalette::Base);
	QColor red(Qt::red);
	QColor blendColor = QColor((bgColor.red() * 4 + red.red()) / 5, (bgColor.green() * 4 + red.green()) / 5,  (bgColor.blue() * 4 + red.blue()) / 5);
	ui->directoryEdit->setProperty("inputInvalid", true);
	ui->fileEdit->setProperty("inputInvalid", true);
	qApp->setStyleSheet("*[inputInvalid='true'] { background-color: " + blendColor.name() + "; }");
}

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


void MainWindow::on_directoryEdit_textChanged(const QString &text)
{
	QFileInfo info(text);
	bool invalid = true;
	if (info.isDir()) {
		invalid = false;
	}
	ui->directoryEdit->setProperty("inputInvalid", invalid);
	ui->directoryEdit->style()->unpolish(ui->directoryEdit);
	ui->directoryEdit->ensurePolished();
}

void MainWindow::on_fileEdit_textChanged(const QString &text)
{
	QFileInfo info(text);
	bool invalid = true;
	if (info.isFile()) {
		invalid = false;
	}
	ui->fileEdit->setProperty("inputInvalid", invalid);
	ui->fileEdit->style()->unpolish(ui->fileEdit);
	ui->fileEdit->ensurePolished();
}
