/***************************************************************************
 * convertascii.h: implementation of ConvertAscii class
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2003-2006 the KTabEdit development team <mrgwen@gmail.com>
 * 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.
 ***************************************************************************/

#ifndef CONVERT_ASCII_H
#define CONVERT_ASCII_H

#include <QFile>

#include "fileexport.h"
#include "global.h"

class TabSong;
class TabBar;
class TabTrack;

class ConvertAscii : public FileExport
{
public:
	ConvertAscii();
	virtual ~ConvertAscii();
	
	virtual bool saveFile(const QString& fileName, const TabSong& tabSong);
private:
	/**
	 * Prints out main song header.
	 */
	void writeHeader(const TabSong& tabSong);

	/**
	 * Formats and prints out one track.
	 */
	void writeTrack(const TabTrack& tabTrack, int n);

	/**
	 * Starts new track, inits variables and prints track header.
	 */
	void startTrack(const TabTrack& tabTrack, int n);

	/**
	 * Starts new row.
	 */
	void startRow(const TabTrack& tabTrack);

	/**
	 * Adds column col of track trk to rendering arrays.
	 */
	void addBar(const TabTrack& tabTrack, const TabBar& tabBar);

	/**
	 * Flushes current bar rendering to row rendering. Flushes row if
	 * necessary.
	 */
	void flushBar(const TabTrack& tabTrack);

	/**
	 * Flushes current row rendering to stream.
	 */
	void flushRow(const TabTrack& tabTrack);

	/**
	 * Utility method to print out single string line, centered.
	 */
	void writeCentered(const QString& l);
	
	static const uint msSpaces;
	
	/**
	 * Options variable: duration to spaces mode.
	 */
	int mDurMode;

	/**
	 * Options variable: right margin of page (page width).
	 */
	uint mPageWidth;

	/**
	 * Minimal offset of row start from the left edge. Either 1 or 2,
	 * depends of what row start contains (ex. "E" = 1, "Eb" = 2)
	 */
	uint mMinstart;
	
	/**
	 * Array of strings that contain ASCII tab representation of
	 * current bar.
	 */
	QString mBar[MAX_STRINGS];

	/**
	 * Number of bar[], already appended to row[].
	 */
	int mRowBars;

	/**
	 * Array of strings that contain ASCII tab representation of
	 * current row.
	 */
	QString mRow[MAX_STRINGS];
	
	QFile mFile;
	QTextStream mStream;
};

#endif
