#ifndef STACKEDWIDGET_H
#define STACKEDWIDGET_H

#include <QStackedWidget>
#include <QBoxLayout>
#include <QVariantAnimation>
#include "shs_widgets_export.h"

QT_BEGIN_NAMESPACE


class SHS_WIDGETS_EXPORT SHSStackedWidget: public QStackedWidget
{
	Q_OBJECT
	Q_PROPERTY(QBoxLayout::Direction swipeDirection READ swipeDirection WRITE setSwipeDirection)
	Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
	Q_PROPERTY(bool swipeMoveToFirstPage READ swipeMoveToFirstPage WRITE setSwipeMoveToFirstPage)
public:
	explicit SHSStackedWidget(QWidget * parent = 0);
	~SHSStackedWidget();

	void setSwipeDirection(QBoxLayout::Direction dir);
	QBoxLayout::Direction swipeDirection() const {return direction;}

	void setAnimationDuration(int d) {anim_duration = d;}
	int animationDuration() const {return anim_duration;}

	bool swipeMoveToFirstPage() const {return is_move_to_first;}
	void setSwipeMoveToFirstPage(bool yes) {is_move_to_first = yes;}

protected:
	bool eventFilter(QObject * o, QEvent * e) override;
	void resizeEvent(QResizeEvent * e) override;
	void mousePressEvent(QMouseEvent * e) override;
	void mouseReleaseEvent(QMouseEvent * e) override;
	void mouseMoveEvent(QMouseEvent * e) override;

	void beginMove(int index);
	void endMove();
	void animate(double dest);
	int nextIndex(QPoint dp);

	QWidget * aw;
	QPoint press_pos, cur_dp;
	QPixmap im_from, im_to;
	QVariantAnimation animation;
	QBoxLayout::Direction direction = QBoxLayout::LeftToRight;
	int next_index = 0, vis_next_index = 0, anim_duration = 400;
	double cur_transition = 0.;
	bool is_moving = false, is_horiz = true, is_move_to_first = false;

public slots:
	void gotoPage(int index);

};

QT_END_NAMESPACE

#endif
