#ifndef SHSCLOCK_H
#define SHSCLOCK_H

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

QT_BEGIN_NAMESPACE

class SHS_WIDGETS_EXPORT SHSClock: public QWidget
{
	Q_OBJECT
	Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
	Q_PROPERTY(QTime time READ time WRITE setTime)
	Q_PROPERTY(float h__anim0 READ g_anim0 WRITE s_anim0 DESIGNABLE false)
	Q_PROPERTY(float h__anim1 READ g_anim1 WRITE s_anim1 DESIGNABLE false)
public:
	explicit SHSClock(QWidget * parent = 0);
	~SHSClock();
	
	bool readOnly() const {return _hours.ro_;}
	QTime time() const;

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

private:

	struct Arrow {
		float thickness;
		float length;
		float alpha;
		float angle;
		float ap_;
	};
	typedef QPair<float, QString> FSPair;
	class _NumericCircle: public QWidget {
	public:
		_NumericCircle(QObject * parent_ = 0);
		void paintEvent(QPaintEvent * event);
		void mousePressEvent(QMouseEvent * e) {mouseMoveEvent(e);}
		void mouseMoveEvent(QMouseEvent * e);
		QSize sizeHint() const {return QSize(128, 128);}
		QSize minimumSizeHint() const {return QSize(32, 32);}
		QVector<QVector<FSPair> > marks;
		QVector<float> offsets;
		QVector<Arrow> arrows;
		QString current;
		int aprev;
		bool ro_;
		QObject * parent;
	};
	
	void init();
	float g_anim0() const {return _hours.arrows[0].ap_;}
	float g_anim1() const {return _hours.arrows[1].ap_;}
	void animate();

	_NumericCircle _hours, _minutes;
	QPropertyAnimation anim[2];
	
private slots:
	void s_anim0(float v);
	void s_anim1(float v);
	void numSelected();

public slots:
	void enable() {setEnabled(true);}
	void disable() {setEnabled(false);}
	void setReadOnly(bool y);
	
	void setTime(QTime t);
	
signals:
	void timeChanged(QTime);

};

QT_END_NAMESPACE

#endif // SHSCLOCK_H
