/*
    QAD - Qt ADvanced

    Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TOUCHSLIDER_H
#define TOUCHSLIDER_H

#include "qad_touch_widgets_export.h"

#include <QGroupBox>
#include <QMouseEvent>


namespace Ui {
class TouchSlider;
}


class QAD_TOUCH_WIDGETS_EXPORT TouchSlider: public QGroupBox {
	Q_OBJECT
	Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
	Q_PROPERTY(bool showMinMax READ showMinMax WRITE setShowMinMax)
	Q_PROPERTY(bool showIncDec READ showIncDec WRITE setShowIncDec)
	Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
	Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
	Q_PROPERTY(double value READ value WRITE setValue)
	Q_PROPERTY(double precision READ precision WRITE setPrecision)
	Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
	Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
	Q_PROPERTY(int clickID READ clickID WRITE setClickID)
	Q_PROPERTY(int setID READ setID WRITE setSetID)

public:
	explicit TouchSlider(QWidget * parent = 0);
	~TouchSlider();

	int clickID() const { return id_click; }
	int setID() const { return id_set; }

	double minimum() const;
	double maximum() const;
	double value() const;
	double precision() const;
	QString prefix() const { return pref; }
	QString suffix() const { return suff; }
	bool readOnly() const { return m_readOnly; }
	bool showMinMax() const { return m_showMinMax; }
	bool showIncDec() const { return m_showIncDec; }

private:
	void updateCaption();

	Ui::TouchSlider * ui;
	bool hasZero;
	bool m_readOnly;
	bool m_showMinMax;
	bool m_showIncDec;
	double prec;
	int id_click, id_set;
	QString pref, suff;

public slots:
	void enable() { setEnabled(true); }
	void disable() { setEnabled(false); }

	void setClickID(int id) { id_click = id; }
	void setSetID(int id) { id_set = id; }

	void setSuffix(const QString & text) {
		suff = text;
		updateCaption();
	}
	void setPrefix(const QString & text) {
		pref = text;
		updateCaption();
	}
	void setPrecision(double precision);
	void setPrecision(int precision) { setPrecision((double)precision); }
	void setMinimum(double min);
	void setMinimum(int min) { setMinimum((double)min); }
	void setMaximum(double max);
	void setMaximum(int max) { setMaximum((double)max); }
	void setReadOnly(bool yes);
	void setShowMinMax(bool yes);
	void setShowIncDec(bool yes);

	void setValue(double val);
	void setValue(int val) { setValue((double)val); }

	void enableID(int set_id) {
		if (set_id == id_set) enable();
	}
	void disableID(int set_id) {
		if (set_id == id_set) disable();
	}

	void setValueID(int set_id, double val) {
		if (set_id == id_set) setValue(val);
	}
	void setValueID(int set_id, int val) {
		if (set_id == id_set) setValue(val);
	}

	void clickMin() { on_pbMin_clicked(); }
	void clickMax() { on_pbMax_clicked(); }
	void clickInc() { on_pbInc_clicked(); }
	void clickDec() { on_pbDec_clicked(); }
	void clickZero() { on_pbZero_clicked(); }

private slots:
	void on_barPos_valueChanged(int value);
	void on_barNeg_valueChanged(int value);
	void on_barNeg_mousePressEvent(QMouseEvent *);
	void on_barPos_mousePressEvent(QMouseEvent *);
	void on_barNeg_mouseMoveEvent(QMouseEvent *);
	void on_barPos_mouseMoveEvent(QMouseEvent *);
	void on_pbZero_clicked();
	void on_pbDec_clicked();
	void on_pbInc_clicked();
	void on_pbMax_clicked();
	void on_pbMin_clicked();

signals:
	void valueChanged(double val);
	void valueChanged(int val);
	void valueChangedID(int id, double val);
	void valueChangedID(int id, int val);
};

#endif // TOUCHSLIDER_H
