/***************************************************************************
 * optionsmelodyeditor.cpp: implementation of OptionsMelodyEditor class
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2003-2006 the KTabEdit development team <mrgwen@gmail.com>
 * copyright (C) 2002-2003 the KGuitar 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 "optionsmelodyeditor.h"

#include <QLabel>
#include <QButtonGroup>

#include <KLocale>

#include "settings.h"

OptionsMelodyEditor::OptionsMelodyEditor(KConfig* conf, QWidget* parent)
: OptionsPage(conf, parent),
  mInlayGroup(0x0),
  mWoodGroup(0x0),
  mInlay(5),
  mWood(4),
  mMouseAction(3),
  mMouseAdvance(3)
{
	int globalMelodyEditorAction[3];
	bool globalMelodyEditorAdvance[3];
	QVBoxLayout* mainLayout = new QVBoxLayout(this);
	QHBoxLayout* designGroup = new QHBoxLayout();
	QGridLayout* gridLayout = new QGridLayout(3, 3);
	
	for (int i = 0; i < 3; i++) {
		globalMelodyEditorAction[0] = Settings::getInstance()->melodyEditorAction(i);
		globalMelodyEditorAdvance[0] = Settings::getInstance()->melodyEditorAdvance(i);
	}
	
	mInlayGroup = new QVBoxLayout();
	QButtonGroup* inlayGroup = new QButtonGroup(this);
	
	mInlay[0] = new QRadioButton(i18n("None"));
	mInlay[1] = new QRadioButton(i18n("Center dots"));
	mInlay[2] = new QRadioButton(i18n("Side dots"));
	mInlay[3] = new QRadioButton(i18n("Blocks"));
	mInlay[4] = new QRadioButton(i18n("Trapezoid"));
	
	for (int i = 0; i < 5; i++) {
		inlayGroup->addButton(mInlay[i]);
		mInlayGroup->addWidget(mInlay[i]);
	}
	
	mInlay[Settings::getInstance()->melodyEditorInlay()]->setChecked(true);
	designGroup->addLayout(mInlayGroup);
	
	mWoodGroup = new QVBoxLayout();
	QButtonGroup* woodGroup = new QButtonGroup(this);
	
	mWood[0] = new QRadioButton(i18n("Schematic"));
	mWood[1] = new QRadioButton(i18n("Maple"));
	mWood[2] = new QRadioButton(i18n("Rosewood"));
	mWood[3] = new QRadioButton(i18n("Ebony"));
	
	for (int i = 0; i < 4; i++) {
		woodGroup->addButton(mWood[i]);
		mWoodGroup->addWidget(mWood[i]);
	}
	
	designGroup->addLayout(mWoodGroup);
	mWood[Settings::getInstance()->melodyEditorWood()]->setChecked(true);
	
	mainLayout->addLayout(designGroup);
	
	for (int i = 0; i < 3; i++) {
		mMouseAction[i] = new QComboBox(false);
		
		gridLayout->addWidget(mMouseAction[i], i, 1);
		
		mMouseAction[i]->insertItem(i18n("No action"));
		mMouseAction[i]->insertItem(i18n("Set note"));
		mMouseAction[i]->insertItem(i18n("Set 02 power chord"));
		mMouseAction[i]->insertItem(i18n("Set 022 power chord"));
		mMouseAction[i]->insertItem(i18n("Set 00 power chord"));
		mMouseAction[i]->insertItem(i18n("Set 0022 power chord"));
		mMouseAction[i]->insertItem(i18n("Delete note"));
		
		mMouseAction[i]->setCurrentItem(globalMelodyEditorAction[i]);
		
		mMouseAdvance[i] = new QCheckBox(i18n("Advance to next column"));
		
		gridLayout->addWidget(mMouseAdvance[i], i, 2);
		
		mMouseAdvance[i]->setChecked(globalMelodyEditorAdvance[i]);
	}
	
	gridLayout->addWidget(new QLabel(mMouseAction[0], i18n("Left button:"), this), 0, 0);
	gridLayout->addWidget(new QLabel(mMouseAction[1], i18n("Middle button:"), this), 1, 0);
	gridLayout->addWidget(new QLabel(mMouseAction[2], i18n("Right button:"), this), 2, 0);
	
	mainLayout->addLayout(gridLayout);
	
	setLayout(mainLayout);
	
	resize(300, 300);
}

void OptionsMelodyEditor::defaultBtnClicked()
{
	mInlay[1]->setChecked(true);
	mWood[2]->setChecked(true);

	mMouseAction[0]->setCurrentItem(1);
	mMouseAction[1]->setCurrentItem(3);
	mMouseAction[2]->setCurrentItem(1);

	mMouseAdvance[0]->setChecked(false);
	mMouseAdvance[1]->setChecked(true);
	mMouseAdvance[2]->setChecked(true);
}

void OptionsMelodyEditor::applyBtnClicked()
{
	/*config->setGroup("MelodyEditor");
	config->writeEntry("Inlay", mInlayGroup->id(mInlayGroup->selected()));
	config->writeEntry("Wood", mWoodGroup->id(mWoodGroup->selected()));
	config->writeEntry("Action0", mMouseAction[0]->currentItem());
	config->writeEntry("Advance0", mMouseAdvance[0]->isChecked());
	config->writeEntry("Action1", mMouseAction[1]->currentItem());
	config->writeEntry("Advance1", mMouseAdvance[1]->isChecked());
	config->writeEntry("Action2", mMouseAction[2]->currentItem());
	config->writeEntry("Advance2", mMouseAdvance[2]->isChecked());*/
}

#include "optionsmelodyeditor.moc"
