/*
    QAD - Qt ADvanced

    Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RIBBON_H
#define RIBBON_H

#include "etabwidget.h"
#include "qad_application_export.h"

#include <QActionGroup>
#include <QDockWidget>
#include <QGroupBox>
#include <QMainWindow>
#include <QMenuBar>
#include <QScrollArea>
#include <QTabWidget>
#include <QToolBar>
#include <QToolButton>
#include <QWidgetAction>


class QAD_APPLICATION_EXPORT Ribbon: public QToolBar {
	Q_OBJECT

public:
	explicit Ribbon(QMainWindow * parent = 0);
	~Ribbon();

	void init();
	void retranslate();
	void setIconSize(const QSize & size);
	void setTabIconSize(const QSize & size);
	void setButtonStyle(const Qt::ToolButtonStyle & style);
	void setAutoSwitchEnabled(bool yes) { delay_e = yes; }
	void setAutoSwitchDelay(float delay_s) { delay = delay_s * 1000; }
	void setCurrentTab(int tab_);
	int currentTab() const { return tab->currentIndex(); }
	QTabWidget * tabWidget() const { return tab; }

private:
	bool eventFilter(QObject * o, QEvent * e);
	void timerEvent(QTimerEvent * e);
	void changeEvent(QEvent * e);
	void _resize();
	void _setIconsSize();
	void _setButtonText(QToolButton * b, QAction * a);

	int hovered = -1, delay = 1000;
	bool delay_e = true;
	QList<QToolButton *> buttons;
	QMap<int, int> hovers;
	ETabWidget * tab          = nullptr;
	QScrollArea * scroll_area = nullptr;
	QMainWindow * parent      = nullptr;

private slots:
	void tabHovered(int tab);

public slots:
	void setVisible(bool yes);
	void setHidden(bool yes) { setVisible(!yes); }
	void show() { setVisible(true); }
	void hide() { setVisible(false); }

signals:
	void currentTabChanged(int);
};

#endif // RIBBON_H
