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

#include "util/assert.h"
#include "../settings.h"

TrackTitleView::TrackTitleView(const TabProperties* tabProperties, uint dpi)
: DrawingItem(dpi),
  mFont(Settings::getInstance()->titleFont()),
  mFontMetrics(mFont),
  mTabProperties(tabProperties),
  mCanvasText(mTabProperties->title())
{
	PRECONDITION( tabProperties != 0x0 );
}

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

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

QRectCm TrackTitleView::boundingRect() const
{
	return QRectCm(position().x(), position().y(), width(), height());
}

Cm TrackTitleView::height() const
{
	Pixel pixel(mFontMetrics.boundingRect(mTabProperties->title()).height(), dpi());
	pixel.fromOtherDpi(75);
	return pixel.toCm();
}

Cm TrackTitleView::width() const
{
	Pixel pixel(mFontMetrics.boundingRect(mTabProperties->title()).width(), dpi());
	pixel.fromOtherDpi(75);
	return pixel.toCm();
}
