00001 00042 #include "aicommand.hpp" 00043 00044 using namespace AiFractals; 00045 00046 AiCommand::AiCommand( QImage & img , AiView *view , QUndoCommand *parent ) 00047 : QUndoCommand( parent ), m_id(-1) 00048 { 00049 image = img; 00050 m_view = view; 00051 this->setText( QTime::currentTime().toString() ); 00052 00053 } 00054 00055 int AiCommand::id() const 00056 { 00057 return m_id; 00058 } 00059 00060 void AiCommand::id( int id ) 00061 { 00062 m_id = id; 00063 } 00064 00065 void AiCommand::redo() 00066 { 00067 m_view->makeUndoUpdate( image ); 00068 m_view->update(); 00069 } 00070 00071 void AiCommand::undo() 00072 { 00073 if ( m_id - 1 > m_view->stack->count() ) 00074 { 00075 return; 00076 } 00077 00078 QImage tmp; 00079 if ( m_id - 1 > -1 ) 00080 { 00081 const AiCommand * cmd = (AiCommand*) m_view->stack->command( this->id() - 1 ); 00082 tmp = cmd->image; 00083 } 00084 else 00085 { 00086 tmp = QImage(); 00087 } 00088 00089 m_view->makeUndoUpdate( tmp ); 00090 m_view->update(); 00091 } 00092