#include "cddirectk_type_dialog.h"
#include "cdutils_core.h"
#include "qcd_core.h"
#include "qcd_model.h"
#include "piqt.h"
#include "spinslider.h"
#include "qvariantedit.h"


CDDirectKTypeDialog::CDDirectKTypeDialog(QWidget * parent) : QDialog(parent), Ui::CDDirectKTypeDialog() {
	setupUi(this);
}


CDDirectKTypeDialog::~CDDirectKTypeDialog() {
}


CDDirectKTypeDialog::TypeInfo CDDirectKTypeDialog::getType() const {
	if (!groupBox->isChecked()) return TypeInfo();
	TypeInfo ret;
	ret.type = comboType->currentIndex();
	ret.params_d[0] = evalMin->value();
	ret.params_d[1] = evalMax->value();
	ret.params_d[2] = spinDecimals->value();
	ret.params_d[3] = evalStep->value();
	ret.params_s[0] = linePrefix->text();
	ret.params_s[1] = lineSuffix->text();
	return ret;
}




CDDirectKTypeDialog::TypeInfo::TypeInfo(int type_) {
	type = type_;
	params_d.resize(4);
	params_s.resize(2);
}


QWidget * CDDirectKTypeDialog::TypeInfo::create() {
	params_d.resize(4);
	params_s.resize(2);
	switch (type) {
	case 0: {
		QDoubleSpinBox * ret = new QDoubleSpinBox();
		ret->setMinimum(params_d[0]);
		ret->setMaximum(params_d[1]);
		ret->setDecimals(params_d[2]);
		ret->setSingleStep(params_d[3]);
		ret->setPrefix(params_s[0]);
		ret->setSuffix(params_s[1]);
		return ret;
		} break;
	case 1: {
		QSlider * ret = new QSlider(Qt::Horizontal);
		ret->setMinimum(params_d[0]);
		ret->setMaximum(params_d[1]);
		ret->setSingleStep(params_d[3]);
		return ret;
		} break;
	case 2: {
		SpinSlider * ret = new SpinSlider();
		ret->setMinimum(params_d[0]);
		ret->setMaximum(params_d[1]);
		ret->setDecimals(params_d[2]);
		ret->setSingleStep(params_d[3]);
		ret->setPrefix(params_s[0]);
		ret->setSuffix(params_s[1]);
		return ret;
		} break;
	default: break;
	}
	return new QVariantEdit();
}
