/***************************************************************************
 * bendeditor.cpp
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2007- the KTabEdit development team <mrgwen@gmail.com>
 ***************************************************************************/

/***************************************************************************
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * See the file COPYING for more information.
 ***************************************************************************/

#include "bendeditor.h"

#include <QtDebug>

#include "tablature/tabbend.h"

BendEditor::BendEditor()
: QDialog(),
  Ui::BendEditorDialog()
{
	setupUi(this);
	
	fillKindOfBends();
	fillHighOfBends();
	
	connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
	connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
}

void BendEditor::fillKindOfBends()
{
	mBendType->addItem(tr("Bend"));
	mBendType->addItem(tr("Bend and release"));
	mBendType->addItem(tr("Pre bend"));
	mBendType->addItem(tr("Pre bend and release"));
}

void BendEditor::fillHighOfBends()
{
	mBendHigh->addItem("1/4");
	mBendHigh->addItem("1/2");
	mBendHigh->addItem("3/4");
	mBendHigh->addItem("1");
	mBendHigh->addItem("1 1/4");
	mBendHigh->addItem("1 1/2");
	mBendHigh->addItem("1 3/4");
	mBendHigh->addItem("2");
	mBendHigh->addItem("2 1/4");
	mBendHigh->addItem("2 1/2");
	mBendHigh->addItem("2 3/4");
	mBendHigh->addItem("3");
	mBendHigh->addItem("3 1/2");
	mBendHigh->addItem("4");
	mBendHigh->addItem("4 1/2");
	mBendHigh->addItem("5");
	mBendHigh->addItem("5 1/2");
	mBendHigh->addItem("6");
}

TabBend BendEditor::bend() const
{
	TabBend bend;
	QList<QListWidgetItem*> type = mBendType->selectedItems();
	QList<QListWidgetItem*> high = mBendHigh->selectedItems();
	QString temp;
	
	if (type.size() == 0 || high.size() == 0)
		return bend;
	
	temp = type.first()->data(Qt::DisplayRole).toString();
	
	if (temp == tr("Bend"))
		bend.setBendType(TabBend::Bend);
	else if (temp == tr("Bend and release"))
		bend.setBendType(TabBend::BendRelease);
	else if (temp == tr("Pre bend"))
		bend.setBendType(TabBend::PreBend);
	else if (temp == tr("Pre bend and release"))
		bend.setBendType(TabBend::PreBendRelease);
	
	temp = high.first()->data(Qt::DisplayRole).toString();
	if (temp == "1/4")
		bend.setBendValue(25);
	else if (temp == "1/2")
		bend.setBendValue(50);
	else if (temp == "3/4")
		bend.setBendValue(75);
	else if (temp == "1")
		bend.setBendValue(100);
	else if (temp == "1 1/4")
		bend.setBendValue(125);
	else if (temp == "1 1/2")
		bend.setBendValue(150);
	else if (temp == "1 3/4")
		bend.setBendValue(175);
	else if (temp == "2")
		bend.setBendValue(200);
	else if (temp == "2 1/4")
		bend.setBendValue(225);
	else if (temp == "2 1/2")
		bend.setBendValue(250);
	else if (temp == "2 3/4")
		bend.setBendValue(275);
	else if (temp == "3")
		bend.setBendValue(300);
	else if (temp == "3 1/2")
		bend.setBendValue(350);
	else if (temp == "4")
		bend.setBendValue(400);
	else if (temp == "4 1/2")
		bend.setBendValue(450);
	else if (temp == "5")
		bend.setBendValue(500);
	else if (temp == "5 1/2")
		bend.setBendValue(550);
	else if (temp == "6")
		bend.setBendValue(600);
	
	return bend;
}

#include "bendeditor.moc"
