/***************************************************************************
 *   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 ECOMMAND_H
#define ECOMMAND_H
#include <qstring.h>
#include <kcommand.h>

#include <visitors/visitor.h>

/**
Base class for all commands
Also derieves from Visitor as it's targets are always elements that can be visited
 
@author Hans Oischinger
 */
class ECommand : public KCommand, public Visitor
{
public:
  enum ExecState
  {
    EXEC_NONE,
    EXEC_FIRSTEXEC,
    EXEC_REEXEC,
    EXEC_UNEXEC
  };

  ECommand( const QString& name );
  ~ECommand();

  QString name() const { return m_name; }
  void setName( const QString& name ) { m_name = name; }

  /**
   * Be sure to call this in the derived class to set the execstate
   */
  virtual void execute();

  /**
   * Be sure to call this in the derived class to set the execstate
   */
  virtual void unexecute();

  /**
   * Usefull to detect if we were called from execute() or unexecute()
   * in the visit() method
   */
  unsigned int getExecState() { return m_execstate; }

  /**
   * Convenience function that returns true on exec @see getExecState()
   */
  bool isExecuting() { return ( m_execstate==EXEC_FIRSTEXEC ); }

  /**
   * Convenience function that returns true on redo @see getExecState()
   */
  bool isRedoing() { return ( m_execstate==EXEC_REEXEC ); }

  /**
   * Convenience function that returns true on undo @see getExecState()
   */
  bool isUndoing() { return ( m_execstate==EXEC_UNEXEC ); }

  /**
   * Returns true if RecordAnimation was set when the object was created
   */
  bool getRecordAnimation() { return m_recordAnimation; }

protected:
  unsigned int m_execstate; // set to the current ExecState when un-/execute() is called
  bool m_recordAnimation; // was m_recordAnimation set when the Command was created

private:
  QString m_name;
};

#endif
