#ifndef SHSSWITCH_H
#define SHSSWITCH_H

#include <QAbstractButton>
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QTime>
#include <QDebug>
#include "shs_widgets_export.h"

QT_BEGIN_NAMESPACE

class SHS_WIDGETS_EXPORT SHSSwitch: public QAbstractButton
{
	Q_OBJECT
	Q_ENUMS(SwitchStyle)
	Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
	Q_PROPERTY(bool invertedAppearance READ invertedAppearance WRITE setInvertedAppearance)
	Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
	Q_PROPERTY(SwitchStyle switchStyle READ switchStyle WRITE setSwitchStyle)
	Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor)
	Q_PROPERTY(QColor backColor READ backColor WRITE setBackColor)
	Q_PROPERTY(double scale READ scale WRITE setScale)
	Q_PROPERTY(float h__anim READ g_anim WRITE s_anim DESIGNABLE false)
	Q_PROPERTY(float h__anim_s READ g_anim_s WRITE s_anim_s DESIGNABLE false)
public:
	explicit SHSSwitch(QWidget * parent = 0);
	~SHSSwitch();
	
	enum SwitchStyle {OneSide, Center};
	
	bool readOnly() const {return ro_;}
	bool invertedAppearance() const {return inv_;}
	Qt::Orientation orientation() const {return orient_;}
	SwitchStyle switchStyle() const {return style_;}
	QColor fillColor() const {return fill_color;}
	QColor backColor() const {return back_color;}
	double scale() const {return scale_;}
	
private:
	void init();
	void setCheckable(bool) {}
	void checkStateSet();
	void nextCheckState();
	QSize minimumSizeHint() const;
	QSize sizeHint() const;
	void paintEvent(QPaintEvent *);
	void mousePressEvent(QMouseEvent * e);
	void mouseReleaseEvent(QMouseEvent * e);
	void mouseMoveEvent(QMouseEvent * e);
	float g_anim() const {return ap_;}
	float g_anim_s() const {return ap_s_;}
	void animate();
	
	QColor fill_color, back_color;
	Qt::Orientation orient_;
	SwitchStyle style_;
	QPropertyAnimation anim, anim_s;
	QPoint pp;
	float ap_, ap_s_;
	double scale_;
	bool ro_, mo_, mp_, inv_, mdir_;
	
private slots:
	void s_anim(float v);
	void s_anim_s(float v);

public slots:
	void enable() {setEnabled(true);}
	void disable() {setEnabled(false);}
	void setReadOnly(bool y);
	
	void setInvertedAppearance(bool y);
	void setOrientation(Qt::Orientation o);
	void setSwitchStyle(SHSSwitch::SwitchStyle s);
	void setOn() {setChecked(true);}
	void setOff() {setChecked(false);}
	void setFillColor(const QColor & c);
	void setBackColor(const QColor & c);
	void setScale(double s);
	
};

QT_END_NAMESPACE

#endif // SHSSWITCH_H
