/***************************************************************************
 * trackwordsmusicview.cpp: implementation of TrackWordsAndMusicView class
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2003-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 "trackwordsmusicview.h"

#include "settings.h"
#include "tablature/tabproperties.h"

TrackWordsAndMusicView::TrackWordsAndMusicView(const TabProperties* tabProperties, uint dpi)
: DrawingItem(dpi),
  mFontSubTitle(Settings::getInstance()->subTitleFont()),
  mFontMetrics(mFontSubTitle),
  mCanvasText(""),
  mTabProperties(tabProperties),
  mText("")
{
	if (mTabProperties->author() == mTabProperties->author())
		mText = "Words and Music by " + mTabProperties->author();
	else
		mText = "Words by " + mTabProperties->author() + " and Music by " + mTabProperties->author();
	
	mCanvasText.setText(mText);
	mCanvasText.setFont(mFontSubTitle);
}

void TrackWordsAndMusicView::hide()
{
	mCanvasText.hide();
}

void TrackWordsAndMusicView::show()
{
	mCanvasText.setPosFromPoint(position());
	addItemToScene(&mCanvasText);
}

QRectCm TrackWordsAndMusicView::boundingRect() const
{
	Pixel pixelWidth(mFontMetrics.boundingRect(mText).width(), dpi());
	Pixel pixelHeight(mFontMetrics.boundingRect(mText).height(), dpi());
	
	pixelWidth.fromOtherDpi(75);
	pixelHeight.fromOtherDpi(75);
	
	return QRectCm(position().x(), position().y(), pixelWidth.toCm(), pixelHeight.toCm());
}

Cm TrackWordsAndMusicView::height() const
{
	Pixel pixelHeight(mFontMetrics.boundingRect(mText).height(), dpi());
	pixelHeight.fromOtherDpi(75);
	
	return pixelHeight.toCm();
}

Cm TrackWordsAndMusicView::width() const
{
	Pixel pixelWidth(mFontMetrics.boundingRect(mText).width(), dpi());
	pixelWidth.fromOtherDpi(75);
	
	return pixelWidth.toCm();
}
