/**
** 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 <QtUiPlugin/QDesignerCustomWidgetInterface>
#include "UIGQMacro.h"
#include "UIGQWidgetBase.h"

namespace UIGQtLib
{
	class UIGQScrollBar;
	class UIGQContainerImpl;
    class UIGEARSQTLIB_EXPORT UIGQContainer : public QWidget, public IUIGQWidgetBase
	{
        Q_OBJECT
	public:
		enum AutoChildLayout
		{
			kHorizontal = 0,
			kVertical,
			kHorizontalFlow,
			kVerticalFlow,
			kUnset
		};

		UIGQContainer(QWidget* pParent = nullptr);
		~UIGQContainer();

		bool isContainer() const;
		bool isInitialized() const;
		QIcon icon() const;
		QString domXml() const;
		QString group() const;
		QString includeFile() const;
		QString name() const;
		QString toolTip() const;
		QString whatsThis() const;
		QWidget* createWidget(QWidget* parent);
		void initialize(QDesignerFormEditorInterface* core);

		UIG_QT_CTRL_DEF("qtcontainer", UIGQContainer);

		void forceResize();
		bool startResizeAnimation(const QSize& startSize, const QSize& endSize, int durationMs);
		bool isResizeAnimationRunning() const;

		void setBackgroundState(CtrlState state, const FillStyle& color);
		const FillStyle& getBackgroundState(CtrlState state);

		void setBackground(const FillStyle& color);
		const FillStyle& getBackground();

		void setDisableBackground(const FillStyle& color);
		const FillStyle& getDisableBackground();

		void setChildLayout(AutoChildLayout layout);
		void setChildSpace(int space);
		void setChildPadding(int allPadding);
		void setChildPadding(int left, int top, int right, int bottom);
		void addChildWidget(QWidget* child, int ratio = 1);
		void setChildRatio(QWidget* child, int ratio);

		AutoChildLayout getChildLayout();
		int getChildSpace();
		void getChildPadding(int& left, int& top, int& right, int& bottom);

		void setUseFillStyle(bool bFillColor);
		bool getUseFillStyle();
		void setDrawBackground(bool drawBackground);
		bool getDrawBackground();
		void setAbsoluteDockAutoSize(bool autoSize);
		bool getAbsoluteDockAutoSize() const;

		void setColor(QColor color);

		void bindScrollBar(UIGQScrollBar* scrollBar, bool isHorizontal);
		UIGQScrollBar* getBindScrollBar(bool isHorizontal) const;
		int getScrollPos(bool isHorizontal) const;
		void setScrollPos(bool isHorizontal, int pos);

		void bindWindowHandle(void* windowHandle);
		void* getWindowHandle();
		void unbindWindowHandle();

	Q_SIGNALS:
		void mouseClickEvent();

	protected:
		void mouseReleaseEvent(QMouseEvent *event);
		void paintEvent(QPaintEvent * evt);
		void resizeEvent(QResizeEvent * event);
		void wheelEvent(QWheelEvent* event);
		bool event(QEvent* event);
		bool eventFilter(QObject* watched, QEvent* event);

		UIGQT_GET_CONTROLBASE;

	private:
		bool				_initialized;
		UIGQContainerImpl*	_ctrlImpl;
	};

}

