#ifndef QTIMERWIDGET_H
#define QTIMERWIDGET_H

#include <QWidget>
#include <QShowEvent>
#include "shs_widgets_export.h"

class SHS_WIDGETS_EXPORT QTimerWidget: public QWidget
{
	Q_OBJECT
	Q_PROPERTY(int emitID READ emitID WRITE setEmitID)
	Q_PROPERTY(int setID READ setID WRITE setSetID)
	Q_PROPERTY(int interval READ interval WRITE setInterval)
	
public:
	QTimerWidget(QWidget * parent = 0);
	~QTimerWidget();
	
	int emitID() const {return id_emit;}
	int setID() const {return id_set;}
	
	int interval() const {return int_;}
	
	void buildDebug() {dimage_.load(":/icons/timer.png"); bdebug_ = true;}
	
private:
	void showEvent(QShowEvent * e) {e->ignore(); if (!bdebug_) hide(); return;}
	void paintEvent(QPaintEvent * );
	void timerEvent(QTimerEvent * e);
	QSize sizeHint() const {return QSize(32, 32);}
	
	QImage dimage_;
	bool bdebug_, once_, enabled_;
	int id_emit, id_set, int_, timer;
	
private slots:
	
public slots:
	void enable() {setEnabled(true);}
	void disable() {setEnabled(false);}
	void setEnabled(bool on) {enabled_ = on;}
	void setDisabled(bool off) {enabled_ = !off;}
	
	void setEmitID(int id) {id_emit = id;}
	void setSetID(int id) {id_set = id;}
	
	
	void setInterval(int msecs) {int_ = msecs;}
	void start();
	void startOnce();
	void stop();
	
	
	void enableID(int set_id) {if (set_id == id_set) enable();}
	void disableID(int set_id) {if (set_id == id_set) disable();}
	void setEnabledID(int set_id, bool on) {if (set_id == id_set) setEnabled(on);}
	void setDisabledID(int set_id, bool off) {if (set_id == id_set) setDisabled(off);}
	
	void setIntervalID(int set_id, int msecs) {if (set_id == id_set) setInterval(msecs);}
	void startID(int set_id) {if (set_id == id_set) start();}
	void startOnceID(int set_id) {if (set_id == id_set) startOnce();}
	void stopID(int set_id) {if (set_id == id_set) stop();}
	
signals:
	void tick();
	void tickID(int id);
	
};

#endif // QTIMERWIDGET_H
