/* -*- mode: c++; indent-tabs-mode: nil; -*-
 *
 * This file is part of the Mango recipe management distribution.
 * Copyright (c) 2000-2003, Roland Jesse
 * All rights reserved.
 *
 * For license and copyright information see the file COPYRIGHT or 
 * <http://www.opensource.org/licenses/bsd-license.html>.
 *
 * $Id: Printer.h,v 1.5 2003/01/12 16:19:56 rjesse Exp $
 */
 
#ifndef PRINTER_H
#define PRINTER_H

#include "Exporter.h"
#include <qpainter.h>
class QPrinter;

/*!
  Class for printing recipes.
*/
class Printer : public Exporter {
	  Q_OBJECT

   public:
	  static Printer* getInstance(); //!< Singleton access.
	  static Printer* getInstance( RecipeModel*);	//!< Singleton access.
	  static Printer* getInstance( const Recipe&); //!< Singleton access.
	  static void deleteInstance();	//!< Delete singleton instance.
	  
	  inline QString getExtensions() { return QString( ""); }
	  void apply() throw( Error);
      void render( const QPaintDevice*) throw( Error);
	  void setParentWidget( QWidget*);
	  
   signals:
	  void message( const QString&, int);
      void message( const QString&);

   protected:
	  Printer();				//!< Constructs a printer object.
	  Printer( RecipeModel*);	//!< Constructs a printer object.
	  Printer( const Recipe&);	//!< Constructs a printer object.
	  ~Printer();				//!< Destructs the object.

	  void createCookbookHeader();
	  void createRecipes();
	  void createRecipeHeader();
	  void createRecipeBody();

   private:
	  void init();
	  void setPrinterDefaults();
      void buildStringList() throw( Error);
      void convertCookbook();
      void convertRecipe();

	  static Printer* m_instance;

      /*!
        Used by render() and all the create...() functions in order
        to render the content to be printed.
      */
      QPainter m_painter;

      /*! List storing a string for each line of output. */
      QStringList m_lines;

	  QPrinter* m_printer;
	  QWidget* m_parent;
};
#endif // PRINTER_H
