[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/korganizer/printing
From:       Ron Goodheart <rong.dev () gmail ! com>
Date:       2009-03-07 5:11:04
Message-ID: 1236402664.297575.17007.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 936135 by rgoodheart:

BUG: 123501

Checks for paging on each line and splits lines to fit on the page width so that long \
lines and paragraphs in the description will print properly. Rich text is converted \
to plain text for printing.




 M  +27 -15    calprintpluginbase.cpp  
 M  +2 -1      calprintpluginbase.h  


--- trunk/KDE/kdepim/korganizer/printing/calprintpluginbase.cpp #936134:936135
@@ -1863,20 +1863,32 @@
 }
 
 void CalPrintPluginBase::drawJournalField( QPainter &p, const QString &entry,
-                                           int x, int &y, int width, int pageHeight \
) +                                           int x, int &y, int width,
+                                           int pageHeight, bool richTextEntry )
 {
-  QRect rect( p.boundingRect( x, y, width, -1, Qt::WordBreak, entry ) );
-  if ( rect.bottom() > pageHeight ) {
-    // Start new page...
-    // FIXME: If it's a multi-line text, draw a few lines on this page, and the
-    // remaining lines on the next page.
-    y = 0;
-    mPrinter->newPage();
-    rect = p.boundingRect( x, y, width, -1, Qt::WordBreak, entry );
+  QString plainEntry = ( richTextEntry ) ? toPlainText( entry ) : entry;
+
+  QRect textrect(0,0,width,-1);
+  int flags = Qt::AlignLeft;
+  QFontMetrics fm = p.fontMetrics();
+
+  QStringList lines = plainEntry.split( '\n' );
+  for ( int currentLine = 0; currentLine < lines.count(); currentLine++ ) {
+    // split paragraphs into lines
+    KWordWrap *ww = KWordWrap::formatText( fm, textrect, flags, lines[currentLine] \
); +    QStringList textLine = ww->wrappedString().split( '\n' );
+    delete ww;
+    // print each individual line
+    for ( int lineCount = 0; lineCount < textLine.count(); lineCount++ ) {
+      if ( y >= pageHeight ) {
+        y = 0;
+        mPrinter->newPage();
+      }
+      y += fm.height();
+      p.drawText( x, y, textLine[ lineCount ] );
+    }
   }
-  QRect newrect;
-  p.drawText( rect, Qt::WordBreak, entry, &newrect );
-  y = newrect.bottom() + 7;
+  y += 7;
 }
 
 void CalPrintPluginBase::drawJournal( Journal * journal, QPainter &p, int x, int &y,
@@ -1909,13 +1921,13 @@
 
   p.drawLine( x + 3, y, x + width - 6, y );
   y += 5;
-
   if ( !( journal->organizer().fullName().isEmpty() ) ) {
     drawJournalField( p, i18n( "Person: %1", journal->organizer().fullName() ),
-                      x, y, width, pageHeight );
+                      x, y, width, pageHeight, false );
   }
   if ( !( journal->description().isEmpty() ) ) {
-    drawJournalField( p, journal->description(), x, y, width, pageHeight );
+    drawJournalField( p, journal->description(), x, y, width, pageHeight,
+                      journal->descriptionIsRich() );
   }
   y += 10;
 }
--- trunk/KDE/kdepim/korganizer/printing/calprintpluginbase.h #936134:936135
@@ -564,7 +564,8 @@
     void drawJournal( Journal * journal, QPainter &p, int x, int &y,
                       int width, int pageHeight );
     void drawJournalField( QPainter &p, const QString &entry,
-                           int x, int &y, int width, int pageHeight );
+                           int x, int &y, int width, int pageHeight,
+                           bool richTextEntry );
 
     void drawSplitHeaderRight( QPainter &p, const QDate &fd, const QDate &td,
                                const QDate &cd, int width, int height );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic