/***************************************************************************
 * tabbar.h: implementation of TabBar class
 *
 * This file is part of KGuitar, a KDE tabulature editor
 *
 * 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 "tabbarproperties.h"
#include "util/assert.h"

TabBarProperties::TabBarProperties()
: markerColor(),
  markerName(),
  repeat(false),
  close(false),
  alt(false),
  repeatStartProp(false),
  repetitionsProp(0),
  alternateEndingsProp(0),
  doubleBarProp(false),
  mKey(0x0),
  mTimeSignature(0x0)
{
	mKey = new SongKey();
	mTimeSignature = new TimeSignature();
}

TabBarProperties::~TabBarProperties()
{
	if (hasSongKey() == true)
		delete songKey();
	
	if (hasTimeSignature() == true)
		delete timeSignature();
}

void TabBarProperties::clone(const TabBarProperties* properties)
{
	PRECONDITION( properties != 0x0 );
	
	if (hasSongKey() == true)
		delete songKey();
	
	if (hasTimeSignature() == true)
		delete timeSignature();
	
	markerColor = properties->markerColor;
	markerName = properties->markerName;
	repeat = properties->repeat;
	close = properties->close;
	alt = properties->alt;
	repeatStartProp = properties->repeatStartProp;
	repetitionsProp = properties->repetitionsProp;
	alternateEndingsProp = properties->alternateEndingsProp;
	doubleBarProp = properties->doubleBarProp;
	
	mKey = new SongKey();
	if (properties->hasSongKey() == true)
		mKey->clone(properties->songKey());
	
	mTimeSignature = new TimeSignature();
	if (properties->hasTimeSignature() == true)
		mTimeSignature->clone(properties->timeSignature());
}

void TabBarProperties::setColor(const QColor& i)
{
	markerColor = i;
}

QColor TabBarProperties::color() const
{
	return markerColor;
}

void TabBarProperties::setMarker(const QString& s)
{
	markerName = s;
}

QString TabBarProperties::marker() const
{
	return markerName;
}

void TabBarProperties::setRepeatBar(bool b)
{
	repeat = b;
}

bool TabBarProperties::isRepeatBar() const
{
	return repeat;
}

void TabBarProperties::setCloseBar(bool b, QChar c)
{
	close = b;
	volta = c;
}

bool TabBarProperties::isCloseBar() const
{
	return close;
}

void TabBarProperties::setAltBar(bool b)
{
	alt = b;
}

bool TabBarProperties::isAltBar() const
{
	return alt;
}

void TabBarProperties::setRepeatStart(bool b)
{
	repeatStartProp = b;
}

bool TabBarProperties::isRepeatStart() const
{
	return repeatStartProp;
}

void TabBarProperties::setRepetitions(int i)
{
	repetitionsProp = i;
}

int TabBarProperties::repetitions() const
{
	return repetitionsProp;
}

void TabBarProperties::setAlternateEndings(int i)
{
	alternateEndingsProp = i;
}

int TabBarProperties::isAlternateEndings() const
{
	return alternateEndingsProp;
}

void TabBarProperties::setDoubleBar(bool b)
{
	doubleBarProp = b;
}

bool TabBarProperties::isDoubleBar() const
{
	return doubleBarProp;
}

void TabBarProperties::setSongKey(SongKey* key)
{
	PRECONDITION( key != 0x0 );
	
	if (mKey != 0x0)
		delete mKey;
	
	mKey = key;
}

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

bool TabBarProperties::hasSongKey() const
{
	return (mKey != 0x0);
}

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

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

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

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

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

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

void TabBarProperties::setTimeSignature(TimeSignature* timeSignature)
{
	PRECONDITION( timeSignature != 0x0 );
	
	if (mTimeSignature != 0x0)
		delete mTimeSignature;
	
	mTimeSignature = timeSignature;
}

TimeSignature* TabBarProperties::timeSignature() const
{
	PRECONDITION( mTimeSignature != 0x0 );
	
	return mTimeSignature;
}

bool TabBarProperties::hasTimeSignature() const
{
	return (mTimeSignature != 0x0);
}

void TabBarProperties::setNumerator(uchar c)
{
	timeSignature()->setNumerator(c);
}

uchar TabBarProperties::numerator() const
{
	return timeSignature()->numerator();
}

void TabBarProperties::setDenominator(uchar c)
{
	timeSignature()->setDenominator(c);
}

uchar TabBarProperties::denominator() const
{
	return timeSignature()->denominator();
}

uint TabBarProperties::timeLigatures() const
{
	return timeSignature()->timeLigatures();
}

bool TabBarProperties::operator==(const TabBarProperties& properties) const
{
	bool songKeyOp;
	bool timeSignatureOp;
	
	if (hasSongKey() == true && songKey()->operator==(*dynamic_cast<const SongKey*>(&properties)))
		songKeyOp = true;
	else
		songKeyOp = false;
	
	if (hasTimeSignature() == true && timeSignature()->operator==(*dynamic_cast<const TimeSignature*>(&properties)))
		timeSignatureOp = true;
	else
		timeSignatureOp = false;
	
	return (markerColor == properties.markerColor && markerName == properties.markerName &&
			repeat == properties.repeat && close == properties.close &&
			volta == properties.volta && alt == properties.alt &&
			repeatStartProp == properties.repeatStartProp && repetitionsProp == properties.repetitionsProp &&
			alternateEndingsProp == properties.alternateEndingsProp && doubleBarProp == properties.doubleBarProp &&
			songKeyOp ==true && timeSignatureOp == true);

}

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