20#include <KoParagCounter.h>
22#include "KWInsertTOCCommand.h"
23#include "KWDocument.h"
24#include "KWTextFrameSet.h"
25#include "KWTextDocument.h"
26#include "KWTextParag.h"
31KWInsertTOCCommand::KWInsertTOCCommand(
KWTextFrameSet * fs, KoTextParag *parag )
32 : KoTextDocCommand( fs->textDocument() ), m_paragId( parag->paragId() )
36KoTextCursor * KWInsertTOCCommand::execute( KoTextCursor *c )
41 fs->kWordDocument()->setTocPresent(
true);
43 KoTextParag *insertionParag = textdoc->paragAt( m_paragId );
44 if ( !insertionParag ) {
45 tqWarning(
"KWInsertTOCCommand:: can't locate parag at %d, last parag: %d", m_paragId, textdoc->lastParag()->paragId() );
50 KWTextParag *parag =
static_cast<KWTextParag *
>( textdoc->createParag( textdoc, body->prev() , body , true ) );
51 parag->append( i18n(
"Table of Contents" ) );
52 KoParagStyle * style = findOrCreateTOCStyle( fs, -1 );
53 parag->setParagLayout( style->paragLayout() );
54 parag->setFormat( 0, parag->string()->length(), textdoc->formatCollection()->format( &style->format() ) );
55 parag->setPartOfTableOfContents(
true );
63 TQMap<KWTextParag *, KWTextParag *> paragMap;
66 if ( p->style() && p->style()->isOutline() )
68 parag =
static_cast<KWTextParag *
>(textdoc->createParag( textdoc, prevTOCParag , body ,
true ));
69 parag->setPartOfTableOfContents(
true );
70 TQString txt = p->toString();
74 paragMap.insert( parag, p );
79 kdDebug() <<
"KWInsertTOCCommand::execute setPageBreaking on " << prevTOCParag <<
" " << prevTOCParag->paragId() << endl;
80 prevTOCParag->
setPageBreaking( prevTOCParag->pageBreaking() | KWParagLayout::HardFrameBreakAfter );
89 TQMap<KWTextParag *, KWTextParag *>::Iterator mapIt = paragMap.begin();
90 for ( ; mapIt != paragMap.end() ; ++mapIt )
100 parag->append(
"\t" );
101 parag->append( TQString::number( frame->
pageNumber() ) );
105 int depth = p->counter() ? p->counter()->depth() : 0;
106 KoParagStyle * tocStyle = findOrCreateTOCStyle( fs, depth );
107 parag->setParagLayout( tocStyle->paragLayout() );
108 parag->setFormat( 0, parag->string()->length(), & tocStyle->format() );
111 prevTOCParag->
setPageBreaking( prevTOCParag->pageBreaking() | KWParagLayout::HardFrameBreakAfter );
115KoTextCursor *KWInsertTOCCommand::unexecute( KoTextCursor *c )
120 removeTOC( fs, c, 0L );
121 fs->kWordDocument()->setTocPresent(
false);
125KoTextCursor * KWInsertTOCCommand::removeTOC(
KWTextFrameSet *fs, KoTextCursor *cursor, KMacroCommand * )
127 KoTextDocument * textdoc = fs->textDocument();
129 KoTextCursor start( textdoc );
130 KoTextCursor end( textdoc );
132 KoTextParag *p = textdoc->lastParag();
133 KoTextCursor *posOfTable=0L;
134 KoTextParag *posOfToc=0L;
139 if ( parag->partOfTableOfContents() )
141 kdDebug() <<
"KWContents::createContents Deleting paragraph " << p <<
" " << p->paragId() << endl;
161 KoTextParag *prev = p->prev();
162 KoTextParag *next = p->next();
164 if ( cursor->parag() == p )
165 cursor->setParag( next ? next : prev );
167 kdDebug() <<
"KWInsertTOCCommand::removeTOC " << p <<
" deleted" << endl;
170 kdDebug() <<
"KWInsertTOCCommand::removeTOC prev=" << prev <<
" p=" << p << endl;
176 p->setParagId( prev->paragId() + 1 );
182 textdoc->setFirstParag( p );
188 textdoc->clear(
true );
189 cursor->setParag( textdoc->firstParag() );
190 posOfToc = textdoc->firstParag();
202 textdoc->invalidate();
205 posOfTable=
new KoTextCursor( textdoc );
206 posOfTable->setParag(posOfToc );
207 posOfTable->setIndex( 0 );
213KoParagStyle * KWInsertTOCCommand::findOrCreateTOCStyle(
KWTextFrameSet *fs,
int depth )
217 TQString displayName;
220 name = TQString(
"Contents_Head_%1" ).arg( depth+1 );
221 displayName = i18n(
"Contents Head %1" ).arg( depth+1 );
223 name =
"Contents_Title";
224 displayName = i18n(
"Contents Title" );
226 KoParagStyle * style = fs->kWordDocument()->styleCollection()->findStyle( name );
229 style =
new KoParagStyle( name );
230 style->setDisplayName( displayName );
231 style->format().setBold( ( ( depth==-1) || ( depth==0 ) ) ?
true : false );
232 style->format().setPointSize( depth==-1 ? 20 : 12 );
235 style->paragLayout().topBorder = KoBorder( TQt::black, KoBorder::SOLID, 1 );
236 style->paragLayout().bottomBorder = KoBorder( TQt::black, KoBorder::SOLID, 1 );
239 style->paragLayout().leftBorder = KoBorder( TQt::black, KoBorder::SOLID, 1 );
240 style->paragLayout().rightBorder = KoBorder( TQt::black, KoBorder::SOLID, 1 );
241 style->paragLayout().alignment = TQt::AlignHCenter;
245 KoTabulatorList tabList;
248 tab.ptPos = KoUnit::fromUserValue( floor( KoUnit::toMM( fs->
frame( 0 )->width() ) ), KoUnit::unit(
"mm") );
251 tab.filling = TF_DOTS;
253 tabList.append( tab );
254 style->paragLayout().setTabList( tabList );
255 style->paragLayout().margins[TQStyleSheetItem::MarginLeft] = KoUnit::fromUserValue( (depth*4.5), KoUnit::unit(
"mm") );
257 style = fs->kWordDocument()->styleCollection()->addStyle( style );
258 fs->kWordDocument()->updateAllStyleLists();
KWFrame * frame(unsigned int _num) const
get a frame by number
This class represents a single frame.
int pageNumber() const
The page on which this frame is.
This is our KoTextDocument reimplementation, to create KWTextParag instead of KoTextParags,...
KWTextFrameSet * textFrameSet() const
Return the text frameset in which this document is.
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
virtual void updateFrames(int flags=0xff)
reshuffle frames so text is always displayed from top-left down and then right.
KWFrame * internalToDocument(const KoPoint &relPoint, KoPoint &dPoint) const
Convert the in the internal qtextdoc coordinates (in layout units) into a point in the document coord...
virtual void layout()
Invalidate all paragraphs and start re-formatting.
This class extends KoTextParag for KWord-specific formatting stuff, custom items, loading and saving.
void setPageBreaking(int pb)
The type of page-breaking behaviour.