#ifndef TABWIDGET_H
#define TABWIDGET_H

#include <QTabWidget>
#include <QTabBar>
#include "shs_widgets_export.h"

QT_BEGIN_NAMESPACE


class SHS_WIDGETS_EXPORT SHSTabBar: public QTabBar
{
	Q_OBJECT
public:
	explicit SHSTabBar(QWidget * parent = 0);
	
	void mousePressEvent(QMouseEvent * e);
	void mouseMoveEvent(QMouseEvent * e);
	void mouseReleaseEvent(QMouseEvent * e);
	void resizeEvent(QResizeEvent * e);
	void paintEvent(QPaintEvent * e);
	
	QImage icon_left, icon_right;
	QPoint pp, sp, dp;
	int dx, pdx;
	bool moveable_;
	
signals:
	void needMoveBar();
	
};


class SHS_WIDGETS_EXPORT SHSTabWidget: public QTabWidget
{
	Q_OBJECT
	Q_ENUMS(VerticalSide)
	Q_ENUMS(HorizontalSide)
	Q_PROPERTY(int emitID READ emitID WRITE setEmitID)
	Q_PROPERTY(int setID READ setID WRITE setSetID)
	Q_PROPERTY(bool autoSide READ isAutoSide WRITE setAutoSide)
	Q_PROPERTY(VerticalSide preferredVerticalSide READ preferredVerticalSide WRITE setPreferredVerticalSide)
	Q_PROPERTY(HorizontalSide preferredHorizontalSide READ preferredHorizontalSide WRITE setPreferredHorizontalSide)
	Q_PROPERTY(QByteArray __hiddenTabs__ READ __hiddenTabs__ WRITE __setHiddenTabs__)
	
public:
	explicit SHSTabWidget(QWidget * parent = 0);
	~SHSTabWidget();

	enum VerticalSide   {Top, Bottom};
	enum HorizontalSide {Left, Right};

	int emitID() const {return id_emit;}
	int setID() const {return id_set;}
	bool isAutoSide() const {return m_autoSide;}
	VerticalSide preferredVerticalSide() const {return m_preferredVerticalSide;}
	HorizontalSide preferredHorizontalSide() const {return m_preferredHorizontalSide;}

	QByteArray __hiddenTabs__() const;
	void __setHiddenTabs__(const QByteArray & ht);

protected:
	QSize minimumSizeHint() const {return QSize(1, QTabWidget::minimumSizeHint().height());}
	QSize sizeHint() const {return QTabWidget::sizeHint();}
	void resizeEvent(QResizeEvent * e);
	void paintEvent(QPaintEvent * );
	
private:
	int id_emit, id_set;
	bool m_autoSide;
	TabPosition prev_pos;
	VerticalSide m_preferredVerticalSide;
	HorizontalSide m_preferredHorizontalSide;
	SHSTabBar * bar;
	QVector<int> m_hiddenTabs;

private slots:
	void moveBar();
	
public slots:
	void enable() {setEnabled(true);}
	void disable() {setEnabled(false);}
	
	void setCurrentIndex(int index) {QTabWidget::setCurrentIndex(index); emit currentChangedID(id_emit, index);}
	
	void setEmitID(int id) {id_emit = id;}
	void setSetID(int id) {id_set = id;}
	
	void enableID(int set_id) {if (set_id == id_set) enable();}
	void disableID(int set_id) {if (set_id == id_set) disable();}
	void setEnabledID(int set_id, bool on) {if (set_id == id_set) setEnabled(on);}
	void setDisabledID(int set_id, bool off) {if (set_id == id_set) setDisabled(off);}
	void setAutoSide(bool autoSide) {m_autoSide = autoSide;}
	void setPreferredVerticalSide(VerticalSide preferredVerticalSide) {m_preferredVerticalSide = preferredVerticalSide;}
	void setPreferredHorizontalSide(HorizontalSide preferredHorizontalSide) {m_preferredHorizontalSide = preferredHorizontalSide;}

	void setTabVisible(int index, bool visible);
	void hideTab(int index) {setTabVisible(index, false);}
	void showTab(int index) {setTabVisible(index, true);}

signals:
	void currentChangedID(int id, int index);
	
};

QT_END_NAMESPACE

#endif // TABWIDGET_H
