#ifndef SHSLIGHT_H
#define SHSLIGHT_H

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

QT_BEGIN_NAMESPACE

class SHS_WIDGETS_EXPORT SHSLight: public QWidget
{
	Q_OBJECT
	Q_ENUMS(IconType)
	Q_PROPERTY(IconType iconType READ iconType WRITE setIconType)
	Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
	Q_PROPERTY(bool binary READ binary WRITE setBinary)
	Q_PROPERTY(bool on READ isOn WRITE setOn)
	Q_PROPERTY(bool restoreLastOnLevel READ isRestoreLastOnLevel WRITE setRestoreLastOnLevel)
	Q_PROPERTY(bool lowLevelIsNull READ lowLevelIsNull WRITE setLowLevelIsNull)
	Q_PROPERTY(double level READ level WRITE setLevel)
	Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor)
	Q_PROPERTY(QColor backColor READ backColor WRITE setBackColor)
	Q_PROPERTY(double angleShift READ angleShift WRITE setAngleShift)
	Q_PROPERTY(double barSize READ barSize WRITE setBarSize)
	Q_PROPERTY(double clickThreshold READ clickThreshold WRITE setClickThreshold)
	Q_PROPERTY(double lowLevel READ lowLevel WRITE setLowLevel)
	Q_PROPERTY(double highLevel READ highLevel WRITE setHighLevel)
	Q_PROPERTY(double onLevel READ onLevel WRITE setOnLevel)
	Q_PROPERTY(double h__anim READ g_anim WRITE s_anim DESIGNABLE false)
public:
	explicit SHSLight(QWidget * parent = 0);
	~SHSLight();

	enum IconType {Bulb, LED, Spot};

	IconType iconType() {return icon_type;}
	bool readOnly() const {return ro_;}
	bool binary() const {return bin_;}
	double level() const;
	double lowLevel() const {return m_lowLevel;}
	double highLevel() const {return m_highLevel;}
	double onLevel() const {return m_onLevel;}
	QColor fillColor() const {return fill_color;}
	QColor backColor() const {return back_color;}
	double angleShift() const {return ang_shift;}
	double barSize() const {return bar_;}
	double clickThreshold() const {return click_thrsh;}
	
	bool isOff() const;
	bool isOn() const;
	bool isRestoreLastOnLevel() const {return m_restoreLastOnLevel;}
	bool lowLevelIsNull() const {return m_lowLevelIsNull;}

	int heightForWidth(int) const;
	bool hasHeightForWidth() const;

private:
	void init();
	QSize minimumSizeHint() const;
	QSize sizeHint() const;
	void mousePressEvent(QMouseEvent * e);
	void mouseReleaseEvent(QMouseEvent * e);
	void mouseMoveEvent(QMouseEvent * e);
	void paintEvent(QPaintEvent *);
	double g_anim() const {return ap_;}
	void animate();
	
	IconType icon_type;
	QColor fill_color, back_color;
	QImage im_0, im_100, im_w, im_h;
	QPropertyAnimation anim;
	double level_, ang_shift, click_thrsh, bar_, ap_;
	double m_lowLevel, m_highLevel, m_onLevel, last_click_level;
	bool ro_, mouse_inner_, track_, bin_, m_restoreLastOnLevel, m_lowLevelIsNull;

private slots:
	void s_anim(double v);

public slots:
	void enable() {setEnabled(true);}
	void disable() {setEnabled(false);}
	void setReadOnly(bool y);
	
	void setIconType(IconType it);
	void setBinary(bool y);
	void setLevel(double l);
	void setLowLevel(double lowLevel);
	void setHighLevel(double highLevel);
	void setOnLevel(double onLevel);
	void setOn(bool on) {setLevel(on ? highLevel() : lowLevel());}
	void setRestoreLastOnLevel(bool yes) {m_restoreLastOnLevel = yes;}
	void setLowLevelIsNull(bool yes);
	void setFillColor(const QColor & c);
	void setBackColor(const QColor & c);
	void setAngleShift(double a);
	void setBarSize(double a);
	void setClickThreshold(double a);
	
	void click();
	

signals:
	void turnedOn();
	void turnedOff();
	void clicked();
	void levelChanged(double);

};


QT_END_NAMESPACE

#endif // SHSLIGHT_H
