/**
** 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/QListView>
#include <QtWidgets/QItemDelegate>
#include "UIGearsQtLib.h"
#include "UIGQWidgetBase.h"
#include "UIGQScrollBar.h"
#include "UIGQLabelEx.h"

#define STYLE_LV_BACKGROUND_NORMAL 0
#define STYLE_LV_BACKGROUND_DISABLE 1

#define STYLE_LV_NORMAL 2
#define STYLE_LV_HOT 3 
#define STYLE_LV_PRESS 4

namespace UIGQtLib
{
	class UIGQWidgetBaseImpl;
	class UIGQListViewImpl;
	class UIGQListViewItemDelegate;

	class UIGEARSQTLIB_EXPORT UIGQListView : public QListView, public IUIGQWidgetBase
	{
		Q_OBJECT

	public:
		typedef void(*ItemDisplayCallBack)(const UIGQListView* pListView, const QWidget* pWidget, const QModelIndex & item);
		typedef QSize(*ItemForSizeCallBack)(const UIGQListView* pListView, const QStyleOptionViewItem &option, const QModelIndex & item);
		typedef void(*LabelExDisplayCallback)(const UIGQListView* pListView, UIGQLabelEx* pWidget, const QModelIndex & item);

	public:
		UIGQListView(QWidget* pParent = nullptr);
		~UIGQListView();
		void initDemoData();
		void paintEvent(QPaintEvent *e);
		bool eventFilter(QObject * watched, QEvent * event);

		void setItemTemplate(QWidget* pTempldate);
		QWidget* getitemTemplate();

		void setBackground(UIGQtLib::CommonCtrlState state, const FillStyle& fillRes);
		const FillStyle& getBackground(UIGQtLib::CommonCtrlState state);

		void setItemHeight(int itemHeight);
		int getItemHeight() const;

		void setItemWidth(int itemWidth);
		int getItemWidth() const;

		void setItemDisplayCallBack(ItemDisplayCallBack pFun);
		ItemDisplayCallBack getItemDisplayCallBack();

		void setItemForSizeCallBack(ItemForSizeCallBack pFun);
		ItemForSizeCallBack getItemForSizeCallBack();

		void setLabelExCallBack(LabelExDisplayCallback pFun);
		LabelExDisplayCallback getLabelExCallBack();

		void setItemBackground(UIGQtLib::CtrlState state, const FillStyle& fillRes);
		const FillStyle& getItemBackground(UIGQtLib::CtrlState state);

		void setEnableSelection(bool enable);
		bool getEnableSelection();

		void clearHighLight();
				
		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);

		UIG_QT_CTRL_DEF("qtlistview", UIGQListView);

	Q_SIGNALS:
		void pressCtrl(QWidget* pWidget, const QModelIndex &index);

	protected:
		void mouseReleaseEvent(QMouseEvent *event);
		void resizeEvent(QResizeEvent* evt);
		
	private:
		UIGQScrollBar*			_horScrollBar;
		UIGQScrollBar*			_verScrollBar;
		UIGQListViewItemDelegate* _itemDelegate;
		UIGQListViewImpl*		_ctrlImpl;

		UIGQT_GET_CONTROLBASE;		
	};
}

