-rw-r--r-- | noncore/apps/opie-write/mainwindow.cpp | 12 | ||||
-rw-r--r-- | noncore/apps/opie-write/opie-write.pro | 3 | ||||
-rw-r--r-- | noncore/apps/opie-write/qcomplextext.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-write/qrichtext.cpp | 28 | ||||
-rw-r--r-- | noncore/apps/opie-write/qrichtext_p.cpp | 15 |
5 files changed, 37 insertions, 25 deletions
diff --git a/noncore/apps/opie-write/mainwindow.cpp b/noncore/apps/opie-write/mainwindow.cpp index 90e1a70..aa03060 100644 --- a/noncore/apps/opie-write/mainwindow.cpp +++ b/noncore/apps/opie-write/mainwindow.cpp | |||
@@ -1,124 +1,128 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** Licensees holding valid Qtopia Developer license may use this | 6 | ** Licensees holding valid Qtopia Developer license may use this |
7 | ** file in accordance with the Qtopia Developer License Agreement | 7 | ** file in accordance with the Qtopia Developer License Agreement |
8 | ** provided with the Software. | 8 | ** provided with the Software. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING |
11 | ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 11 | ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
12 | ** PURPOSE. | 12 | ** PURPOSE. |
13 | ** | 13 | ** |
14 | ** email sales@trolltech.com for information about Qtopia License | 14 | ** email sales@trolltech.com for information about Qtopia License |
15 | ** Agreements. | 15 | ** Agreements. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #include "mainwindow.h" | 22 | #include "mainwindow.h" |
23 | |||
24 | /* OPIE */ | ||
25 | #include <opie2/odebug.h> | ||
23 | #include <qpe/fileselector.h> | 26 | #include <qpe/fileselector.h> |
24 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
25 | #include <qpe/resource.h> | 28 | #include <qpe/resource.h> |
26 | #include <qpe/fontdatabase.h> | 29 | #include <qpe/fontdatabase.h> |
30 | using namespace Opie::Core; | ||
27 | 31 | ||
28 | //#include "qspellchecker.h" | 32 | /* QT */ |
29 | #include "qtextedit.h" | 33 | #include "qtextedit.h" |
30 | #include <qaction.h> | 34 | #include <qaction.h> |
31 | #include <qtoolbar.h> | 35 | #include <qtoolbar.h> |
32 | #include <qtoolbutton.h> | 36 | #include <qtoolbutton.h> |
33 | #include <qtabwidget.h> | 37 | #include <qtabwidget.h> |
34 | #include <qapplication.h> | 38 | #include <qapplication.h> |
35 | #include <qfontdatabase.h> | 39 | #include <qfontdatabase.h> |
36 | #include <qcombobox.h> | 40 | #include <qcombobox.h> |
37 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
38 | #include <qfileinfo.h> | 42 | #include <qfileinfo.h> |
39 | #include <qfile.h> | 43 | #include <qfile.h> |
40 | #include <qfiledialog.h> | 44 | #include <qfiledialog.h> |
41 | #include <qprinter.h> | 45 | #include <qprinter.h> |
42 | #include <qpaintdevicemetrics.h> | 46 | #include <qpaintdevicemetrics.h> |
43 | #include <qmenubar.h> | 47 | #include <qmenubar.h> |
44 | #include <qpopupmenu.h> | 48 | #include <qpopupmenu.h> |
45 | #include <qcolordialog.h> | 49 | #include <qcolordialog.h> |
46 | #include <qpainter.h> | 50 | #include <qpainter.h> |
47 | #include <qstyle.h> | 51 | #include <qstyle.h> |
48 | 52 | ||
49 | class ButtonMenu : public QToolButton | 53 | class ButtonMenu : public QToolButton |
50 | { | 54 | { |
51 | Q_OBJECT | 55 | Q_OBJECT |
52 | public: | 56 | public: |
53 | ButtonMenu( QWidget *parent, const char *name=0 ) | 57 | ButtonMenu( QWidget *parent, const char *name=0 ) |
54 | : QToolButton( parent, name ), current(0) | 58 | : QToolButton( parent, name ), current(0) |
55 | { | 59 | { |
56 | setPopup( new QPopupMenu( this ) ); | 60 | setPopup( new QPopupMenu( this ) ); |
57 | setPopupDelay( 1 ); | 61 | setPopupDelay( 1 ); |
58 | connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); | 62 | connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); |
59 | } | 63 | } |
60 | 64 | ||
61 | int insertItem(const QIconSet &icon, const QString &text, int id ) { | 65 | int insertItem(const QIconSet &icon, const QString &text, int id ) { |
62 | if ( !popup()->count() ) { | 66 | if ( !popup()->count() ) { |
63 | setIconSet( icon ); | 67 | setIconSet( icon ); |
64 | current = id; | 68 | current = id; |
65 | } | 69 | } |
66 | return popup()->insertItem( icon, text, id ); | 70 | return popup()->insertItem( icon, text, id ); |
67 | } | 71 | } |
68 | 72 | ||
69 | void setCurrentItem( int id ) { | 73 | void setCurrentItem( int id ) { |
70 | if ( id != current ) { | 74 | if ( id != current ) { |
71 | current = id; | 75 | current = id; |
72 | setIconSet( *popup()->iconSet( id ) ); | 76 | setIconSet( *popup()->iconSet( id ) ); |
73 | } | 77 | } |
74 | } | 78 | } |
75 | 79 | ||
76 | virtual QSize sizeHint() const { | 80 | virtual QSize sizeHint() const { |
77 | return QToolButton::sizeHint() + QSize( 4, 0 ); | 81 | return QToolButton::sizeHint() + QSize( 4, 0 ); |
78 | } | 82 | } |
79 | 83 | ||
80 | signals: | 84 | signals: |
81 | void activated( int id ); | 85 | void activated( int id ); |
82 | 86 | ||
83 | protected slots: | 87 | protected slots: |
84 | void selected( int id ) { | 88 | void selected( int id ) { |
85 | current = id; | 89 | current = id; |
86 | setIconSet( *popup()->iconSet( id ) ); | 90 | setIconSet( *popup()->iconSet( id ) ); |
87 | emit activated( id ); | 91 | emit activated( id ); |
88 | } | 92 | } |
89 | 93 | ||
90 | protected: | 94 | protected: |
91 | virtual void drawButtonLabel( QPainter *p ) { | 95 | virtual void drawButtonLabel( QPainter *p ) { |
92 | p->translate( -4, 0 ); | 96 | p->translate( -4, 0 ); |
93 | QToolButton::drawButtonLabel( p ); | 97 | QToolButton::drawButtonLabel( p ); |
94 | p->translate( 4, 0 ); | 98 | p->translate( 4, 0 ); |
95 | } | 99 | } |
96 | 100 | ||
97 | private: | 101 | private: |
98 | int current; | 102 | int current; |
99 | }; | 103 | }; |
100 | 104 | ||
101 | //=========================================================================== | 105 | //=========================================================================== |
102 | 106 | ||
103 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl ) | 107 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl ) |
104 | : QMainWindow( parent, name, fl ), | 108 | : QMainWindow( parent, name, fl ), |
105 | doc( 0 ) | 109 | doc( 0 ) |
106 | { | 110 | { |
107 | setRightJustification(TRUE); | 111 | setRightJustification(TRUE); |
108 | 112 | ||
109 | editorStack = new QWidgetStack( this ); | 113 | editorStack = new QWidgetStack( this ); |
110 | 114 | ||
111 | fileSelector = new FileSelector( "text/html", | 115 | fileSelector = new FileSelector( "text/html", |
112 | editorStack, "fileselector" ); | 116 | editorStack, "fileselector" ); |
113 | 117 | ||
114 | 118 | ||
115 | fileSelector->setCloseVisible( FALSE ); | 119 | fileSelector->setCloseVisible( FALSE ); |
116 | editorStack->addWidget( fileSelector, 0 ); | 120 | editorStack->addWidget( fileSelector, 0 ); |
117 | 121 | ||
118 | editor = new Qt3::QTextEdit( editorStack ); | 122 | editor = new Qt3::QTextEdit( editorStack ); |
119 | editor->setTextFormat( Qt::RichText ); | 123 | editor->setTextFormat( Qt::RichText ); |
120 | editorStack->addWidget( editor, 1 ); | 124 | editorStack->addWidget( editor, 1 ); |
121 | 125 | ||
122 | setupActions(); | 126 | setupActions(); |
123 | 127 | ||
124 | QObject::connect( fileSelector, SIGNAL(closeMe()), | 128 | QObject::connect( fileSelector, SIGNAL(closeMe()), |
@@ -351,224 +355,224 @@ void MainWindow::textFamily( const QString &f ) | |||
351 | currentEditor()->setFamily( f ); | 355 | currentEditor()->setFamily( f ); |
352 | currentEditor()->viewport()->setFocus(); | 356 | currentEditor()->viewport()->setFocus(); |
353 | } | 357 | } |
354 | 358 | ||
355 | void MainWindow::textSize( const QString &p ) | 359 | void MainWindow::textSize( const QString &p ) |
356 | { | 360 | { |
357 | if ( !currentEditor() ) | 361 | if ( !currentEditor() ) |
358 | return; | 362 | return; |
359 | currentEditor()->setPointSize( p.toInt() ); | 363 | currentEditor()->setPointSize( p.toInt() ); |
360 | currentEditor()->viewport()->setFocus(); | 364 | currentEditor()->viewport()->setFocus(); |
361 | } | 365 | } |
362 | 366 | ||
363 | void MainWindow::textStyle( int i ) | 367 | void MainWindow::textStyle( int i ) |
364 | { | 368 | { |
365 | if ( !currentEditor() ) | 369 | if ( !currentEditor() ) |
366 | return; | 370 | return; |
367 | if ( i == 0 ) | 371 | if ( i == 0 ) |
368 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, | 372 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, |
369 | Qt3::QStyleSheetItem::ListDisc ); | 373 | Qt3::QStyleSheetItem::ListDisc ); |
370 | else if ( i == 1 ) | 374 | else if ( i == 1 ) |
371 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 375 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
372 | Qt3::QStyleSheetItem::ListDisc ); | 376 | Qt3::QStyleSheetItem::ListDisc ); |
373 | else if ( i == 2 ) | 377 | else if ( i == 2 ) |
374 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 378 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
375 | Qt3::QStyleSheetItem::ListCircle ); | 379 | Qt3::QStyleSheetItem::ListCircle ); |
376 | else if ( i == 3 ) | 380 | else if ( i == 3 ) |
377 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 381 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
378 | Qt3::QStyleSheetItem::ListSquare ); | 382 | Qt3::QStyleSheetItem::ListSquare ); |
379 | else if ( i == 4 ) | 383 | else if ( i == 4 ) |
380 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 384 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
381 | Qt3::QStyleSheetItem::ListDecimal ); | 385 | Qt3::QStyleSheetItem::ListDecimal ); |
382 | else if ( i == 5 ) | 386 | else if ( i == 5 ) |
383 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 387 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
384 | Qt3::QStyleSheetItem::ListLowerAlpha ); | 388 | Qt3::QStyleSheetItem::ListLowerAlpha ); |
385 | else if ( i == 6 ) | 389 | else if ( i == 6 ) |
386 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 390 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
387 | Qt3::QStyleSheetItem::ListUpperAlpha ); | 391 | Qt3::QStyleSheetItem::ListUpperAlpha ); |
388 | currentEditor()->viewport()->setFocus(); | 392 | currentEditor()->viewport()->setFocus(); |
389 | } | 393 | } |
390 | 394 | ||
391 | void MainWindow::textAlign( int a ) | 395 | void MainWindow::textAlign( int a ) |
392 | { | 396 | { |
393 | if ( !currentEditor() ) | 397 | if ( !currentEditor() ) |
394 | return; | 398 | return; |
395 | editor->setAlignment( a ); | 399 | editor->setAlignment( a ); |
396 | } | 400 | } |
397 | 401 | ||
398 | void MainWindow::fontChanged( const QFont &f ) | 402 | void MainWindow::fontChanged( const QFont &f ) |
399 | { | 403 | { |
400 | comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( f.family() ) ) ); | 404 | comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( f.family() ) ) ); |
401 | updateFontSizeCombo( f ); | 405 | updateFontSizeCombo( f ); |
402 | comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); | 406 | comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); |
403 | actionTextBold->setOn( f.bold() ); | 407 | actionTextBold->setOn( f.bold() ); |
404 | actionTextItalic->setOn( f.italic() ); | 408 | actionTextItalic->setOn( f.italic() ); |
405 | actionTextUnderline->setOn( f.underline() ); | 409 | actionTextUnderline->setOn( f.underline() ); |
406 | } | 410 | } |
407 | 411 | ||
408 | void MainWindow::colorChanged( const QColor & ) | 412 | void MainWindow::colorChanged( const QColor & ) |
409 | { | 413 | { |
410 | } | 414 | } |
411 | 415 | ||
412 | void MainWindow::alignmentChanged( int a ) | 416 | void MainWindow::alignmentChanged( int a ) |
413 | { | 417 | { |
414 | if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) { | 418 | if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) { |
415 | alignMenu->setCurrentItem(AlignLeft); | 419 | alignMenu->setCurrentItem(AlignLeft); |
416 | } else if ( ( a & AlignCenter ) ) { | 420 | } else if ( ( a & AlignCenter ) ) { |
417 | alignMenu->setCurrentItem(AlignCenter); | 421 | alignMenu->setCurrentItem(AlignCenter); |
418 | } else if ( ( a & AlignRight ) ) { | 422 | } else if ( ( a & AlignRight ) ) { |
419 | alignMenu->setCurrentItem(AlignRight); | 423 | alignMenu->setCurrentItem(AlignRight); |
420 | } else if ( ( a & Qt3::AlignJustify ) ) { | 424 | } else if ( ( a & Qt3::AlignJustify ) ) { |
421 | alignMenu->setCurrentItem(Qt3::AlignJustify); | 425 | alignMenu->setCurrentItem(Qt3::AlignJustify); |
422 | } | 426 | } |
423 | } | 427 | } |
424 | 428 | ||
425 | void MainWindow::editorChanged( QWidget * ) | 429 | void MainWindow::editorChanged( QWidget * ) |
426 | { | 430 | { |
427 | if ( !currentEditor() ) | 431 | if ( !currentEditor() ) |
428 | return; | 432 | return; |
429 | fontChanged( currentEditor()->font() ); | 433 | fontChanged( currentEditor()->font() ); |
430 | colorChanged( currentEditor()->color() ); | 434 | colorChanged( currentEditor()->color() ); |
431 | alignmentChanged( currentEditor()->alignment() ); | 435 | alignmentChanged( currentEditor()->alignment() ); |
432 | } | 436 | } |
433 | 437 | ||
434 | void MainWindow::fileOpen() | 438 | void MainWindow::fileOpen() |
435 | { | 439 | { |
436 | save(); | 440 | save(); |
437 | editorStack->raiseWidget( fileSelector ); | 441 | editorStack->raiseWidget( fileSelector ); |
438 | fileSelector->reread(); | 442 | fileSelector->reread(); |
439 | hideEditTools(); | 443 | hideEditTools(); |
440 | fileSelector->setNewVisible( TRUE ); | 444 | fileSelector->setNewVisible( TRUE ); |
441 | clear(); | 445 | clear(); |
442 | updateCaption(); | 446 | updateCaption(); |
443 | } | 447 | } |
444 | 448 | ||
445 | void MainWindow::fileRevert() | 449 | void MainWindow::fileRevert() |
446 | { | 450 | { |
447 | qDebug( "QMainWindow::fileRevert needs to be done" ); | 451 | odebug << "QMainWindow::fileRevert needs to be done" << oendl; |
448 | } | 452 | } |
449 | 453 | ||
450 | void MainWindow::fileNew() | 454 | void MainWindow::fileNew() |
451 | { | 455 | { |
452 | editor->setTextFormat( Qt::RichText ); | 456 | editor->setTextFormat( Qt::RichText ); |
453 | save(); | 457 | save(); |
454 | newFile(DocLnk()); | 458 | newFile(DocLnk()); |
455 | } | 459 | } |
456 | 460 | ||
457 | void MainWindow::insertTable() | 461 | void MainWindow::insertTable() |
458 | { | 462 | { |
459 | qDebug( "MainWindow::insertTable() needs to be done" ); | 463 | odebug << "MainWindow::insertTable() needs to be done" << oendl; |
460 | } | 464 | } |
461 | 465 | ||
462 | void MainWindow::newFile( const DocLnk &dl ) | 466 | void MainWindow::newFile( const DocLnk &dl ) |
463 | { | 467 | { |
464 | DocLnk nf = dl; | 468 | DocLnk nf = dl; |
465 | nf.setType( "text/html" ); | 469 | nf.setType( "text/html" ); |
466 | clear(); | 470 | clear(); |
467 | editorStack->raiseWidget( editor ); | 471 | editorStack->raiseWidget( editor ); |
468 | editor->viewport()->setFocus(); | 472 | editor->viewport()->setFocus(); |
469 | doc = new DocLnk( nf ); | 473 | doc = new DocLnk( nf ); |
470 | updateCaption(); | 474 | updateCaption(); |
471 | } | 475 | } |
472 | 476 | ||
473 | void MainWindow::openFile( const DocLnk &dl ) | 477 | void MainWindow::openFile( const DocLnk &dl ) |
474 | { | 478 | { |
475 | FileManager fm; | 479 | FileManager fm; |
476 | QString txt; | 480 | QString txt; |
477 | if ( !fm.loadFile( dl, txt ) ) | 481 | if ( !fm.loadFile( dl, txt ) ) |
478 | qDebug( "couldn't open file" ); | 482 | odebug << "couldn't open file" << oendl; |
479 | clear(); | 483 | clear(); |
480 | editorStack->raiseWidget( editor ); | 484 | editorStack->raiseWidget( editor ); |
481 | editor->viewport()->setFocus(); | 485 | editor->viewport()->setFocus(); |
482 | doc = new DocLnk( dl ); | 486 | doc = new DocLnk( dl ); |
483 | editor->setText( txt ); | 487 | editor->setText( txt ); |
484 | editor->setModified( FALSE ); | 488 | editor->setModified( FALSE ); |
485 | updateCaption(); | 489 | updateCaption(); |
486 | } | 490 | } |
487 | 491 | ||
488 | void MainWindow::showEditTools( void ) | 492 | void MainWindow::showEditTools( void ) |
489 | { | 493 | { |
490 | tbMenu->show(); | 494 | tbMenu->show(); |
491 | tbEdit->show(); | 495 | tbEdit->show(); |
492 | tbFont->show(); | 496 | tbFont->show(); |
493 | tbStyle->show(); | 497 | tbStyle->show(); |
494 | } | 498 | } |
495 | 499 | ||
496 | void MainWindow::hideEditTools( void ) | 500 | void MainWindow::hideEditTools( void ) |
497 | { | 501 | { |
498 | // let's reset the buttons... | 502 | // let's reset the buttons... |
499 | actionTextBold->setOn( FALSE ); | 503 | actionTextBold->setOn( FALSE ); |
500 | actionTextItalic->setOn( FALSE ); | 504 | actionTextItalic->setOn( FALSE ); |
501 | actionTextUnderline->setOn( FALSE ); | 505 | actionTextUnderline->setOn( FALSE ); |
502 | //comboFont->setCurrentText( QApplication::font().family() ); | 506 | //comboFont->setCurrentText( QApplication::font().family() ); |
503 | comboSize->lineEdit()->setText( QString::number(QApplication::font().pointSize() ) ); | 507 | comboSize->lineEdit()->setText( QString::number(QApplication::font().pointSize() ) ); |
504 | tbMenu->hide(); | 508 | tbMenu->hide(); |
505 | tbEdit->hide(); | 509 | tbEdit->hide(); |
506 | tbFont->hide(); | 510 | tbFont->hide(); |
507 | tbStyle->hide(); | 511 | tbStyle->hide(); |
508 | } | 512 | } |
509 | 513 | ||
510 | 514 | ||
511 | void MainWindow::save() | 515 | void MainWindow::save() |
512 | { | 516 | { |
513 | if ( !doc ) | 517 | if ( !doc ) |
514 | return; | 518 | return; |
515 | if ( !editor->isModified() ) | 519 | if ( !editor->isModified() ) |
516 | return; | 520 | return; |
517 | 521 | ||
518 | QString rt = editor->text(); | 522 | QString rt = editor->text(); |
519 | 523 | ||
520 | // quick hack to get around formatting... | 524 | // quick hack to get around formatting... |
521 | editor->setTextFormat( Qt::PlainText ); | 525 | editor->setTextFormat( Qt::PlainText ); |
522 | QString pt = editor->text(); | 526 | QString pt = editor->text(); |
523 | editor->setTextFormat( Qt::RichText ); | 527 | editor->setTextFormat( Qt::RichText ); |
524 | 528 | ||
525 | if ( doc->name().isEmpty() ) { | 529 | if ( doc->name().isEmpty() ) { |
526 | unsigned ispace = pt.find( ' ' ); | 530 | unsigned ispace = pt.find( ' ' ); |
527 | unsigned ienter = pt.find( '\n' ); | 531 | unsigned ienter = pt.find( '\n' ); |
528 | int i = (ispace < ienter) ? ispace : ienter; | 532 | int i = (ispace < ienter) ? ispace : ienter; |
529 | QString docname; | 533 | QString docname; |
530 | if ( i == -1 ) { | 534 | if ( i == -1 ) { |
531 | if ( pt.isEmpty() ) | 535 | if ( pt.isEmpty() ) |
532 | docname = "Empty Text"; | 536 | docname = "Empty Text"; |
533 | else | 537 | else |
534 | docname = pt; | 538 | docname = pt; |
535 | } else { | 539 | } else { |
536 | docname = pt.left( i ); | 540 | docname = pt.left( i ); |
537 | } | 541 | } |
538 | doc->setName(docname); | 542 | doc->setName(docname); |
539 | } | 543 | } |
540 | FileManager fm; | 544 | FileManager fm; |
541 | fm.saveFile( *doc, rt ); | 545 | fm.saveFile( *doc, rt ); |
542 | } | 546 | } |
543 | 547 | ||
544 | void MainWindow::clear() | 548 | void MainWindow::clear() |
545 | { | 549 | { |
546 | delete doc; | 550 | delete doc; |
547 | doc = 0; | 551 | doc = 0; |
548 | editor->clear(); | 552 | editor->clear(); |
549 | } | 553 | } |
550 | 554 | ||
551 | void MainWindow::updateCaption() | 555 | void MainWindow::updateCaption() |
552 | { | 556 | { |
553 | if ( !doc ) | 557 | if ( !doc ) |
554 | setCaption( tr("Rich Text Editor") ); | 558 | setCaption( tr("Rich Text Editor") ); |
555 | else { | 559 | else { |
556 | QString s = doc->name(); | 560 | QString s = doc->name(); |
557 | if ( s.isEmpty() ) | 561 | if ( s.isEmpty() ) |
558 | s = tr( "Unnamed" ); | 562 | s = tr( "Unnamed" ); |
559 | setCaption( s + " - " + tr("Rich Text Editor") ); | 563 | setCaption( s + " - " + tr("Rich Text Editor") ); |
560 | } | 564 | } |
561 | } | 565 | } |
562 | 566 | ||
563 | void MainWindow::closeEvent( QCloseEvent *e ) | 567 | void MainWindow::closeEvent( QCloseEvent *e ) |
564 | { | 568 | { |
565 | if ( editorStack->visibleWidget() == editor ) { | 569 | if ( editorStack->visibleWidget() == editor ) { |
566 | // call fileOpen instead, don't close it | 570 | // call fileOpen instead, don't close it |
567 | fileOpen(); | 571 | fileOpen(); |
568 | e->ignore(); | 572 | e->ignore(); |
569 | } else { | 573 | } else { |
570 | e->accept(); | 574 | e->accept(); |
571 | } | 575 | } |
572 | } | 576 | } |
573 | 577 | ||
574 | #include "mainwindow.moc" | 578 | #include "mainwindow.moc" |
diff --git a/noncore/apps/opie-write/opie-write.pro b/noncore/apps/opie-write/opie-write.pro index 044ce7e..8e514d4 100644 --- a/noncore/apps/opie-write/opie-write.pro +++ b/noncore/apps/opie-write/opie-write.pro | |||
@@ -1,27 +1,26 @@ | |||
1 | 1 | ||
2 | CONFIG += qt warn on quick-app | 2 | CONFIG += qt warn on quick-app |
3 | |||
4 | 3 | ||
5 | HEADERS = qcleanuphandler.h \ | 4 | HEADERS = qcleanuphandler.h \ |
6 | qcomplextext_p.h \ | 5 | qcomplextext_p.h \ |
7 | qrichtext_p.h \ | 6 | qrichtext_p.h \ |
8 | qstylesheet.h \ | 7 | qstylesheet.h \ |
9 | qtextedit.h \ | 8 | qtextedit.h \ |
10 | mainwindow.h | 9 | mainwindow.h |
11 | 10 | ||
12 | SOURCES = qcomplextext.cpp \ | 11 | SOURCES = qcomplextext.cpp \ |
13 | qstylesheet.cpp \ | 12 | qstylesheet.cpp \ |
14 | qrichtext_p.cpp \ | 13 | qrichtext_p.cpp \ |
15 | qrichtext.cpp \ | 14 | qrichtext.cpp \ |
16 | qtextedit.cpp \ | 15 | qtextedit.cpp \ |
17 | main.cpp \ | 16 | main.cpp \ |
18 | mainwindow.cpp | 17 | mainwindow.cpp |
19 | 18 | ||
20 | INCLUDEPATH += $(OPIEDIR)/include | 19 | INCLUDEPATH += $(OPIEDIR)/include |
21 | DEPENDPATH += $(OPIEDIR)/include | 20 | DEPENDPATH += $(OPIEDIR)/include |
22 | LIBS += -lqpe -lopiecore2 | 21 | LIBS += -lqpe -lopiecore2 |
23 | 22 | ||
24 | TARGET = opie-write | 23 | TARGET = opie-write |
25 | 24 | ||
26 | 25 | ||
27 | include ( $(OPIEDIR)/include.pro ) | 26 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/apps/opie-write/qcomplextext.cpp b/noncore/apps/opie-write/qcomplextext.cpp index 473f184..00a91c5 100644 --- a/noncore/apps/opie-write/qcomplextext.cpp +++ b/noncore/apps/opie-write/qcomplextext.cpp | |||
@@ -13,134 +13,134 @@ | |||
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | 38 | ||
39 | #include "qrichtext_p.h" | 39 | #include "qrichtext_p.h" |
40 | 40 | ||
41 | #include <stdlib.h> | 41 | #include <stdlib.h> |
42 | 42 | ||
43 | using namespace Qt3; | 43 | using namespace Qt3; |
44 | 44 | ||
45 | // ----------------------------------------------------- | 45 | // ----------------------------------------------------- |
46 | 46 | ||
47 | /* a small helper class used internally to resolve Bidi embedding levels. | 47 | /* a small helper class used internally to resolve Bidi embedding levels. |
48 | Each line of text caches the embedding level at the start of the line for faster | 48 | Each line of text caches the embedding level at the start of the line for faster |
49 | relayouting | 49 | relayouting |
50 | */ | 50 | */ |
51 | QBidiContext::QBidiContext( uchar l, QChar::Direction e, QBidiContext *p, bool o ) | 51 | QBidiContext::QBidiContext( uchar l, QChar::Direction e, QBidiContext *p, bool o ) |
52 | : level(l) , override(o), dir(e) | 52 | : level(l) , override(o), dir(e) |
53 | { | 53 | { |
54 | if ( p ) | 54 | if ( p ) |
55 | p->ref(); | 55 | p->ref(); |
56 | parent = p; | 56 | parent = p; |
57 | count = 0; | 57 | count = 0; |
58 | } | 58 | } |
59 | 59 | ||
60 | QBidiContext::~QBidiContext() | 60 | QBidiContext::~QBidiContext() |
61 | { | 61 | { |
62 | if( parent && parent->deref() ) | 62 | if( parent && parent->deref() ) |
63 | delete parent; | 63 | delete parent; |
64 | } | 64 | } |
65 | 65 | ||
66 | /* | 66 | /* |
67 | Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on | 67 | Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on |
68 | arabic). | 68 | arabic). |
69 | 69 | ||
70 | Each unicode char has a joining class (right, dual (left&right), center (joincausing) or transparent). | 70 | Each unicode char has a joining class (right, dual (left&right), center (joincausing) or transparent). |
71 | transparent joining is not encoded in QChar::joining(), but applies to all combining marks and format marks. | 71 | transparent joining is not encoded in QChar::joining(), but applies to all combining marks and format marks. |
72 | 72 | ||
73 | Right join-causing: dual + center | 73 | Right join-causing: dual + center |
74 | Left join-causing: dual + right + center | 74 | Left join-causing: dual + right + center |
75 | 75 | ||
76 | Rules are as follows (for a string already in visual order, as we have it here): | 76 | Rules are as follows (for a string already in visual order, as we have it here): |
77 | 77 | ||
78 | R1 Transparent characters do not affect joining behaviour. | 78 | R1 Transparent characters do not affect joining behaviour. |
79 | R2 A right joining character, that has a right join-causing char on the right will get form XRight | 79 | R2 A right joining character, that has a right join-causing char on the right will get form XRight |
80 | (R3 A left joining character, that has a left join-causing char on the left will get form XLeft) | 80 | (R3 A left joining character, that has a left join-causing char on the left will get form XLeft) |
81 | Note: the above rule is meaningless, as there are no pure left joining characters defined in Unicode | 81 | Note: the above rule is meaningless, as there are no pure left joining characters defined in Unicode |
82 | R4 A dual joining character, that has a left join-causing char on the left and a right join-causing char on | 82 | R4 A dual joining character, that has a left join-causing char on the left and a right join-causing char on |
83 | the right will get form XMedial | 83 | the right will get form XMedial |
84 | R5 A dual joining character, that has a right join causing char on the right, and no left join causing char on the left | 84 | R5 A dual joining character, that has a right join causing char on the right, and no left join causing char on the left |
85 | will get form XRight | 85 | will get form XRight |
86 | R6 A dual joining character, that has a left join causing char on the left, and no right join causing char on the right | 86 | R6 A dual joining character, that has a left join causing char on the left, and no right join causing char on the right |
87 | will get form XLeft | 87 | will get form XLeft |
88 | R7 Otherwise the character will get form XIsolated | 88 | R7 Otherwise the character will get form XIsolated |
89 | 89 | ||
90 | Additionally we have to do the minimal ligature support for lam-alef ligatures: | 90 | Additionally we have to do the minimal ligature support for lam-alef ligatures: |
91 | 91 | ||
92 | L1 Transparent characters do not affect ligature behaviour. | 92 | L1 Transparent characters do not affect ligature behaviour. |
93 | L2 Any sequence of Alef(XRight) + Lam(XMedial) will form the ligature Alef.Lam(XLeft) | 93 | L2 Any sequence of Alef(XRight) + Lam(XMedial) will form the ligature Alef.Lam(XLeft) |
94 | L3 Any sequence of Alef(XRight) + Lam(XLeft) will form the ligature Alef.Lam(XIsolated) | 94 | L3 Any sequence of Alef(XRight) + Lam(XLeft) will form the ligature Alef.Lam(XIsolated) |
95 | 95 | ||
96 | The two functions defined in this class do shaping in visual and logical order. For logical order just replace right with | 96 | The two functions defined in this class do shaping in visual and logical order. For logical order just replace right with |
97 | previous and left with next in the above rules ;-) | 97 | previous and left with next in the above rules ;-) |
98 | */ | 98 | */ |
99 | 99 | ||
100 | /* | 100 | /* |
101 | Two small helper functions for arabic shaping. They get the next shape causing character on either | 101 | Two small helper functions for arabic shaping. They get the next shape causing character on either |
102 | side of the char in question. Implements rule R1. | 102 | side of the char in question. Implements rule R1. |
103 | 103 | ||
104 | leftChar() returns true if the char to the left is a left join-causing char | 104 | leftChar() returns true if the char to the left is a left join-causing char |
105 | rightChar() returns true if the char to the right is a right join-causing char | 105 | rightChar() returns true if the char to the right is a right join-causing char |
106 | */ | 106 | */ |
107 | static inline const QChar *prevChar( const QString &str, int pos ) | 107 | static inline const QChar *prevChar( const QString &str, int pos ) |
108 | { | 108 | { |
109 | //qDebug("leftChar: pos=%d", pos); | 109 | //odebug << "leftChar: pos=" << pos << "" << oendl; |
110 | pos--; | 110 | pos--; |
111 | const QChar *ch = str.unicode() + pos; | 111 | const QChar *ch = str.unicode() + pos; |
112 | while( pos > -1 ) { | 112 | while( pos > -1 ) { |
113 | if( !ch->isMark() ) | 113 | if( !ch->isMark() ) |
114 | return ch; | 114 | return ch; |
115 | pos--; | 115 | pos--; |
116 | ch--; | 116 | ch--; |
117 | } | 117 | } |
118 | return &QChar::replacement; | 118 | return &QChar::replacement; |
119 | } | 119 | } |
120 | 120 | ||
121 | static inline const QChar *nextChar( const QString &str, int pos) | 121 | static inline const QChar *nextChar( const QString &str, int pos) |
122 | { | 122 | { |
123 | pos++; | 123 | pos++; |
124 | int len = str.length(); | 124 | int len = str.length(); |
125 | const QChar *ch = str.unicode() + pos; | 125 | const QChar *ch = str.unicode() + pos; |
126 | while( pos < len ) { | 126 | while( pos < len ) { |
127 | //qDebug("rightChar: %d isLetter=%d, joining=%d", pos, ch.isLetter(), ch.joining()); | 127 | //odebug << "rightChar: " << pos << " isLetter=" << ch.isLetter() << ", joining=" << ch.joining() << "" << oendl; |
128 | if( !ch->isMark() ) | 128 | if( !ch->isMark() ) |
129 | return ch; | 129 | return ch; |
130 | // assume it's a transparent char, this might not be 100% correct | 130 | // assume it's a transparent char, this might not be 100% correct |
131 | pos++; | 131 | pos++; |
132 | ch++; | 132 | ch++; |
133 | } | 133 | } |
134 | return &QChar::replacement; | 134 | return &QChar::replacement; |
135 | } | 135 | } |
136 | 136 | ||
137 | static inline bool prevVisualCharJoins( const QString &str, int pos) | 137 | static inline bool prevVisualCharJoins( const QString &str, int pos) |
138 | { | 138 | { |
139 | return ( prevChar( str, pos )->joining() != QChar::OtherJoining ); | 139 | return ( prevChar( str, pos )->joining() != QChar::OtherJoining ); |
140 | } | 140 | } |
141 | 141 | ||
142 | static inline bool nextVisualCharJoins( const QString &str, int pos) | 142 | static inline bool nextVisualCharJoins( const QString &str, int pos) |
143 | { | 143 | { |
144 | QChar::Joining join = nextChar( str, pos )->joining(); | 144 | QChar::Joining join = nextChar( str, pos )->joining(); |
145 | return ( join == QChar::Dual || join == QChar::Center ); | 145 | return ( join == QChar::Dual || join == QChar::Center ); |
146 | } | 146 | } |
diff --git a/noncore/apps/opie-write/qrichtext.cpp b/noncore/apps/opie-write/qrichtext.cpp index b77a0fc..c27eb1e 100644 --- a/noncore/apps/opie-write/qrichtext.cpp +++ b/noncore/apps/opie-write/qrichtext.cpp | |||
@@ -1,311 +1,317 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of the internal Qt classes dealing with rich text | 4 | ** Implementation of the internal Qt classes dealing with rich text |
5 | ** | 5 | ** |
6 | ** Created : 990101 | 6 | ** Created : 990101 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the kernel module of the Qt GUI Toolkit. | 10 | ** This file is part of the kernel module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #include "qrichtext_p.h" | 38 | #include "qrichtext_p.h" |
39 | 39 | ||
40 | /* OPIE */ | ||
41 | #include <opie2/odebug.h> | ||
42 | using namespace Opie::Core; | ||
43 | |||
44 | /* QT */ | ||
40 | #include "qdragobject.h" | 45 | #include "qdragobject.h" |
41 | #include "qpaintdevicemetrics.h" | 46 | #include "qpaintdevicemetrics.h" |
42 | #include "qdrawutil.h" | 47 | #include "qdrawutil.h" |
43 | #include "qcleanuphandler.h" | 48 | #include "qcleanuphandler.h" |
44 | 49 | ||
50 | /* STD */ | ||
45 | #include <stdlib.h> | 51 | #include <stdlib.h> |
46 | 52 | ||
47 | using namespace Qt3; | 53 | using namespace Qt3; |
48 | 54 | ||
49 | static QTextCursor* richTextExportStart = 0; | 55 | static QTextCursor* richTextExportStart = 0; |
50 | static QTextCursor* richTextExportEnd = 0; | 56 | static QTextCursor* richTextExportEnd = 0; |
51 | 57 | ||
52 | static QTextFormatCollection *qFormatCollection = 0; | 58 | static QTextFormatCollection *qFormatCollection = 0; |
53 | 59 | ||
54 | const int border_tolerance = 2; | 60 | const int border_tolerance = 2; |
55 | 61 | ||
56 | #ifdef Q_WS_WIN | 62 | #ifdef Q_WS_WIN |
57 | #include "qt_windows.h" | 63 | #include "qt_windows.h" |
58 | #endif | 64 | #endif |
59 | 65 | ||
60 | #define QChar_linesep QChar(0x2028U) | 66 | #define QChar_linesep QChar(0x2028U) |
61 | 67 | ||
62 | static inline bool is_printer( QPainter *p ) | 68 | static inline bool is_printer( QPainter *p ) |
63 | { | 69 | { |
64 | if ( !p || !p->device() ) | 70 | if ( !p || !p->device() ) |
65 | return FALSE; | 71 | return FALSE; |
66 | return p->device()->devType() == QInternal::Printer; | 72 | return p->device()->devType() == QInternal::Printer; |
67 | } | 73 | } |
68 | 74 | ||
69 | static inline int scale( int value, QPainter *painter ) | 75 | static inline int scale( int value, QPainter *painter ) |
70 | { | 76 | { |
71 | if ( is_printer( painter ) ) { | 77 | if ( is_printer( painter ) ) { |
72 | QPaintDeviceMetrics metrics( painter->device() ); | 78 | QPaintDeviceMetrics metrics( painter->device() ); |
73 | #if defined(Q_WS_X11) | 79 | #if defined(Q_WS_X11) |
74 | value = value * metrics.logicalDpiY() / QPaintDevice::x11AppDpiY(); | 80 | value = value * metrics.logicalDpiY() / QPaintDevice::x11AppDpiY(); |
75 | #elif defined (Q_WS_WIN) | 81 | #elif defined (Q_WS_WIN) |
76 | HDC hdc = GetDC( 0 ); | 82 | HDC hdc = GetDC( 0 ); |
77 | int gdc = GetDeviceCaps( hdc, LOGPIXELSY ); | 83 | int gdc = GetDeviceCaps( hdc, LOGPIXELSY ); |
78 | if ( gdc ) | 84 | if ( gdc ) |
79 | value = value * metrics.logicalDpiY() / gdc; | 85 | value = value * metrics.logicalDpiY() / gdc; |
80 | ReleaseDC( 0, hdc ); | 86 | ReleaseDC( 0, hdc ); |
81 | #elif defined (Q_WS_MAC) | 87 | #elif defined (Q_WS_MAC) |
82 | value = value * metrics.logicalDpiY() / 75; // ##### FIXME | 88 | value = value * metrics.logicalDpiY() / 75; // ##### FIXME |
83 | #elif defined (Q_WS_QWS) | 89 | #elif defined (Q_WS_QWS) |
84 | value = value * metrics.logicalDpiY() / 75; | 90 | value = value * metrics.logicalDpiY() / 75; |
85 | #endif | 91 | #endif |
86 | } | 92 | } |
87 | return value; | 93 | return value; |
88 | } | 94 | } |
89 | 95 | ||
90 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 96 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
91 | 97 | ||
92 | void QTextCommandHistory::addCommand( QTextCommand *cmd ) | 98 | void QTextCommandHistory::addCommand( QTextCommand *cmd ) |
93 | { | 99 | { |
94 | if ( current < (int)history.count() - 1 ) { | 100 | if ( current < (int)history.count() - 1 ) { |
95 | QPtrList<QTextCommand> commands; | 101 | QPtrList<QTextCommand> commands; |
96 | commands.setAutoDelete( FALSE ); | 102 | commands.setAutoDelete( FALSE ); |
97 | 103 | ||
98 | for( int i = 0; i <= current; ++i ) { | 104 | for( int i = 0; i <= current; ++i ) { |
99 | commands.insert( i, history.at( 0 ) ); | 105 | commands.insert( i, history.at( 0 ) ); |
100 | history.take( 0 ); | 106 | history.take( 0 ); |
101 | } | 107 | } |
102 | 108 | ||
103 | commands.append( cmd ); | 109 | commands.append( cmd ); |
104 | history.clear(); | 110 | history.clear(); |
105 | history = commands; | 111 | history = commands; |
106 | history.setAutoDelete( TRUE ); | 112 | history.setAutoDelete( TRUE ); |
107 | } else { | 113 | } else { |
108 | history.append( cmd ); | 114 | history.append( cmd ); |
109 | } | 115 | } |
110 | 116 | ||
111 | if ( (int)history.count() > steps ) | 117 | if ( (int)history.count() > steps ) |
112 | history.removeFirst(); | 118 | history.removeFirst(); |
113 | else | 119 | else |
114 | ++current; | 120 | ++current; |
115 | } | 121 | } |
116 | 122 | ||
117 | QTextCursor *QTextCommandHistory::undo( QTextCursor *c ) | 123 | QTextCursor *QTextCommandHistory::undo( QTextCursor *c ) |
118 | { | 124 | { |
119 | if ( current > -1 ) { | 125 | if ( current > -1 ) { |
120 | QTextCursor *c2 = history.at( current )->unexecute( c ); | 126 | QTextCursor *c2 = history.at( current )->unexecute( c ); |
121 | --current; | 127 | --current; |
122 | return c2; | 128 | return c2; |
123 | } | 129 | } |
124 | return 0; | 130 | return 0; |
125 | } | 131 | } |
126 | 132 | ||
127 | QTextCursor *QTextCommandHistory::redo( QTextCursor *c ) | 133 | QTextCursor *QTextCommandHistory::redo( QTextCursor *c ) |
128 | { | 134 | { |
129 | if ( current > -1 ) { | 135 | if ( current > -1 ) { |
130 | if ( current < (int)history.count() - 1 ) { | 136 | if ( current < (int)history.count() - 1 ) { |
131 | ++current; | 137 | ++current; |
132 | return history.at( current )->execute( c ); | 138 | return history.at( current )->execute( c ); |
133 | } | 139 | } |
134 | } else { | 140 | } else { |
135 | if ( history.count() > 0 ) { | 141 | if ( history.count() > 0 ) { |
136 | ++current; | 142 | ++current; |
137 | return history.at( current )->execute( c ); | 143 | return history.at( current )->execute( c ); |
138 | } | 144 | } |
139 | } | 145 | } |
140 | return 0; | 146 | return 0; |
141 | } | 147 | } |
142 | 148 | ||
143 | bool QTextCommandHistory::isUndoAvailable() | 149 | bool QTextCommandHistory::isUndoAvailable() |
144 | { | 150 | { |
145 | return current > -1; | 151 | return current > -1; |
146 | } | 152 | } |
147 | 153 | ||
148 | bool QTextCommandHistory::isRedoAvailable() | 154 | bool QTextCommandHistory::isRedoAvailable() |
149 | { | 155 | { |
150 | return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0; | 156 | return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0; |
151 | } | 157 | } |
152 | 158 | ||
153 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 159 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
154 | 160 | ||
155 | QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, | 161 | QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, |
156 | const QByteArray& oldStyleInfo ) | 162 | const QByteArray& oldStyleInfo ) |
157 | : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo ) | 163 | : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo ) |
158 | { | 164 | { |
159 | for ( int j = 0; j < (int)text.size(); ++j ) { | 165 | for ( int j = 0; j < (int)text.size(); ++j ) { |
160 | if ( text[ j ].format() ) | 166 | if ( text[ j ].format() ) |
161 | text[ j ].format()->addRef(); | 167 | text[ j ].format()->addRef(); |
162 | } | 168 | } |
163 | } | 169 | } |
164 | 170 | ||
165 | QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) | 171 | QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) |
166 | : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str ) | 172 | : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str ) |
167 | { | 173 | { |
168 | for ( int i = 0; i < (int)text.size(); ++i ) { | 174 | for ( int i = 0; i < (int)text.size(); ++i ) { |
169 | if ( text[ i ].format() ) | 175 | if ( text[ i ].format() ) |
170 | text[ i ].format()->addRef(); | 176 | text[ i ].format()->addRef(); |
171 | } | 177 | } |
172 | } | 178 | } |
173 | 179 | ||
174 | QTextDeleteCommand::~QTextDeleteCommand() | 180 | QTextDeleteCommand::~QTextDeleteCommand() |
175 | { | 181 | { |
176 | for ( int i = 0; i < (int)text.size(); ++i ) { | 182 | for ( int i = 0; i < (int)text.size(); ++i ) { |
177 | if ( text[ i ].format() ) | 183 | if ( text[ i ].format() ) |
178 | text[ i ].format()->removeRef(); | 184 | text[ i ].format()->removeRef(); |
179 | } | 185 | } |
180 | text.resize( 0 ); | 186 | text.resize( 0 ); |
181 | } | 187 | } |
182 | 188 | ||
183 | QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) | 189 | QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) |
184 | { | 190 | { |
185 | QTextParagraph *s = doc ? doc->paragAt( id ) : parag; | 191 | QTextParagraph *s = doc ? doc->paragAt( id ) : parag; |
186 | if ( !s ) { | 192 | if ( !s ) { |
187 | qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() ); | 193 | owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl; |
188 | return 0; | 194 | return 0; |
189 | } | 195 | } |
190 | 196 | ||
191 | cursor.setParagraph( s ); | 197 | cursor.setParagraph( s ); |
192 | cursor.setIndex( index ); | 198 | cursor.setIndex( index ); |
193 | int len = text.size(); | 199 | int len = text.size(); |
194 | if ( c ) | 200 | if ( c ) |
195 | *c = cursor; | 201 | *c = cursor; |
196 | if ( doc ) { | 202 | if ( doc ) { |
197 | doc->setSelectionStart( QTextDocument::Temp, cursor ); | 203 | doc->setSelectionStart( QTextDocument::Temp, cursor ); |
198 | for ( int i = 0; i < len; ++i ) | 204 | for ( int i = 0; i < len; ++i ) |
199 | cursor.gotoNextLetter(); | 205 | cursor.gotoNextLetter(); |
200 | doc->setSelectionEnd( QTextDocument::Temp, cursor ); | 206 | doc->setSelectionEnd( QTextDocument::Temp, cursor ); |
201 | doc->removeSelectedText( QTextDocument::Temp, &cursor ); | 207 | doc->removeSelectedText( QTextDocument::Temp, &cursor ); |
202 | if ( c ) | 208 | if ( c ) |
203 | *c = cursor; | 209 | *c = cursor; |
204 | } else { | 210 | } else { |
205 | s->remove( index, len ); | 211 | s->remove( index, len ); |
206 | } | 212 | } |
207 | 213 | ||
208 | return c; | 214 | return c; |
209 | } | 215 | } |
210 | 216 | ||
211 | QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c ) | 217 | QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c ) |
212 | { | 218 | { |
213 | QTextParagraph *s = doc ? doc->paragAt( id ) : parag; | 219 | QTextParagraph *s = doc ? doc->paragAt( id ) : parag; |
214 | if ( !s ) { | 220 | if ( !s ) { |
215 | qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() ); | 221 | owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl; |
216 | return 0; | 222 | return 0; |
217 | } | 223 | } |
218 | 224 | ||
219 | cursor.setParagraph( s ); | 225 | cursor.setParagraph( s ); |
220 | cursor.setIndex( index ); | 226 | cursor.setIndex( index ); |
221 | QString str = QTextString::toString( text ); | 227 | QString str = QTextString::toString( text ); |
222 | cursor.insert( str, TRUE, &text ); | 228 | cursor.insert( str, TRUE, &text ); |
223 | cursor.setParagraph( s ); | 229 | cursor.setParagraph( s ); |
224 | cursor.setIndex( index ); | 230 | cursor.setIndex( index ); |
225 | if ( c ) { | 231 | if ( c ) { |
226 | c->setParagraph( s ); | 232 | c->setParagraph( s ); |
227 | c->setIndex( index ); | 233 | c->setIndex( index ); |
228 | for ( int i = 0; i < (int)text.size(); ++i ) | 234 | for ( int i = 0; i < (int)text.size(); ++i ) |
229 | c->gotoNextLetter(); | 235 | c->gotoNextLetter(); |
230 | } | 236 | } |
231 | 237 | ||
232 | if ( !styleInformation.isEmpty() ) { | 238 | if ( !styleInformation.isEmpty() ) { |
233 | QDataStream styleStream( styleInformation, IO_ReadOnly ); | 239 | QDataStream styleStream( styleInformation, IO_ReadOnly ); |
234 | int num; | 240 | int num; |
235 | styleStream >> num; | 241 | styleStream >> num; |
236 | QTextParagraph *p = s; | 242 | QTextParagraph *p = s; |
237 | while ( num-- && p ) { | 243 | while ( num-- && p ) { |
238 | p->readStyleInformation( styleStream ); | 244 | p->readStyleInformation( styleStream ); |
239 | p = p->next(); | 245 | p = p->next(); |
240 | } | 246 | } |
241 | } | 247 | } |
242 | s = cursor.paragraph(); | 248 | s = cursor.paragraph(); |
243 | while ( s ) { | 249 | while ( s ) { |
244 | s->format(); | 250 | s->format(); |
245 | s->setChanged( TRUE ); | 251 | s->setChanged( TRUE ); |
246 | if ( s == c->paragraph() ) | 252 | if ( s == c->paragraph() ) |
247 | break; | 253 | break; |
248 | s = s->next(); | 254 | s = s->next(); |
249 | } | 255 | } |
250 | 256 | ||
251 | return &cursor; | 257 | return &cursor; |
252 | } | 258 | } |
253 | 259 | ||
254 | QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, | 260 | QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, |
255 | const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ) | 261 | const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ) |
256 | : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl ) | 262 | : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl ) |
257 | { | 263 | { |
258 | format = d->formatCollection()->format( f ); | 264 | format = d->formatCollection()->format( f ); |
259 | for ( int j = 0; j < (int)oldFormats.size(); ++j ) { | 265 | for ( int j = 0; j < (int)oldFormats.size(); ++j ) { |
260 | if ( oldFormats[ j ].format() ) | 266 | if ( oldFormats[ j ].format() ) |
261 | oldFormats[ j ].format()->addRef(); | 267 | oldFormats[ j ].format()->addRef(); |
262 | } | 268 | } |
263 | } | 269 | } |
264 | 270 | ||
265 | QTextFormatCommand::~QTextFormatCommand() | 271 | QTextFormatCommand::~QTextFormatCommand() |
266 | { | 272 | { |
267 | format->removeRef(); | 273 | format->removeRef(); |
268 | for ( int j = 0; j < (int)oldFormats.size(); ++j ) { | 274 | for ( int j = 0; j < (int)oldFormats.size(); ++j ) { |
269 | if ( oldFormats[ j ].format() ) | 275 | if ( oldFormats[ j ].format() ) |
270 | oldFormats[ j ].format()->removeRef(); | 276 | oldFormats[ j ].format()->removeRef(); |
271 | } | 277 | } |
272 | } | 278 | } |
273 | 279 | ||
274 | QTextCursor *QTextFormatCommand::execute( QTextCursor *c ) | 280 | QTextCursor *QTextFormatCommand::execute( QTextCursor *c ) |
275 | { | 281 | { |
276 | QTextParagraph *sp = doc->paragAt( startId ); | 282 | QTextParagraph *sp = doc->paragAt( startId ); |
277 | QTextParagraph *ep = doc->paragAt( endId ); | 283 | QTextParagraph *ep = doc->paragAt( endId ); |
278 | if ( !sp || !ep ) | 284 | if ( !sp || !ep ) |
279 | return c; | 285 | return c; |
280 | 286 | ||
281 | QTextCursor start( doc ); | 287 | QTextCursor start( doc ); |
282 | start.setParagraph( sp ); | 288 | start.setParagraph( sp ); |
283 | start.setIndex( startIndex ); | 289 | start.setIndex( startIndex ); |
284 | QTextCursor end( doc ); | 290 | QTextCursor end( doc ); |
285 | end.setParagraph( ep ); | 291 | end.setParagraph( ep ); |
286 | end.setIndex( endIndex ); | 292 | end.setIndex( endIndex ); |
287 | 293 | ||
288 | doc->setSelectionStart( QTextDocument::Temp, start ); | 294 | doc->setSelectionStart( QTextDocument::Temp, start ); |
289 | doc->setSelectionEnd( QTextDocument::Temp, end ); | 295 | doc->setSelectionEnd( QTextDocument::Temp, end ); |
290 | doc->setFormat( QTextDocument::Temp, format, flags ); | 296 | doc->setFormat( QTextDocument::Temp, format, flags ); |
291 | doc->removeSelection( QTextDocument::Temp ); | 297 | doc->removeSelection( QTextDocument::Temp ); |
292 | if ( endIndex == ep->length() ) | 298 | if ( endIndex == ep->length() ) |
293 | end.gotoLeft(); | 299 | end.gotoLeft(); |
294 | *c = end; | 300 | *c = end; |
295 | return c; | 301 | return c; |
296 | } | 302 | } |
297 | 303 | ||
298 | QTextCursor *QTextFormatCommand::unexecute( QTextCursor *c ) | 304 | QTextCursor *QTextFormatCommand::unexecute( QTextCursor *c ) |
299 | { | 305 | { |
300 | QTextParagraph *sp = doc->paragAt( startId ); | 306 | QTextParagraph *sp = doc->paragAt( startId ); |
301 | QTextParagraph *ep = doc->paragAt( endId ); | 307 | QTextParagraph *ep = doc->paragAt( endId ); |
302 | if ( !sp || !ep ) | 308 | if ( !sp || !ep ) |
303 | return 0; | 309 | return 0; |
304 | 310 | ||
305 | int idx = startIndex; | 311 | int idx = startIndex; |
306 | int fIndex = 0; | 312 | int fIndex = 0; |
307 | for ( ;; ) { | 313 | for ( ;; ) { |
308 | if ( oldFormats.at( fIndex ).c == '\n' ) { | 314 | if ( oldFormats.at( fIndex ).c == '\n' ) { |
309 | if ( idx > 0 ) { | 315 | if ( idx > 0 ) { |
310 | if ( idx < sp->length() && fIndex > 0 ) | 316 | if ( idx < sp->length() && fIndex > 0 ) |
311 | sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() ); | 317 | sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() ); |
@@ -1451,196 +1457,196 @@ void QTextDocument::setRichTextInternal( const QString &text, QTextCursor* curso | |||
1451 | NEWPAR; | 1457 | NEWPAR; |
1452 | } | 1458 | } |
1453 | 1459 | ||
1454 | // set rtext spacing to FALSE for the initial paragraph. | 1460 | // set rtext spacing to FALSE for the initial paragraph. |
1455 | curpar->rtext = FALSE; | 1461 | curpar->rtext = FALSE; |
1456 | 1462 | ||
1457 | QString wellKnownTags = "br hr wsp table qt body meta title"; | 1463 | QString wellKnownTags = "br hr wsp table qt body meta title"; |
1458 | 1464 | ||
1459 | while ( pos < length ) { | 1465 | while ( pos < length ) { |
1460 | if ( hasPrefix(doc, length, pos, '<' ) ){ | 1466 | if ( hasPrefix(doc, length, pos, '<' ) ){ |
1461 | if ( !hasPrefix( doc, length, pos+1, QChar('/') ) ) { | 1467 | if ( !hasPrefix( doc, length, pos+1, QChar('/') ) ) { |
1462 | // open tag | 1468 | // open tag |
1463 | QMap<QString, QString> attr; | 1469 | QMap<QString, QString> attr; |
1464 | bool emptyTag = FALSE; | 1470 | bool emptyTag = FALSE; |
1465 | QString tagname = parseOpenTag(doc, length, pos, attr, emptyTag); | 1471 | QString tagname = parseOpenTag(doc, length, pos, attr, emptyTag); |
1466 | if ( tagname.isEmpty() ) | 1472 | if ( tagname.isEmpty() ) |
1467 | continue; // nothing we could do with this, probably parse error | 1473 | continue; // nothing we could do with this, probably parse error |
1468 | 1474 | ||
1469 | const QStyleSheetItem* nstyle = sheet_->item(tagname); | 1475 | const QStyleSheetItem* nstyle = sheet_->item(tagname); |
1470 | 1476 | ||
1471 | if ( nstyle ) { | 1477 | if ( nstyle ) { |
1472 | // we might have to close some 'forgotten' tags | 1478 | // we might have to close some 'forgotten' tags |
1473 | while ( !nstyle->allowedInContext( curtag.style ) ) { | 1479 | while ( !nstyle->allowedInContext( curtag.style ) ) { |
1474 | QString msg; | 1480 | QString msg; |
1475 | msg.sprintf( "QText Warning: Document not valid ( '%s' not allowed in '%s' #%d)", | 1481 | msg.sprintf( "QText Warning: Document not valid ( '%s' not allowed in '%s' #%d)", |
1476 | tagname.ascii(), curtag.style->name().ascii(), pos); | 1482 | tagname.ascii(), curtag.style->name().ascii(), pos); |
1477 | sheet_->error( msg ); | 1483 | sheet_->error( msg ); |
1478 | if ( tags.isEmpty() ) | 1484 | if ( tags.isEmpty() ) |
1479 | break; | 1485 | break; |
1480 | curtag = tags.pop(); | 1486 | curtag = tags.pop(); |
1481 | } | 1487 | } |
1482 | 1488 | ||
1483 | /* special handling for p and li for HTML | 1489 | /* special handling for p and li for HTML |
1484 | compatibility. We do not want to embed blocks in | 1490 | compatibility. We do not want to embed blocks in |
1485 | p, and we do not want new blocks inside non-empty | 1491 | p, and we do not want new blocks inside non-empty |
1486 | lis. Plus we want to merge empty lis sometimes. */ | 1492 | lis. Plus we want to merge empty lis sometimes. */ |
1487 | if( nstyle->displayMode() == QStyleSheetItem::DisplayListItem ) { | 1493 | if( nstyle->displayMode() == QStyleSheetItem::DisplayListItem ) { |
1488 | canMergeLi = TRUE; | 1494 | canMergeLi = TRUE; |
1489 | } else if ( nstyle->displayMode() == QStyleSheetItem::DisplayBlock ) { | 1495 | } else if ( nstyle->displayMode() == QStyleSheetItem::DisplayBlock ) { |
1490 | while ( curtag.style->name() == "p" ) { | 1496 | while ( curtag.style->name() == "p" ) { |
1491 | if ( tags.isEmpty() ) | 1497 | if ( tags.isEmpty() ) |
1492 | break; | 1498 | break; |
1493 | curtag = tags.pop(); | 1499 | curtag = tags.pop(); |
1494 | } | 1500 | } |
1495 | 1501 | ||
1496 | if ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) { | 1502 | if ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) { |
1497 | // we are in a li and a new block comes along | 1503 | // we are in a li and a new block comes along |
1498 | if ( nstyle->name() == "ul" || nstyle->name() == "ol" ) | 1504 | if ( nstyle->name() == "ul" || nstyle->name() == "ol" ) |
1499 | hasNewPar = FALSE; // we want an empty li (like most browsers) | 1505 | hasNewPar = FALSE; // we want an empty li (like most browsers) |
1500 | if ( !hasNewPar ) { | 1506 | if ( !hasNewPar ) { |
1501 | /* do not add new blocks inside | 1507 | /* do not add new blocks inside |
1502 | non-empty lis */ | 1508 | non-empty lis */ |
1503 | while ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) { | 1509 | while ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) { |
1504 | if ( tags.isEmpty() ) | 1510 | if ( tags.isEmpty() ) |
1505 | break; | 1511 | break; |
1506 | curtag = tags.pop(); | 1512 | curtag = tags.pop(); |
1507 | } | 1513 | } |
1508 | } else if ( canMergeLi ) { | 1514 | } else if ( canMergeLi ) { |
1509 | /* we have an empty li and a block | 1515 | /* we have an empty li and a block |
1510 | comes along, merge them */ | 1516 | comes along, merge them */ |
1511 | nstyle = curtag.style; | 1517 | nstyle = curtag.style; |
1512 | } | 1518 | } |
1513 | canMergeLi = FALSE; | 1519 | canMergeLi = FALSE; |
1514 | } | 1520 | } |
1515 | } | 1521 | } |
1516 | } | 1522 | } |
1517 | 1523 | ||
1518 | QTextCustomItem* custom = 0; | 1524 | QTextCustomItem* custom = 0; |
1519 | 1525 | ||
1520 | // some well-known tags, some have a nstyle, some not | 1526 | // some well-known tags, some have a nstyle, some not |
1521 | if ( wellKnownTags.find( tagname ) != -1 ) { | 1527 | if ( wellKnownTags.find( tagname ) != -1 ) { |
1522 | if ( tagname == "br" ) { | 1528 | if ( tagname == "br" ) { |
1523 | emptyTag = space = TRUE; | 1529 | emptyTag = space = TRUE; |
1524 | int index = QMAX( curpar->length(),1) - 1; | 1530 | int index = QMAX( curpar->length(),1) - 1; |
1525 | QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); | 1531 | QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); |
1526 | curpar->append( QChar_linesep ); | 1532 | curpar->append( QChar_linesep ); |
1527 | curpar->setFormat( index, 1, &format ); | 1533 | curpar->setFormat( index, 1, &format ); |
1528 | } else if ( tagname == "hr" ) { | 1534 | } else if ( tagname == "hr" ) { |
1529 | emptyTag = space = TRUE; | 1535 | emptyTag = space = TRUE; |
1530 | custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this ); | 1536 | custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this ); |
1531 | NEWPAR; | 1537 | NEWPAR; |
1532 | } else if ( tagname == "table" ) { | 1538 | } else if ( tagname == "table" ) { |
1533 | emptyTag = space = TRUE; | 1539 | emptyTag = space = TRUE; |
1534 | QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); | 1540 | QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); |
1535 | curpar->setAlignment( curtag.alignment ); | 1541 | curpar->setAlignment( curtag.alignment ); |
1536 | custom = parseTable( attr, format, doc, length, pos, curpar ); | 1542 | custom = parseTable( attr, format, doc, length, pos, curpar ); |
1537 | } else if ( tagname == "qt" || tagname == "body" ) { | 1543 | } else if ( tagname == "qt" || tagname == "body" ) { |
1538 | if ( attr.contains( "bgcolor" ) ) { | 1544 | if ( attr.contains( "bgcolor" ) ) { |
1539 | QBrush *b = new QBrush( QColor( attr["bgcolor"] ) ); | 1545 | QBrush *b = new QBrush( QColor( attr["bgcolor"] ) ); |
1540 | setPaper( b ); | 1546 | setPaper( b ); |
1541 | } | 1547 | } |
1542 | if ( attr.contains( "background" ) ) { | 1548 | if ( attr.contains( "background" ) ) { |
1543 | QImage img; | 1549 | QImage img; |
1544 | QString bg = attr["background"]; | 1550 | QString bg = attr["background"]; |
1545 | const QMimeSource* m = factory_->data( bg, contxt ); | 1551 | const QMimeSource* m = factory_->data( bg, contxt ); |
1546 | if ( !m ) { | 1552 | if ( !m ) { |
1547 | qWarning("QRichText: no mimesource for %s", bg.latin1() ); | 1553 | owarn << "QRichText: no mimesource for " << bg.latin1() << "" << oendl; |
1548 | } else { | 1554 | } else { |
1549 | if ( !QImageDrag::decode( m, img ) ) { | 1555 | if ( !QImageDrag::decode( m, img ) ) { |
1550 | qWarning("QTextImage: cannot decode %s", bg.latin1() ); | 1556 | owarn << "QTextImage: cannot decode " << bg.latin1() << "" << oendl; |
1551 | } | 1557 | } |
1552 | } | 1558 | } |
1553 | if ( !img.isNull() ) { | 1559 | if ( !img.isNull() ) { |
1554 | QPixmap pm; | 1560 | QPixmap pm; |
1555 | pm.convertFromImage( img ); | 1561 | pm.convertFromImage( img ); |
1556 | QBrush *b = new QBrush( QColor(), pm ); | 1562 | QBrush *b = new QBrush( QColor(), pm ); |
1557 | setPaper( b ); | 1563 | setPaper( b ); |
1558 | } | 1564 | } |
1559 | } | 1565 | } |
1560 | if ( attr.contains( "text" ) ) { | 1566 | if ( attr.contains( "text" ) ) { |
1561 | QColor c( attr["text"] ); | 1567 | QColor c( attr["text"] ); |
1562 | if ( formatCollection()->defaultFormat()->color() != c ) { | 1568 | if ( formatCollection()->defaultFormat()->color() != c ) { |
1563 | QDict<QTextFormat> formats = formatCollection()->dict(); | 1569 | QDict<QTextFormat> formats = formatCollection()->dict(); |
1564 | QDictIterator<QTextFormat> it( formats ); | 1570 | QDictIterator<QTextFormat> it( formats ); |
1565 | while ( it.current() ) { | 1571 | while ( it.current() ) { |
1566 | if ( it.current() == formatCollection()->defaultFormat() ) { | 1572 | if ( it.current() == formatCollection()->defaultFormat() ) { |
1567 | ++it; | 1573 | ++it; |
1568 | continue; | 1574 | continue; |
1569 | } | 1575 | } |
1570 | it.current()->setColor( c ); | 1576 | it.current()->setColor( c ); |
1571 | ++it; | 1577 | ++it; |
1572 | } | 1578 | } |
1573 | formatCollection()->defaultFormat()->setColor( c ); | 1579 | formatCollection()->defaultFormat()->setColor( c ); |
1574 | curtag.format.setColor( c ); | 1580 | curtag.format.setColor( c ); |
1575 | } | 1581 | } |
1576 | } | 1582 | } |
1577 | if ( attr.contains( "link" ) ) | 1583 | if ( attr.contains( "link" ) ) |
1578 | linkColor = QColor( attr["link"] ); | 1584 | linkColor = QColor( attr["link"] ); |
1579 | if ( attr.contains( "title" ) ) | 1585 | if ( attr.contains( "title" ) ) |
1580 | attribs.replace( "title", attr["title"] ); | 1586 | attribs.replace( "title", attr["title"] ); |
1581 | 1587 | ||
1582 | if ( textEditMode ) { | 1588 | if ( textEditMode ) { |
1583 | if ( attr.contains("style" ) ) { | 1589 | if ( attr.contains("style" ) ) { |
1584 | QString a = attr["style"]; | 1590 | QString a = attr["style"]; |
1585 | for ( int s = 0; s < a.contains(';')+1; s++ ) { | 1591 | for ( int s = 0; s < a.contains(';')+1; s++ ) { |
1586 | QString style = QTextDocument::section( a, ";", s, s ); | 1592 | QString style = QTextDocument::section( a, ";", s, s ); |
1587 | if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) { | 1593 | if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) { |
1588 | scaleFontsFactor = double( formatCollection()->defaultFormat()->fn.pointSize() ) / | 1594 | scaleFontsFactor = double( formatCollection()->defaultFormat()->fn.pointSize() ) / |
1589 | style.mid( 10, style.length() - 12 ).toInt(); | 1595 | style.mid( 10, style.length() - 12 ).toInt(); |
1590 | } | 1596 | } |
1591 | } | 1597 | } |
1592 | } | 1598 | } |
1593 | nstyle = 0; // ignore body in textEditMode | 1599 | nstyle = 0; // ignore body in textEditMode |
1594 | } | 1600 | } |
1595 | // end qt- and body-tag handling | 1601 | // end qt- and body-tag handling |
1596 | } else if ( tagname == "meta" ) { | 1602 | } else if ( tagname == "meta" ) { |
1597 | if ( attr["name"] == "qrichtext" && attr["content"] == "1" ) | 1603 | if ( attr["name"] == "qrichtext" && attr["content"] == "1" ) |
1598 | textEditMode = TRUE; | 1604 | textEditMode = TRUE; |
1599 | } else if ( tagname == "title" ) { | 1605 | } else if ( tagname == "title" ) { |
1600 | QString title; | 1606 | QString title; |
1601 | while ( pos < length ) { | 1607 | while ( pos < length ) { |
1602 | if ( hasPrefix( doc, length, pos, QChar('<') ) && hasPrefix( doc, length, pos+1, QChar('/') ) && | 1608 | if ( hasPrefix( doc, length, pos, QChar('<') ) && hasPrefix( doc, length, pos+1, QChar('/') ) && |
1603 | parseCloseTag( doc, length, pos ) == "title" ) | 1609 | parseCloseTag( doc, length, pos ) == "title" ) |
1604 | break; | 1610 | break; |
1605 | title += doc[ pos ]; | 1611 | title += doc[ pos ]; |
1606 | ++pos; | 1612 | ++pos; |
1607 | } | 1613 | } |
1608 | attribs.replace( "title", title ); | 1614 | attribs.replace( "title", title ); |
1609 | } | 1615 | } |
1610 | } // end of well-known tag handling | 1616 | } // end of well-known tag handling |
1611 | 1617 | ||
1612 | if ( !custom ) // try generic custom item | 1618 | if ( !custom ) // try generic custom item |
1613 | custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this ); | 1619 | custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this ); |
1614 | 1620 | ||
1615 | if ( !nstyle && !custom ) // we have no clue what this tag could be, ignore it | 1621 | if ( !nstyle && !custom ) // we have no clue what this tag could be, ignore it |
1616 | continue; | 1622 | continue; |
1617 | 1623 | ||
1618 | if ( custom ) { | 1624 | if ( custom ) { |
1619 | int index = QMAX( curpar->length(),1) - 1; | 1625 | int index = QMAX( curpar->length(),1) - 1; |
1620 | QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); | 1626 | QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); |
1621 | curpar->append( QChar('*') ); | 1627 | curpar->append( QChar('*') ); |
1622 | curpar->setFormat( index, 1, &format ); | 1628 | curpar->setFormat( index, 1, &format ); |
1623 | curpar->at( index )->setCustomItem( custom ); | 1629 | curpar->at( index )->setCustomItem( custom ); |
1624 | if ( !curtag.anchorHref.isEmpty() ) | 1630 | if ( !curtag.anchorHref.isEmpty() ) |
1625 | curpar->at(index)->setAnchor( QString::null, curtag.anchorHref ); | 1631 | curpar->at(index)->setAnchor( QString::null, curtag.anchorHref ); |
1626 | if ( !anchorName.isEmpty() ) { | 1632 | if ( !anchorName.isEmpty() ) { |
1627 | curpar->at(index)->setAnchor( anchorName, curpar->at(index)->anchorHref() ); | 1633 | curpar->at(index)->setAnchor( anchorName, curpar->at(index)->anchorHref() ); |
1628 | anchorName = QString::null; | 1634 | anchorName = QString::null; |
1629 | } | 1635 | } |
1630 | registerCustomItem( custom, curpar ); | 1636 | registerCustomItem( custom, curpar ); |
1631 | hasNewPar = FALSE; | 1637 | hasNewPar = FALSE; |
1632 | } else if ( !emptyTag ) { | 1638 | } else if ( !emptyTag ) { |
1633 | /* if we do nesting, push curtag on the stack, | 1639 | /* if we do nesting, push curtag on the stack, |
1634 | otherwise reinint curag. */ | 1640 | otherwise reinint curag. */ |
1635 | if ( curtag.style->name() != tagname || nstyle->selfNesting() ) { | 1641 | if ( curtag.style->name() != tagname || nstyle->selfNesting() ) { |
1636 | tags.push( curtag ); | 1642 | tags.push( curtag ); |
1637 | } else { | 1643 | } else { |
1638 | if ( !tags.isEmpty() ) | 1644 | if ( !tags.isEmpty() ) |
1639 | curtag = tags.top(); | 1645 | curtag = tags.top(); |
1640 | else | 1646 | else |
1641 | curtag = initag; | 1647 | curtag = initag; |
1642 | } | 1648 | } |
1643 | 1649 | ||
1644 | curtag.name = tagname; | 1650 | curtag.name = tagname; |
1645 | curtag.style = nstyle; | 1651 | curtag.style = nstyle; |
1646 | curtag.name = tagname; | 1652 | curtag.name = tagname; |
@@ -2059,193 +2065,193 @@ QString QTextDocument::plainText() const | |||
2059 | } else { | 2065 | } else { |
2060 | s += p->at( i )->c; | 2066 | s += p->at( i )->c; |
2061 | } | 2067 | } |
2062 | } | 2068 | } |
2063 | } | 2069 | } |
2064 | s.remove( s.length() - 1, 1 ); | 2070 | s.remove( s.length() - 1, 1 ); |
2065 | if ( p->next() ) | 2071 | if ( p->next() ) |
2066 | s += "\n"; | 2072 | s += "\n"; |
2067 | buffer += s; | 2073 | buffer += s; |
2068 | p = p->next(); | 2074 | p = p->next(); |
2069 | } | 2075 | } |
2070 | return buffer; | 2076 | return buffer; |
2071 | } | 2077 | } |
2072 | 2078 | ||
2073 | static QString align_to_string( int a ) | 2079 | static QString align_to_string( int a ) |
2074 | { | 2080 | { |
2075 | if ( a & Qt::AlignRight ) | 2081 | if ( a & Qt::AlignRight ) |
2076 | return " align=\"right\""; | 2082 | return " align=\"right\""; |
2077 | if ( a & Qt::AlignHCenter ) | 2083 | if ( a & Qt::AlignHCenter ) |
2078 | return " align=\"center\""; | 2084 | return " align=\"center\""; |
2079 | if ( a & Qt3::AlignJustify ) | 2085 | if ( a & Qt3::AlignJustify ) |
2080 | return " align=\"justify\""; | 2086 | return " align=\"justify\""; |
2081 | return QString::null; | 2087 | return QString::null; |
2082 | } | 2088 | } |
2083 | 2089 | ||
2084 | static QString direction_to_string( int d ) | 2090 | static QString direction_to_string( int d ) |
2085 | { | 2091 | { |
2086 | if ( d != QChar::DirON ) | 2092 | if ( d != QChar::DirON ) |
2087 | return ( d == QChar::DirL? " dir=\"ltr\"" : " dir=\"rtl\"" ); | 2093 | return ( d == QChar::DirL? " dir=\"ltr\"" : " dir=\"rtl\"" ); |
2088 | return QString::null; | 2094 | return QString::null; |
2089 | } | 2095 | } |
2090 | 2096 | ||
2091 | static QString list_value_to_string( int v ) | 2097 | static QString list_value_to_string( int v ) |
2092 | { | 2098 | { |
2093 | if ( v != -1 ) | 2099 | if ( v != -1 ) |
2094 | return " listvalue=\"" + QString::number( v ) + "\""; | 2100 | return " listvalue=\"" + QString::number( v ) + "\""; |
2095 | return QString::null; | 2101 | return QString::null; |
2096 | } | 2102 | } |
2097 | 2103 | ||
2098 | static QString list_style_to_string( int v ) | 2104 | static QString list_style_to_string( int v ) |
2099 | { | 2105 | { |
2100 | switch( v ) { | 2106 | switch( v ) { |
2101 | case QStyleSheetItem::ListDecimal: return "\"1\""; | 2107 | case QStyleSheetItem::ListDecimal: return "\"1\""; |
2102 | case QStyleSheetItem::ListLowerAlpha: return "\"a\""; | 2108 | case QStyleSheetItem::ListLowerAlpha: return "\"a\""; |
2103 | case QStyleSheetItem::ListUpperAlpha: return "\"A\""; | 2109 | case QStyleSheetItem::ListUpperAlpha: return "\"A\""; |
2104 | case QStyleSheetItem::ListDisc: return "\"disc\""; | 2110 | case QStyleSheetItem::ListDisc: return "\"disc\""; |
2105 | case QStyleSheetItem::ListSquare: return "\"square\""; | 2111 | case QStyleSheetItem::ListSquare: return "\"square\""; |
2106 | case QStyleSheetItem::ListCircle: return "\"circle\""; | 2112 | case QStyleSheetItem::ListCircle: return "\"circle\""; |
2107 | default: | 2113 | default: |
2108 | return QString::null; | 2114 | return QString::null; |
2109 | } | 2115 | } |
2110 | } | 2116 | } |
2111 | 2117 | ||
2112 | static inline bool list_is_ordered( int v ) | 2118 | static inline bool list_is_ordered( int v ) |
2113 | { | 2119 | { |
2114 | return v == QStyleSheetItem::ListDecimal || | 2120 | return v == QStyleSheetItem::ListDecimal || |
2115 | v == QStyleSheetItem::ListLowerAlpha || | 2121 | v == QStyleSheetItem::ListLowerAlpha || |
2116 | v == QStyleSheetItem::ListUpperAlpha; | 2122 | v == QStyleSheetItem::ListUpperAlpha; |
2117 | } | 2123 | } |
2118 | 2124 | ||
2119 | 2125 | ||
2120 | static QString margin_to_string( QStyleSheetItem* style, int t, int b, int l, int r, int fl ) | 2126 | static QString margin_to_string( QStyleSheetItem* style, int t, int b, int l, int r, int fl ) |
2121 | { | 2127 | { |
2122 | QString s; | 2128 | QString s; |
2123 | if ( l > 0 ) | 2129 | if ( l > 0 ) |
2124 | s += QString(!!s?";":"") + "margin-left:" + QString::number(l+QMAX(0,style->margin(QStyleSheetItem::MarginLeft))) + "px"; | 2130 | s += QString(!!s?";":"") + "margin-left:" + QString::number(l+QMAX(0,style->margin(QStyleSheetItem::MarginLeft))) + "px"; |
2125 | if ( r > 0 ) | 2131 | if ( r > 0 ) |
2126 | s += QString(!!s?";":"") + "margin-right:" + QString::number(r+QMAX(0,style->margin(QStyleSheetItem::MarginRight))) + "px"; | 2132 | s += QString(!!s?";":"") + "margin-right:" + QString::number(r+QMAX(0,style->margin(QStyleSheetItem::MarginRight))) + "px"; |
2127 | if ( t > 0 ) | 2133 | if ( t > 0 ) |
2128 | s += QString(!!s?";":"") + "margin-top:" + QString::number(t+QMAX(0,style->margin(QStyleSheetItem::MarginTop))) + "px"; | 2134 | s += QString(!!s?";":"") + "margin-top:" + QString::number(t+QMAX(0,style->margin(QStyleSheetItem::MarginTop))) + "px"; |
2129 | if ( b > 0 ) | 2135 | if ( b > 0 ) |
2130 | s += QString(!!s?";":"") + "margin-bottom:" + QString::number(b+QMAX(0,style->margin(QStyleSheetItem::MarginBottom))) + "px"; | 2136 | s += QString(!!s?";":"") + "margin-bottom:" + QString::number(b+QMAX(0,style->margin(QStyleSheetItem::MarginBottom))) + "px"; |
2131 | if ( fl > 0 ) | 2137 | if ( fl > 0 ) |
2132 | s += QString(!!s?";":"") + "text-indent:" + QString::number(fl+QMAX(0,style->margin(QStyleSheetItem::MarginFirstLine))) + "px"; | 2138 | s += QString(!!s?";":"") + "text-indent:" + QString::number(fl+QMAX(0,style->margin(QStyleSheetItem::MarginFirstLine))) + "px"; |
2133 | if ( !!s ) | 2139 | if ( !!s ) |
2134 | return " style=\"" + s + "\""; | 2140 | return " style=\"" + s + "\""; |
2135 | return QString::null; | 2141 | return QString::null; |
2136 | } | 2142 | } |
2137 | 2143 | ||
2138 | QString QTextDocument::richText() const | 2144 | QString QTextDocument::richText() const |
2139 | { | 2145 | { |
2140 | QString s = ""; | 2146 | QString s = ""; |
2141 | if ( !par ) { | 2147 | if ( !par ) { |
2142 | s += "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:" ; | 2148 | s += "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:" ; |
2143 | s += QString::number( formatCollection()->defaultFormat()->font().pointSize() ); | 2149 | s += QString::number( formatCollection()->defaultFormat()->font().pointSize() ); |
2144 | s += "pt;font-family:"; | 2150 | s += "pt;font-family:"; |
2145 | s += formatCollection()->defaultFormat()->font().family(); | 2151 | s += formatCollection()->defaultFormat()->font().family(); |
2146 | s +="\">"; | 2152 | s +="\">"; |
2147 | } | 2153 | } |
2148 | QTextParagraph* p = fParag; | 2154 | QTextParagraph* p = fParag; |
2149 | 2155 | ||
2150 | QStyleSheetItem* item_p = styleSheet()->item("p"); | 2156 | QStyleSheetItem* item_p = styleSheet()->item("p"); |
2151 | QStyleSheetItem* item_ul = styleSheet()->item("ul"); | 2157 | QStyleSheetItem* item_ul = styleSheet()->item("ul"); |
2152 | QStyleSheetItem* item_ol = styleSheet()->item("ol"); | 2158 | QStyleSheetItem* item_ol = styleSheet()->item("ol"); |
2153 | QStyleSheetItem* item_li = styleSheet()->item("li"); | 2159 | QStyleSheetItem* item_li = styleSheet()->item("li"); |
2154 | if ( !item_p || !item_ul || !item_ol || !item_li ) { | 2160 | if ( !item_p || !item_ul || !item_ol || !item_li ) { |
2155 | qWarning( "QTextEdit: cannot export HTML due to insufficient stylesheet (lack of p, ul, ol, or li)" ); | 2161 | owarn << "QTextEdit: cannot export HTML due to insufficient stylesheet (lack of p, ul, ol, or li)" << oendl; |
2156 | return QString::null; | 2162 | return QString::null; |
2157 | } | 2163 | } |
2158 | int pastListDepth = 0; | 2164 | int pastListDepth = 0; |
2159 | int listDepth = 0; | 2165 | int listDepth = 0; |
2160 | int futureListDepth = 0; | 2166 | int futureListDepth = 0; |
2161 | QMemArray<int> listStyles(10); | 2167 | QMemArray<int> listStyles(10); |
2162 | 2168 | ||
2163 | while ( p ) { | 2169 | while ( p ) { |
2164 | listDepth = p->listDepth(); | 2170 | listDepth = p->listDepth(); |
2165 | if ( listDepth < pastListDepth ) { | 2171 | if ( listDepth < pastListDepth ) { |
2166 | for ( int i = listDepth+1; i <= pastListDepth; i++ ) | 2172 | for ( int i = listDepth+1; i <= pastListDepth; i++ ) |
2167 | s += list_is_ordered( listStyles[i] ) ? "</ol>" : "</ul>"; | 2173 | s += list_is_ordered( listStyles[i] ) ? "</ol>" : "</ul>"; |
2168 | s += '\n'; | 2174 | s += '\n'; |
2169 | } else if ( listDepth > pastListDepth ) { | 2175 | } else if ( listDepth > pastListDepth ) { |
2170 | s += '\n'; | 2176 | s += '\n'; |
2171 | listStyles.resize( QMAX( (int)listStyles.size(), listDepth+1 ) ); | 2177 | listStyles.resize( QMAX( (int)listStyles.size(), listDepth+1 ) ); |
2172 | QString list_type; | 2178 | QString list_type; |
2173 | listStyles[listDepth] = p->listStyle(); | 2179 | listStyles[listDepth] = p->listStyle(); |
2174 | if ( !list_is_ordered( p->listStyle() ) || item_ol->listStyle() != p->listStyle() ) | 2180 | if ( !list_is_ordered( p->listStyle() ) || item_ol->listStyle() != p->listStyle() ) |
2175 | list_type = " type=" + list_style_to_string( p->listStyle() ); | 2181 | list_type = " type=" + list_style_to_string( p->listStyle() ); |
2176 | for ( int i = pastListDepth; i < listDepth; i++ ) { | 2182 | for ( int i = pastListDepth; i < listDepth; i++ ) { |
2177 | s += list_is_ordered( p->listStyle() ) ? "<ol" : "<ul" ; | 2183 | s += list_is_ordered( p->listStyle() ) ? "<ol" : "<ul" ; |
2178 | s += list_type + ">"; | 2184 | s += list_type + ">"; |
2179 | } | 2185 | } |
2180 | } else { | 2186 | } else { |
2181 | s += '\n'; | 2187 | s += '\n'; |
2182 | } | 2188 | } |
2183 | 2189 | ||
2184 | QString ps = p->richText(); | 2190 | QString ps = p->richText(); |
2185 | 2191 | ||
2186 | // for the bottom margin we need to know whether we are at the end of a list | 2192 | // for the bottom margin we need to know whether we are at the end of a list |
2187 | futureListDepth = 0; | 2193 | futureListDepth = 0; |
2188 | if ( listDepth > 0 && p->next() ) | 2194 | if ( listDepth > 0 && p->next() ) |
2189 | futureListDepth = p->next()->listDepth(); | 2195 | futureListDepth = p->next()->listDepth(); |
2190 | 2196 | ||
2191 | if ( richTextExportStart && richTextExportStart->paragraph() ==p && | 2197 | if ( richTextExportStart && richTextExportStart->paragraph() ==p && |
2192 | richTextExportStart->index() == 0 ) | 2198 | richTextExportStart->index() == 0 ) |
2193 | s += "<selstart/>"; | 2199 | s += "<selstart/>"; |
2194 | 2200 | ||
2195 | if ( p->isListItem() ) { | 2201 | if ( p->isListItem() ) { |
2196 | s += "<li"; | 2202 | s += "<li"; |
2197 | if ( p->listStyle() != listStyles[listDepth] ) | 2203 | if ( p->listStyle() != listStyles[listDepth] ) |
2198 | s += " type=" + list_style_to_string( p->listStyle() ); | 2204 | s += " type=" + list_style_to_string( p->listStyle() ); |
2199 | s +=align_to_string( p->alignment() ); | 2205 | s +=align_to_string( p->alignment() ); |
2200 | s += margin_to_string( item_li, p->utm, p->ubm, p->ulm, p->urm, p->uflm ); | 2206 | s += margin_to_string( item_li, p->utm, p->ubm, p->ulm, p->urm, p->uflm ); |
2201 | s += list_value_to_string( p->listValue() ); | 2207 | s += list_value_to_string( p->listValue() ); |
2202 | s += direction_to_string( p->direction() ); | 2208 | s += direction_to_string( p->direction() ); |
2203 | s +=">"; | 2209 | s +=">"; |
2204 | s += ps; | 2210 | s += ps; |
2205 | s += "</li>"; | 2211 | s += "</li>"; |
2206 | } else { | 2212 | } else { |
2207 | // normal paragraph item | 2213 | // normal paragraph item |
2208 | s += "<p"; | 2214 | s += "<p"; |
2209 | s += align_to_string( p->alignment() ); | 2215 | s += align_to_string( p->alignment() ); |
2210 | s += margin_to_string( item_p, p->utm, p->ubm, p->ulm, p->urm, p->uflm ); | 2216 | s += margin_to_string( item_p, p->utm, p->ubm, p->ulm, p->urm, p->uflm ); |
2211 | s +=direction_to_string( p->direction() ); | 2217 | s +=direction_to_string( p->direction() ); |
2212 | s += ">"; | 2218 | s += ">"; |
2213 | s += ps; | 2219 | s += ps; |
2214 | s += "</p>"; | 2220 | s += "</p>"; |
2215 | } | 2221 | } |
2216 | pastListDepth = listDepth; | 2222 | pastListDepth = listDepth; |
2217 | p = p->next(); | 2223 | p = p->next(); |
2218 | } | 2224 | } |
2219 | while ( listDepth > 0 ) { | 2225 | while ( listDepth > 0 ) { |
2220 | s += list_is_ordered( listStyles[listDepth] ) ? "</ol>" : "</ul>"; | 2226 | s += list_is_ordered( listStyles[listDepth] ) ? "</ol>" : "</ul>"; |
2221 | listDepth--; | 2227 | listDepth--; |
2222 | } | 2228 | } |
2223 | 2229 | ||
2224 | if ( !par ) | 2230 | if ( !par ) |
2225 | s += "\n</body></html>\n"; | 2231 | s += "\n</body></html>\n"; |
2226 | 2232 | ||
2227 | return s; | 2233 | return s; |
2228 | } | 2234 | } |
2229 | 2235 | ||
2230 | QString QTextDocument::text() const | 2236 | QString QTextDocument::text() const |
2231 | { | 2237 | { |
2232 | if ( txtFormat == Qt::AutoText && preferRichText || txtFormat == Qt::RichText ) | 2238 | if ( txtFormat == Qt::AutoText && preferRichText || txtFormat == Qt::RichText ) |
2233 | return richText(); | 2239 | return richText(); |
2234 | return plainText(); | 2240 | return plainText(); |
2235 | } | 2241 | } |
2236 | 2242 | ||
2237 | QString QTextDocument::text( int parag ) const | 2243 | QString QTextDocument::text( int parag ) const |
2238 | { | 2244 | { |
2239 | QTextParagraph *p = paragAt( parag ); | 2245 | QTextParagraph *p = paragAt( parag ); |
2240 | if ( !p ) | 2246 | if ( !p ) |
2241 | return QString::null; | 2247 | return QString::null; |
2242 | 2248 | ||
2243 | if ( txtFormat == Qt::AutoText && preferRichText || txtFormat == Qt::RichText ) | 2249 | if ( txtFormat == Qt::AutoText && preferRichText || txtFormat == Qt::RichText ) |
2244 | return p->richText(); | 2250 | return p->richText(); |
2245 | else | 2251 | else |
2246 | return p->string()->toString(); | 2252 | return p->string()->toString(); |
2247 | } | 2253 | } |
2248 | 2254 | ||
2249 | void QTextDocument::invalidate() | 2255 | void QTextDocument::invalidate() |
2250 | { | 2256 | { |
2251 | QTextParagraph *s = fParag; | 2257 | QTextParagraph *s = fParag; |
@@ -4003,246 +4009,246 @@ void QTextParagraph::format( int start, bool doMove ) | |||
4003 | // with has to be the full document width on mac as the selections | 4009 | // with has to be the full document width on mac as the selections |
4004 | // always extend completely to the right. This is a bit unefficient, | 4010 | // always extend completely to the right. This is a bit unefficient, |
4005 | // as this results in a bigger double buffer than needed but ok for | 4011 | // as this results in a bigger double buffer than needed but ok for |
4006 | // now. | 4012 | // now. |
4007 | if ( lineStarts.count() == 1 ) { | 4013 | if ( lineStarts.count() == 1 ) { |
4008 | if ( !string()->isBidi() ) { | 4014 | if ( !string()->isBidi() ) { |
4009 | c = &str->at( str->length() - 1 ); | 4015 | c = &str->at( str->length() - 1 ); |
4010 | r.setWidth( c->x + str->width( str->length() - 1 ) ); | 4016 | r.setWidth( c->x + str->width( str->length() - 1 ) ); |
4011 | } else { | 4017 | } else { |
4012 | r.setWidth( lineStarts[0]->w ); | 4018 | r.setWidth( lineStarts[0]->w ); |
4013 | } | 4019 | } |
4014 | } | 4020 | } |
4015 | 4021 | ||
4016 | if ( !hasdoc ) { // qt_format_text bounding rect handling | 4022 | if ( !hasdoc ) { // qt_format_text bounding rect handling |
4017 | it = lineStarts.begin(); | 4023 | it = lineStarts.begin(); |
4018 | int usedw = 0; | 4024 | int usedw = 0; |
4019 | for ( ; it != lineStarts.end(); ++it ) | 4025 | for ( ; it != lineStarts.end(); ++it ) |
4020 | usedw = QMAX( usedw, (*it)->w ); | 4026 | usedw = QMAX( usedw, (*it)->w ); |
4021 | if ( r.width() <= 0 ) { | 4027 | if ( r.width() <= 0 ) { |
4022 | // if the user specifies an invalid rect, this means that the | 4028 | // if the user specifies an invalid rect, this means that the |
4023 | // bounding box should grow to the width that the text actually | 4029 | // bounding box should grow to the width that the text actually |
4024 | // needs | 4030 | // needs |
4025 | r.setWidth( usedw ); | 4031 | r.setWidth( usedw ); |
4026 | } else { | 4032 | } else { |
4027 | r.setWidth( QMIN( usedw, r.width() ) ); | 4033 | r.setWidth( QMIN( usedw, r.width() ) ); |
4028 | } | 4034 | } |
4029 | } | 4035 | } |
4030 | 4036 | ||
4031 | if ( y != r.height() ) | 4037 | if ( y != r.height() ) |
4032 | r.setHeight( y ); | 4038 | r.setHeight( y ); |
4033 | 4039 | ||
4034 | if ( !visible ) { | 4040 | if ( !visible ) { |
4035 | r.setHeight( 0 ); | 4041 | r.setHeight( 0 ); |
4036 | } else { | 4042 | } else { |
4037 | int minw = formatter()->minimumWidth(); | 4043 | int minw = formatter()->minimumWidth(); |
4038 | int wused = formatter()->widthUsed(); | 4044 | int wused = formatter()->widthUsed(); |
4039 | wused = QMAX( minw, wused ); | 4045 | wused = QMAX( minw, wused ); |
4040 | if ( hasdoc ) { | 4046 | if ( hasdoc ) { |
4041 | document()->setMinimumWidth( minw, wused, this ); | 4047 | document()->setMinimumWidth( minw, wused, this ); |
4042 | } else { | 4048 | } else { |
4043 | pseudoDocument()->minw = QMAX( pseudoDocument()->minw, minw ); | 4049 | pseudoDocument()->minw = QMAX( pseudoDocument()->minw, minw ); |
4044 | pseudoDocument()->wused = QMAX( pseudoDocument()->wused, wused ); | 4050 | pseudoDocument()->wused = QMAX( pseudoDocument()->wused, wused ); |
4045 | } | 4051 | } |
4046 | } | 4052 | } |
4047 | 4053 | ||
4048 | // do page breaks if required | 4054 | // do page breaks if required |
4049 | if ( hasdoc && document()->isPageBreakEnabled() ) { | 4055 | if ( hasdoc && document()->isPageBreakEnabled() ) { |
4050 | int shift = document()->formatter()->formatVertically( document(), this ); | 4056 | int shift = document()->formatter()->formatVertically( document(), this ); |
4051 | if ( shift && !formattedAgain ) { | 4057 | if ( shift && !formattedAgain ) { |
4052 | formattedAgain = TRUE; | 4058 | formattedAgain = TRUE; |
4053 | goto formatAgain; | 4059 | goto formatAgain; |
4054 | } | 4060 | } |
4055 | } | 4061 | } |
4056 | 4062 | ||
4057 | if ( n && doMove && n->invalid == -1 && r.y() + r.height() != n->r.y() ) { | 4063 | if ( n && doMove && n->invalid == -1 && r.y() + r.height() != n->r.y() ) { |
4058 | int dy = ( r.y() + r.height() ) - n->r.y(); | 4064 | int dy = ( r.y() + r.height() ) - n->r.y(); |
4059 | QTextParagraph *s = n; | 4065 | QTextParagraph *s = n; |
4060 | bool makeInvalid = p && p->lastInFrame; | 4066 | bool makeInvalid = p && p->lastInFrame; |
4061 | while ( s && dy ) { | 4067 | while ( s && dy ) { |
4062 | if ( !s->isFullWidth() ) | 4068 | if ( !s->isFullWidth() ) |
4063 | makeInvalid = TRUE; | 4069 | makeInvalid = TRUE; |
4064 | if ( makeInvalid ) | 4070 | if ( makeInvalid ) |
4065 | s->invalidate( 0 ); | 4071 | s->invalidate( 0 ); |
4066 | s->move( dy ); | 4072 | s->move( dy ); |
4067 | if ( s->lastInFrame ) | 4073 | if ( s->lastInFrame ) |
4068 | makeInvalid = TRUE; | 4074 | makeInvalid = TRUE; |
4069 | s = s->n; | 4075 | s = s->n; |
4070 | } | 4076 | } |
4071 | } | 4077 | } |
4072 | 4078 | ||
4073 | firstFormat = FALSE; | 4079 | firstFormat = FALSE; |
4074 | changed = TRUE; | 4080 | changed = TRUE; |
4075 | invalid = -1; | 4081 | invalid = -1; |
4076 | //##### string()->setTextChanged( FALSE ); | 4082 | //##### string()->setTextChanged( FALSE ); |
4077 | } | 4083 | } |
4078 | 4084 | ||
4079 | int QTextParagraph::lineHeightOfChar( int i, int *bl, int *y ) const | 4085 | int QTextParagraph::lineHeightOfChar( int i, int *bl, int *y ) const |
4080 | { | 4086 | { |
4081 | if ( !isValid() ) | 4087 | if ( !isValid() ) |
4082 | ( (QTextParagraph*)this )->format(); | 4088 | ( (QTextParagraph*)this )->format(); |
4083 | 4089 | ||
4084 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.end(); | 4090 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.end(); |
4085 | --it; | 4091 | --it; |
4086 | for ( ;; ) { | 4092 | for ( ;; ) { |
4087 | if ( i >= it.key() ) { | 4093 | if ( i >= it.key() ) { |
4088 | if ( bl ) | 4094 | if ( bl ) |
4089 | *bl = ( *it )->baseLine; | 4095 | *bl = ( *it )->baseLine; |
4090 | if ( y ) | 4096 | if ( y ) |
4091 | *y = ( *it )->y; | 4097 | *y = ( *it )->y; |
4092 | return ( *it )->h; | 4098 | return ( *it )->h; |
4093 | } | 4099 | } |
4094 | if ( it == lineStarts.begin() ) | 4100 | if ( it == lineStarts.begin() ) |
4095 | break; | 4101 | break; |
4096 | --it; | 4102 | --it; |
4097 | } | 4103 | } |
4098 | 4104 | ||
4099 | qWarning( "QTextParagraph::lineHeightOfChar: couldn't find lh for %d", i ); | 4105 | owarn << "QTextParagraph::lineHeightOfChar: couldn't find lh for " << i << "" << oendl; |
4100 | return 15; | 4106 | return 15; |
4101 | } | 4107 | } |
4102 | 4108 | ||
4103 | QTextStringChar *QTextParagraph::lineStartOfChar( int i, int *index, int *line ) const | 4109 | QTextStringChar *QTextParagraph::lineStartOfChar( int i, int *index, int *line ) const |
4104 | { | 4110 | { |
4105 | if ( !isValid() ) | 4111 | if ( !isValid() ) |
4106 | ( (QTextParagraph*)this )->format(); | 4112 | ( (QTextParagraph*)this )->format(); |
4107 | 4113 | ||
4108 | int l = (int)lineStarts.count() - 1; | 4114 | int l = (int)lineStarts.count() - 1; |
4109 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.end(); | 4115 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.end(); |
4110 | --it; | 4116 | --it; |
4111 | for ( ;; ) { | 4117 | for ( ;; ) { |
4112 | if ( i >= it.key() ) { | 4118 | if ( i >= it.key() ) { |
4113 | if ( index ) | 4119 | if ( index ) |
4114 | *index = it.key(); | 4120 | *index = it.key(); |
4115 | if ( line ) | 4121 | if ( line ) |
4116 | *line = l; | 4122 | *line = l; |
4117 | return &str->at( it.key() ); | 4123 | return &str->at( it.key() ); |
4118 | } | 4124 | } |
4119 | if ( it == lineStarts.begin() ) | 4125 | if ( it == lineStarts.begin() ) |
4120 | break; | 4126 | break; |
4121 | --it; | 4127 | --it; |
4122 | --l; | 4128 | --l; |
4123 | } | 4129 | } |
4124 | 4130 | ||
4125 | qWarning( "QTextParagraph::lineStartOfChar: couldn't find %d", i ); | 4131 | owarn << "QTextParagraph::lineStartOfChar: couldn't find " << i << "" << oendl; |
4126 | return 0; | 4132 | return 0; |
4127 | } | 4133 | } |
4128 | 4134 | ||
4129 | int QTextParagraph::lines() const | 4135 | int QTextParagraph::lines() const |
4130 | { | 4136 | { |
4131 | if ( !isValid() ) | 4137 | if ( !isValid() ) |
4132 | ( (QTextParagraph*)this )->format(); | 4138 | ( (QTextParagraph*)this )->format(); |
4133 | 4139 | ||
4134 | return (int)lineStarts.count(); | 4140 | return (int)lineStarts.count(); |
4135 | } | 4141 | } |
4136 | 4142 | ||
4137 | QTextStringChar *QTextParagraph::lineStartOfLine( int line, int *index ) const | 4143 | QTextStringChar *QTextParagraph::lineStartOfLine( int line, int *index ) const |
4138 | { | 4144 | { |
4139 | if ( !isValid() ) | 4145 | if ( !isValid() ) |
4140 | ( (QTextParagraph*)this )->format(); | 4146 | ( (QTextParagraph*)this )->format(); |
4141 | 4147 | ||
4142 | if ( line >= 0 && line < (int)lineStarts.count() ) { | 4148 | if ( line >= 0 && line < (int)lineStarts.count() ) { |
4143 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); | 4149 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
4144 | while ( line-- > 0 ) | 4150 | while ( line-- > 0 ) |
4145 | ++it; | 4151 | ++it; |
4146 | int i = it.key(); | 4152 | int i = it.key(); |
4147 | if ( index ) | 4153 | if ( index ) |
4148 | *index = i; | 4154 | *index = i; |
4149 | return &str->at( i ); | 4155 | return &str->at( i ); |
4150 | } | 4156 | } |
4151 | 4157 | ||
4152 | qWarning( "QTextParagraph::lineStartOfLine: couldn't find %d", line ); | 4158 | owarn << "QTextParagraph::lineStartOfLine: couldn't find " << line << "" << oendl; |
4153 | return 0; | 4159 | return 0; |
4154 | } | 4160 | } |
4155 | 4161 | ||
4156 | int QTextParagraph::leftGap() const | 4162 | int QTextParagraph::leftGap() const |
4157 | { | 4163 | { |
4158 | if ( !isValid() ) | 4164 | if ( !isValid() ) |
4159 | ( (QTextParagraph*)this )->format(); | 4165 | ( (QTextParagraph*)this )->format(); |
4160 | 4166 | ||
4161 | int line = 0; | 4167 | int line = 0; |
4162 | int x = str->at(0).x; /* set x to x of first char */ | 4168 | int x = str->at(0).x; /* set x to x of first char */ |
4163 | if ( str->isBidi() ) { | 4169 | if ( str->isBidi() ) { |
4164 | for ( int i = 1; i < str->length()-1; ++i ) | 4170 | for ( int i = 1; i < str->length()-1; ++i ) |
4165 | x = QMIN(x, str->at(i).x); | 4171 | x = QMIN(x, str->at(i).x); |
4166 | return x; | 4172 | return x; |
4167 | } | 4173 | } |
4168 | 4174 | ||
4169 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); | 4175 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
4170 | while (line < (int)lineStarts.count()) { | 4176 | while (line < (int)lineStarts.count()) { |
4171 | int i = it.key(); /* char index */ | 4177 | int i = it.key(); /* char index */ |
4172 | x = QMIN(x, str->at(i).x); | 4178 | x = QMIN(x, str->at(i).x); |
4173 | ++it; | 4179 | ++it; |
4174 | ++line; | 4180 | ++line; |
4175 | } | 4181 | } |
4176 | return x; | 4182 | return x; |
4177 | } | 4183 | } |
4178 | 4184 | ||
4179 | void QTextParagraph::setFormat( int index, int len, QTextFormat *f, bool useCollection, int flags ) | 4185 | void QTextParagraph::setFormat( int index, int len, QTextFormat *f, bool useCollection, int flags ) |
4180 | { | 4186 | { |
4181 | if ( !f ) | 4187 | if ( !f ) |
4182 | return; | 4188 | return; |
4183 | if ( index < 0 ) | 4189 | if ( index < 0 ) |
4184 | index = 0; | 4190 | index = 0; |
4185 | if ( index > str->length() - 1 ) | 4191 | if ( index > str->length() - 1 ) |
4186 | index = str->length() - 1; | 4192 | index = str->length() - 1; |
4187 | if ( index + len >= str->length() ) | 4193 | if ( index + len >= str->length() ) |
4188 | len = str->length() - index; | 4194 | len = str->length() - index; |
4189 | 4195 | ||
4190 | QTextFormatCollection *fc = 0; | 4196 | QTextFormatCollection *fc = 0; |
4191 | if ( useCollection ) | 4197 | if ( useCollection ) |
4192 | fc = formatCollection(); | 4198 | fc = formatCollection(); |
4193 | QTextFormat *of; | 4199 | QTextFormat *of; |
4194 | for ( int i = 0; i < len; ++i ) { | 4200 | for ( int i = 0; i < len; ++i ) { |
4195 | of = str->at( i + index ).format(); | 4201 | of = str->at( i + index ).format(); |
4196 | if ( !changed && f->key() != of->key() ) | 4202 | if ( !changed && f->key() != of->key() ) |
4197 | changed = TRUE; | 4203 | changed = TRUE; |
4198 | if ( invalid == -1 && | 4204 | if ( invalid == -1 && |
4199 | ( f->font().family() != of->font().family() || | 4205 | ( f->font().family() != of->font().family() || |
4200 | f->font().pointSize() != of->font().pointSize() || | 4206 | f->font().pointSize() != of->font().pointSize() || |
4201 | f->font().weight() != of->font().weight() || | 4207 | f->font().weight() != of->font().weight() || |
4202 | f->font().italic() != of->font().italic() || | 4208 | f->font().italic() != of->font().italic() || |
4203 | f->vAlign() != of->vAlign() ) ) { | 4209 | f->vAlign() != of->vAlign() ) ) { |
4204 | invalidate( 0 ); | 4210 | invalidate( 0 ); |
4205 | } | 4211 | } |
4206 | if ( flags == -1 || flags == QTextFormat::Format || !fc ) { | 4212 | if ( flags == -1 || flags == QTextFormat::Format || !fc ) { |
4207 | if ( fc ) | 4213 | if ( fc ) |
4208 | f = fc->format( f ); | 4214 | f = fc->format( f ); |
4209 | str->setFormat( i + index, f, useCollection ); | 4215 | str->setFormat( i + index, f, useCollection ); |
4210 | } else { | 4216 | } else { |
4211 | QTextFormat *fm = fc->format( of, f, flags ); | 4217 | QTextFormat *fm = fc->format( of, f, flags ); |
4212 | str->setFormat( i + index, fm, useCollection ); | 4218 | str->setFormat( i + index, fm, useCollection ); |
4213 | } | 4219 | } |
4214 | } | 4220 | } |
4215 | } | 4221 | } |
4216 | 4222 | ||
4217 | void QTextParagraph::indent( int *oldIndent, int *newIndent ) | 4223 | void QTextParagraph::indent( int *oldIndent, int *newIndent ) |
4218 | { | 4224 | { |
4219 | if ( !hasdoc || !document()->indent() || isListItem() ) { | 4225 | if ( !hasdoc || !document()->indent() || isListItem() ) { |
4220 | if ( oldIndent ) | 4226 | if ( oldIndent ) |
4221 | *oldIndent = 0; | 4227 | *oldIndent = 0; |
4222 | if ( newIndent ) | 4228 | if ( newIndent ) |
4223 | *newIndent = 0; | 4229 | *newIndent = 0; |
4224 | if ( oldIndent && newIndent ) | 4230 | if ( oldIndent && newIndent ) |
4225 | *newIndent = *oldIndent; | 4231 | *newIndent = *oldIndent; |
4226 | return; | 4232 | return; |
4227 | } | 4233 | } |
4228 | document()->indent()->indent( document(), this, oldIndent, newIndent ); | 4234 | document()->indent()->indent( document(), this, oldIndent, newIndent ); |
4229 | } | 4235 | } |
4230 | 4236 | ||
4231 | void QTextParagraph::paint( QPainter &painter, const QColorGroup &cg, QTextCursor *cursor, bool drawSelections, | 4237 | void QTextParagraph::paint( QPainter &painter, const QColorGroup &cg, QTextCursor *cursor, bool drawSelections, |
4232 | int clipx, int clipy, int clipw, int cliph ) | 4238 | int clipx, int clipy, int clipw, int cliph ) |
4233 | { | 4239 | { |
4234 | if ( !visible ) | 4240 | if ( !visible ) |
4235 | return; | 4241 | return; |
4236 | QTextStringChar *chr = 0; | 4242 | QTextStringChar *chr = 0; |
4237 | int i, y, h, baseLine, xstart, xend; | 4243 | int i, y, h, baseLine, xstart, xend; |
4238 | i = y =h = baseLine = 0; | 4244 | i = y =h = baseLine = 0; |
4239 | QRect cursorRect; | 4245 | QRect cursorRect; |
4240 | drawSelections &= ( mSelections != 0 ); | 4246 | drawSelections &= ( mSelections != 0 ); |
4241 | // macintosh full-width selection style | 4247 | // macintosh full-width selection style |
4242 | bool fullWidthStyle = FALSE; | 4248 | bool fullWidthStyle = FALSE; |
4243 | int fullSelectionWidth = 0; | 4249 | int fullSelectionWidth = 0; |
4244 | if ( drawSelections && fullWidthStyle ) | 4250 | if ( drawSelections && fullWidthStyle ) |
4245 | fullSelectionWidth = (hasdoc ? document()->width() : r.width()); | 4251 | fullSelectionWidth = (hasdoc ? document()->width() : r.width()); |
4246 | 4252 | ||
4247 | QString qstr = str->toString(); | 4253 | QString qstr = str->toString(); |
4248 | // ### workaround so that \n are not drawn, actually this should | 4254 | // ### workaround so that \n are not drawn, actually this should |
@@ -5604,193 +5610,193 @@ QTextFormat *QTextFormatCollection::format( QTextFormat *f ) | |||
5604 | return lastFormat; | 5610 | return lastFormat; |
5605 | } | 5611 | } |
5606 | 5612 | ||
5607 | if ( f == lastFormat || ( lastFormat && f->key() == lastFormat->key() ) ) { | 5613 | if ( f == lastFormat || ( lastFormat && f->key() == lastFormat->key() ) ) { |
5608 | lastFormat->addRef(); | 5614 | lastFormat->addRef(); |
5609 | return lastFormat; | 5615 | return lastFormat; |
5610 | } | 5616 | } |
5611 | 5617 | ||
5612 | QTextFormat *fm = cKey.find( f->key() ); | 5618 | QTextFormat *fm = cKey.find( f->key() ); |
5613 | if ( fm ) { | 5619 | if ( fm ) { |
5614 | lastFormat = fm; | 5620 | lastFormat = fm; |
5615 | lastFormat->addRef(); | 5621 | lastFormat->addRef(); |
5616 | return lastFormat; | 5622 | return lastFormat; |
5617 | } | 5623 | } |
5618 | 5624 | ||
5619 | if ( f->key() == defFormat->key() ) | 5625 | if ( f->key() == defFormat->key() ) |
5620 | return defFormat; | 5626 | return defFormat; |
5621 | 5627 | ||
5622 | lastFormat = createFormat( *f ); | 5628 | lastFormat = createFormat( *f ); |
5623 | lastFormat->collection = this; | 5629 | lastFormat->collection = this; |
5624 | cKey.insert( lastFormat->key(), lastFormat ); | 5630 | cKey.insert( lastFormat->key(), lastFormat ); |
5625 | return lastFormat; | 5631 | return lastFormat; |
5626 | } | 5632 | } |
5627 | 5633 | ||
5628 | QTextFormat *QTextFormatCollection::format( QTextFormat *of, QTextFormat *nf, int flags ) | 5634 | QTextFormat *QTextFormatCollection::format( QTextFormat *of, QTextFormat *nf, int flags ) |
5629 | { | 5635 | { |
5630 | if ( cres && kof == of->key() && knf == nf->key() && cflags == flags ) { | 5636 | if ( cres && kof == of->key() && knf == nf->key() && cflags == flags ) { |
5631 | cres->addRef(); | 5637 | cres->addRef(); |
5632 | return cres; | 5638 | return cres; |
5633 | } | 5639 | } |
5634 | 5640 | ||
5635 | cres = createFormat( *of ); | 5641 | cres = createFormat( *of ); |
5636 | kof = of->key(); | 5642 | kof = of->key(); |
5637 | knf = nf->key(); | 5643 | knf = nf->key(); |
5638 | cflags = flags; | 5644 | cflags = flags; |
5639 | if ( flags & QTextFormat::Bold ) | 5645 | if ( flags & QTextFormat::Bold ) |
5640 | cres->fn.setBold( nf->fn.bold() ); | 5646 | cres->fn.setBold( nf->fn.bold() ); |
5641 | if ( flags & QTextFormat::Italic ) | 5647 | if ( flags & QTextFormat::Italic ) |
5642 | cres->fn.setItalic( nf->fn.italic() ); | 5648 | cres->fn.setItalic( nf->fn.italic() ); |
5643 | if ( flags & QTextFormat::Underline ) | 5649 | if ( flags & QTextFormat::Underline ) |
5644 | cres->fn.setUnderline( nf->fn.underline() ); | 5650 | cres->fn.setUnderline( nf->fn.underline() ); |
5645 | if ( flags & QTextFormat::StrikeOut ) | 5651 | if ( flags & QTextFormat::StrikeOut ) |
5646 | cres->fn.setStrikeOut( nf->fn.strikeOut() ); | 5652 | cres->fn.setStrikeOut( nf->fn.strikeOut() ); |
5647 | if ( flags & QTextFormat::Family ) | 5653 | if ( flags & QTextFormat::Family ) |
5648 | cres->fn.setFamily( nf->fn.family() ); | 5654 | cres->fn.setFamily( nf->fn.family() ); |
5649 | if ( flags & QTextFormat::Size ) { | 5655 | if ( flags & QTextFormat::Size ) { |
5650 | if ( of->usePixelSizes ) | 5656 | if ( of->usePixelSizes ) |
5651 | cres->fn.setPixelSize( nf->fn.pixelSize() ); | 5657 | cres->fn.setPixelSize( nf->fn.pixelSize() ); |
5652 | else | 5658 | else |
5653 | cres->fn.setPointSize( nf->fn.pointSize() ); | 5659 | cres->fn.setPointSize( nf->fn.pointSize() ); |
5654 | } | 5660 | } |
5655 | if ( flags & QTextFormat::Color ) | 5661 | if ( flags & QTextFormat::Color ) |
5656 | cres->col = nf->col; | 5662 | cres->col = nf->col; |
5657 | if ( flags & QTextFormat::Misspelled ) | 5663 | if ( flags & QTextFormat::Misspelled ) |
5658 | cres->missp = nf->missp; | 5664 | cres->missp = nf->missp; |
5659 | if ( flags & QTextFormat::VAlign ) | 5665 | if ( flags & QTextFormat::VAlign ) |
5660 | cres->ha = nf->ha; | 5666 | cres->ha = nf->ha; |
5661 | cres->update(); | 5667 | cres->update(); |
5662 | 5668 | ||
5663 | QTextFormat *fm = cKey.find( cres->key() ); | 5669 | QTextFormat *fm = cKey.find( cres->key() ); |
5664 | if ( !fm ) { | 5670 | if ( !fm ) { |
5665 | cres->collection = this; | 5671 | cres->collection = this; |
5666 | cKey.insert( cres->key(), cres ); | 5672 | cKey.insert( cres->key(), cres ); |
5667 | } else { | 5673 | } else { |
5668 | delete cres; | 5674 | delete cres; |
5669 | cres = fm; | 5675 | cres = fm; |
5670 | cres->addRef(); | 5676 | cres->addRef(); |
5671 | } | 5677 | } |
5672 | 5678 | ||
5673 | return cres; | 5679 | return cres; |
5674 | } | 5680 | } |
5675 | 5681 | ||
5676 | QTextFormat *QTextFormatCollection::format( const QFont &f, const QColor &c ) | 5682 | QTextFormat *QTextFormatCollection::format( const QFont &f, const QColor &c ) |
5677 | { | 5683 | { |
5678 | if ( cachedFormat && cfont == f && ccol == c ) { | 5684 | if ( cachedFormat && cfont == f && ccol == c ) { |
5679 | cachedFormat->addRef(); | 5685 | cachedFormat->addRef(); |
5680 | return cachedFormat; | 5686 | return cachedFormat; |
5681 | } | 5687 | } |
5682 | 5688 | ||
5683 | QString key = QTextFormat::getKey( f, c, FALSE, QTextFormat::AlignNormal ); | 5689 | QString key = QTextFormat::getKey( f, c, FALSE, QTextFormat::AlignNormal ); |
5684 | cachedFormat = cKey.find( key ); | 5690 | cachedFormat = cKey.find( key ); |
5685 | cfont = f; | 5691 | cfont = f; |
5686 | ccol = c; | 5692 | ccol = c; |
5687 | 5693 | ||
5688 | if ( cachedFormat ) { | 5694 | if ( cachedFormat ) { |
5689 | cachedFormat->addRef(); | 5695 | cachedFormat->addRef(); |
5690 | return cachedFormat; | 5696 | return cachedFormat; |
5691 | } | 5697 | } |
5692 | 5698 | ||
5693 | if ( key == defFormat->key() ) | 5699 | if ( key == defFormat->key() ) |
5694 | return defFormat; | 5700 | return defFormat; |
5695 | 5701 | ||
5696 | cachedFormat = createFormat( f, c ); | 5702 | cachedFormat = createFormat( f, c ); |
5697 | cachedFormat->collection = this; | 5703 | cachedFormat->collection = this; |
5698 | cKey.insert( cachedFormat->key(), cachedFormat ); | 5704 | cKey.insert( cachedFormat->key(), cachedFormat ); |
5699 | if ( cachedFormat->key() != key ) | 5705 | if ( cachedFormat->key() != key ) |
5700 | qWarning("ASSERT: keys for format not identical: '%s '%s'", cachedFormat->key().latin1(), key.latin1() ); | 5706 | owarn << "ASSERT: keys for format not identical: '" << cachedFormat->key().latin1() << " '" << key.latin1() << "'" << oendl; |
5701 | return cachedFormat; | 5707 | return cachedFormat; |
5702 | } | 5708 | } |
5703 | 5709 | ||
5704 | void QTextFormatCollection::remove( QTextFormat *f ) | 5710 | void QTextFormatCollection::remove( QTextFormat *f ) |
5705 | { | 5711 | { |
5706 | if ( lastFormat == f ) | 5712 | if ( lastFormat == f ) |
5707 | lastFormat = 0; | 5713 | lastFormat = 0; |
5708 | if ( cres == f ) | 5714 | if ( cres == f ) |
5709 | cres = 0; | 5715 | cres = 0; |
5710 | if ( cachedFormat == f ) | 5716 | if ( cachedFormat == f ) |
5711 | cachedFormat = 0; | 5717 | cachedFormat = 0; |
5712 | cKey.remove( f->key() ); | 5718 | cKey.remove( f->key() ); |
5713 | } | 5719 | } |
5714 | 5720 | ||
5715 | #define UPDATE( up, lo, rest ) \ | 5721 | #define UPDATE( up, lo, rest ) \ |
5716 | if ( font.lo##rest() != defFormat->fn.lo##rest() && fm->fn.lo##rest() == defFormat->fn.lo##rest() ) \ | 5722 | if ( font.lo##rest() != defFormat->fn.lo##rest() && fm->fn.lo##rest() == defFormat->fn.lo##rest() ) \ |
5717 | fm->fn.set##up##rest( font.lo##rest() ) | 5723 | fm->fn.set##up##rest( font.lo##rest() ) |
5718 | 5724 | ||
5719 | void QTextFormatCollection::updateDefaultFormat( const QFont &font, const QColor &color, QStyleSheet *sheet ) | 5725 | void QTextFormatCollection::updateDefaultFormat( const QFont &font, const QColor &color, QStyleSheet *sheet ) |
5720 | { | 5726 | { |
5721 | QDictIterator<QTextFormat> it( cKey ); | 5727 | QDictIterator<QTextFormat> it( cKey ); |
5722 | QTextFormat *fm; | 5728 | QTextFormat *fm; |
5723 | bool usePixels = font.pointSize() == -1; | 5729 | bool usePixels = font.pointSize() == -1; |
5724 | bool changeSize = usePixels ? font.pixelSize() != defFormat->fn.pixelSize() : | 5730 | bool changeSize = usePixels ? font.pixelSize() != defFormat->fn.pixelSize() : |
5725 | font.pointSize() != defFormat->fn.pointSize(); | 5731 | font.pointSize() != defFormat->fn.pointSize(); |
5726 | int base = usePixels ? font.pixelSize() : font.pointSize(); | 5732 | int base = usePixels ? font.pixelSize() : font.pointSize(); |
5727 | while ( ( fm = it.current() ) ) { | 5733 | while ( ( fm = it.current() ) ) { |
5728 | ++it; | 5734 | ++it; |
5729 | UPDATE( F, f, amily ); | 5735 | UPDATE( F, f, amily ); |
5730 | UPDATE( W, w, eight ); | 5736 | UPDATE( W, w, eight ); |
5731 | UPDATE( B, b, old ); | 5737 | UPDATE( B, b, old ); |
5732 | UPDATE( I, i, talic ); | 5738 | UPDATE( I, i, talic ); |
5733 | UPDATE( U, u, nderline ); | 5739 | UPDATE( U, u, nderline ); |
5734 | if ( changeSize ) { | 5740 | if ( changeSize ) { |
5735 | fm->stdSize = base; | 5741 | fm->stdSize = base; |
5736 | fm->usePixelSizes = usePixels; | 5742 | fm->usePixelSizes = usePixels; |
5737 | if ( usePixels ) | 5743 | if ( usePixels ) |
5738 | fm->fn.setPixelSize( fm->stdSize ); | 5744 | fm->fn.setPixelSize( fm->stdSize ); |
5739 | else | 5745 | else |
5740 | fm->fn.setPointSize( fm->stdSize ); | 5746 | fm->fn.setPointSize( fm->stdSize ); |
5741 | sheet->scaleFont( fm->fn, fm->logicalFontSize ); | 5747 | sheet->scaleFont( fm->fn, fm->logicalFontSize ); |
5742 | } | 5748 | } |
5743 | if ( color.isValid() && color != defFormat->col && fm->col == defFormat->col ) | 5749 | if ( color.isValid() && color != defFormat->col && fm->col == defFormat->col ) |
5744 | fm->col = color; | 5750 | fm->col = color; |
5745 | fm->update(); | 5751 | fm->update(); |
5746 | } | 5752 | } |
5747 | 5753 | ||
5748 | defFormat->fn = font; | 5754 | defFormat->fn = font; |
5749 | defFormat->col = color; | 5755 | defFormat->col = color; |
5750 | defFormat->update(); | 5756 | defFormat->update(); |
5751 | defFormat->stdSize = base; | 5757 | defFormat->stdSize = base; |
5752 | defFormat->usePixelSizes = usePixels; | 5758 | defFormat->usePixelSizes = usePixels; |
5753 | 5759 | ||
5754 | updateKeys(); | 5760 | updateKeys(); |
5755 | } | 5761 | } |
5756 | 5762 | ||
5757 | // the keys in cKey have changed, rebuild the hashtable | 5763 | // the keys in cKey have changed, rebuild the hashtable |
5758 | void QTextFormatCollection::updateKeys() | 5764 | void QTextFormatCollection::updateKeys() |
5759 | { | 5765 | { |
5760 | if ( cKey.isEmpty() ) | 5766 | if ( cKey.isEmpty() ) |
5761 | return; | 5767 | return; |
5762 | cKey.setAutoDelete( FALSE ); | 5768 | cKey.setAutoDelete( FALSE ); |
5763 | QTextFormat** formats = new QTextFormat*[ cKey.count() + 1 ]; | 5769 | QTextFormat** formats = new QTextFormat*[ cKey.count() + 1 ]; |
5764 | QTextFormat **f = formats; | 5770 | QTextFormat **f = formats; |
5765 | QDictIterator<QTextFormat> it( cKey ); | 5771 | QDictIterator<QTextFormat> it( cKey ); |
5766 | while ( ( *f = it.current() ) ) { | 5772 | while ( ( *f = it.current() ) ) { |
5767 | ++it; | 5773 | ++it; |
5768 | ++f; | 5774 | ++f; |
5769 | } | 5775 | } |
5770 | cKey.clear(); | 5776 | cKey.clear(); |
5771 | for ( f = formats; *f; f++ ) | 5777 | for ( f = formats; *f; f++ ) |
5772 | cKey.insert( (*f)->key(), *f ); | 5778 | cKey.insert( (*f)->key(), *f ); |
5773 | cKey.setAutoDelete( TRUE ); | 5779 | cKey.setAutoDelete( TRUE ); |
5774 | delete [] formats; | 5780 | delete [] formats; |
5775 | } | 5781 | } |
5776 | 5782 | ||
5777 | 5783 | ||
5778 | 5784 | ||
5779 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 5785 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5780 | 5786 | ||
5781 | void QTextFormat::setBold( bool b ) | 5787 | void QTextFormat::setBold( bool b ) |
5782 | { | 5788 | { |
5783 | if ( b == fn.bold() ) | 5789 | if ( b == fn.bold() ) |
5784 | return; | 5790 | return; |
5785 | fn.setBold( b ); | 5791 | fn.setBold( b ); |
5786 | update(); | 5792 | update(); |
5787 | } | 5793 | } |
5788 | 5794 | ||
5789 | void QTextFormat::setMisspelled( bool b ) | 5795 | void QTextFormat::setMisspelled( bool b ) |
5790 | { | 5796 | { |
5791 | if ( b == (bool)missp ) | 5797 | if ( b == (bool)missp ) |
5792 | return; | 5798 | return; |
5793 | missp = b; | 5799 | missp = b; |
5794 | update(); | 5800 | update(); |
5795 | } | 5801 | } |
5796 | 5802 | ||
@@ -5990,197 +5996,197 @@ QTextFormat QTextFormat::makeTextFormat( const QStyleSheetItem *style, const QMa | |||
5990 | if ( attr.contains("size") ) { | 5996 | if ( attr.contains("size") ) { |
5991 | QString a = attr["size"]; | 5997 | QString a = attr["size"]; |
5992 | int n = a.toInt(); | 5998 | int n = a.toInt(); |
5993 | if ( a[0] == '+' || a[0] == '-' ) | 5999 | if ( a[0] == '+' || a[0] == '-' ) |
5994 | n += format.logicalFontSize; | 6000 | n += format.logicalFontSize; |
5995 | format.logicalFontSize = n; | 6001 | format.logicalFontSize = n; |
5996 | if ( format.usePixelSizes ) | 6002 | if ( format.usePixelSizes ) |
5997 | format.fn.setPixelSize( format.stdSize ); | 6003 | format.fn.setPixelSize( format.stdSize ); |
5998 | else | 6004 | else |
5999 | format.fn.setPointSize( format.stdSize ); | 6005 | format.fn.setPointSize( format.stdSize ); |
6000 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); | 6006 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); |
6001 | } | 6007 | } |
6002 | } | 6008 | } |
6003 | if ( attr.contains("style" ) ) { | 6009 | if ( attr.contains("style" ) ) { |
6004 | QString a = attr["style"]; | 6010 | QString a = attr["style"]; |
6005 | for ( int s = 0; s < a.contains(';')+1; s++ ) { | 6011 | for ( int s = 0; s < a.contains(';')+1; s++ ) { |
6006 | QString style = QTextDocument::section( a, ";", s, s ); | 6012 | QString style = QTextDocument::section( a, ";", s, s ); |
6007 | if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) { | 6013 | if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) { |
6008 | format.logicalFontSize = 0; | 6014 | format.logicalFontSize = 0; |
6009 | format.setPointSize( int( scaleFontsFactor * style.mid( 10, style.length() - 12 ).toInt() ) ); | 6015 | format.setPointSize( int( scaleFontsFactor * style.mid( 10, style.length() - 12 ).toInt() ) ); |
6010 | } if ( style.startsWith("font-style:" ) ) { | 6016 | } if ( style.startsWith("font-style:" ) ) { |
6011 | QString s = style.mid( 11 ).stripWhiteSpace(); | 6017 | QString s = style.mid( 11 ).stripWhiteSpace(); |
6012 | if ( s == "normal" ) | 6018 | if ( s == "normal" ) |
6013 | format.fn.setItalic( FALSE ); | 6019 | format.fn.setItalic( FALSE ); |
6014 | else if ( s == "italic" || s == "oblique" ) | 6020 | else if ( s == "italic" || s == "oblique" ) |
6015 | format.fn.setItalic( TRUE ); | 6021 | format.fn.setItalic( TRUE ); |
6016 | } else if ( style.startsWith("font-weight:" ) ) { | 6022 | } else if ( style.startsWith("font-weight:" ) ) { |
6017 | QString s = style.mid( 12 ); | 6023 | QString s = style.mid( 12 ); |
6018 | bool ok = TRUE; | 6024 | bool ok = TRUE; |
6019 | int n = s.toInt( &ok ); | 6025 | int n = s.toInt( &ok ); |
6020 | if ( ok ) | 6026 | if ( ok ) |
6021 | format.fn.setWeight( n/8 ); | 6027 | format.fn.setWeight( n/8 ); |
6022 | } else if ( style.startsWith("font-family:" ) ) { | 6028 | } else if ( style.startsWith("font-family:" ) ) { |
6023 | format.fn.setFamily( QTextDocument::section(style.mid(12),",",0,0).stripWhiteSpace() ); | 6029 | format.fn.setFamily( QTextDocument::section(style.mid(12),",",0,0).stripWhiteSpace() ); |
6024 | } else if ( style.startsWith("text-decoration:" ) ) { | 6030 | } else if ( style.startsWith("text-decoration:" ) ) { |
6025 | QString s = style.mid( 16 ).stripWhiteSpace(); | 6031 | QString s = style.mid( 16 ).stripWhiteSpace(); |
6026 | format.fn.setUnderline( s == "underline" ); | 6032 | format.fn.setUnderline( s == "underline" ); |
6027 | } else if ( style.startsWith("vertical-align:" ) ) { | 6033 | } else if ( style.startsWith("vertical-align:" ) ) { |
6028 | QString s = style.mid( 15 ).stripWhiteSpace(); | 6034 | QString s = style.mid( 15 ).stripWhiteSpace(); |
6029 | if ( s == "sub" ) | 6035 | if ( s == "sub" ) |
6030 | format.setVAlign( QTextFormat::AlignSubScript ); | 6036 | format.setVAlign( QTextFormat::AlignSubScript ); |
6031 | else if ( s == "super" ) | 6037 | else if ( s == "super" ) |
6032 | format.setVAlign( QTextFormat::AlignSuperScript ); | 6038 | format.setVAlign( QTextFormat::AlignSuperScript ); |
6033 | else | 6039 | else |
6034 | format.setVAlign( QTextFormat::AlignNormal ); | 6040 | format.setVAlign( QTextFormat::AlignNormal ); |
6035 | } else if ( style.startsWith("color:" ) ) { | 6041 | } else if ( style.startsWith("color:" ) ) { |
6036 | format.col.setNamedColor( style.mid(6) ); | 6042 | format.col.setNamedColor( style.mid(6) ); |
6037 | format.linkColor = FALSE; | 6043 | format.linkColor = FALSE; |
6038 | } | 6044 | } |
6039 | } | 6045 | } |
6040 | } | 6046 | } |
6041 | 6047 | ||
6042 | format.update(); | 6048 | format.update(); |
6043 | return format; | 6049 | return format; |
6044 | } | 6050 | } |
6045 | 6051 | ||
6046 | struct QPixmapInt | 6052 | struct QPixmapInt |
6047 | { | 6053 | { |
6048 | QPixmapInt() : ref( 0 ) {} | 6054 | QPixmapInt() : ref( 0 ) {} |
6049 | QPixmap pm; | 6055 | QPixmap pm; |
6050 | int ref; | 6056 | int ref; |
6051 | }; | 6057 | }; |
6052 | 6058 | ||
6053 | static QMap<QString, QPixmapInt> *pixmap_map = 0; | 6059 | static QMap<QString, QPixmapInt> *pixmap_map = 0; |
6054 | 6060 | ||
6055 | QTextImage::QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, | 6061 | QTextImage::QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, |
6056 | QMimeSourceFactory &factory ) | 6062 | QMimeSourceFactory &factory ) |
6057 | : QTextCustomItem( p ) | 6063 | : QTextCustomItem( p ) |
6058 | { | 6064 | { |
6059 | width = height = 0; | 6065 | width = height = 0; |
6060 | if ( attr.contains("width") ) | 6066 | if ( attr.contains("width") ) |
6061 | width = attr["width"].toInt(); | 6067 | width = attr["width"].toInt(); |
6062 | if ( attr.contains("height") ) | 6068 | if ( attr.contains("height") ) |
6063 | height = attr["height"].toInt(); | 6069 | height = attr["height"].toInt(); |
6064 | 6070 | ||
6065 | reg = 0; | 6071 | reg = 0; |
6066 | QString imageName = attr["src"]; | 6072 | QString imageName = attr["src"]; |
6067 | 6073 | ||
6068 | if (!imageName) | 6074 | if (!imageName) |
6069 | imageName = attr["source"]; | 6075 | imageName = attr["source"]; |
6070 | 6076 | ||
6071 | if ( !imageName.isEmpty() ) { | 6077 | if ( !imageName.isEmpty() ) { |
6072 | imgId = QString( "%1,%2,%3,%4" ).arg( imageName ).arg( width ).arg( height ).arg( (ulong)&factory ); | 6078 | imgId = QString( "%1,%2,%3,%4" ).arg( imageName ).arg( width ).arg( height ).arg( (ulong)&factory ); |
6073 | if ( !pixmap_map ) | 6079 | if ( !pixmap_map ) |
6074 | pixmap_map = new QMap<QString, QPixmapInt>; | 6080 | pixmap_map = new QMap<QString, QPixmapInt>; |
6075 | if ( pixmap_map->contains( imgId ) ) { | 6081 | if ( pixmap_map->contains( imgId ) ) { |
6076 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6082 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6077 | pm = pmi.pm; | 6083 | pm = pmi.pm; |
6078 | pmi.ref++; | 6084 | pmi.ref++; |
6079 | width = pm.width(); | 6085 | width = pm.width(); |
6080 | height = pm.height(); | 6086 | height = pm.height(); |
6081 | } else { | 6087 | } else { |
6082 | QImage img; | 6088 | QImage img; |
6083 | const QMimeSource* m = | 6089 | const QMimeSource* m = |
6084 | factory.data( imageName, context ); | 6090 | factory.data( imageName, context ); |
6085 | if ( !m ) { | 6091 | if ( !m ) { |
6086 | qWarning("QTextImage: no mimesource for %s", imageName.latin1() ); | 6092 | owarn << "QTextImage: no mimesource for " << imageName.latin1() << "" << oendl; |
6087 | } | 6093 | } |
6088 | else { | 6094 | else { |
6089 | if ( !QImageDrag::decode( m, img ) ) { | 6095 | if ( !QImageDrag::decode( m, img ) ) { |
6090 | qWarning("QTextImage: cannot decode %s", imageName.latin1() ); | 6096 | owarn << "QTextImage: cannot decode " << imageName.latin1() << "" << oendl; |
6091 | } | 6097 | } |
6092 | } | 6098 | } |
6093 | 6099 | ||
6094 | if ( !img.isNull() ) { | 6100 | if ( !img.isNull() ) { |
6095 | if ( width == 0 ) { | 6101 | if ( width == 0 ) { |
6096 | width = img.width(); | 6102 | width = img.width(); |
6097 | if ( height != 0 ) { | 6103 | if ( height != 0 ) { |
6098 | width = img.width() * height / img.height(); | 6104 | width = img.width() * height / img.height(); |
6099 | } | 6105 | } |
6100 | } | 6106 | } |
6101 | if ( height == 0 ) { | 6107 | if ( height == 0 ) { |
6102 | height = img.height(); | 6108 | height = img.height(); |
6103 | if ( width != img.width() ) { | 6109 | if ( width != img.width() ) { |
6104 | height = img.height() * width / img.width(); | 6110 | height = img.height() * width / img.width(); |
6105 | } | 6111 | } |
6106 | } | 6112 | } |
6107 | if ( img.width() != width || img.height() != height ){ | 6113 | if ( img.width() != width || img.height() != height ){ |
6108 | #ifndef QT_NO_IMAGE_SMOOTHSCALE | 6114 | #ifndef QT_NO_IMAGE_SMOOTHSCALE |
6109 | img = img.smoothScale(width, height); | 6115 | img = img.smoothScale(width, height); |
6110 | #endif | 6116 | #endif |
6111 | width = img.width(); | 6117 | width = img.width(); |
6112 | height = img.height(); | 6118 | height = img.height(); |
6113 | } | 6119 | } |
6114 | pm.convertFromImage( img ); | 6120 | pm.convertFromImage( img ); |
6115 | } | 6121 | } |
6116 | if ( !pm.isNull() ) { | 6122 | if ( !pm.isNull() ) { |
6117 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6123 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6118 | pmi.pm = pm; | 6124 | pmi.pm = pm; |
6119 | pmi.ref++; | 6125 | pmi.ref++; |
6120 | } | 6126 | } |
6121 | } | 6127 | } |
6122 | if ( pm.mask() ) { | 6128 | if ( pm.mask() ) { |
6123 | QRegion mask( *pm.mask() ); | 6129 | QRegion mask( *pm.mask() ); |
6124 | QRegion all( 0, 0, pm.width(), pm.height() ); | 6130 | QRegion all( 0, 0, pm.width(), pm.height() ); |
6125 | reg = new QRegion( all.subtract( mask ) ); | 6131 | reg = new QRegion( all.subtract( mask ) ); |
6126 | } | 6132 | } |
6127 | } | 6133 | } |
6128 | 6134 | ||
6129 | if ( pm.isNull() && (width*height)==0 ) | 6135 | if ( pm.isNull() && (width*height)==0 ) |
6130 | width = height = 50; | 6136 | width = height = 50; |
6131 | 6137 | ||
6132 | place = PlaceInline; | 6138 | place = PlaceInline; |
6133 | if ( attr["align"] == "left" ) | 6139 | if ( attr["align"] == "left" ) |
6134 | place = PlaceLeft; | 6140 | place = PlaceLeft; |
6135 | else if ( attr["align"] == "right" ) | 6141 | else if ( attr["align"] == "right" ) |
6136 | place = PlaceRight; | 6142 | place = PlaceRight; |
6137 | 6143 | ||
6138 | tmpwidth = width; | 6144 | tmpwidth = width; |
6139 | tmpheight = height; | 6145 | tmpheight = height; |
6140 | 6146 | ||
6141 | attributes = attr; | 6147 | attributes = attr; |
6142 | } | 6148 | } |
6143 | 6149 | ||
6144 | QTextImage::~QTextImage() | 6150 | QTextImage::~QTextImage() |
6145 | { | 6151 | { |
6146 | if ( pixmap_map && pixmap_map->contains( imgId ) ) { | 6152 | if ( pixmap_map && pixmap_map->contains( imgId ) ) { |
6147 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6153 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6148 | pmi.ref--; | 6154 | pmi.ref--; |
6149 | if ( !pmi.ref ) { | 6155 | if ( !pmi.ref ) { |
6150 | pixmap_map->remove( imgId ); | 6156 | pixmap_map->remove( imgId ); |
6151 | if ( pixmap_map->isEmpty() ) { | 6157 | if ( pixmap_map->isEmpty() ) { |
6152 | delete pixmap_map; | 6158 | delete pixmap_map; |
6153 | pixmap_map = 0; | 6159 | pixmap_map = 0; |
6154 | } | 6160 | } |
6155 | } | 6161 | } |
6156 | } | 6162 | } |
6157 | delete reg; | 6163 | delete reg; |
6158 | } | 6164 | } |
6159 | 6165 | ||
6160 | QString QTextImage::richText() const | 6166 | QString QTextImage::richText() const |
6161 | { | 6167 | { |
6162 | QString s; | 6168 | QString s; |
6163 | s += "<img "; | 6169 | s += "<img "; |
6164 | QMap<QString, QString>::ConstIterator it = attributes.begin(); | 6170 | QMap<QString, QString>::ConstIterator it = attributes.begin(); |
6165 | for ( ; it != attributes.end(); ++it ) | 6171 | for ( ; it != attributes.end(); ++it ) |
6166 | s += it.key() + "=" + *it + " "; | 6172 | s += it.key() + "=" + *it + " "; |
6167 | s += ">"; | 6173 | s += ">"; |
6168 | return s; | 6174 | return s; |
6169 | } | 6175 | } |
6170 | 6176 | ||
6171 | void QTextImage::adjustToPainter( QPainter* p ) | 6177 | void QTextImage::adjustToPainter( QPainter* p ) |
6172 | { | 6178 | { |
6173 | width = scale( tmpwidth, p ); | 6179 | width = scale( tmpwidth, p ); |
6174 | height = scale( tmpheight, p ); | 6180 | height = scale( tmpheight, p ); |
6175 | } | 6181 | } |
6176 | 6182 | ||
6177 | #if !defined(Q_WS_X11) | 6183 | #if !defined(Q_WS_X11) |
6178 | #include <qbitmap.h> | 6184 | #include <qbitmap.h> |
6179 | #include "qcleanuphandler.h" | 6185 | #include "qcleanuphandler.h" |
6180 | static QPixmap *qrt_selection = 0; | 6186 | static QPixmap *qrt_selection = 0; |
6181 | static QSingleCleanupHandler<QPixmap> qrt_cleanup_pixmap; | 6187 | static QSingleCleanupHandler<QPixmap> qrt_cleanup_pixmap; |
6182 | static void qrt_createSelectionPixmap( const QColorGroup &cg ) | 6188 | static void qrt_createSelectionPixmap( const QColorGroup &cg ) |
6183 | { | 6189 | { |
6184 | qrt_selection = new QPixmap( 2, 2 ); | 6190 | qrt_selection = new QPixmap( 2, 2 ); |
6185 | qrt_cleanup_pixmap.set( &qrt_selection ); | 6191 | qrt_cleanup_pixmap.set( &qrt_selection ); |
6186 | qrt_selection->fill( Qt::color0 ); | 6192 | qrt_selection->fill( Qt::color0 ); |
diff --git a/noncore/apps/opie-write/qrichtext_p.cpp b/noncore/apps/opie-write/qrichtext_p.cpp index 6783e0b..2e8b09c 100644 --- a/noncore/apps/opie-write/qrichtext_p.cpp +++ b/noncore/apps/opie-write/qrichtext_p.cpp | |||
@@ -1,236 +1,239 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of the internal Qt classes dealing with rich text | 4 | ** Implementation of the internal Qt classes dealing with rich text |
5 | ** | 5 | ** |
6 | ** Created : 990101 | 6 | ** Created : 990101 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the kernel module of the Qt GUI Toolkit. | 10 | ** This file is part of the kernel module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #include <opie2/odebug.h> | ||
39 | using namespace Opie::Core; | ||
40 | |||
38 | #include "qrichtext_p.h" | 41 | #include "qrichtext_p.h" |
39 | 42 | ||
40 | using namespace Qt3; | 43 | using namespace Qt3; |
41 | 44 | ||
42 | QTextCommand::~QTextCommand() {} | 45 | QTextCommand::~QTextCommand() {} |
43 | QTextCommand::Commands QTextCommand::type() const { return Invalid; } | 46 | QTextCommand::Commands QTextCommand::type() const { return Invalid; } |
44 | 47 | ||
45 | 48 | ||
46 | QTextCustomItem::~QTextCustomItem() {} | 49 | QTextCustomItem::~QTextCustomItem() {} |
47 | void QTextCustomItem::adjustToPainter( QPainter* p){ if ( p ) width = 0; } | 50 | void QTextCustomItem::adjustToPainter( QPainter* p){ if ( p ) width = 0; } |
48 | QTextCustomItem::Placement QTextCustomItem::placement() const { return PlaceInline; } | 51 | QTextCustomItem::Placement QTextCustomItem::placement() const { return PlaceInline; } |
49 | 52 | ||
50 | bool QTextCustomItem::ownLine() const { return FALSE; } | 53 | bool QTextCustomItem::ownLine() const { return FALSE; } |
51 | void QTextCustomItem::resize( int nwidth ){ width = nwidth; } | 54 | void QTextCustomItem::resize( int nwidth ){ width = nwidth; } |
52 | void QTextCustomItem::invalidate() {} | 55 | void QTextCustomItem::invalidate() {} |
53 | 56 | ||
54 | bool QTextCustomItem::isNested() const { return FALSE; } | 57 | bool QTextCustomItem::isNested() const { return FALSE; } |
55 | int QTextCustomItem::minimumWidth() const { return 0; } | 58 | int QTextCustomItem::minimumWidth() const { return 0; } |
56 | 59 | ||
57 | QString QTextCustomItem::richText() const { return QString::null; } | 60 | QString QTextCustomItem::richText() const { return QString::null; } |
58 | 61 | ||
59 | bool QTextCustomItem::enter( QTextCursor *, QTextDocument*&, QTextParagraph *&, int &, int &, int &, bool ) | 62 | bool QTextCustomItem::enter( QTextCursor *, QTextDocument*&, QTextParagraph *&, int &, int &, int &, bool ) |
60 | { | 63 | { |
61 | return TRUE; | 64 | return TRUE; |
62 | } | 65 | } |
63 | bool QTextCustomItem::enterAt( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int &, const QPoint & ) | 66 | bool QTextCustomItem::enterAt( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int &, const QPoint & ) |
64 | { | 67 | { |
65 | return TRUE; | 68 | return TRUE; |
66 | } | 69 | } |
67 | bool QTextCustomItem::next( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) | 70 | bool QTextCustomItem::next( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
68 | { | 71 | { |
69 | return TRUE; | 72 | return TRUE; |
70 | } | 73 | } |
71 | bool QTextCustomItem::prev( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) | 74 | bool QTextCustomItem::prev( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
72 | { | 75 | { |
73 | return TRUE; | 76 | return TRUE; |
74 | } | 77 | } |
75 | bool QTextCustomItem::down( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) | 78 | bool QTextCustomItem::down( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
76 | { | 79 | { |
77 | return TRUE; | 80 | return TRUE; |
78 | } | 81 | } |
79 | bool QTextCustomItem::up( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) | 82 | bool QTextCustomItem::up( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & ) |
80 | { | 83 | { |
81 | return TRUE; | 84 | return TRUE; |
82 | } | 85 | } |
83 | 86 | ||
84 | void QTextFlow::setPageSize( int ps ) { pagesize = ps; } | 87 | void QTextFlow::setPageSize( int ps ) { pagesize = ps; } |
85 | bool QTextFlow::isEmpty() { return leftItems.isEmpty() && rightItems.isEmpty(); } | 88 | bool QTextFlow::isEmpty() { return leftItems.isEmpty() && rightItems.isEmpty(); } |
86 | 89 | ||
87 | void QTextTableCell::invalidate() { cached_width = -1; cached_sizehint = -1; } | 90 | void QTextTableCell::invalidate() { cached_width = -1; cached_sizehint = -1; } |
88 | 91 | ||
89 | void QTextTable::invalidate() { cachewidth = -1; } | 92 | void QTextTable::invalidate() { cachewidth = -1; } |
90 | 93 | ||
91 | QTextParagraphData::~QTextParagraphData() {} | 94 | QTextParagraphData::~QTextParagraphData() {} |
92 | void QTextParagraphData::join( QTextParagraphData * ) {} | 95 | void QTextParagraphData::join( QTextParagraphData * ) {} |
93 | 96 | ||
94 | QTextFormatter::~QTextFormatter() {} | 97 | QTextFormatter::~QTextFormatter() {} |
95 | void QTextFormatter::setWrapEnabled( bool b ) { wrapEnabled = b; } | 98 | void QTextFormatter::setWrapEnabled( bool b ) { wrapEnabled = b; } |
96 | void QTextFormatter::setWrapAtColumn( int c ) { wrapColumn = c; } | 99 | void QTextFormatter::setWrapAtColumn( int c ) { wrapColumn = c; } |
97 | 100 | ||
98 | 101 | ||
99 | 102 | ||
100 | int QTextCursor::x() const | 103 | int QTextCursor::x() const |
101 | { | 104 | { |
102 | QTextStringChar *c = para->at( idx ); | 105 | QTextStringChar *c = para->at( idx ); |
103 | int curx = c->x; | 106 | int curx = c->x; |
104 | if ( !c->rightToLeft && | 107 | if ( !c->rightToLeft && |
105 | c->c.isSpace() && | 108 | c->c.isSpace() && |
106 | idx > 0 && | 109 | idx > 0 && |
107 | !c->lineStart && | 110 | !c->lineStart && |
108 | ( para->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify ) | 111 | ( para->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify ) |
109 | curx = para->at( idx - 1 )->x + para->string()->width( idx - 1 ); | 112 | curx = para->at( idx - 1 )->x + para->string()->width( idx - 1 ); |
110 | if ( c->rightToLeft ) | 113 | if ( c->rightToLeft ) |
111 | curx += para->string()->width( idx ); | 114 | curx += para->string()->width( idx ); |
112 | return curx; | 115 | return curx; |
113 | } | 116 | } |
114 | 117 | ||
115 | int QTextCursor::y() const | 118 | int QTextCursor::y() const |
116 | { | 119 | { |
117 | int dummy, line; | 120 | int dummy, line; |
118 | para->lineStartOfChar( idx, &dummy, &line ); | 121 | para->lineStartOfChar( idx, &dummy, &line ); |
119 | return para->lineY( line ); | 122 | return para->lineY( line ); |
120 | } | 123 | } |
121 | 124 | ||
122 | int QTextCursor::globalX() const { return totalOffsetX() + para->rect().x() + x(); } | 125 | int QTextCursor::globalX() const { return totalOffsetX() + para->rect().x() + x(); } |
123 | int QTextCursor::globalY() const { return totalOffsetY() + para->rect().y() + y(); } | 126 | int QTextCursor::globalY() const { return totalOffsetY() + para->rect().y() + y(); } |
124 | 127 | ||
125 | QTextDocument *QTextCursor::document() const | 128 | QTextDocument *QTextCursor::document() const |
126 | { | 129 | { |
127 | return para ? para->document() : 0; | 130 | return para ? para->document() : 0; |
128 | } | 131 | } |
129 | 132 | ||
130 | void QTextCursor::gotoPosition( QTextParagraph* p, int index ) | 133 | void QTextCursor::gotoPosition( QTextParagraph* p, int index ) |
131 | { | 134 | { |
132 | if ( para && p != para ) { | 135 | if ( para && p != para ) { |
133 | while ( para->document() != p->document() && !indices.isEmpty() ) | 136 | while ( para->document() != p->document() && !indices.isEmpty() ) |
134 | pop(); | 137 | pop(); |
135 | Q_ASSERT( indices.isEmpty() || para->document() == p->document() ); | 138 | Q_ASSERT( indices.isEmpty() || para->document() == p->document() ); |
136 | } | 139 | } |
137 | para = p; | 140 | para = p; |
138 | if ( index < 0 || index >= para->length() ) { | 141 | if ( index < 0 || index >= para->length() ) { |
139 | #if defined(QT_CHECK_RANGE) | 142 | #if defined(QT_CHECK_RANGE) |
140 | qWarning( "QTextCursor::gotoParagraph Index: %d out of range", index ); | 143 | owarn << "QTextCursor::gotoParagraph Index: " << index << " out of range" << oendl; |
141 | #endif | 144 | #endif |
142 | index = index < 0 ? 0 : para->length() - 1; | 145 | index = index < 0 ? 0 : para->length() - 1; |
143 | } | 146 | } |
144 | 147 | ||
145 | tmpIndex = -1; | 148 | tmpIndex = -1; |
146 | idx = index; | 149 | idx = index; |
147 | } | 150 | } |
148 | 151 | ||
149 | bool QTextDocument::hasSelection( int id, bool visible ) const | 152 | bool QTextDocument::hasSelection( int id, bool visible ) const |
150 | { | 153 | { |
151 | return ( selections.find( id ) != selections.end() && | 154 | return ( selections.find( id ) != selections.end() && |
152 | ( !visible || | 155 | ( !visible || |
153 | ( (QTextDocument*)this )->selectionStartCursor( id ) != | 156 | ( (QTextDocument*)this )->selectionStartCursor( id ) != |
154 | ( (QTextDocument*)this )->selectionEndCursor( id ) ) ); | 157 | ( (QTextDocument*)this )->selectionEndCursor( id ) ) ); |
155 | } | 158 | } |
156 | 159 | ||
157 | void QTextDocument::setSelectionStart( int id, const QTextCursor &cursor ) | 160 | void QTextDocument::setSelectionStart( int id, const QTextCursor &cursor ) |
158 | { | 161 | { |
159 | QTextDocumentSelection sel; | 162 | QTextDocumentSelection sel; |
160 | sel.startCursor = cursor; | 163 | sel.startCursor = cursor; |
161 | sel.endCursor = cursor; | 164 | sel.endCursor = cursor; |
162 | sel.swapped = FALSE; | 165 | sel.swapped = FALSE; |
163 | selections[ id ] = sel; | 166 | selections[ id ] = sel; |
164 | } | 167 | } |
165 | 168 | ||
166 | QTextParagraph *QTextDocument::paragAt( int i ) const | 169 | QTextParagraph *QTextDocument::paragAt( int i ) const |
167 | { | 170 | { |
168 | QTextParagraph* p = curParag; | 171 | QTextParagraph* p = curParag; |
169 | if ( !p || p->paragId() > i ) | 172 | if ( !p || p->paragId() > i ) |
170 | p = fParag; | 173 | p = fParag; |
171 | while ( p && p->paragId() != i ) | 174 | while ( p && p->paragId() != i ) |
172 | p = p->next(); | 175 | p = p->next(); |
173 | ((QTextDocument*)this)->curParag = p; | 176 | ((QTextDocument*)this)->curParag = p; |
174 | return p; | 177 | return p; |
175 | } | 178 | } |
176 | 179 | ||
177 | 180 | ||
178 | QTextFormat::~QTextFormat() | 181 | QTextFormat::~QTextFormat() |
179 | { | 182 | { |
180 | } | 183 | } |
181 | 184 | ||
182 | QTextFormat::QTextFormat() | 185 | QTextFormat::QTextFormat() |
183 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ) | 186 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ) |
184 | { | 187 | { |
185 | ref = 0; | 188 | ref = 0; |
186 | 189 | ||
187 | usePixelSizes = FALSE; | 190 | usePixelSizes = FALSE; |
188 | if ( stdSize == -1 ) { | 191 | if ( stdSize == -1 ) { |
189 | stdSize = qApp->font().pixelSize(); | 192 | stdSize = qApp->font().pixelSize(); |
190 | usePixelSizes = TRUE; | 193 | usePixelSizes = TRUE; |
191 | } | 194 | } |
192 | 195 | ||
193 | missp = FALSE; | 196 | missp = FALSE; |
194 | ha = AlignNormal; | 197 | ha = AlignNormal; |
195 | collection = 0; | 198 | collection = 0; |
196 | } | 199 | } |
197 | 200 | ||
198 | QTextFormat::QTextFormat( const QStyleSheetItem *style ) | 201 | QTextFormat::QTextFormat( const QStyleSheetItem *style ) |
199 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ) | 202 | : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ) |
200 | { | 203 | { |
201 | ref = 0; | 204 | ref = 0; |
202 | 205 | ||
203 | usePixelSizes = FALSE; | 206 | usePixelSizes = FALSE; |
204 | if ( stdSize == -1 ) { | 207 | if ( stdSize == -1 ) { |
205 | stdSize = qApp->font().pixelSize(); | 208 | stdSize = qApp->font().pixelSize(); |
206 | usePixelSizes = TRUE; | 209 | usePixelSizes = TRUE; |
207 | } | 210 | } |
208 | 211 | ||
209 | missp = FALSE; | 212 | missp = FALSE; |
210 | ha = AlignNormal; | 213 | ha = AlignNormal; |
211 | collection = 0; | 214 | collection = 0; |
212 | fn = QFont( style->fontFamily(), | 215 | fn = QFont( style->fontFamily(), |
213 | style->fontSize(), | 216 | style->fontSize(), |
214 | style->fontWeight(), | 217 | style->fontWeight(), |
215 | style->fontItalic() ); | 218 | style->fontItalic() ); |
216 | fn.setUnderline( style->fontUnderline() ); | 219 | fn.setUnderline( style->fontUnderline() ); |
217 | fn.setStrikeOut( style->fontStrikeOut() ); | 220 | fn.setStrikeOut( style->fontStrikeOut() ); |
218 | col = style->color(); | 221 | col = style->color(); |
219 | fm = QFontMetrics( fn ); | 222 | fm = QFontMetrics( fn ); |
220 | leftBearing = fm.minLeftBearing(); | 223 | leftBearing = fm.minLeftBearing(); |
221 | rightBearing = fm.minRightBearing(); | 224 | rightBearing = fm.minRightBearing(); |
222 | hei = fm.lineSpacing(); | 225 | hei = fm.lineSpacing(); |
223 | asc = fm.ascent() + (fm.leading()+1)/2; | 226 | asc = fm.ascent() + (fm.leading()+1)/2; |
224 | dsc = fm.descent(); | 227 | dsc = fm.descent(); |
225 | missp = FALSE; | 228 | missp = FALSE; |
226 | ha = AlignNormal; | 229 | ha = AlignNormal; |
227 | memset( widths, 0, 256 ); | 230 | memset( widths, 0, 256 ); |
228 | generateKey(); | 231 | generateKey(); |
229 | addRef(); | 232 | addRef(); |
230 | } | 233 | } |
231 | 234 | ||
232 | QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent ) | 235 | QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent ) |
233 | : fn( f ), col( c ), fm( QFontMetrics( f ) ), linkColor( TRUE ), | 236 | : fn( f ), col( c ), fm( QFontMetrics( f ) ), linkColor( TRUE ), |
234 | logicalFontSize( 3 ), stdSize( f.pointSize() ) | 237 | logicalFontSize( 3 ), stdSize( f.pointSize() ) |
235 | { | 238 | { |
236 | ref = 0; | 239 | ref = 0; |
@@ -384,220 +387,220 @@ QString QTextFormat::getKey( const QFont &fn, const QColor &col, bool misspelled | |||
384 | k += '/'; | 387 | k += '/'; |
385 | k += QString::number( (uint)col.rgb() ); | 388 | k += QString::number( (uint)col.rgb() ); |
386 | k += '/'; | 389 | k += '/'; |
387 | k += QString::number( (int)misspelled ); | 390 | k += QString::number( (int)misspelled ); |
388 | k += '/'; | 391 | k += '/'; |
389 | k += QString::number( (int)a ); | 392 | k += QString::number( (int)a ); |
390 | return k; | 393 | return k; |
391 | } | 394 | } |
392 | 395 | ||
393 | QString QTextString::toString( const QMemArray<QTextStringChar> &data ) | 396 | QString QTextString::toString( const QMemArray<QTextStringChar> &data ) |
394 | { | 397 | { |
395 | QString s; | 398 | QString s; |
396 | int l = data.size(); | 399 | int l = data.size(); |
397 | s.setUnicode( 0, l ); | 400 | s.setUnicode( 0, l ); |
398 | QTextStringChar *c = data.data(); | 401 | QTextStringChar *c = data.data(); |
399 | QChar *uc = (QChar *)s.unicode(); | 402 | QChar *uc = (QChar *)s.unicode(); |
400 | while ( l-- ) { | 403 | while ( l-- ) { |
401 | *uc = c->c; | 404 | *uc = c->c; |
402 | // ### workaround so that non-breaking whitespaces are drawn | 405 | // ### workaround so that non-breaking whitespaces are drawn |
403 | // properly, actually this should be fixed in QFont somewhere | 406 | // properly, actually this should be fixed in QFont somewhere |
404 | if ( *uc == (char)0xa0 ) | 407 | if ( *uc == (char)0xa0 ) |
405 | *uc = 0x20; | 408 | *uc = 0x20; |
406 | uc++; | 409 | uc++; |
407 | c++; | 410 | c++; |
408 | } | 411 | } |
409 | 412 | ||
410 | return s; | 413 | return s; |
411 | } | 414 | } |
412 | 415 | ||
413 | QString QTextString::toString() const | 416 | QString QTextString::toString() const |
414 | { | 417 | { |
415 | return toString( data ); | 418 | return toString( data ); |
416 | } | 419 | } |
417 | 420 | ||
418 | void QTextParagraph::setSelection( int id, int start, int end ) | 421 | void QTextParagraph::setSelection( int id, int start, int end ) |
419 | { | 422 | { |
420 | QMap<int, QTextParagraphSelection>::ConstIterator it = selections().find( id ); | 423 | QMap<int, QTextParagraphSelection>::ConstIterator it = selections().find( id ); |
421 | if ( it != mSelections->end() ) { | 424 | if ( it != mSelections->end() ) { |
422 | if ( start == ( *it ).start && end == ( *it ).end ) | 425 | if ( start == ( *it ).start && end == ( *it ).end ) |
423 | return; | 426 | return; |
424 | } | 427 | } |
425 | 428 | ||
426 | QTextParagraphSelection sel; | 429 | QTextParagraphSelection sel; |
427 | sel.start = start; | 430 | sel.start = start; |
428 | sel.end = end; | 431 | sel.end = end; |
429 | (*mSelections)[ id ] = sel; | 432 | (*mSelections)[ id ] = sel; |
430 | setChanged( TRUE, TRUE ); | 433 | setChanged( TRUE, TRUE ); |
431 | } | 434 | } |
432 | 435 | ||
433 | void QTextParagraph::removeSelection( int id ) | 436 | void QTextParagraph::removeSelection( int id ) |
434 | { | 437 | { |
435 | if ( !hasSelection( id ) ) | 438 | if ( !hasSelection( id ) ) |
436 | return; | 439 | return; |
437 | if ( mSelections ) | 440 | if ( mSelections ) |
438 | mSelections->remove( id ); | 441 | mSelections->remove( id ); |
439 | setChanged( TRUE, TRUE ); | 442 | setChanged( TRUE, TRUE ); |
440 | } | 443 | } |
441 | 444 | ||
442 | int QTextParagraph::selectionStart( int id ) const | 445 | int QTextParagraph::selectionStart( int id ) const |
443 | { | 446 | { |
444 | if ( !mSelections ) | 447 | if ( !mSelections ) |
445 | return -1; | 448 | return -1; |
446 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); | 449 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); |
447 | if ( it == mSelections->end() ) | 450 | if ( it == mSelections->end() ) |
448 | return -1; | 451 | return -1; |
449 | return ( *it ).start; | 452 | return ( *it ).start; |
450 | } | 453 | } |
451 | 454 | ||
452 | int QTextParagraph::selectionEnd( int id ) const | 455 | int QTextParagraph::selectionEnd( int id ) const |
453 | { | 456 | { |
454 | if ( !mSelections ) | 457 | if ( !mSelections ) |
455 | return -1; | 458 | return -1; |
456 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); | 459 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); |
457 | if ( it == mSelections->end() ) | 460 | if ( it == mSelections->end() ) |
458 | return -1; | 461 | return -1; |
459 | return ( *it ).end; | 462 | return ( *it ).end; |
460 | } | 463 | } |
461 | 464 | ||
462 | bool QTextParagraph::hasSelection( int id ) const | 465 | bool QTextParagraph::hasSelection( int id ) const |
463 | { | 466 | { |
464 | return mSelections ? mSelections->contains( id ) : FALSE; | 467 | return mSelections ? mSelections->contains( id ) : FALSE; |
465 | } | 468 | } |
466 | 469 | ||
467 | bool QTextParagraph::fullSelected( int id ) const | 470 | bool QTextParagraph::fullSelected( int id ) const |
468 | { | 471 | { |
469 | if ( !mSelections ) | 472 | if ( !mSelections ) |
470 | return FALSE; | 473 | return FALSE; |
471 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); | 474 | QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id ); |
472 | if ( it == mSelections->end() ) | 475 | if ( it == mSelections->end() ) |
473 | return FALSE; | 476 | return FALSE; |
474 | return ( *it ).start == 0 && ( *it ).end == str->length() - 1; | 477 | return ( *it ).start == 0 && ( *it ).end == str->length() - 1; |
475 | } | 478 | } |
476 | 479 | ||
477 | int QTextParagraph::lineY( int l ) const | 480 | int QTextParagraph::lineY( int l ) const |
478 | { | 481 | { |
479 | if ( l > (int)lineStarts.count() - 1 ) { | 482 | if ( l > (int)lineStarts.count() - 1 ) { |
480 | qWarning( "QTextParagraph::lineY: line %d out of range!", l ); | 483 | owarn << "QTextParagraph::lineY: line " << l << " out of range!" << oendl; |
481 | return 0; | 484 | return 0; |
482 | } | 485 | } |
483 | 486 | ||
484 | if ( !isValid() ) | 487 | if ( !isValid() ) |
485 | ( (QTextParagraph*)this )->format(); | 488 | ( (QTextParagraph*)this )->format(); |
486 | 489 | ||
487 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); | 490 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
488 | while ( l-- > 0 ) | 491 | while ( l-- > 0 ) |
489 | ++it; | 492 | ++it; |
490 | return ( *it )->y; | 493 | return ( *it )->y; |
491 | } | 494 | } |
492 | 495 | ||
493 | int QTextParagraph::lineBaseLine( int l ) const | 496 | int QTextParagraph::lineBaseLine( int l ) const |
494 | { | 497 | { |
495 | if ( l > (int)lineStarts.count() - 1 ) { | 498 | if ( l > (int)lineStarts.count() - 1 ) { |
496 | qWarning( "QTextParagraph::lineBaseLine: line %d out of range!", l ); | 499 | owarn << "QTextParagraph::lineBaseLine: line " << l << " out of range!" << oendl; |
497 | return 10; | 500 | return 10; |
498 | } | 501 | } |
499 | 502 | ||
500 | if ( !isValid() ) | 503 | if ( !isValid() ) |
501 | ( (QTextParagraph*)this )->format(); | 504 | ( (QTextParagraph*)this )->format(); |
502 | 505 | ||
503 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); | 506 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
504 | while ( l-- > 0 ) | 507 | while ( l-- > 0 ) |
505 | ++it; | 508 | ++it; |
506 | return ( *it )->baseLine; | 509 | return ( *it )->baseLine; |
507 | } | 510 | } |
508 | 511 | ||
509 | int QTextParagraph::lineHeight( int l ) const | 512 | int QTextParagraph::lineHeight( int l ) const |
510 | { | 513 | { |
511 | if ( l > (int)lineStarts.count() - 1 ) { | 514 | if ( l > (int)lineStarts.count() - 1 ) { |
512 | qWarning( "QTextParagraph::lineHeight: line %d out of range!", l ); | 515 | owarn << "QTextParagraph::lineHeight: line " << l << " out of range!" << oendl; |
513 | return 15; | 516 | return 15; |
514 | } | 517 | } |
515 | 518 | ||
516 | if ( !isValid() ) | 519 | if ( !isValid() ) |
517 | ( (QTextParagraph*)this )->format(); | 520 | ( (QTextParagraph*)this )->format(); |
518 | 521 | ||
519 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); | 522 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
520 | while ( l-- > 0 ) | 523 | while ( l-- > 0 ) |
521 | ++it; | 524 | ++it; |
522 | return ( *it )->h; | 525 | return ( *it )->h; |
523 | } | 526 | } |
524 | 527 | ||
525 | void QTextParagraph::lineInfo( int l, int &y, int &h, int &bl ) const | 528 | void QTextParagraph::lineInfo( int l, int &y, int &h, int &bl ) const |
526 | { | 529 | { |
527 | if ( l > (int)lineStarts.count() - 1 ) { | 530 | if ( l > (int)lineStarts.count() - 1 ) { |
528 | qWarning( "QTextParagraph::lineInfo: line %d out of range!", l ); | 531 | owarn << "QTextParagraph::lineInfo: line " << l << " out of range!" << oendl; |
529 | qDebug( "%d %d", (int)lineStarts.count() - 1, l ); | 532 | odebug << "" << (int)lineStarts.count() - 1 << " " << l << "" << oendl; |
530 | y = 0; | 533 | y = 0; |
531 | h = 15; | 534 | h = 15; |
532 | bl = 10; | 535 | bl = 10; |
533 | return; | 536 | return; |
534 | } | 537 | } |
535 | 538 | ||
536 | if ( !isValid() ) | 539 | if ( !isValid() ) |
537 | ( (QTextParagraph*)this )->format(); | 540 | ( (QTextParagraph*)this )->format(); |
538 | 541 | ||
539 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); | 542 | QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin(); |
540 | while ( l-- > 0 ) | 543 | while ( l-- > 0 ) |
541 | ++it; | 544 | ++it; |
542 | y = ( *it )->y; | 545 | y = ( *it )->y; |
543 | h = ( *it )->h; | 546 | h = ( *it )->h; |
544 | bl = ( *it )->baseLine; | 547 | bl = ( *it )->baseLine; |
545 | } | 548 | } |
546 | 549 | ||
547 | 550 | ||
548 | void QTextParagraph::setAlignment( int a ) | 551 | void QTextParagraph::setAlignment( int a ) |
549 | { | 552 | { |
550 | if ( a == (int)align ) | 553 | if ( a == (int)align ) |
551 | return; | 554 | return; |
552 | align = a; | 555 | align = a; |
553 | invalidate( 0 ); | 556 | invalidate( 0 ); |
554 | } | 557 | } |
555 | 558 | ||
556 | QTextFormatter *QTextParagraph::formatter() const | 559 | QTextFormatter *QTextParagraph::formatter() const |
557 | { | 560 | { |
558 | if ( hasdoc ) | 561 | if ( hasdoc ) |
559 | return document()->formatter(); | 562 | return document()->formatter(); |
560 | if ( pseudoDocument()->pFormatter ) | 563 | if ( pseudoDocument()->pFormatter ) |
561 | return pseudoDocument()->pFormatter; | 564 | return pseudoDocument()->pFormatter; |
562 | return ( ( (QTextParagraph*)this )->pseudoDocument()->pFormatter = new QTextFormatterBreakWords ); | 565 | return ( ( (QTextParagraph*)this )->pseudoDocument()->pFormatter = new QTextFormatterBreakWords ); |
563 | } | 566 | } |
564 | 567 | ||
565 | void QTextParagraph::setTabArray( int *a ) | 568 | void QTextParagraph::setTabArray( int *a ) |
566 | { | 569 | { |
567 | delete [] tArray; | 570 | delete [] tArray; |
568 | tArray = a; | 571 | tArray = a; |
569 | } | 572 | } |
570 | 573 | ||
571 | void QTextParagraph::setTabStops( int tw ) | 574 | void QTextParagraph::setTabStops( int tw ) |
572 | { | 575 | { |
573 | if ( hasdoc ) | 576 | if ( hasdoc ) |
574 | document()->setTabStops( tw ); | 577 | document()->setTabStops( tw ); |
575 | else | 578 | else |
576 | tabStopWidth = tw; | 579 | tabStopWidth = tw; |
577 | } | 580 | } |
578 | 581 | ||
579 | QMap<int, QTextParagraphSelection> &QTextParagraph::selections() const | 582 | QMap<int, QTextParagraphSelection> &QTextParagraph::selections() const |
580 | { | 583 | { |
581 | if ( !mSelections ) | 584 | if ( !mSelections ) |
582 | ((QTextParagraph *)this)->mSelections = new QMap<int, QTextParagraphSelection>; | 585 | ((QTextParagraph *)this)->mSelections = new QMap<int, QTextParagraphSelection>; |
583 | return *mSelections; | 586 | return *mSelections; |
584 | } | 587 | } |
585 | 588 | ||
586 | 589 | ||
587 | QPtrList<QTextCustomItem> &QTextParagraph::floatingItems() const | 590 | QPtrList<QTextCustomItem> &QTextParagraph::floatingItems() const |
588 | { | 591 | { |
589 | if ( !mFloatingItems ) | 592 | if ( !mFloatingItems ) |
590 | ((QTextParagraph *)this)->mFloatingItems = new QPtrList<QTextCustomItem>; | 593 | ((QTextParagraph *)this)->mFloatingItems = new QPtrList<QTextCustomItem>; |
591 | return *mFloatingItems; | 594 | return *mFloatingItems; |
592 | } | 595 | } |
593 | 596 | ||
594 | QTextStringChar::~QTextStringChar() | 597 | QTextStringChar::~QTextStringChar() |
595 | { | 598 | { |
596 | if ( format() ) | 599 | if ( format() ) |
597 | format()->removeRef(); | 600 | format()->removeRef(); |
598 | if ( type ) // not Regular | 601 | if ( type ) // not Regular |
599 | delete d.custom; | 602 | delete d.custom; |
600 | } | 603 | } |
601 | 604 | ||
602 | QTextParagraphPseudoDocument::QTextParagraphPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0){} | 605 | QTextParagraphPseudoDocument::QTextParagraphPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0){} |
603 | QTextParagraphPseudoDocument::~QTextParagraphPseudoDocument(){ delete pFormatter; delete commandHistory; } | 606 | QTextParagraphPseudoDocument::~QTextParagraphPseudoDocument(){ delete pFormatter; delete commandHistory; } |