#ifndef ETABWIDGET_H
#define ETABWIDGET_H

#include <QTabWidget>
#include <QDebug>
#include <QTabBar>
#include <QMouseEvent>
#include <QEvent>
#include <QToolButton>
#include <QPushButton>
#include <QLayout>
#include <QHBoxLayout>
#include <QApplication>
#include "qad_export.h"


class QAD_EXPORT ETabWidget: public QTabWidget
{
	Q_OBJECT
public:
	explicit ETabWidget(QWidget * parent = 0);
	
	void retranslate();
	void addTabButton(int role, const QIcon & icon, const QString & toolTip = QString()) {buttons << TabButton(role, icon, toolTip);}
	int addTab(QWidget * page, const QIcon & icon, const QString & label);
	int addTab(QWidget * page, const QString & label) {return addTab(page, QIcon(), label);}
	void setButtonVisible(int role, bool yes);
	
private:
	bool eventFilter(QObject * o, QEvent * e);
	void tabInserted(int) {emit countChanged();}
	void tabRemoved(int) {emit countChanged();}
	
	struct TabButton {
		TabButton(int r, const QIcon & i, const QString & t) {role = r; icon = i; visible = true; srcToolTip = t; toolTip = QApplication::translate("MainWindow", t.toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/);}
		int role;
		bool visible;
		QIcon icon;
		QString srcToolTip;
		QString toolTip;
	};
	
	QList<TabButton> buttons;
	
private slots:
	void buttonClicked();
	
signals:
	void countChanged();
	void tabHovered(int tab);
	void tabButtonClicked(int tab, int role);
	
};

#endif // ETABWIDGET_H
