/***************************************************************************
 * tabproperties.cpp: implementation of TabProperties class
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2008- 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 "tabproperties.h"
#include "util/assert.h"

#include "songkey.h"
#include "tablyrics.h"

TabProperties::TabProperties()
: titleProp(),
  subTitleProp(),
  artistProp(),
  albumProp(),
  authorProp(),
  copyrightProp(),
  transcriberProp(),
  instructionsProp(),
  commentsProp(),
  shuffle(false),
  tempoProp(120),
  octaveProp(0),
  mSongKey(0x0),
  mLyrics(0x0)
{
	mSongKey = new SongKey();
	mLyrics = new TabLyrics();
}

TabProperties::~TabProperties()
{
	if (hasSongKey() == true)
		delete songKey();
	
	if (hasLyrics() == true)
		delete tabLyrics();
}

void TabProperties::clone(const TabProperties* properties)
{
	PRECONDITION( properties != 0x0 );
	
	if (hasSongKey() == true)
		delete songKey();
	
	if (hasLyrics() == true)
		delete tabLyrics();
	
	mSongKey = new SongKey();
	if (properties->hasSongKey() == true)
		mSongKey->clone(properties->songKey());
	
	mLyrics = new TabLyrics();
	if (properties->hasLyrics() == true)
		mLyrics->clone(properties->tabLyrics());
	
	titleProp = properties->titleProp;
	subTitleProp = properties->subTitleProp;
	artistProp = properties->artistProp;
	albumProp = properties->albumProp;
	authorProp = properties->authorProp;
	copyrightProp = properties->copyrightProp;
	transcriberProp = properties->transcriberProp;
	instructionsProp = properties->instructionsProp;
	commentsProp = properties->commentsProp;
	shuffle = properties->shuffle;
	tempoProp = properties->tempoProp;
	octaveProp = properties->octaveProp;
}

void TabProperties::setTitle(const QString &s)
{
	titleProp = s;
}

QString TabProperties::title() const
{
	return titleProp;
}

void TabProperties::setSubTitle(const QString &s)
{
	subTitleProp = s;
}

QString TabProperties::subTitle() const
{
	return subTitleProp;
}

void TabProperties::setArtist(const QString &s)
{
	artistProp = s;
}

QString TabProperties::artist() const
{
	return artistProp;
}

void TabProperties::setAlbum(const QString &s)
{
	albumProp = s;
}

QString TabProperties::album() const
{
	return albumProp;
}

void TabProperties::setAuthor(const QString &s)
{
	authorProp = s;
}

QString TabProperties::author() const
{
	return authorProp;
}

void TabProperties::setCopyright(const QString &s)
{
	copyrightProp = s;
}

QString TabProperties::copyright() const
{
	return copyrightProp;
}

void TabProperties::setTranscriber(const QString &s)
{
	transcriberProp = s;
}

QString TabProperties::transcriber() const
{
	return transcriberProp;
}

void TabProperties::setInstructions(const QString &s)
{
	instructionsProp = s;
}

QString TabProperties::instructions() const
{
	return instructionsProp;
}

void TabProperties::setComments(const QString &s)
{
	commentsProp = s;
}

QString TabProperties::comments() const
{
	return commentsProp;
}

void TabProperties::setShuffle(bool i)
{
	shuffle = i;
}

bool TabProperties::isShuffle() const
{
	return shuffle;
}

void TabProperties::setTempo(unsigned int i)
{
	tempoProp = i;
}

unsigned int TabProperties::tempo() const
{
	return tempoProp;
}

void TabProperties::setOctave(int i)
{
	octaveProp = i;
}

int TabProperties::octave() const
{
	return octaveProp;
}

void TabProperties::setSongKey(SongKey* songKey)
{
	PRECONDITION( songKey != 0x0 );
	
	if (mSongKey != 0x0)
		delete mSongKey;
	
	mSongKey = songKey;
}

SongKey* TabProperties::songKey() const
{
	PRECONDITION( mSongKey != 0x0 );
	
	return mSongKey;
}

bool TabProperties::hasSongKey() const
{
	return (mSongKey != 0x0);
}

void TabProperties::setKey(QChar c)
{
	songKey()->setKey(c);
}

QChar TabProperties::key() const
{
	return songKey()->key();
}

char TabProperties::asciiCodeOfKey() const
{
	return songKey()->asciiCodeOfKey();
}

QString TabProperties::nameOfKey() const
{
	return songKey()->nameOfKey();
}

void TabProperties::setMinor(bool i)
{
	songKey()->setMinor(i);
}

bool TabProperties::isMinor() const
{
	return songKey()->isMinor();
}

void TabProperties::setTabLyrics(TabLyrics* lyrics)
{
	PRECONDITION( lyrics != 0x0 );
	
	if (mLyrics != 0x0)
		delete mLyrics;
	
	mLyrics = lyrics;
}

TabLyrics* TabProperties::tabLyrics() const
{
	PRECONDITION( mLyrics != 0x0 );
	
	return mLyrics;
}

bool TabProperties::hasLyrics() const
{
	return (mLyrics != 0x0);
}

void TabProperties::setLyricsTrack(int i)
{
	tabLyrics()->setLyricsTrack(i);
}

int TabProperties::lyricsTrack() const
{
	return tabLyrics()->lyricsTrack();
}

void TabProperties::setLyricsMeasure(int i, int j)
{
	tabLyrics()->setLyricsMeasure(i, j);
}

int TabProperties::lyricsMeasure(int i) const
{
	return tabLyrics()->lyricsMeasure(i);
}

void TabProperties::setLyrics(int i, const QString& s)
{
	tabLyrics()->setLyrics(i, s);
}

QString TabProperties::lyrics(int i) const
{
	return tabLyrics()->lyrics(i);
}

bool TabProperties::operator==(const TabProperties& tabProperties) const
{
	return (titleProp == tabProperties.titleProp && subTitleProp == tabProperties.subTitleProp &&
			artistProp == tabProperties.artistProp && albumProp == tabProperties.albumProp &&
			authorProp == tabProperties.authorProp && copyrightProp == tabProperties.copyrightProp &&
			transcriberProp == tabProperties.transcriberProp && instructionsProp == tabProperties.instructionsProp &&
			commentsProp == tabProperties.commentsProp && shuffle == tabProperties.shuffle &&
			tempoProp == tabProperties.tempoProp && octaveProp == tabProperties.octaveProp &&
			mSongKey == tabProperties.mSongKey && mLyrics == tabProperties.mLyrics);

}

bool TabProperties::operator!=(const TabProperties& tabProperties) const
{
	return !(this->operator==(tabProperties));
}
