author | leseb <leseb> | 2002-07-15 23:22:50 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-07-15 23:22:50 (UTC) |
commit | 72eb74051ed8f1b7696041e241ab99df3af5b08d (patch) (unidiff) | |
tree | bf9beee9469bc4384cb8178fbd6565cf161b4708 /noncore/apps/opie-write/qrichtext_p.cpp | |
parent | dcea0e50a00ed9efb988ded5abf5d39de1bea393 (diff) | |
download | opie-72eb74051ed8f1b7696041e241ab99df3af5b08d.zip opie-72eb74051ed8f1b7696041e241ab99df3af5b08d.tar.gz opie-72eb74051ed8f1b7696041e241ab99df3af5b08d.tar.bz2 |
Sync with Qt 3.0.5
Diffstat (limited to 'noncore/apps/opie-write/qrichtext_p.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-write/qrichtext_p.cpp | 303 |
1 files changed, 100 insertions, 203 deletions
diff --git a/noncore/apps/opie-write/qrichtext_p.cpp b/noncore/apps/opie-write/qrichtext_p.cpp index fb20730..6783e0b 100644 --- a/noncore/apps/opie-write/qrichtext_p.cpp +++ b/noncore/apps/opie-write/qrichtext_p.cpp | |||
@@ -53,95 +53,122 @@ void QTextCustomItem::invalidate() {} | |||
53 | 53 | ||
54 | bool QTextCustomItem::isNested() const { return FALSE; } | 54 | bool QTextCustomItem::isNested() const { return FALSE; } |
55 | int QTextCustomItem::minimumWidth() const { return 0; } | 55 | int QTextCustomItem::minimumWidth() const { return 0; } |
56 | 56 | ||
57 | QString QTextCustomItem::richText() const { return QString::null; } | 57 | QString QTextCustomItem::richText() const { return QString::null; } |
58 | 58 | ||
59 | bool QTextCustomItem::enter( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy, bool atEnd ) | 59 | bool QTextCustomItem::enter( QTextCursor *, QTextDocument*&, QTextParagraph *&, int &, int &, int &, bool ) |
60 | { | 60 | { |
61 | doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; Q_UNUSED( atEnd ) return TRUE; | 61 | return TRUE; |
62 | |||
63 | } | 62 | } |
64 | bool QTextCustomItem::enterAt( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy, const QPoint & ) | 63 | bool QTextCustomItem::enterAt( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int &, const QPoint & ) |
65 | { | 64 | { |
66 | doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; | 65 | return TRUE; |
67 | } | 66 | } |
68 | bool QTextCustomItem::next( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ) | 67 | bool QTextCustomItem::next( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
69 | { | 68 | { |
70 | doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; | 69 | return TRUE; |
71 | } | 70 | } |
72 | bool QTextCustomItem::prev( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ) | 71 | bool QTextCustomItem::prev( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
73 | { | 72 | { |
74 | doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; | 73 | return TRUE; |
75 | } | 74 | } |
76 | bool QTextCustomItem::down( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ) | 75 | bool QTextCustomItem::down( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
77 | { | 76 | { |
78 | doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; | 77 | return TRUE; |
79 | } | 78 | } |
80 | bool QTextCustomItem::up( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ) | 79 | bool QTextCustomItem::up( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
81 | { | 80 | { |
82 | doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; | 81 | return TRUE; |
83 | } | 82 | } |
84 | 83 | ||
85 | void QTextFlow::setPageSize( int ps ) { pagesize = ps; } | 84 | void QTextFlow::setPageSize( int ps ) { pagesize = ps; } |
86 | bool QTextFlow::isEmpty() { return leftItems.isEmpty() && rightItems.isEmpty(); } | 85 | bool QTextFlow::isEmpty() { return leftItems.isEmpty() && rightItems.isEmpty(); } |
87 | 86 | ||
88 | void QTextTableCell::invalidate() { cached_width = -1; cached_sizehint = -1; } | 87 | void QTextTableCell::invalidate() { cached_width = -1; cached_sizehint = -1; } |
89 | 88 | ||
90 | void QTextTable::invalidate() { cachewidth = -1; } | 89 | void QTextTable::invalidate() { cachewidth = -1; } |
91 | 90 | ||
92 | QTextParagData::~QTextParagData() {} | 91 | QTextParagraphData::~QTextParagraphData() {} |
93 | void QTextParagData::join( QTextParagData * ) {} | 92 | void QTextParagraphData::join( QTextParagraphData * ) {} |
94 | 93 | ||
95 | QTextFormatter::~QTextFormatter() {} | 94 | QTextFormatter::~QTextFormatter() {} |
96 | void QTextFormatter::setWrapEnabled( bool b ) { wrapEnabled = b; } | 95 | void QTextFormatter::setWrapEnabled( bool b ) { wrapEnabled = b; } |
97 | void QTextFormatter::setWrapAtColumn( int c ) { wrapColumn = c; } | 96 | void QTextFormatter::setWrapAtColumn( int c ) { wrapColumn = c; } |
98 | 97 | ||
99 | 98 | ||
100 | 99 | ||
101 | int QTextCursor::x() const | 100 | int QTextCursor::x() const |
102 | { | 101 | { |
103 | QTextStringChar *c = string->at( idx ); | 102 | QTextStringChar *c = para->at( idx ); |
104 | int curx = c->x; | 103 | int curx = c->x; |
105 | if ( !c->rightToLeft && | 104 | if ( !c->rightToLeft && |
106 | c->c.isSpace() && | 105 | c->c.isSpace() && |
107 | idx > 0 && | 106 | idx > 0 && |
108 | ( string->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify ) | 107 | !c->lineStart && |
109 | curx = string->at( idx - 1 )->x + string->string()->width( idx - 1 ); | 108 | ( para->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify ) |
109 | curx = para->at( idx - 1 )->x + para->string()->width( idx - 1 ); | ||
110 | if ( c->rightToLeft ) | 110 | if ( c->rightToLeft ) |
111 | curx += string->string()->width( idx ); | 111 | curx += para->string()->width( idx ); |
112 | return curx; | 112 | return curx; |
113 | } | 113 | } |
114 | 114 | ||
115 | int QTextCursor::y() const | 115 | int QTextCursor::y() const |
116 | { | 116 | { |
117 | int dummy, line; | 117 | int dummy, line; |
118 | string->lineStartOfChar( idx, &dummy, &line ); | 118 | para->lineStartOfChar( idx, &dummy, &line ); |
119 | return string->lineY( line ); | 119 | return para->lineY( line ); |
120 | } | ||
121 | |||
122 | int QTextCursor::globalX() const { return totalOffsetX() + para->rect().x() + x(); } | ||
123 | int QTextCursor::globalY() const { return totalOffsetY() + para->rect().y() + y(); } | ||
124 | |||
125 | QTextDocument *QTextCursor::document() const | ||
126 | { | ||
127 | return para ? para->document() : 0; | ||
128 | } | ||
129 | |||
130 | void QTextCursor::gotoPosition( QTextParagraph* p, int index ) | ||
131 | { | ||
132 | if ( para && p != para ) { | ||
133 | while ( para->document() != p->document() && !indices.isEmpty() ) | ||
134 | pop(); | ||
135 | Q_ASSERT( indices.isEmpty() || para->document() == p->document() ); | ||
136 | } | ||
137 | para = p; | ||
138 | if ( index < 0 || index >= para->length() ) { | ||
139 | #if defined(QT_CHECK_RANGE) | ||
140 | qWarning( "QTextCursor::gotoParagraph Index: %d out of range", index ); | ||
141 | #endif | ||
142 | index = index < 0 ? 0 : para->length() - 1; | ||
143 | } | ||
144 | |||
145 | tmpIndex = -1; | ||
146 | idx = index; | ||
120 | } | 147 | } |
121 | 148 | ||
122 | bool QTextDocument::hasSelection( int id, bool visible ) const | 149 | bool QTextDocument::hasSelection( int id, bool visible ) const |
123 | { | 150 | { |
124 | return ( selections.find( id ) != selections.end() && | 151 | return ( selections.find( id ) != selections.end() && |
125 | ( !visible || | 152 | ( !visible || |
126 | ( (QTextDocument*)this )->selectionStartCursor( id ) != | 153 | ( (QTextDocument*)this )->selectionStartCursor( id ) != |
127 | ( (QTextDocument*)this )->selectionEndCursor( id ) ) ); | 154 | ( (QTextDocument*)this )->selectionEndCursor( id ) ) ); |
128 | } | 155 | } |
129 | 156 | ||
130 | void QTextDocument::setSelectionStart( int id, QTextCursor *cursor ) | 157 | void QTextDocument::setSelectionStart( int id, const QTextCursor &cursor ) |
131 | { | 158 | { |
132 | QTextDocumentSelection sel; | 159 | QTextDocumentSelection sel; |
133 | sel.startCursor = *cursor; | 160 | sel.startCursor = cursor; |
134 | sel.endCursor = *cursor; | 161 | sel.endCursor = cursor; |
135 | sel.swapped = FALSE; | 162 | sel.swapped = FALSE; |
136 | selections[ id ] = sel; | 163 | selections[ id ] = sel; |
137 | } | 164 | } |
138 | 165 | ||
139 | QTextParag *QTextDocument::paragAt( int i ) const | 166 | QTextParagraph *QTextDocument::paragAt( int i ) const |
140 | { | 167 | { |
141 | QTextParag* p = curParag; | 168 | QTextParagraph* p = curParag; |
142 | if ( !p || p->paragId() > i ) | 169 | if ( !p || p->paragId() > i ) |
143 | p = fParag; | 170 | p = fParag; |
144 | while ( p && p->paragId() != i ) | 171 | while ( p && p->paragId() != i ) |
145 | p = p->next(); | 172 | p = p->next(); |
146 | ((QTextDocument*)this)->curParag = p; | 173 | ((QTextDocument*)this)->curParag = p; |
147 | return p; | 174 | return p; |
@@ -150,67 +177,64 @@ QTextParag *QTextDocument::paragAt( int i ) const | |||
150 | 177 | ||
151 | QTextFormat::~QTextFormat() | 178 | QTextFormat::~QTextFormat() |
152 | { | 179 | { |
153 | } | 180 | } |
154 | 181 | ||
155 | QTextFormat::QTextFormat() | 182 | QTextFormat::QTextFormat() |
156 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ), | 183 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ) |
157 | different( NoFlags ) | ||
158 | { | 184 | { |
159 | ref = 0; | 185 | ref = 0; |
160 | 186 | ||
161 | usePixelSizes = FALSE; | 187 | usePixelSizes = FALSE; |
162 | if ( stdSize == -1 ) { | 188 | if ( stdSize == -1 ) { |
163 | stdSize = qApp->font().pixelSize(); | 189 | stdSize = qApp->font().pixelSize(); |
164 | usePixelSizes = TRUE; | 190 | usePixelSizes = TRUE; |
165 | } | 191 | } |
166 | 192 | ||
167 | missp = FALSE; | 193 | missp = FALSE; |
168 | ha = AlignNormal; | 194 | ha = AlignNormal; |
169 | collection = 0; | 195 | collection = 0; |
170 | } | 196 | } |
171 | 197 | ||
172 | QTextFormat::QTextFormat( const QStyleSheetItem *style ) | 198 | QTextFormat::QTextFormat( const QStyleSheetItem *style ) |
173 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ), | 199 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ) |
174 | different( NoFlags ) | ||
175 | { | 200 | { |
176 | ref = 0; | 201 | ref = 0; |
177 | 202 | ||
178 | usePixelSizes = FALSE; | 203 | usePixelSizes = FALSE; |
179 | if ( stdSize == -1 ) { | 204 | if ( stdSize == -1 ) { |
180 | stdSize = qApp->font().pixelSize(); | 205 | stdSize = qApp->font().pixelSize(); |
181 | usePixelSizes = TRUE; | 206 | usePixelSizes = TRUE; |
182 | } | 207 | } |
183 | 208 | ||
184 | this->style = style->name(); | ||
185 | missp = FALSE; | 209 | missp = FALSE; |
186 | ha = AlignNormal; | 210 | ha = AlignNormal; |
187 | collection = 0; | 211 | collection = 0; |
188 | fn = QFont( style->fontFamily(), | 212 | fn = QFont( style->fontFamily(), |
189 | style->fontSize(), | 213 | style->fontSize(), |
190 | style->fontWeight(), | 214 | style->fontWeight(), |
191 | style->fontItalic() ); | 215 | style->fontItalic() ); |
192 | fn.setUnderline( style->fontUnderline() ); | 216 | fn.setUnderline( style->fontUnderline() ); |
217 | fn.setStrikeOut( style->fontStrikeOut() ); | ||
193 | col = style->color(); | 218 | col = style->color(); |
194 | fm = QFontMetrics( fn ); | 219 | fm = QFontMetrics( fn ); |
195 | leftBearing = fm.minLeftBearing(); | 220 | leftBearing = fm.minLeftBearing(); |
196 | rightBearing = fm.minRightBearing(); | 221 | rightBearing = fm.minRightBearing(); |
197 | hei = fm.lineSpacing(); | 222 | hei = fm.lineSpacing(); |
198 | asc = fm.ascent() + (fm.leading()+1)/2; | 223 | asc = fm.ascent() + (fm.leading()+1)/2; |
199 | dsc = fm.descent(); | 224 | dsc = fm.descent(); |
200 | missp = FALSE; | 225 | missp = FALSE; |
201 | ha = AlignNormal; | 226 | ha = AlignNormal; |
202 | memset( widths, 0, 256 ); | 227 | memset( widths, 0, 256 ); |
203 | generateKey(); | 228 | generateKey(); |
204 | addRef(); | 229 | addRef(); |
205 | updateStyleFlags(); | ||
206 | } | 230 | } |
207 | 231 | ||
208 | QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent ) | 232 | QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent ) |
209 | : fn( f ), col( c ), fm( QFontMetrics( f ) ), linkColor( TRUE ), | 233 | : fn( f ), col( c ), fm( QFontMetrics( f ) ), linkColor( TRUE ), |
210 | logicalFontSize( 3 ), stdSize( f.pointSize() ), different( NoFlags ) | 234 | logicalFontSize( 3 ), stdSize( f.pointSize() ) |
211 | { | 235 | { |
212 | ref = 0; | 236 | ref = 0; |
213 | usePixelSizes = FALSE; | 237 | usePixelSizes = FALSE; |
214 | if ( stdSize == -1 ) { | 238 | if ( stdSize == -1 ) { |
215 | stdSize = f.pixelSize(); | 239 | stdSize = f.pixelSize(); |
216 | usePixelSizes = TRUE; | 240 | usePixelSizes = TRUE; |
@@ -223,13 +247,12 @@ QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection | |||
223 | dsc = fm.descent(); | 247 | dsc = fm.descent(); |
224 | missp = FALSE; | 248 | missp = FALSE; |
225 | ha = AlignNormal; | 249 | ha = AlignNormal; |
226 | memset( widths, 0, 256 ); | 250 | memset( widths, 0, 256 ); |
227 | generateKey(); | 251 | generateKey(); |
228 | addRef(); | 252 | addRef(); |
229 | updateStyleFlags(); | ||
230 | } | 253 | } |
231 | 254 | ||
232 | QTextFormat::QTextFormat( const QTextFormat &f ) | 255 | QTextFormat::QTextFormat( const QTextFormat &f ) |
233 | : fm( f.fm ) | 256 | : fm( f.fm ) |
234 | { | 257 | { |
235 | ref = 0; | 258 | ref = 0; |
@@ -246,14 +269,12 @@ QTextFormat::QTextFormat( const QTextFormat &f ) | |||
246 | usePixelSizes = f.usePixelSizes; | 269 | usePixelSizes = f.usePixelSizes; |
247 | logicalFontSize = f.logicalFontSize; | 270 | logicalFontSize = f.logicalFontSize; |
248 | missp = f.missp; | 271 | missp = f.missp; |
249 | ha = f.ha; | 272 | ha = f.ha; |
250 | k = f.k; | 273 | k = f.k; |
251 | linkColor = f.linkColor; | 274 | linkColor = f.linkColor; |
252 | style = f.style; | ||
253 | different = f.different; | ||
254 | addRef(); | 275 | addRef(); |
255 | } | 276 | } |
256 | 277 | ||
257 | QTextFormat& QTextFormat::operator=( const QTextFormat &f ) | 278 | QTextFormat& QTextFormat::operator=( const QTextFormat &f ) |
258 | { | 279 | { |
259 | ref = 0; | 280 | ref = 0; |
@@ -271,14 +292,12 @@ QTextFormat& QTextFormat::operator=( const QTextFormat &f ) | |||
271 | usePixelSizes = f.usePixelSizes; | 292 | usePixelSizes = f.usePixelSizes; |
272 | logicalFontSize = f.logicalFontSize; | 293 | logicalFontSize = f.logicalFontSize; |
273 | missp = f.missp; | 294 | missp = f.missp; |
274 | ha = f.ha; | 295 | ha = f.ha; |
275 | k = f.k; | 296 | k = f.k; |
276 | linkColor = f.linkColor; | 297 | linkColor = f.linkColor; |
277 | style = f.style; | ||
278 | different = f.different; | ||
279 | addRef(); | 298 | addRef(); |
280 | return *this; | 299 | return *this; |
281 | } | 300 | } |
282 | 301 | ||
283 | void QTextFormat::update() | 302 | void QTextFormat::update() |
284 | { | 303 | { |
@@ -287,13 +306,12 @@ void QTextFormat::update() | |||
287 | rightBearing = fm.minRightBearing(); | 306 | rightBearing = fm.minRightBearing(); |
288 | hei = fm.lineSpacing(); | 307 | hei = fm.lineSpacing(); |
289 | asc = fm.ascent() + (fm.leading()+1)/2; | 308 | asc = fm.ascent() + (fm.leading()+1)/2; |
290 | dsc = fm.descent(); | 309 | dsc = fm.descent(); |
291 | memset( widths, 0, 256 ); | 310 | memset( widths, 0, 256 ); |
292 | generateKey(); | 311 | generateKey(); |
293 | updateStyleFlags(); | ||
294 | } | 312 | } |
295 | 313 | ||
296 | 314 | ||
297 | QPainter* QTextFormat::pntr = 0; | 315 | QPainter* QTextFormat::pntr = 0; |
298 | 316 | ||
299 | void QTextFormat::setPainter( QPainter *p ) | 317 | void QTextFormat::setPainter( QPainter *p ) |
@@ -369,58 +387,12 @@ QString QTextFormat::getKey( const QFont &fn, const QColor &col, bool misspelled | |||
369 | k += QString::number( (int)misspelled ); | 387 | k += QString::number( (int)misspelled ); |
370 | k += '/'; | 388 | k += '/'; |
371 | k += QString::number( (int)a ); | 389 | k += QString::number( (int)a ); |
372 | return k; | 390 | return k; |
373 | } | 391 | } |
374 | 392 | ||
375 | void QTextFormat::updateStyle() | ||
376 | { | ||
377 | if ( !collection || !collection->styleSheet() ) | ||
378 | return; | ||
379 | QStyleSheetItem *item = collection->styleSheet()->item( style ); | ||
380 | if ( !item ) | ||
381 | return; | ||
382 | if ( !( different & Color ) && item->color().isValid() ) | ||
383 | col = item->color(); | ||
384 | if ( !( different & Size ) && item->fontSize() != -1 ) | ||
385 | fn.setPointSize( item->fontSize() ); | ||
386 | if ( !( different & Family ) && !item->fontFamily().isEmpty() ) | ||
387 | fn.setFamily( item->fontFamily() ); | ||
388 | if ( !( different & Bold ) && item->fontWeight() != -1 ) | ||
389 | fn.setWeight( item->fontWeight() ); | ||
390 | if ( !( different & Italic ) && item->definesFontItalic() ) | ||
391 | fn.setItalic( item->fontItalic() ); | ||
392 | if ( !( different & Underline ) && item->definesFontUnderline() ) | ||
393 | fn.setUnderline( item->fontUnderline() ); | ||
394 | generateKey(); | ||
395 | update(); | ||
396 | |||
397 | } | ||
398 | |||
399 | void QTextFormat::updateStyleFlags() | ||
400 | { | ||
401 | different = NoFlags; | ||
402 | if ( !collection || !collection->styleSheet() ) | ||
403 | return; | ||
404 | QStyleSheetItem *item = collection->styleSheet()->item( style ); | ||
405 | if ( !item ) | ||
406 | return; | ||
407 | if ( item->color() != col ) | ||
408 | different |= Color; | ||
409 | if ( item->fontSize() != fn.pointSize() ) | ||
410 | different |= Size; | ||
411 | if ( item->fontFamily() != fn.family() ) | ||
412 | different |= Family; | ||
413 | if ( item->fontItalic() != fn.italic() ) | ||
414 | different |= Italic; | ||
415 | if ( item->fontUnderline() != fn.underline() ) | ||
416 | different |= Underline; | ||
417 | if ( item->fontWeight() != fn.weight() ) | ||
418 | different |= Bold; | ||
419 | } | ||
420 | |||
421 | QString QTextString::toString( const QMemArray<QTextStringChar> &data ) | 393 | QString QTextString::toString( const QMemArray<QTextStringChar> &data ) |
422 | { | 394 | { |
423 | QString s; | 395 | QString s; |
424 | int l = data.size(); | 396 | int l = data.size(); |
425 | s.setUnicode( 0, l ); | 397 | s.setUnicode( 0, l ); |
426 | QTextStringChar *c = data.data(); | 398 | QTextStringChar *c = data.data(); |
@@ -440,267 +412,192 @@ QString QTextString::toString( const QMemArray<QTextStringChar> &data ) | |||
440 | 412 | ||
441 | QString QTextString::toString() const | 413 | QString QTextString::toString() const |
442 | { | 414 | { |
443 | return toString( data ); | 415 | return toString( data ); |
444 | } | 416 | } |
445 | 417 | ||
446 | void QTextParag::setSelection( int id, int start, int end ) | 418 | void QTextParagraph::setSelection( int id, int start, int end ) |
447 | { | 419 | { |
448 | QMap<int, QTextParagSelection>::ConstIterator it = selections().find( id ); | 420 | QMap<int, QTextParagraphSelection>::ConstIterator it = selections().find( id ); |
449 | if ( it != mSelections->end() ) { | 421 | if ( it != mSelections->end() ) { |
450 | if ( start == ( *it ).start && end == ( *it ).end ) | 422 | if ( start == ( *it ).start && end == ( *it ).end ) |
451 | return; | 423 | return; |
452 | } | 424 | } |
453 | 425 | ||
454 | QTextParagSelection sel; | 426 | QTextParagraphSelection sel; |
455 | sel.start = start; | 427 | sel.start = start; |
456 | sel.end = end; | 428 | sel.end = end; |
457 | (*mSelections)[ id ] = sel; | 429 | (*mSelections)[ id ] = sel; |
458 | setChanged( TRUE, TRUE ); | 430 | setChanged( TRUE, TRUE ); |
459 | } | 431 | } |
460 | 432 | ||
461 | void QTextParag::removeSelection( int id ) | 433 | void QTextParagraph::removeSelection( int id ) |
462 | { | 434 | { |
463 | if ( !hasSelection( id ) ) | 435 | if ( !hasSelection( id ) ) |
464 | return; | 436 | return; |
465 | if ( mSelections ) | 437 | if ( mSelections ) |
466 | mSelections->remove( id ); | 438 | mSelections->remove( id ); |
467 | setChanged( TRUE, TRUE ); | 439 | setChanged( TRUE, TRUE ); |
468 | } | 440 | } |
469 | 441 | ||
470 | int QTextParag::selectionStart( int id ) const | 442 | int QTextParagraph::selectionStart( int id ) const |
471 | { | 443 | { |
472 | if ( !mSelections ) | 444 | if ( !mSelections ) |
473 | return -1; | 445 | return -1; |
474 | QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id ); | 446 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); |
475 | if ( it == mSelections->end() ) | 447 | if ( it == mSelections->end() ) |
476 | return -1; | 448 | return -1; |
477 | return ( *it ).start; | 449 | return ( *it ).start; |
478 | } | 450 | } |
479 | 451 | ||
480 | int QTextParag::selectionEnd( int id ) const | 452 | int QTextParagraph::selectionEnd( int id ) const |
481 | { | 453 | { |
482 | if ( !mSelections ) | 454 | if ( !mSelections ) |
483 | return -1; | 455 | return -1; |
484 | QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id ); | 456 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); |
485 | if ( it == mSelections->end() ) | 457 | if ( it == mSelections->end() ) |
486 | return -1; | 458 | return -1; |
487 | return ( *it ).end; | 459 | return ( *it ).end; |
488 | } | 460 | } |
489 | 461 | ||
490 | bool QTextParag::hasSelection( int id ) const | 462 | bool QTextParagraph::hasSelection( int id ) const |
491 | { | 463 | { |
492 | if ( !mSelections ) | 464 | return mSelections ? mSelections->contains( id ) : FALSE; |
493 | return FALSE; | ||
494 | QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id ); | ||
495 | if ( it == mSelections->end() ) | ||
496 | return FALSE; | ||
497 | return ( *it ).start != ( *it ).end || length() == 1; | ||
498 | } | 465 | } |
499 | 466 | ||
500 | bool QTextParag::fullSelected( int id ) const | 467 | bool QTextParagraph::fullSelected( int id ) const |
501 | { | 468 | { |
502 | if ( !mSelections ) | 469 | if ( !mSelections ) |
503 | return FALSE; | 470 | return FALSE; |
504 | QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id ); | 471 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); |
505 | if ( it == mSelections->end() ) | 472 | if ( it == mSelections->end() ) |
506 | return FALSE; | 473 | return FALSE; |
507 | return ( *it ).start == 0 && ( *it ).end == str->length() - 1; | 474 | return ( *it ).start == 0 && ( *it ).end == str->length() - 1; |
508 | } | 475 | } |
509 | 476 | ||
510 | int QTextParag::lineY( int l ) const | 477 | int QTextParagraph::lineY( int l ) const |
511 | { | 478 | { |
512 | if ( l > (int)lineStarts.count() - 1 ) { | 479 | if ( l > (int)lineStarts.count() - 1 ) { |
513 | qWarning( "QTextParag::lineY: line %d out of range!", l ); | 480 | qWarning( "QTextParagraph::lineY: line %d out of range!", l ); |
514 | return 0; | 481 | return 0; |
515 | } | 482 | } |
516 | 483 | ||
517 | if ( !isValid() ) | 484 | if ( !isValid() ) |
518 | ( (QTextParag*)this )->format(); | 485 | ( (QTextParagraph*)this )->format(); |
519 | 486 | ||
520 | QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); | 487 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
521 | while ( l-- > 0 ) | 488 | while ( l-- > 0 ) |
522 | ++it; | 489 | ++it; |
523 | return ( *it )->y; | 490 | return ( *it )->y; |
524 | } | 491 | } |
525 | 492 | ||
526 | int QTextParag::lineBaseLine( int l ) const | 493 | int QTextParagraph::lineBaseLine( int l ) const |
527 | { | 494 | { |
528 | if ( l > (int)lineStarts.count() - 1 ) { | 495 | if ( l > (int)lineStarts.count() - 1 ) { |
529 | qWarning( "QTextParag::lineBaseLine: line %d out of range!", l ); | 496 | qWarning( "QTextParagraph::lineBaseLine: line %d out of range!", l ); |
530 | return 10; | 497 | return 10; |
531 | } | 498 | } |
532 | 499 | ||
533 | if ( !isValid() ) | 500 | if ( !isValid() ) |
534 | ( (QTextParag*)this )->format(); | 501 | ( (QTextParagraph*)this )->format(); |
535 | 502 | ||
536 | QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); | 503 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
537 | while ( l-- > 0 ) | 504 | while ( l-- > 0 ) |
538 | ++it; | 505 | ++it; |
539 | return ( *it )->baseLine; | 506 | return ( *it )->baseLine; |
540 | } | 507 | } |
541 | 508 | ||
542 | int QTextParag::lineHeight( int l ) const | 509 | int QTextParagraph::lineHeight( int l ) const |
543 | { | 510 | { |
544 | if ( l > (int)lineStarts.count() - 1 ) { | 511 | if ( l > (int)lineStarts.count() - 1 ) { |
545 | qWarning( "QTextParag::lineHeight: line %d out of range!", l ); | 512 | qWarning( "QTextParagraph::lineHeight: line %d out of range!", l ); |
546 | return 15; | 513 | return 15; |
547 | } | 514 | } |
548 | 515 | ||
549 | if ( !isValid() ) | 516 | if ( !isValid() ) |
550 | ( (QTextParag*)this )->format(); | 517 | ( (QTextParagraph*)this )->format(); |
551 | 518 | ||
552 | QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); | 519 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
553 | while ( l-- > 0 ) | 520 | while ( l-- > 0 ) |
554 | ++it; | 521 | ++it; |
555 | return ( *it )->h; | 522 | return ( *it )->h; |
556 | } | 523 | } |
557 | 524 | ||
558 | void QTextParag::lineInfo( int l, int &y, int &h, int &bl ) const | 525 | void QTextParagraph::lineInfo( int l, int &y, int &h, int &bl ) const |
559 | { | 526 | { |
560 | if ( l > (int)lineStarts.count() - 1 ) { | 527 | if ( l > (int)lineStarts.count() - 1 ) { |
561 | qWarning( "QTextParag::lineInfo: line %d out of range!", l ); | 528 | qWarning( "QTextParagraph::lineInfo: line %d out of range!", l ); |
562 | qDebug( "%d %d", (int)lineStarts.count() - 1, l ); | 529 | qDebug( "%d %d", (int)lineStarts.count() - 1, l ); |
563 | y = 0; | 530 | y = 0; |
564 | h = 15; | 531 | h = 15; |
565 | bl = 10; | 532 | bl = 10; |
566 | return; | 533 | return; |
567 | } | 534 | } |
568 | 535 | ||
569 | if ( !isValid() ) | 536 | if ( !isValid() ) |
570 | ( (QTextParag*)this )->format(); | 537 | ( (QTextParagraph*)this )->format(); |
571 | 538 | ||
572 | QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); | 539 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
573 | while ( l-- > 0 ) | 540 | while ( l-- > 0 ) |
574 | ++it; | 541 | ++it; |
575 | y = ( *it )->y; | 542 | y = ( *it )->y; |
576 | h = ( *it )->h; | 543 | h = ( *it )->h; |
577 | bl = ( *it )->baseLine; | 544 | bl = ( *it )->baseLine; |
578 | } | 545 | } |
579 | 546 | ||
580 | int QTextParag::alignment() const | ||
581 | { | ||
582 | if ( align != -1 ) | ||
583 | return align; | ||
584 | QStyleSheetItem *item = style(); | ||
585 | if ( !item ) | ||
586 | return Qt3::AlignAuto; | ||
587 | if ( mStyleSheetItemsVec ) { | ||
588 | for ( int i = 0; i < (int)mStyleSheetItemsVec->size(); ++i ) { | ||
589 | item = (*mStyleSheetItemsVec)[ i ]; | ||
590 | if ( item->alignment() != QStyleSheetItem::Undefined ) | ||
591 | return item->alignment(); | ||
592 | } | ||
593 | } | ||
594 | return Qt3::AlignAuto; | ||
595 | } | ||
596 | 547 | ||
597 | QPtrVector<QStyleSheetItem> QTextParag::styleSheetItems() const | 548 | void QTextParagraph::setAlignment( int a ) |
598 | { | 549 | { |
599 | QPtrVector<QStyleSheetItem> vec; | 550 | if ( a == (int)align ) |
600 | if ( mStyleSheetItemsVec ) { | ||
601 | vec.resize( mStyleSheetItemsVec->size() ); | ||
602 | for ( int i = 0; i < (int)vec.size(); ++i ) | ||
603 | vec.insert( i, (*mStyleSheetItemsVec)[ i ] ); | ||
604 | } | ||
605 | return vec; | ||
606 | } | ||
607 | |||
608 | QStyleSheetItem *QTextParag::style() const | ||
609 | { | ||
610 | if ( !mStyleSheetItemsVec || mStyleSheetItemsVec->size() == 0 ) | ||
611 | return 0; | ||
612 | return (*mStyleSheetItemsVec)[ mStyleSheetItemsVec->size() - 1 ]; | ||
613 | } | ||
614 | |||
615 | int QTextParag::numberOfSubParagraph() const | ||
616 | { | ||
617 | if ( list_val != -1 ) | ||
618 | return list_val; | ||
619 | if ( numSubParag != -1 ) | ||
620 | return numSubParag; | ||
621 | int n = 0; | ||
622 | QTextParag *p = (QTextParag*)this; | ||
623 | while ( p && ( styleSheetItemsVec().size() >= p->styleSheetItemsVec().size() && | ||
624 | styleSheetItemsVec()[ (int)p->styleSheetItemsVec().size() - 1 ] == p->style() || | ||
625 | p->styleSheetItemsVec().size() >= styleSheetItemsVec().size() && | ||
626 | p->styleSheetItemsVec()[ (int)styleSheetItemsVec().size() - 1 ] == style() ) ) { | ||
627 | if ( p->style() == style() && listStyle() != p->listStyle() | ||
628 | && p->styleSheetItemsVec().size() == styleSheetItemsVec().size() ) | ||
629 | break; | ||
630 | if ( p->style()->displayMode() == QStyleSheetItem::DisplayListItem | ||
631 | && p->style() != style() || styleSheetItemsVec().size() == p->styleSheetItemsVec().size() ) | ||
632 | ++n; | ||
633 | p = p->prev(); | ||
634 | } | ||
635 | ( (QTextParag*)this )->numSubParag = n; | ||
636 | return n; | ||
637 | } | ||
638 | |||
639 | void QTextParag::setFormat( QTextFormat *fm ) | ||
640 | { | ||
641 | bool doUpdate = FALSE; | ||
642 | if (defFormat && (defFormat != formatCollection()->defaultFormat())) | ||
643 | doUpdate = TRUE; | ||
644 | defFormat = formatCollection()->format( fm ); | ||
645 | if ( !doUpdate ) | ||
646 | return; | 551 | return; |
647 | for ( int i = 0; i < length(); ++i ) { | 552 | align = a; |
648 | if ( at( i )->format()->styleName() == defFormat->styleName() ) | 553 | invalidate( 0 ); |
649 | at( i )->format()->updateStyle(); | ||
650 | } | ||
651 | } | 554 | } |
652 | 555 | ||
653 | QTextFormatter *QTextParag::formatter() const | 556 | QTextFormatter *QTextParagraph::formatter() const |
654 | { | 557 | { |
655 | if ( hasdoc ) | 558 | if ( hasdoc ) |
656 | return document()->formatter(); | 559 | return document()->formatter(); |
657 | if ( pseudoDocument()->pFormatter ) | 560 | if ( pseudoDocument()->pFormatter ) |
658 | return pseudoDocument()->pFormatter; | 561 | return pseudoDocument()->pFormatter; |
659 | return ( ( (QTextParag*)this )->pseudoDocument()->pFormatter = new QTextFormatterBreakWords ); | 562 | return ( ( (QTextParagraph*)this )->pseudoDocument()->pFormatter = new QTextFormatterBreakWords ); |
660 | } | 563 | } |
661 | 564 | ||
662 | void QTextParag::setTabArray( int *a ) | 565 | void QTextParagraph::setTabArray( int *a ) |
663 | { | 566 | { |
664 | delete [] tArray; | 567 | delete [] tArray; |
665 | tArray = a; | 568 | tArray = a; |
666 | } | 569 | } |
667 | 570 | ||
668 | void QTextParag::setTabStops( int tw ) | 571 | void QTextParagraph::setTabStops( int tw ) |
669 | { | 572 | { |
670 | if ( hasdoc ) | 573 | if ( hasdoc ) |
671 | document()->setTabStops( tw ); | 574 | document()->setTabStops( tw ); |
672 | else | 575 | else |
673 | tabStopWidth = tw; | 576 | tabStopWidth = tw; |
674 | } | 577 | } |
675 | 578 | ||
676 | QMap<int, QTextParagSelection> &QTextParag::selections() const | 579 | QMap<int, QTextParagraphSelection> &QTextParagraph::selections() const |
677 | { | 580 | { |
678 | if ( !mSelections ) | 581 | if ( !mSelections ) |
679 | ((QTextParag *)this)->mSelections = new QMap<int, QTextParagSelection>; | 582 | ((QTextParagraph *)this)->mSelections = new QMap<int, QTextParagraphSelection>; |
680 | return *mSelections; | 583 | return *mSelections; |
681 | } | 584 | } |
682 | 585 | ||
683 | QPtrVector<QStyleSheetItem> &QTextParag::styleSheetItemsVec() const | ||
684 | { | ||
685 | if ( !mStyleSheetItemsVec ) | ||
686 | ((QTextParag *)this)->mStyleSheetItemsVec = new QPtrVector<QStyleSheetItem>; | ||
687 | return *mStyleSheetItemsVec; | ||
688 | } | ||
689 | 586 | ||
690 | QPtrList<QTextCustomItem> &QTextParag::floatingItems() const | 587 | QPtrList<QTextCustomItem> &QTextParagraph::floatingItems() const |
691 | { | 588 | { |
692 | if ( !mFloatingItems ) | 589 | if ( !mFloatingItems ) |
693 | ((QTextParag *)this)->mFloatingItems = new QPtrList<QTextCustomItem>; | 590 | ((QTextParagraph *)this)->mFloatingItems = new QPtrList<QTextCustomItem>; |
694 | return *mFloatingItems; | 591 | return *mFloatingItems; |
695 | } | 592 | } |
696 | 593 | ||
697 | QTextStringChar::~QTextStringChar() | 594 | QTextStringChar::~QTextStringChar() |
698 | { | 595 | { |
699 | if ( format() ) | 596 | if ( format() ) |
700 | format()->removeRef(); | 597 | format()->removeRef(); |
701 | if ( type ) // not Regular | 598 | if ( type ) // not Regular |
702 | delete d.custom; | 599 | delete d.custom; |
703 | } | 600 | } |
704 | 601 | ||
705 | QTextParagPseudoDocument::QTextParagPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0){} | 602 | QTextParagraphPseudoDocument::QTextParagraphPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0){} |
706 | QTextParagPseudoDocument::~QTextParagPseudoDocument(){ delete pFormatter; delete commandHistory; } | 603 | QTextParagraphPseudoDocument::~QTextParagraphPseudoDocument(){ delete pFormatter; delete commandHistory; } |