20#include "KoTextCommand.h"
21#include "KoTextObject.h"
22#include "KoTextParag.h"
23#include "KoVariable.h"
28void KoTextCommand::execute()
34void KoTextCommand::unexecute()
39KoTextDeleteCommand::KoTextDeleteCommand(
40 KoTextDocument *d,
int i,
int idx,
const TQMemArray<KoTextStringChar> &str,
42 const TQValueList<KoParagLayout> &oldParagLayouts )
43 : KoTextDocDeleteCommand( d, i, idx, str ),
44 m_oldParagLayouts( oldParagLayouts ),
45 m_customItemsMap( customItemsMap )
50KoTextCursor * KoTextDeleteCommand::execute( KoTextCursor *c )
52 KoTextParag *s = doc ? doc->paragAt(
id ) : parag;
54 kdWarning() <<
"can't locate parag at " <<
id <<
", last parag: " << doc->lastParag()->paragId() << endl;
58 cursor.setIndex( index );
59 int len = text.size();
62 for (
int i = 0; i < len; ++i )
64 KoTextStringChar * ch = cursor.parag()->at( cursor.index() );
67 ch->customItem()->setDeleted(
true );
68 cursor.parag()->removeCustomItem(cursor.index());
73 return KoTextDocDeleteCommand::execute(c);
76KoTextCursor * KoTextDeleteCommand::unexecute( KoTextCursor *c )
79 KoTextCursor * cr = KoTextDocDeleteCommand::unexecute(c);
81 KoTextParag *s = doc ? doc->paragAt(
id ) : parag;
83 kdWarning() <<
"can't locate parag at " <<
id <<
", last parag: " << (doc ? doc->lastParag()->paragId() : -1) << endl;
87 cursor.setIndex( index );
89 m_customItemsMap.
insertItems( cursor, text.size() );
92 TQValueList<KoParagLayout>::Iterator lit = m_oldParagLayouts.begin();
93 kdDebug(32500) <<
"KoTextDeleteCommand::unexecute " << m_oldParagLayouts.count() <<
" parag layouts. First parag=" << s->paragId() << endl;
94 Q_ASSERT(
id == s->paragId() );
97 if ( lit != m_oldParagLayouts.end() )
99 kdDebug(32500) <<
"KoTextDeleteCommand::unexecute applying paraglayout to parag " << p->paragId() << endl;
100 p->setParagLayout( *lit );
112KoTextParagCommand::KoTextParagCommand( KoTextDocument *d,
int fParag,
int lParag,
113 const TQValueList<KoParagLayout> &oldParagLayouts,
116 TQStyleSheetItem::Margin margin )
117 : KoTextDocCommand( d ), firstParag( fParag ), lastParag( lParag ), m_oldParagLayouts( oldParagLayouts ),
118 m_newParagLayout( newParagLayout ), m_flags( flags ), m_margin( margin )
120 Q_ASSERT( fParag >= 0 );
121 Q_ASSERT( lParag >= 0 );
124KoTextCursor * KoTextParagCommand::execute( KoTextCursor *c )
127 KoTextParag *p = doc->paragAt( firstParag );
130 kdWarning() <<
"KoTextParagCommand::execute paragraph " << firstParag <<
"not found" << endl;
134 if ( ( m_flags & KoParagLayout::Margins ) && m_margin != (TQStyleSheetItem::Margin)-1 )
135 p->setMargin(
static_cast<TQStyleSheetItem::Margin
>(m_margin), m_newParagLayout.
margins[m_margin] );
138 p->setParagLayout( m_newParagLayout, m_flags );
140 if ( p->paragId() == lastParag )
147 c->setIndex( p->length()-1 );
151KoTextCursor * KoTextParagCommand::unexecute( KoTextCursor *c )
153 kdDebug(32500) <<
"KoTextParagCommand::unexecute" << endl;
154 KoTextParag *p = doc->paragAt( firstParag );
157 kdDebug(32500) <<
"KoTextParagCommand::unexecute paragraph " << firstParag <<
"not found" << endl;
160 TQValueList<KoParagLayout>::Iterator lit = m_oldParagLayouts.begin();
162 if ( lit == m_oldParagLayouts.end() )
164 kdDebug(32500) <<
"KoTextParagCommand::unexecute m_oldParagLayouts not big enough!" << endl;
167 if ( m_flags & KoParagLayout::Margins && m_margin != (TQStyleSheetItem::Margin)-1 )
168 p->setMargin(
static_cast<TQStyleSheetItem::Margin
>(m_margin), (*lit).margins[m_margin] );
171 p->setParagLayout( *lit, m_flags );
173 if ( p->paragId() == lastParag )
180 c->setIndex( p->length()-1 );
186KoParagFormatCommand::KoParagFormatCommand( KoTextDocument *d,
int fParag,
int lParag,
187 const TQValueList<KoTextFormat *> &oldFormats,
189 : KoTextDocCommand( d ), firstParag( fParag ), lastParag( lParag ), m_oldFormats( oldFormats ),
190 m_newFormat( newFormat )
192 TQValueList<KoTextFormat *>::Iterator lit = m_oldFormats.begin();
193 for ( ; lit != m_oldFormats.end() ; ++lit )
197KoParagFormatCommand::~KoParagFormatCommand()
199 TQValueList<KoTextFormat *>::Iterator lit = m_oldFormats.begin();
200 for ( ; lit != m_oldFormats.end() ; ++lit )
204KoTextCursor * KoParagFormatCommand::execute( KoTextCursor *c )
206 KoTextParag *p = doc->paragAt( firstParag );
209 kdDebug(32500) <<
"KoTextParagCommand::execute paragraph " << firstParag <<
"not found" << endl;
213 p->setFormat( m_newFormat );
215 if ( p->paragId() == lastParag )
222KoTextCursor * KoParagFormatCommand::unexecute( KoTextCursor *c )
224 kdDebug(32500) <<
"KoParagFormatCommand::unexecute" << endl;
225 KoTextParag *p = doc->paragAt( firstParag );
228 kdDebug(32500) <<
"KoParagFormatCommand::unexecute paragraph " << firstParag <<
"not found" << endl;
231 TQValueList<KoTextFormat *>::Iterator lit = m_oldFormats.begin();
233 if ( lit == m_oldFormats.end() )
235 kdDebug(32500) <<
"KoParagFormatCommand::unexecute m_oldFormats not big enough!" << endl;
238 p->setFormat( (*lit) );
239 if ( p->paragId() == lastParag )
247KoTextFormatCommand::KoTextFormatCommand(KoTextDocument *d,
int sid,
int sidx,
int eid,
int eidx,
const TQMemArray<KoTextStringChar> &old,
const KoTextFormat *f,
int fl )
248 : KoTextDocFormatCommand(d, sid, sidx, eid, eidx, old, f, fl)
253KoTextFormatCommand::~KoTextFormatCommand()
257void KoTextFormatCommand::resizeCustomItems()
259 KoTextParag *sp = doc->paragAt( startId );
260 KoTextParag *ep = doc->paragAt( endId );
264 KoTextCursor start( doc );
265 start.setParag( sp );
266 start.setIndex( startIndex );
267 KoTextCursor end( doc );
269 end.setIndex( endIndex );
271 doc->setSelectionStart( KoTextDocument::Temp, &start );
272 doc->setSelectionEnd( KoTextDocument::Temp, &end );
276 if ( start.parag() == end.parag() )
278 TQString text = start.parag()->string()->toString().mid( start.index(), end.index() - start.index() );
279 for (
int i = start.index(); i < end.index(); ++i )
281 if( start.parag()->at(i)->isCustom())
283 start.parag()->at(i)->customItem()->resize();
290 TQString text = start.parag()->string()->toString().mid( start.index(), start.parag()->length() - 1 - start.index() );
291 for ( i = start.index(); i < start.parag()->length(); ++i )
292 if( start.parag()->at(i)->isCustom())
294 start.parag()->at(i)->customItem()->resize();
297 KoTextParag *p = start.parag()->next();
298 while ( p && p != end.parag() )
300 text = p->string()->toString().left( p->length() - 1 );
301 for ( i = 0; i < p->length(); ++i )
303 if( p->at(i)->isCustom())
305 p->at(i)->customItem()->resize();
310 text = end.parag()->string()->toString().left( end.index() );
311 for ( i = 0; i < end.index(); ++i )
313 if( end.parag()->at(i)->isCustom())
315 end.parag()->at(i)->customItem()->resize();
321KoTextCursor *KoTextFormatCommand::execute( KoTextCursor *c )
323 c = KoTextDocFormatCommand::execute( c );
328KoTextCursor *KoTextFormatCommand::unexecute( KoTextCursor *c )
330 kdDebug(32500) <<
"KoTextFormatCommand::unexecute c:" << c <<
" index:" << c->index() << endl;
331 c = KoTextDocFormatCommand::unexecute( c );
332 kdDebug(32500) <<
"KoTextFormatCommand::unexecute after KoTextFormatCommand c:" << c <<
" index:" << c->index() << endl;
339KoChangeVariableSubType::KoChangeVariableSubType(
340 short int _oldValue,
short int _newValue,
343 m_newValue(_newValue),
344 m_oldValue(_oldValue),
349void KoChangeVariableSubType::execute()
356void KoChangeVariableSubType::unexecute()
363TQString KoChangeVariableSubType::name()
const
365 return i18n(
"Change Variable Subtype" );
370KoChangeVariableFormatProperties::KoChangeVariableFormatProperties(
371 const TQString &_oldValue,
const TQString &_newValue,
374 m_newValue(_newValue),
375 m_oldValue(_oldValue),
380void KoChangeVariableFormatProperties::execute()
385 m_var->setVariableFormat( coll->
format( m_var->variableFormat()->
getKey( m_newValue ) ) );
389void KoChangeVariableFormatProperties::unexecute()
394 m_var->setVariableFormat( coll->
format( m_var->variableFormat()->
getKey( m_oldValue ) ) );
398TQString KoChangeVariableFormatProperties::name()
const
400 return i18n(
"Change Variable Format" );
A CustomItemsMap associates a custom item to an index Used in the undo/redo info for insert/delete te...
void insertItems(const KoTextCursor &startCursor, int size)
Insert all the items from the map, into the existing text.
This class holds the paragraph-specific formatting information It's separated from KoTextParag so tha...
double margins[5]
left, right, top, bottom, firstLineSpacing - in pt
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
A KoVariable is a custom item, i.e.
virtual void setVariableSubType(short int)
Set this variable's subtype.
void recalcAndRepaint()
Ask this variable to recalculate and to repaint itself Only use this if you're working on a single va...