#ifndef QCD_CORE_H
#define QCD_CORE_H

#include <QObject>
#include <QMultiMap>
#include <QVariant>
#include "piobject.h"
#include "cdutils_types.h"


class QCDCore;


class __QCore_Initializer__ {
public:
	__QCore_Initializer__();
	~__QCore_Initializer__();
	static int count_;
	static QCDCore * __instance__;
};


class QCDCore: public QObject, public PIObject
{
	Q_OBJECT
	PIOBJECT(QCDCore)
	friend class __QCore_Initializer__;
public:
	static QCDCore * instance() {return __QCore_Initializer__::__instance__;}

	int bindWindow(QWidget * wnd);
	int bindWidgets(QList<QWidget * > wl);
	bool bindWidget(QWidget * w);
	bool bindWidget(QWidget * w, const CDUtils::CDType & k);

	int unbindWindow(QWidget * wnd);
	int unbindWidgets(QList<QWidget * > wl);
	bool unbindWidget(QWidget * w);
	void unbindAllWidgets();

	void updateBindedWidget(const CDUtils::CDType & k_);
	void setDirectKEnabled(bool yes) {direct_on = yes;}
	bool isDirectKEnabled() const {return direct_on;}

private:
	QCDCore();
	~QCDCore();

	void bindView(QWidget * v);
	void setWidgetValue(QWidget * w, const CDUtils::CDType & k);
	void finishEdit(const QList<PIDeque<int> > & pathes);
	EVENT_HANDLER(void, K_ChangedGlobal);

	QMultiMap<QWidget * , PIDeque<int> > binded_widgets;
	bool updating, direct_on;

private slots:
	void slotBool(bool v);
	void slotInt(int v);
	void slotDouble(double v);
	void slotText(QString v);
	void slotVariant(QVariant v);
	void slotDestroyed(QObject * );

public slots:
	void updateBindedWidgets();

signals:
	void updateViewRequest();

};


static __QCore_Initializer__ __QCore_initializer__;


#endif // QCD_CORE_H
