~ubuntu-branches/ubuntu/oneiric/kde4libs/oneiric-proposed

« back to all changes in this revision

Viewing changes to kdeui/widgets/krichtextedit.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 00:08:34 UTC
  • mto: This revision was merged to the branch mainline in revision 247.
  • Revision ID: package-import@ubuntu.com-20110708000834-dr9a8my4iml90qe5
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
524
524
{
525
525
  QString result = toHtml();
526
526
 
527
 
  static const QString EMPTYLINEFROMQT = QLatin1String(
528
 
  "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; "
529
 
  "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "
530
 
  "-qt-user-state:0;\"></p>" );
531
 
 
532
527
  static const QString EMPTYLINEHTML = QLatin1String(
533
528
  "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; "
534
 
  "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "
535
 
  "-qt-user-state:0;\"><br /></p>" );
 
529
  "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \">&nbsp;</p>" );
536
530
 
 
531
  // Qt inserts various style properties based on the current mode of the editor (underline, 
 
532
  // bold, etc), but only empty paragraphs *also* have qt-paragraph-type set to 'empty'.
 
533
  static const QString EMPTYLINEREGEX = QLatin1String(
 
534
    "<p style=\"-qt-paragraph-type:empty;(.*)</p>" );
 
535
  
537
536
  static const QString OLLISTPATTERNQT = QLatin1String(
538
537
  "<ol style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px;" );
539
538
 
549
548
  // fix 1 - empty lines should show as empty lines - MS Outlook treats margin-top:0px; as
550
549
  // a non-existing line.
551
550
  // Although we can simply remove the margin-top style property, we still get unwanted results
552
 
  // if you have three or more empty lines. It's best to replace empty <p> elements with <p><br /></p>.
553
 
  // As per http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict, <br> elements are still proper
554
 
  // HTML.
555
 
  result.replace(EMPTYLINEFROMQT, EMPTYLINEHTML);
 
551
  // if you have three or more empty lines. It's best to replace empty <p> elements with <p>&nbsp;</p>.
556
552
 
 
553
  QRegExp emptyLineFinder( EMPTYLINEREGEX );
 
554
  emptyLineFinder.setMinimal( true );
 
555
  
 
556
  // find the first occurance
 
557
  int offset = emptyLineFinder.indexIn( result, 0 );
 
558
  while (offset != -1) {
 
559
    // replace all the matching text with the new line text
 
560
    result.replace( offset, emptyLineFinder.matchedLength(), EMPTYLINEHTML );
 
561
    // advance the search offset to just beyond the last replace
 
562
    offset += EMPTYLINEHTML.length();
 
563
    // find the next occurance
 
564
    offset = emptyLineFinder.indexIn( result, offset );
 
565
  }
 
566
  
557
567
  // fix 2a - ordered lists - MS Outlook treats margin-left:0px; as
558
568
  // a non-existing number; e.g: "1. First item" turns into "First Item"
559
569
  result.replace(OLLISTPATTERNQT, ORDEREDLISTHTML);