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

namespace UIGQtLib
{
	class UIGQLabelExImpl;
	class UIGEARSQTLIB_EXPORT UIGQLabelEx : public QLabel, public IUIGQWidgetBase
	{
	public:
		enum CursorPos
		{
			BeginPos = 0,
			EndPos
		};

		struct HitTestInfo
		{
			int blockIdx;
			int lineIdx;
			int charPos;
			HitTestInfo()
			{
				reset();
			}

			HitTestInfo(int bidx, int lIdx, int cPos)
			{
				blockIdx = bidx;
				lineIdx = lIdx;
				charPos = cPos;
			}

			bool isValid()
			{
				return blockIdx != -1 &&
					lineIdx != -1 &&
					charPos != -1;
			}

			void reset()
			{
				blockIdx = -1;
				lineIdx = -1;
				charPos = -1;
			}

			bool operator==(const HitTestInfo& other)const
			{
				return blockIdx == other.blockIdx &&
					lineIdx == other.lineIdx &&
					charPos == other.charPos;
			}

			bool operator!=(const HitTestInfo& other)const
			{
				return blockIdx != other.blockIdx ||
					lineIdx != other.lineIdx ||
					charPos != other.charPos;
			}

			bool operator>(const HitTestInfo& other)const
			{
				return blockIdx > other.blockIdx ||
					lineIdx > other.lineIdx ||
					charPos > other.charPos;
			}
		};

	public:
		UIGQLabelEx(QWidget* pParent = nullptr);
		~UIGQLabelEx();

		UIG_QT_CTRL_DEF("qtlabelex", UIGQLabelEx);

		QString getHtmlContent();
		void setHtmlContent(const QString& html);
		void setText(const QString& text);
		void setColor(const QColor& color);
		void setDisableColor(const QColor& color);
		void setTextStyle(CtrlState eState, const UIGQtLib::TextStyleDesc& textStyle);

		const QColor& getColor();
		const QColor& getDisableColor();
		const TextStyleDesc& getTextStyle(CtrlState eState);
		
		QSize calcSize(const QString& text, int maxWidth);
		
	protected:
		void paintEvent(QPaintEvent * event);
		void resizeEvent(QResizeEvent *event);
		void mousePressEvent(QMouseEvent *event);
		void mouseMoveEvent(QMouseEvent *event);
		void mouseReleaseEvent(QMouseEvent *event);
		void mouseDoubleClickEvent(QMouseEvent *event);

	private:
		UIGQLabelExImpl* _ctrlImpl;

		UIGQT_GET_CONTROLBASE;
	};
}
