/**
** 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

#ifdef _MSC_VER
#include <QTableView>
#include <QItemDelegate>
#include <QHeaderView>
#else
#include <QtWidgets/QTableView>
#include <QtWidgets/QItemDelegate>
#include <QtWidgets/QHeaderView>
#endif
#include "UIGQMacro.h"
#include "UIGearsQtLib.h"
#include "UIGQScrollBar.h"
#include "UIGQWidgetBase.h"

#define UIG_USER_ROLE_IMAGE Qt::UserRole + 100
#define UIG_USER_ROLE_WIDGET Qt::UserRole + 101

namespace UIGQtLib
{
	class UIGQTableViewImpl;
	class UIGQTableViewitemDelegate;
	class UIGQTableHeader;
	class UIGQConerWidget;
	class UIGQViewport;
	class UIGQContainer;

	class UIGEARSQTLIB_EXPORT UIGQTableView : public QTableView, public IUIGQWidgetBase
	{
		Q_OBJECT;
	public:
		UIGQTableView(QWidget* pParent = nullptr);
		~UIGQTableView();

		UIG_QT_CTRL_DEF("qtdatagrid", UIGQTableView);

		void setScrollbarBtnSize(bool isHorizontalScrollbar, int size);
		void setScrollbarSize(bool isHorizontalScrollbar, int size);
		void setScrollbarBackgroundStyle(bool isHorizontalScrollbar, const FillStyle& background );
		void setScrollbarThumbStyle(bool isHorizontalScrollbar, CtrlState state, const FillStyle& style);
		void setScrollbarButtonStyle(bool isHorizontalScrollbar, bool isUp, CtrlState state, const FillStyle& style);
		void setScrollbarButtonIcon(bool isHorizontalScrollbar, bool isUpOrLeft, const QString& iconPath);
		void setScrollbarButtonIconStyle(bool isHorizontalScrollbar, bool isUpOrLeft, const IconStyleDesc& style);
		void setScrollbarThumb(bool isHorizontalScrollbar, const QString& thumb);

		void setBackground(CommonCtrlState state, const FillStyle& style);
		const FillStyle& getBackground(CommonCtrlState state);

		void setItemBackground(CtrlState state, const FillStyle& style);
		const FillStyle& getItemBackground(CtrlState state);
		
		void setItemTextStyle(CtrlState state, const TextStyleDesc& style);
		const TextStyleDesc& getItemTextStyle(CtrlState state);

		void setHeaderBackground(CtrlState state, const FillStyle& style);
		const FillStyle& getHeaderBackground(CtrlState state);

		void setHeaderTextStyle(CtrlState state, const TextStyleDesc& style);
		const TextStyleDesc& getHeaderTextStyle(CtrlState state);

		void setItemHeight(int height);
		int getItemHeight();

		void setCheckstyle(bool checkbox);
		bool getCheckstyle();

		void setColumnWidget(int col, UIGQContainer* pCtrl);
		const UIGQContainer* getColumnWidget(int col);

		void setCheckBoxImage(bool check, QString imagePath);
		const QString getCheckBoxImage(bool check);

		void setCheckedImage(QString imagePath);
		const QString getCheckedImage();

		void setUncheckedImage(QString imagePath);
		const QString getUncheckedImage();

		void initDemoData();

		QList<int> selectedRows() const;

		friend class UIGQTableHeader;

	Q_SIGNALS:
		void headerCheckedChanged(bool check);
		void customControlClicked(int row, const QString& name);

	protected:
		void leaveEvent(QEvent *event);
		void paintEvent(QPaintEvent * evt);
		bool eventFilter(QObject * watched, QEvent * event);
		void headerChecked(bool check);

	private:
		UIGQTableHeader*			_horHeader;
		UIGQTableHeader*			_verHeader;
		UIGQScrollBar*				_horScrollBar;
		UIGQScrollBar*				_verScrollBar;
		UIGQTableViewImpl*			_ctrlImpl;
		UIGQTableViewitemDelegate*	_itemDelegate;
		UIGQConerWidget*			_conerWidget;
		UIGQViewport*				_viewport;

		UIGQT_GET_CONTROLBASE;
	};
}
