17
17
Boston, MA 02111-1307, USA.
20
#include "kwtextdocument.h"
20
21
#include "kwtextparag.h"
21
#include "kwtextdocument.h"
23
23
#include "kwtextframeset.h"
26
24
#include <kdebug.h>
28
KoTextDocument::KoTextDocument( KoZoomHandler * zoomHandler, QTextDocument *p, KWTextFormatCollection *fc )
29
: QTextDocument( p, fc ), m_zoomHandler( zoomHandler ), m_bDestroying( false )
31
setAddMargins( true ); // top margin and bottom are added, not max'ed
32
QTextFormatter * formatter = new QTextFormatterBreakWords;
33
formatter->setAllowBreakInWords( true ); // Necessary for lines without a single space
34
setFormatter( formatter );
40
// TODO clear(true) here if kpresenter uses kotextdocument directly,
41
// otherwise in the derived constructor [virtual method call is the problem]
44
KoTextDocument::~KoTextDocument()
50
QTextParag * KoTextDocument::createParag( QTextDocument *d, QTextParag *pr, QTextParag *nx, bool updateIds )
52
return new KoTextParag( d, pr, nx, updateIds );
55
bool KoTextDocument::visitSelection( int selectionId, KWParagVisitor* visitor, bool forward )
57
QTextCursor c1 = selectionStartCursor( selectionId );
58
QTextCursor c2 = selectionEndCursor( selectionId );
61
return visitFromTo( c1.parag(), c1.index(), c2.parag(), c2.index(), visitor, forward );
64
bool KoTextDocument::visitDocument( KWParagVisitor *visitor, bool forward )
66
return visitFromTo( firstParag(), 0, lastParag(), lastParag()->length()-1, visitor, forward );
69
bool KoTextDocument::visitFromTo( QTextParag *firstParag, int firstIndex, QTextParag* lastParag, int lastIndex, KWParagVisitor* visitor, bool forw )
71
if ( firstParag == lastParag )
73
return visitor->visit( firstParag, firstIndex, lastIndex );
80
// the -1 is for the trailing space
81
ret = visitor->visit( firstParag, firstIndex, firstParag->length() - 1 );
82
if (!ret) return false;
86
ret = visitor->visit( lastParag, 0, lastIndex );
87
if (!ret) return false;
90
QTextParag* currentParag = forw ? firstParag->next() : lastParag->prev();
91
QTextParag * endParag = forw ? lastParag : firstParag;
92
while ( currentParag && currentParag != endParag )
94
ret = visitor->visit( currentParag, 0, currentParag->length() - 1 );
95
if (!ret) return false;
96
currentParag = forw ? currentParag->next() : currentParag->prev();
98
ASSERT( currentParag );
99
ASSERT( endParag == currentParag );
101
ret = visitor->visit( lastParag, 0, lastIndex );
103
ret = visitor->visit( currentParag, firstIndex, currentParag->length() - 1 );
110
KWTextDocument::KWTextDocument( KWTextFrameSet * textfs, QTextDocument *p, KWTextFormatCollection *fc )
111
: KoTextDocument( textfs->kWordDocument(), p, fc ), m_textfs( textfs )
25
#include <kglobalsettings.h>
26
#include "kwcommand.h"
29
KWTextDocument::KWTextDocument( KWTextFrameSet * textfs, KoTextFormatCollection *fc, KoTextFormatter *formatter )
30
: KoTextDocument( textfs->kWordDocument(), fc, formatter, false ), m_textfs( textfs )
116
35
KWTextDocument::KWTextDocument( KoZoomHandler * zoomHandler )
117
: KoTextDocument( zoomHandler, 0, new KWTextFormatCollection( QFont("helvetica") /*unused*/ ) ),
36
: KoTextDocument( zoomHandler, new KoTextFormatCollection( KGlobalSettings::generalFont() /*unused*/, QColor(), KGlobal::locale()->language() , false, 1.0), 0L, false ),
124
42
void KWTextDocument::init()
126
// QTextDocument::QTextDocument creates a parag, but too early for our createParag to get called !
127
// So we have to get rid of it.
44
// Create initial paragraph as a KWTextParag
129
// Using clear( false ) is a bit dangerous, since we don't always check cursor->parag() for != 0
132
QTextParag * KWTextDocument::createParag( QTextDocument *d, QTextParag *pr, QTextParag *nx, bool updateIds )
134
return new KWTextParag( d, pr, nx, updateIds );
137
int KWTextCustomItem::index() const
139
ASSERT( paragraph() );
140
KWTextParag * parag = static_cast<KWTextParag *>( paragraph() );
141
return parag->findCustomItem( this );
144
QTextFormat * KWTextCustomItem::format() const
146
QTextParag * parag = paragraph();
147
//kdDebug() << "KWTextCustomItem::format index=" << index() << " format=" << parag->at( index() )->format() << endl;
148
return parag->at( index() )->format();
151
void CustomItemsMap::insertItems( const QTextCursor & startCursor, int size )
156
QTextCursor cursor( startCursor );
157
for ( int i = 0; i < size; ++i )
159
CustomItemsMap::Iterator it = find( i );
162
kdDebug() << "CustomItemsMap::insertItems setting custom item " << it.data() << endl;
163
static_cast<KWTextParag *>(cursor.parag())->setCustomItem( cursor.index(), it.data(), 0 );
164
it.data()->setDeleted( false );
170
void CustomItemsMap::deleteAll( KMacroCommand *macroCmd )
172
Iterator it = begin();
173
for ( ; it != end(); ++it )
175
KWTextCustomItem * item = it.data();
176
KCommand * itemCmd = item->deleteCommand();
177
if ( itemCmd && macroCmd )
179
macroCmd->addCommand( itemCmd );
180
itemCmd->execute(); // the item-specific delete stuff hasn't been done
182
item->setDeleted( true );
48
KWTextDocument::~KWTextDocument()
52
KoTextParag * KWTextDocument::createParag( KoTextDocument *d, KoTextParag *pr, KoTextParag *nx, bool updateIds )
54
return new KWTextParag( static_cast<KoTextDocument *>(d), static_cast<KoTextParag *>(pr), static_cast<KoTextParag *>(nx), updateIds );
57
KoTextDocCommand *KWTextDocument::deleteTextCommand( KoTextDocument *textdoc, int id, int index, const QMemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const QValueList<KoParagLayout> & oldParagLayouts )
59
//kdDebug()<<" KoTextDocument::deleteTextCommand************\n";
60
return new KWTextDeleteCommand( textdoc, id, index, str, customItemsMap, oldParagLayouts );
186
64
#include "kwtextdocument.moc"