/***************************************************************************
 * trackbarview.h: implementation of TrackBarView 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.
 ***************************************************************************/

#ifndef TRACKBARVIEW_H
#define TRACKBARVIEW_H

#include <QFont>
#include <QFontMetrics>

#include "cm.h"
#include "tablature/tabbar.h"
#include "tablature/trackproperties.h"

#include "drawingitem.h"

class QCanvasLineCm;
class QCanvasTextCm;
class QPointCm;
class TrackBarLineView;
class TrackClassicalClefView;
class TrackDurationView;
class TrackPos;
class TrackTabClefView;
class TrackTimesView;
class TrackTimesClassicalView;
class TrackTimeSignatureView;

class TrackBarView : public DrawingItem
{
public:
	TrackBarView(uint nb, const TabBar* bar, const TrackProperties* properties, uint strings, uint dpi);
	virtual ~TrackBarView();
	
	virtual void setTabBar(const TabBar* tabBar);
	
	virtual bool isBarNumber(uint barNumber) const;
	
	virtual inline void displayClef(bool t)
	{ clef = t; }
	
	virtual inline bool isDisplayClef() const
	{ return clef; }
	
	virtual inline void displayArmor(bool t)
	{ armor = t; }
	
	virtual inline bool isDisplayArmor() const
	{ return armor; }
	
	virtual void displayTimeSignature(bool t, const QFont& timeFont);
	virtual bool isDisplayTimeSignature() const;
	
	inline void displayTempo(bool t)
	{ tempo = t; }
	
	inline bool isDisplayTempo() const
	{ return tempo; }
	
	virtual void displayPartition(bool t);
	virtual bool isDisplayPartition() const;

	virtual void displayPartitionClef(bool t);
	virtual bool isDisplayPartitionClef() const;

	virtual void displayTablature(bool t);
	virtual bool isDisplayTablature() const;
	
	virtual void displayTablatureClef(bool t, const QFont& clefFont);
	virtual bool isDisplayTablatureClef() const;
	
	virtual void displayBarNumber(bool t);
	virtual bool isDisplayBarNumber() const;
	
	virtual QPoint classicalPosition(const QPoint& position) const;
	virtual QPointCm tablaturePosition(const QPointCm& position) const;
	
	virtual void hidePartitionBody();
	virtual void showPartitionBody();
	
	virtual void drawDuration(TrackTimesClassicalView* classicalView, TrackDurationView* durationView, const TabTime* tabTime,
					  const QPointCm& position, uint barNumber, double* durationCount, const Cm& space);
	
	virtual void hideClassicalAndTablatureLink();
	virtual void drawClassicalAndTablatureLink(const QPointCm& position);
	
	virtual void hide();
	virtual void show();
	virtual void refresh();
	virtual void refreshTimeAt(int time, const TabTime* tabTime);
	virtual void refreshNoteAt(int time, int note, const TabNote* tabNote);
	
	virtual QPointCm positionTablature(const TrackPos& cursorPos) const;
	virtual QPointCm positionPartiton(const TrackPos& cursorPos) const;
	virtual QPointCm positionViewer() const;
	
	virtual void setDrawEffects(bool b)
	{ effects = b; }
	virtual bool isDrawEffects() const
	{ return effects; }
	
	virtual TrackPos cursorPositionAt(const QPointCm& point);
	virtual bool isPointInBar(const QPointCm& point) const;
	
	virtual QRectCm boundingRect() const;
	virtual Cm height() const;
	virtual void setWidth(const Cm& width);
	virtual Cm width() const;
	virtual Cm minimalWidth() const;
	virtual Cm tablatureBodyWidth() const;
	
	virtual void spacesBetweenTimes();
	
	virtual void initObjects();
	
	virtual void deleteObjects();
private:
	typedef QList<TrackTimesView*>::iterator time_it;
	typedef QList<TrackTimesView*>::const_iterator const_time_it;
	typedef QList<TrackDurationView*>::iterator duration_it;
	typedef QList<TrackDurationView*>::const_iterator const_duration_it;
	typedef QList<TrackTimesClassicalView*>::iterator classical_it;
	typedef QList<TrackTimesClassicalView*>::const_iterator const_classical_it;
	typedef QList<TrackDurationView*>::iterator classical_duration_it;
	typedef QList<TrackDurationView*>::const_iterator const_classical_duration_it;
	
	void initDefaultFont();
	
	void calcDurationSize();
	
	uint clefSize() const;
	Cm armorSize() const;
	
	Cm timesSize() const;
	Cm timeSpace(const TabTime& time) const;
	
	void drawTimeChords(const TabTime& time, const QPoint& position);
	void drawTuplet(const Cm& ntupletLength ,unsigned int ntuplet, const QPointCm& position);
	void drawAllTuplets(const TabBar &tabBar, const QPointCm& position);
	
	static bool DefaultFontInit;
	static QFont DefaultTextFont;
	static QFontMetrics DefaultTextFontInfo;
	static Cm DefaultTextWidth;
	static Cm DefaultTextHeight;
	
	Cm WholeSize;
	Cm HalfSize;
	Cm QuarterSize;
	Cm EighthSize;
	Cm SixteenthSize;
	Cm ThirthSecondSize;
	Cm SixtyFourthSize;
	Cm HundredTwentyEighthSize;
	
	const TabBar* mTabBar;
	const TrackProperties* trackProperties;
	const int nbStrings;
	bool clef;
	bool armor;
	bool time;
	bool tempo;
	
	Cm mMinimalBarWidth;
	Cm mBarWidth;
	
	TrackBarLineView* partitionView;
	TrackBarLineView* tablatureView;
	TrackClassicalClefView* classicalClefView;
	TrackTabClefView* tablatureClefView;
	TrackTimeSignatureView* timeSignatureView;
	QList<TrackTimesView*> fretView;
	QList<TrackDurationView*> mDurationViewList;
	QList<TrackTimesClassicalView*> noteClassicalView;
	QList<TrackDurationView*> durationClassicalView;
	QCanvasLineCm* linkView[2];
	bool partition;
	bool partitionClef;
	bool tablature;
	bool tablatureClef;
	bool displayBarNumberView;
	uint mBarNumber;
	QCanvasTextCm* barNumberView;
	
	QFont textFont;
	QFontMetrics textFontInfo;
	Cm mTextWidth;
	Cm mTextHeight;
	
	bool effects;
	
	Cm mSpaceBetweenTimes;
	
	Duration mPreviousDuration;
};

#endif
