#ifndef SH_UI_LOADER_H
#define SH_UI_LOADER_H

#include <QElapsedTimer>
#include <QUiLoader>
#include <QMap>

class SHSGraphic;

class SHSUiLoader: public QUiLoader
{
public:
	SHSUiLoader();
	

	QWidget * load(QIODevice * device, QWidget * parentWidget = Q_NULLPTR, bool emit_appevents = false);
	QWidget * load(QByteArray data, QWidget * parentWidget = Q_NULLPTR, bool emit_appevents = false);
	void adjust(QWidget * form);

	QWidget * createWidget(const QString & className, QWidget * parent = 0, const QString & name = QString()) override;
	
	static QString prepareUI(const QString & file, const QString & src);
	static QStringList iconsRegexpList();

	QObjectList loaded_widgets;
	QMap<QWidget*, QList<QWidget*> > loaded_tree;
	QList<SHSGraphic*> graphics;
	QStringList graphic_variables;
	QMap<QString, QList<QPair<SHSGraphic*, int>>> variables_map;

private:
	bool eventFilter(QObject * o, QEvent * e) override;
	void checkAppEvents();

	QElapsedTimer etm;
	bool appevents;
	
};


#endif // SH_UI_LOADER_H
