#ifndef SLIDER_WITH_TWO_TEXTS_TWO_CURRENTS_H
#define SLIDER_WITH_TWO_TEXTS_TWO_CURRENTS_H

#include <QtGui>
#include <climits>
#include <cassert>
#include "softProj\DevicesWidget\SliderULongLong.h"
#include "softProj\settings.h"

class SliderWithTwoTextsTwoCurrents : public SliderULongLong {
Q_OBJECT
private:
	QString leftText_;
	QString rightText_;
	QString leftCurrent_;
	QString rightCurrent_;

	bool showText_;
	unsigned long long maximum_;
	QColor fontColor_;
public:
	SliderWithTwoTextsTwoCurrents(QWidget * parent) : SliderULongLong(parent) {
		showText_ = true;
		fontColor_ = QColor::fromRgb(200, 200, 200);
	}
protected:
	virtual void valueChangedEvent() {
		unsigned long long leftValue = getValue();

		leftCurrent_ = Settings::instance().formatNumber(leftValue);
		rightCurrent_ = Settings::instance().formatNumber(maximum_ - leftValue);

		SliderULongLong::valueChangedEvent();
	}

	virtual void paintEvent(QPaintEvent * paintEvent) {
		QSlider::paintEvent(paintEvent);

		if (!showText_) {
			return;
		}

		QPainter painter(this);
		QFont font("tahoma", 8, QFont::Bold);

		painter.setRenderHint(QPainter::Antialiasing, true);
		painter.setPen(fontColor_);
		painter.setFont(font);

		QFontMetrics fm = painter.fontMetrics();
 
		if (orientation() == Qt::Horizontal) {
			painter.drawText(QRect(4, 2, width() - 8, height() - 4), leftText_);
			painter.drawText(QRect(4, 2, width() - 8, height() - 4), rightText_, QTextOption(Qt::AlignRight));
			painter.drawText(QRect(4, 2, width() - 8, height() - 4), leftCurrent_, QTextOption(Qt::AlignLeft | Qt::AlignBottom));
			painter.drawText(QRect(4, 2, width() - 8, height() - 4), rightCurrent_, QTextOption(Qt::AlignRight | Qt::AlignBottom));
		}
	}
public:
	void setLeftText(const std::wstring & value) {
		leftText_ = QString::fromUtf16(value.c_str());
	}

	void setRightText(const std::wstring & value) {
		rightText_ = QString::fromUtf16(value.c_str());
	}

	void setValues(unsigned long long leftValue, unsigned long long rightValue) {
		this->maximum_ = leftValue + rightValue;

		SliderULongLong::setMaximum(maximum_);
		SliderULongLong::setValue(leftValue);
		valueChangedEvent();
	}

	void drawRotatedText(QPainter * painter, float degrees, int x, int y, const QString &text) {
		painter->save();
		painter->translate(x, y);
		painter->rotate(degrees);
		painter->drawText(0, 0, text);
		painter->restore();
	}

	void setShowText(bool show) {
		this->showText_ = show;
	}

	void setFontColor(const QColor & color) {
		this->fontColor_ = color;
	}
};

#endif