#ifndef INTERVAL_SLIDER_H
#define INTERVAL_SLIDER_H

#include "qt_version.h"

#include "QbTimeEditors.h"
// #if QT_VERSION < 0x040000
// #include <qwidget.h>
// #include <qapplication.h>
// #include <qpainter.h>
// #else
// #include <QWidget>
// #include <QApplication>
// #include <QtGui>
// #endif
//TODO clean includes
#if QT_VERSION < 0x040000
#include <qpainter.h>
#else
#include <QPainter>
#endif

#define H_MARGIN 20
#define V_MARGIN 3
#define SLIDER_HEIGHT 16
#define TOTAL_HEIGHT 30
#define MOUSE_MARGIN 5

class IntervalSlider: public QWidget
{
	Q_OBJECT
			
	public:
		
		IntervalSlider(double min=0., double max=100., double start=0., double end=100.);
		
		IntervalSlider(QWidget * parent, double min=0., double max=100., double start=0., double end=100.);
		
		void setValue(double start, double end);
		
		void reset(double min, double max, double start, double end);
		
		double min, max, start, end;
	signals:
		
		void changed(double start, double end);
		
	protected slots:
		
		void resizeEvent(QResizeEvent *e);
		void paintEvent(QPaintEvent* e);
		void mouseMoveEvent(QMouseEvent* e);
		void mousePressEvent(QMouseEvent* e);
		void mouseReleaseEvent(QMouseEvent* e);
		void keyPressEvent(QKeyEvent* e);
		void leaveEvent(QEvent * e);
		
	protected:
		
// 		bool isTime;
		
		int min_pos, max_pos, start_pos, end_pos; // in pixels - recompute when resize
		
		int tracking; //0 of not, 1 if moving start, 2 if moving end, 3 if moving all
		int tracking_position; //if sliding the whole, this records the position of the cursor relatively to min_pos, in pixels
};

#endif
