#include <QApplication>
#include <QSplashScreen>
#include <QScreen>
#include <QDir>
#include "SH_designer.h"
#include "help_window.h"
#include "SH_builtin.h"
#include "SH_plugins_manager.h"


int main(int argc, char * argv[]) {
	Q_INIT_RESOURCE(SHS_doc);
	initAbout();
	QApplication app(argc, argv);
	QApplication::setApplicationName("SH_designer");
	app.setAttribute(Qt::AA_DontUseNativeMenuBar);
	enableHighDPI();

	//HelpWindow hw;
	//hw.show();
	//return app.exec();

	//qDebug()<< app.applicationDirPath();
	//qDebug()<< QDir::setCurrent(app.applicationDirPath());
	//qDebug()<< app.applicationDirPath();

	QPixmap pixmap(":/icons/splash.png");
	QScreen * mscrn = app.primaryScreen();
	if (mscrn && !pixmap.isNull()) {
		QSize ds = mscrn->size();
		if (!ds.isNull()) {
			double wa = pixmap.width() / double(ds.width());
			double ha = pixmap.height() / double(ds.height());
			if (wa >= ha) pixmap = pixmap.scaledToWidth(ds.width() / 3, Qt::SmoothTransformation);
			else pixmap = pixmap.scaledToHeight(ds.height() / 3, Qt::SmoothTransformation);
		}
	}
	QSplashScreen splash(pixmap);
	splash.show();
	app.processEvents();
	int ret = 0;
	{
	RUNTIME->plugins_manager = new SHPluginsManager();
	SHDesigner w;
	w.show();
	if (app.arguments().size() > 1)
		for (int i = 1; i < app.arguments().size(); ++i)
			w.loadFile(app.arguments()[i]);
	splash.close();
	ret = app.exec();
	delete RUNTIME->plugins_manager;
	}
	return ret;
}
