#ifndef DRYCONDESIGNER_H
#define DRYCONDESIGNER_H

#include <QMainWindow>
#include <QListWidget>
#include <QTreeWidget>
#include <emainwindow.h>
#include <ribbon.h>
#include <qsingleapplication.h>
#include "ui_device_designer.h"
#include "session_manager.h"
#include "SH_plugin_widgets.h"


class DeviceDesigner: public EMainWindow, public Ui::DeviceDesigner, public PIObject {
	Q_OBJECT
	PIOBJECT(DeviceDesigner)
public:
	explicit DeviceDesigner();
	~DeviceDesigner();

	void showMain();
	void loadFile(const QString & fp);
	bool isFirst() const;

protected:
	void closeEvent(QCloseEvent*) override;
	void reset(bool full = false) override;
	bool load(const QString & path) override;
	bool save(const QString & path) override;
	QString loadFilter() override;
	QString saveFilter() override;
	virtual void setAddress(int a) {}
	virtual void setDevice(const QString & d) {}

private:
	void savingSession(QPIConfig & conf) override;
	void loadingSession(QPIConfig & conf) override;
	void initAbout();
	bool procArgs(const QStringList & args, bool check = false);
	void assignEditor(int index);

	struct Editor {
		Editor() {base = 0; main_widget = 0; center = 0;}
		static Editor make(SHBlockWidgetBase * e);
		SHBlockWidgetBase * base;
		QWidget * main_widget;
		QWidget * center;
		QList<QAction*> menus;
		QList<QDockWidget*> docks;
	};

	Editor * editor;
	QList<Editor> editors;
	QMap<QString, int> extensions;
	QString load_filters;
	Ribbon * ribbon;

public slots:
	void unchange();
	void showAbout();
	void on_widgetDevice_opened();
	void on_widgetDevice_closed();
	void on_widgetDevice_readed(QByteArray data);

private slots:
	void anotherAppMessage(QByteArray data);

};

#endif // DRYCONDESIGNER_H
