/**
** This file is owned by VisualGear Technology Co., Ltd.
** Unauthorized copying of this file, via any medium is strictly prohibited
** Otherwise VisualGear Technology Co., Ltd. will have the right to pursue
** maximum responsibilities within scope of legal.
**
** Copyright 2018-2020 VisualGear All rights reserved.
**/

#pragma once

#include <QtWidgets/QWidget>
#include <QVector>
#include <QVariant>

#include "UIGQMacro.h"

namespace Json
{
	class Value;
};

#define UIGQT_GET_CONTROLBASE \
public: \
    Q_PROPERTY(QString jsonData READ jsonData WRITE setJsonData DESIGNABLE true) \
    QString jsonData() const; \
    void setJsonData(const QString &data); \
    QString m_jsonData; \
public:  \
UIGQWidgetBase* getControlBase() \
{	return &_controlBase; } \
void setThemeName(const QString& themeName){ _controlBase.setThemeName(themeName); } \
QString getThemeName() const{ return _controlBase.getThemeName(); } \
bool readJsonValue(void* value); \
void setLayoutRatio(int ratio){ _controlBase.setLayoutRatio(ratio); } \
int getLayoutRatio() const{ return _controlBase.getLayoutRatio(); } \
void setWidthPolicy(LayoutSizePolicy policy){ _controlBase.setWidthPolicy(policy); } \
LayoutSizePolicy getWidthPolicy() const{ return _controlBase.getWidthPolicy(); } \
void setHeightPolicy(LayoutSizePolicy policy){ _controlBase.setHeightPolicy(policy); } \
LayoutSizePolicy getHeightPolicy() const{ return _controlBase.getHeightPolicy(); } \
void setAbsoluteLayout(bool absoluteLayout){ _controlBase.setAbsoluteLayout(absoluteLayout); } \
bool getAbsoluteLayout() const{ return _controlBase.getAbsoluteLayout(); } \
void setAbsoluteDock(DockLayoutType hor, DockLayoutType ver, int offsetX = 0, int offsetY = 0){ _controlBase.setAbsoluteDock(hor, ver, offsetX, offsetY); } \
void getAbsoluteDock(DockLayoutType& hor, DockLayoutType& ver) const{ _controlBase.getAbsoluteDock(hor, ver); } \
void getAbsoluteDock(DockLayoutType& hor, DockLayoutType& ver, int& offsetX, int& offsetY) const{ _controlBase.getAbsoluteDock(hor, ver, offsetX, offsetY); } \
void setOpacity(int alpha){ _controlBase.setOpacity((float)alpha / 255.0f); } \
int getOpacity() const { return (int)(_controlBase.getOpacity() * 255.0f); } \
void getLayoutData(void*& layoutData) const { return _controlBase.getLayoutData(layoutData); } \
LayoutType getLayoutType()const{ return _controlBase.getLayoutType(); } \
virtual void setGeometry(int ax, int ay, int aw, int ah) { _controlBase.setGeometry(ax, ay, aw, ah); } \
virtual void setGeometry(const QRect& rect) { _controlBase.setGeometry(rect); } \
void createComplete(); \
void resizeWidget(){ _controlBase.resizeWidget(); } \
UIGQWidgetBaseImpl* getControlImpl(){ return (UIGQWidgetBaseImpl*)(_ctrlImpl); } \
bool serializeJsonValue(Json::Value* value, bool bRead = true); \
void notifyChangeLanguage(); \
private: \
UIGQWidgetBase _controlBase;


#define UIGQT_GET_CONTROLBASE_IMPL(CLASS_NAME) \
void CLASS_NAME::setJsonData(const QString &data) \
{ \
    if (m_jsonData != data) \
    { \
        if(m_jsonData.isEmpty() && !data.isEmpty()) \
        { \
            Json::Value value;  \
            Json::Reader reader;  \
            while(true) \
            { \
                if (!reader.parse(data.toUtf8().data(), value)) \
                { \
                    break; \
                } \
                readJsonValue(&value); \
                break; \
            } \
        } \
        m_jsonData = data; \
    } \
}  \
QString CLASS_NAME::jsonData() const { \
    return m_jsonData; \
} \
bool CLASS_NAME::readJsonValue(void* value) \
{ \
	if(_ctrlImpl == NULL)return false; \
	Json::Value* jsonValue = (Json::Value*)value; \
	_controlBase.serializeJsonValue(jsonValue); \
	return _ctrlImpl->serializeJsonValue(jsonValue); \
} \
void CLASS_NAME::notifyChangeLanguage(){ \
_ctrlImpl->notifyChangeLanguage(); \
}\
void CLASS_NAME::createComplete()\
{\
	_ctrlImpl->createComplete();\
} \
void CLASS_NAME::setDelegateItemVisible(bool visible) \
{\
	_ctrlImpl->setDelegateItemVisible(visible); \
} \
bool CLASS_NAME::getDelegateItemVisible() \
{\
	return _ctrlImpl->getDelegateItemVisible(); \
}\
bool CLASS_NAME::serializeJsonValue(Json::Value* value, bool bRead) \
{\
	Json::Value* jsonValue = (Json::Value*)value; \
    _controlBase.serializeJsonValue(jsonValue, bRead); \
	return _ctrlImpl->serializeJsonValue(value, bRead); \
}\

namespace UIGQtLib
{
	QString getUnicodeString(const char* strText);
	class UIGQWidgetBaseImpl;

	enum CtrlState
	{
		UIG_NORMAL = 0,
		UIG_HOT,
		UIG_PRESSED,
		UIG_DISABLE,
		UIG_STATE_COUNT,
		UIG_STATE_ALL = UIG_STATE_COUNT
	};

	enum CommonCtrlState
	{
		UIG_COMMON_NORMAL = 0,
		UIG_COMMON_DISABLE,
		UIG_COMMON_STATE_COUNT,
		UIG_COMMON_STATE_ALL = UIG_COMMON_STATE_COUNT
	};

	enum RadioIconState
	{
		UIG_RAD_CHECK,
		UIG_RAD_HOT_CHECK,
		UIG_RAD_UNCHECK,
		UIG_RAD_HOT_UNCHECK,
		UIG_RAD_STATE_COUNT,
		UIG_RAD_STATE_ALL = UIG_RAD_STATE_COUNT
	};

	enum CheckBoxTextState
	{
		UIG_CBK_CHECK,
		UIG_CBK_UNCHECK,
		UIG_CBK_DISABLE,
		UIG_CBK_STATE_COUNT
	};

	enum LayoutType
	{
		UIG_LAYOUT_UNSET = -1,
		UIG_LAYOUT_RATIO = 0,
		UIG_LAYOUT_RECT
	};

	enum LayoutSizePolicy
	{
		UIG_SIZE_AUTO = -1,
		UIG_SIZE_FILL = 0,
		UIG_SIZE_FIXED = 1
	};

	enum DockLayoutSizeType
	{
		UIG_FIX_SIZE = 0,
		UIG_DOCK_SIZE
	};

	enum DockLayoutType
	{
		UIG_LEFT_TOP = 0,
		UIG_MIDDLE_CENTER,
		UIG_RIGHT_BOTTOM
	};

	struct TextFontDesc
	{
		bool bold;
		bool italic;
		bool overline;
		int fontSize;
		bool underline;
		bool strikeline;
		QString fontFamily;
		TextFontDesc()
		{
			bold = false;
			italic = false;
			overline = false;
			fontSize = 12;
			underline = false;
			strikeline = false;
            fontFamily = UIGQtLib::getUnicodeString(u8"΢���ź�");
		}
	};

	enum ElideMode
	{
		UIG_EILDE_LEFT,
		UIG_ELIDE_RIGHT,
		UIG_ELIDE_MIDDLE,
		UIG_ELIDE_NONE
	};

	struct BaseStyle
	{
		bool isTextStyle;
		QString name;
	};

	struct TextStyleDesc : public BaseStyle
	{
		TextFontDesc _font;
		QColor color;
		int offsetX;
		int offsetY;
		bool isHor;
		bool isSingleLine;
		DockLayoutType dockHor;
		DockLayoutType dockVer;
		ElideMode elideMode;
		TextStyleDesc()
		{
			name = "";
			isTextStyle = true;
			isHor = true;
			isSingleLine = true;
			dockVer = UIG_MIDDLE_CENTER;
			dockHor = UIG_LEFT_TOP;
			elideMode = UIG_ELIDE_RIGHT;
			color = Qt::black;
			offsetY = 0;
			offsetX = 0;
		}

		bool operator==(const TextStyleDesc& other)
		{
			return  name == other.name;
		}

		bool operator!=(const TextStyleDesc& other)
		{
			return !(*this == other);
		}
	};

	struct ImageDesc
	{
		int		_left;
		int		_right;
		int		_top;
		int		_bottom;
		bool	_repeatLeft;
		bool	_repeatRight;
		bool	_repeatTop;
		bool	_repeatBottom;
		bool	_repeatCenter;

		ImageDesc()
		{
			reset();
		}

		bool operator==(const ImageDesc& other)
		{
			return _left == _left &&
				_right == _right &&
				_top == _top &&
				_bottom == _bottom &&
				_repeatLeft == _repeatLeft &&
				_repeatRight == _repeatRight &&
				_repeatTop == _repeatTop &&
				_repeatBottom == _repeatBottom &&
				_repeatCenter == _repeatCenter;
		}

		void reset()
		{
			memset(this, 0, sizeof(ImageDesc));
		}
		void setMargin(int left, int top, int right, int bottom)
		{
			_left = left;
			_top = top;
			_right = right;
			_bottom = bottom;
		}
		void setRepeat(bool repeatLeft, bool repeatTop, bool repeatRight, bool repeatBottom, bool repeatCenter)
		{
			_repeatLeft = repeatLeft;
			_repeatRight = repeatRight;
			_repeatTop = repeatTop;
			_repeatBottom = repeatBottom;
			_repeatCenter = repeatCenter;
		}
	};

	enum AttrType
	{
		AT_BOOL,
		AT_STRING,
		AT_S8,
		AT_U8,
		AT_S16,
		AT_U16,
		AT_U32,
		AT_S32,
		AT_U64,
		AT_S64,
		AT_F32,
		AT_F64,
		AT_ARRAY_STR
	};

	union ControlAttr
	{
		bool					_bool;
		QString*				_string;
		std::vector<QString>*	_strings;
		char					_s8;
		unsigned char			_u8;
		short					_s16;
		unsigned short			_u16;
		int						_s32;
		unsigned int			_u32;
		unsigned long long		_u64;
		long long				_s64;
		float					_f32;
		double					_f64;
	};

	struct attrValue
	{
		AttrType			_type;
		ControlAttr			_attr;
		unsigned int		_size;

		void SetString(QString text)
		{
			_type = AT_STRING;
			_attr._string = new QString(text);
		}

		void SetBool(bool value)
		{
			_type = AT_BOOL;
			_attr._bool = value;
		}

		void SetInt(int value)
		{
			_type = AT_S32;
			_attr._s32 = value;
		}

		void SetUInt(unsigned int value)
		{
			_type = AT_U32;
			_attr._u32 = value;
		}
	};

	struct ImageRes
	{
		QString imageRes;
		ImageDesc imageDesc;

		void reset()
		{
			imageRes = "";
			imageDesc.reset();
		}

		bool operator==(const ImageRes& other)
		{
			return imageRes == other.imageRes &&
				imageDesc == other.imageDesc;
		}
	};

	struct FillRes : public BaseStyle
	{
		QColor	fillColor;
		QColor	endFillColor;
		QColor	borderColor;
		bool	gradientFill;

		int		roundSize;
		int		borderWidth;
		int		gradientAngle;
		bool	drawBorder;

		bool	borderLeft;
		bool	borderTop;
		bool	borderRight;
		bool	borderBottom;
		bool	roundTopLeft;
		bool	roundTopRight;
		bool	roundBottomRight;
		bool	roundBottomLeft;

		FillRes()
		{
			reset();
		}

		bool operator==(const FillRes& other)
		{
			return fillColor == other.fillColor &&
				endFillColor == other.endFillColor &&
				borderColor == other.borderColor &&
				gradientFill == other.gradientFill &&
				roundSize == other.roundSize &&
				borderWidth == other.borderWidth &&
				gradientAngle == other.gradientAngle &&
				drawBorder == other.drawBorder &&
				borderLeft == other.borderLeft &&
				borderTop == other.borderTop &&
				borderRight == other.borderRight &&
				borderBottom == other.borderBottom &&
				roundTopLeft == other.roundTopLeft &&
				roundTopRight == other.roundTopRight &&
				roundBottomRight == other.roundBottomRight &&
				roundBottomLeft == other.roundBottomLeft;
		}

		void reset()
		{
			gradientAngle = 0;
			gradientFill = false;
			roundSize = 0;
			borderWidth = 0;
			drawBorder = false;
			fillColor.setRgb(255, 255, 255);
			endFillColor.setRgb(255, 255, 255);
			borderColor.setRgb(128, 128, 128);
			borderLeft = true;
			borderTop = true;
			borderRight = true;
			borderBottom = true;
			roundTopLeft = true;
			roundTopRight = true;
			roundBottomRight = true;
			roundBottomLeft = true;
		}

		void setBorderSides(bool left, bool top, bool right, bool bottom)
		{
			borderLeft = left;
			borderTop = top;
			borderRight = right;
			borderBottom = bottom;
		}

		void setAllBorderSides(bool visible)
		{
			setBorderSides(visible, visible, visible, visible);
		}

		void setBorderLeft(bool visible)
		{
			borderLeft = visible;
		}

		bool getBorderLeft() const
		{
			return borderLeft;
		}

		void setBorderTop(bool visible)
		{
			borderTop = visible;
		}

		bool getBorderTop() const
		{
			return borderTop;
		}

		void setBorderRight(bool visible)
		{
			borderRight = visible;
		}

		bool getBorderRight() const
		{
			return borderRight;
		}

		void setBorderBottom(bool visible)
		{
			borderBottom = visible;
		}

		bool getBorderBottom() const
		{
			return borderBottom;
		}

		void setRoundCorners(bool topLeft, bool topRight, bool bottomRight, bool bottomLeft)
		{
			roundTopLeft = topLeft;
			roundTopRight = topRight;
			roundBottomRight = bottomRight;
			roundBottomLeft = bottomLeft;
		}

		void setAllRoundCorners(bool visible)
		{
			setRoundCorners(visible, visible, visible, visible);
		}

		void setRoundTopLeft(bool visible)
		{
			roundTopLeft = visible;
		}

		bool getRoundTopLeft() const
		{
			return roundTopLeft;
		}

		void setRoundTopRight(bool visible)
		{
			roundTopRight = visible;
		}

		bool getRoundTopRight() const
		{
			return roundTopRight;
		}

		void setRoundBottomRight(bool visible)
		{
			roundBottomRight = visible;
		}

		bool getRoundBottomRight() const
		{
			return roundBottomRight;
		}

		void setRoundBottomLeft(bool visible)
		{
			roundBottomLeft = visible;
		}

		bool getRoundBottomLeft() const
		{
			return roundBottomLeft;
		}
	};

	struct FillStyle : public BaseStyle
	{ 
		bool _bShow;
		bool _bUseColor;
		bool _bUseImage;
		FillRes _fillColor;
		ImageRes _imageRes;

		FillStyle()
		{
			isTextStyle = false;
			_bShow = true;
			_bUseColor = true;
			_bUseImage = true;
		}

		void reset()
		{
			_bShow = true;
			_bUseColor = true;
			_bUseImage = true;
			_fillColor.reset();
			_imageRes.reset();
		}

		bool operator!=(const FillStyle& other)
		{
			return !(*this == other);
		}

		bool operator==(const FillStyle& other)
		{
			bool result = _bShow == other._bShow &&
			_bUseColor == other._bUseColor;

			if (!result)
				return result;

			if (_bUseColor)
			{
				return _fillColor == other._fillColor;
			}
			else
			{
				return _imageRes == other._imageRes;
			}
		}

		void setBorderSides(bool left, bool top, bool right, bool bottom)
		{
			_fillColor.setBorderSides(left, top, right, bottom);
		}

		void setAllBorderSides(bool visible)
		{
			_fillColor.setAllBorderSides(visible);
		}

		void setBorderLeft(bool visible)
		{
			_fillColor.setBorderLeft(visible);
		}

		bool getBorderLeft() const
		{
			return _fillColor.getBorderLeft();
		}

		void setBorderTop(bool visible)
		{
			_fillColor.setBorderTop(visible);
		}

		bool getBorderTop() const
		{
			return _fillColor.getBorderTop();
		}

		void setBorderRight(bool visible)
		{
			_fillColor.setBorderRight(visible);
		}

		bool getBorderRight() const
		{
			return _fillColor.getBorderRight();
		}

		void setBorderBottom(bool visible)
		{
			_fillColor.setBorderBottom(visible);
		}

		bool getBorderBottom() const
		{
			return _fillColor.getBorderBottom();
		}

		void setRoundCorners(bool topLeft, bool topRight, bool bottomRight, bool bottomLeft)
		{
			_fillColor.setRoundCorners(topLeft, topRight, bottomRight, bottomLeft);
		}

		void setAllRoundCorners(bool visible)
		{
			_fillColor.setAllRoundCorners(visible);
		}

		void setRoundTopLeft(bool visible)
		{
			_fillColor.setRoundTopLeft(visible);
		}

		bool getRoundTopLeft() const
		{
			return _fillColor.getRoundTopLeft();
		}

		void setRoundTopRight(bool visible)
		{
			_fillColor.setRoundTopRight(visible);
		}

		bool getRoundTopRight() const
		{
			return _fillColor.getRoundTopRight();
		}

		void setRoundBottomRight(bool visible)
		{
			_fillColor.setRoundBottomRight(visible);
		}

		bool getRoundBottomRight() const
		{
			return _fillColor.getRoundBottomRight();
		}

		void setRoundBottomLeft(bool visible)
		{
			_fillColor.setRoundBottomLeft(visible);
		}

		bool getRoundBottomLeft() const
		{
			return _fillColor.getRoundBottomLeft();
		}
	};

	struct IconStyleDesc
	{
		int _offsetX;
		int _offsetY;
		bool _useColor;
		QColor _color;
		DockLayoutType	_horDockType;
		DockLayoutType	_verDockType;

		IconStyleDesc()
		{
			_offsetX = 0;
			_offsetY = 0;
			_useColor = false;
			_color = QColor(0, 0, 0);
			_horDockType = UIG_MIDDLE_CENTER;
			_verDockType = UIG_MIDDLE_CENTER;
		}
	};

	struct RatioLayoutData
	{
		int _ratio;
		
		void reset()
		{
			_ratio = 1;
		}
	};

	struct RectLayoutData
	{
		int		_x;
		int		_y;
		int		_w;
		int		_h;
	};

	class IUIGQWidgetBase;

	typedef void (QWidget::*SetStyleFun)(CtrlState, const BaseStyle*);
	typedef BaseStyle*(QWidget::*GetStyleFun)(CtrlState);
	typedef void (QWidget::*SetStringFun)(const QString&);
	typedef QString(QWidget::*GetStringFun)(void) const;
	typedef void (QWidget::*SetBoolFun)(bool);
	typedef bool (QWidget::*GetBoolFun)(void) const;
	typedef void (QWidget::*SetNumFun)(int);
	typedef int (QWidget::*GetNumFun)(void) const;
	typedef void (QWidget::*Set2NumFun)(int, int);
	typedef void (QWidget::*Get2NumFun)(int&, int&);
	typedef void (QWidget::*Set4NumFun)(int, int, int, int);
	typedef void (QWidget::*Get4NumFun)(int&, int&, int&, int&);
	typedef void (QWidget::*SetStateStringFun)(CtrlState, const QString&);
	typedef QString(QWidget::*GetStateStringFun)(CtrlState);
	typedef void (QWidget::*SetFillStyleFun)(CtrlState, const FillStyle&);
	typedef const FillStyle& (QWidget::*GetFillStyleFun)(CtrlState);
	typedef void (QWidget::*SetTextStyleFun)(CtrlState, const TextStyleDesc&);
	typedef const TextStyleDesc& (QWidget::*GetTextStyleFun)(CtrlState);
	typedef void (QWidget::*SetCBKTextStyleFun)(CheckBoxTextState, const TextStyleDesc&);
	typedef const TextStyleDesc& (QWidget::*GetCBKTextStyleFun)(CheckBoxTextState);
		
	enum PropType
	{
		PT_EDIT,
		PT_EDIT_TRANSLATE,
		PT_STATIC,
		PT_CHECK,
		PT_LINE,
		PT_RECTSTYLE,
		PT_TEXTSTYLE,
		PT_CBK_TEXTSTYLE,
		PT_IMAGESTYLE,
		PT_IMAGE,
		PT_NUM,
		PT_2NUM,
		PT_4NUM,
		PT_COMBO,
		PT_COLOR,
		PT_FAMILY
	};

	enum ResType
	{
		RT_DEFAULT = 0,
		RT_STYLE,
		RT_PROJECT
	};

	struct PropertyDef
	{
		QString			name;
		int				type;
		SetStringFun	setStringFun;
		GetStringFun	getStringFun;
		SetBoolFun		setBoolFun;
		GetBoolFun		getBoolFun;
		SetFillStyleFun		setFillStyleFun;
		GetFillStyleFun		getFillStyleFun;
		SetTextStyleFun		setTextStyleFun;
		GetTextStyleFun		getTextStyleFun;
		SetStateStringFun setStateStringFun;
		GetStateStringFun getStateStringFun;
		GetNumFun		getNumFun;
		SetNumFun		setNumFun;
		Get2NumFun		get2NumFun;
		Set2NumFun		set2NumFun;
		Get4NumFun		get4NumFun;
		Set4NumFun		set4NumFun;
		QWidget*			control;
		std::vector<int>			vecStates;
		std::vector<QString>	vecStatesName;
		bool			effectOtherProp;
		QString			tip;
		int				maxValue;
		int				minValue;
        bool            displayInEditor;
		PropertyDef()
		{
			effectOtherProp = false;
			control = NULL;
			setStringFun = NULL;
			getStringFun = NULL;
			setBoolFun = NULL;
			getBoolFun = NULL;
			setFillStyleFun = NULL;
			getFillStyleFun = NULL;
			setTextStyleFun = NULL;
			getTextStyleFun = NULL;
			getNumFun = NULL;
			setNumFun = NULL;
			get2NumFun = NULL;
			set2NumFun = NULL;
			getStateStringFun = NULL;
			setStateStringFun = NULL;
			maxValue = -10000;
			minValue = 10000;
            displayInEditor = true;
		}
	};

	struct EventInfo
	{
		QString							eventName;
		QString							helpString;
		std::vector<QString>			parameterName;
	};

	struct ControlInfo
	{
		bool						displayInControl;
		std::string					typeName;
		std::string					className;
		std::string					displayName;
		const char*					iconData;
		std::string					descrption;
		std::string					bigIconName;
		std::vector<PropertyDef>	props;
		std::vector<EventInfo>		events;
		void*						bigImg;
		unsigned int				imgLen;
		void*						smallImg;
		unsigned int				simgLen;
		ControlInfo()
		{
			displayInControl = true;
			iconData = 0;
			bigImg = 0;
			imgLen = 0;
			smallImg = 0;
			simgLen = 0;
		}
	};


	class UIGEARSQTLIB_EXPORT UIGQWidgetBase
	{
	public:
		enum AlignType
		{
			HT_LEFT_TOP = 0,
			HT_CENTER_MIDDLE,
			HT_RIGHT_BOTTOM
		};

		enum SizeType
		{
			ST_FIXED = 0,
			ST_ALIGN_TO_LEFT_TOP,
			ST_ALIGN_TO_RIGHT_BOTTOM,
			ST_PERCENT
		};

		UIGQWidgetBase(QWidget* pOwner) :
			_owner(pOwner),
            _layoutType(UIG_LAYOUT_RECT),
			_horSizeType(UIG_SIZE_AUTO),
			_verSizeType(UIG_SIZE_AUTO),
			_absoluteLayout(false),
			_absoluteDockHor(UIG_LEFT_TOP),
			_absoluteDockVer(UIG_LEFT_TOP),
			_absoluteDockOffsetX(0),
			_absoluteDockOffsetY(0),
			_opacity(255)
		{
			memset(&_layoutData, 0, sizeof(_layoutData));
		}

		void resizeWidget();
		void LoadLayout(const Json::Value& value);
		void SaveLayout(Json::Value& value);
		void setLayoutRatio(int ratio);
		int getLayoutRatio() const;
		void setWidthPolicy(LayoutSizePolicy policy);
		LayoutSizePolicy getWidthPolicy() const;
		void setHeightPolicy(LayoutSizePolicy policy);
		LayoutSizePolicy getHeightPolicy() const;
		void setAbsoluteLayout(bool absoluteLayout);
		bool getAbsoluteLayout() const;
		void setAbsoluteDock(DockLayoutType hor, DockLayoutType ver, int offsetX = 0, int offsetY = 0);
		void getAbsoluteDock(DockLayoutType& hor, DockLayoutType& ver) const;
		void getAbsoluteDock(DockLayoutType& hor, DockLayoutType& ver, int& offsetX, int& offsetY) const;
		void setGeometry(int ax, int ay, int aw, int ah);
		void setOpacity(int alpha);
		int getOpacity() const;
		void setGeometry(const QRect& rect);

		QWidget* cloneWidget(const QString& name);

		QString getThemeName()const;
		void setThemeName(const QString& themeName);
        void refreshTheme();

		void getLayoutData(void*& layoutData) const;
		void createComplete();
		LayoutType getLayoutType() const;
		const QWidget* getOwner() const{ return _owner; }

		virtual void serializeJsonValue(Json::Value* value, bool bRead = true);

	protected:
		int	_opacity;
		AlignType _horAlignType;
		AlignType _verAlignType;
		LayoutSizePolicy _horSizeType;
		LayoutSizePolicy _verSizeType;
		bool _absoluteLayout;
		DockLayoutType _absoluteDockHor;
		DockLayoutType _absoluteDockVer;
		int _absoluteDockOffsetX;
		int _absoluteDockOffsetY;

		LayoutType				_layoutType;
		union 
		{
			RatioLayoutData		_ratioLayout;
			RectLayoutData		_rectLayout;
		} _layoutData;

		QWidget* _owner;
	};

	class Q_DECL_EXPORT IUIGQWidgetBase
	{
	public:
		virtual UIGQWidgetBase* getControlBase() = 0;
		virtual bool readJsonValue(void* value) = 0;
		virtual void setLayoutRatio(int ratio) = 0;
		virtual int getLayoutRatio() const = 0;
		virtual void setWidthPolicy(LayoutSizePolicy policy) = 0;
		virtual LayoutSizePolicy getWidthPolicy() const = 0;
		virtual void setHeightPolicy(LayoutSizePolicy policy) = 0;
		virtual LayoutSizePolicy getHeightPolicy() const = 0;
		virtual void setAbsoluteLayout(bool absoluteLayout) = 0;
		virtual bool getAbsoluteLayout() const = 0;
		virtual void setAbsoluteDock(DockLayoutType hor, DockLayoutType ver, int offsetX = 0, int offsetY = 0) = 0;
		virtual void getAbsoluteDock(DockLayoutType& hor, DockLayoutType& ver) const = 0;
		virtual void getAbsoluteDock(DockLayoutType& hor, DockLayoutType& ver, int& offsetX, int& offsetY) const = 0;
		virtual void getLayoutData(void*& layoutData) const = 0;
		virtual void setGeometry(int ax, int ay, int aw, int ah) = 0;
		virtual void setOpacity(int alpha) = 0;
		virtual int getOpacity() const = 0;

		virtual LayoutType getLayoutType() const = 0;
		virtual QString getTypeName() const = 0;
		virtual UIGQWidgetBaseImpl* getControlImpl() = 0;
		virtual void createComplete() = 0;
		virtual void resizeWidget() = 0;
		virtual void notifyChangeLanguage() = 0;
		virtual bool serializeJsonValue(Json::Value* value, bool bRead = true) = 0;
		virtual void setThemeName(const QString& name) = 0;

        virtual QString jsonData() const = 0;
        virtual void setJsonData(const QString &data) = 0;
	};
}
