/***************************************************************************
 *   Copyright (C) 2004 by Hans Oischinger                                 *
 *   hans.oischinger@kdemail.net                                           *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#ifndef DIREKTORINSTANCE_H
#define DIREKTORINSTANCE_H

#include <qobject.h>
#include <qwidget.h>

class TimeServer;
class MainWindow;
class DocumentWidget;
class ElementDatabase;
class ToolManager;
class KURL;
class KCommandHistory;
class KActionCollection;
class KCommand;
/**
KInstance-like singleton that holds all impostant instances
 
@author Hans Oischinger
*/
class Kast : public QObject
{
  Q_OBJECT
protected:
  Kast(QObject *parent = 0, const char *name = 0);
  ~Kast();

  void init();

public:
  static Kast* self();

  ///
  /// Important accessors:
  ///
  TimeServer &timeServer() { return *m_timeServer; }
  ElementDatabase &elementDB() { return *m_elemDB; }
  MainWindow &mainWindow() { return *m_mainwin; }
  DocumentWidget &docWidget() { return *m_docWidget; }
  ToolManager &toolManager() { return *m_toolManager; }


  enum STYLETARGET { ST_STROKE, ST_FILL };
  /**
   * Returns the part of the selected shape that should be affected by
   * style operations
   */
  STYLETARGET getStyleTarget() { return m_styleTarget; }
  /**
   * Sets the part of the selected shape that should be affected by
   * style operations
   */
  void setStyleTarget( STYLETARGET t );

  /**
   * Adds the command to the history and executes it if execute=true (default)
   */
  void addCommand (KCommand *command, bool execute=true);
  KCommandHistory &cmdHistory() { return *m_cmdHistory; }

  /**
   * toggle m_recordAnimation
   */
  void toggleRecordAnimation();
  void setRecordAnimation(bool b=true) { m_recordAnimation = b; }
  bool getRecordAnimation() { return m_recordAnimation; }

  /**
   * Setup the GUI with a given mainwindow and actionCollection
   * @param win 
   * @param actionCollection 
   */
  void setupGUI( MainWindow *win, KActionCollection *actionCollection );
  bool isGUIReady() { return m_guiReady; }

signals:
  void styleTargetChanged();

public slots:
  bool openURL( const KURL& url );

private:
  static Kast* m_instance;
  TimeServer* m_timeServer;
  MainWindow *m_mainwin;
  DocumentWidget *m_docWidget;
  ElementDatabase *m_elemDB;
  ToolManager *m_toolManager;
  KCommandHistory *m_cmdHistory;
  bool m_recordAnimation;
  bool m_guiReady;
  STYLETARGET m_styleTarget;
};

#endif
