[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-02 6:03:00
Message-ID: 1235973780.097382.31694.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 934007 by rgoodheart:
Added real rich text printing
Made small calendars in header slightly smaller
Removed extra config line for 'Use Colors'
M +3 -11 calprintdefaultplugins.cpp
M +114 -85 calprintpluginbase.cpp
M +4 -2 calprintpluginbase.h
--- trunk/KDE/kdepim/korganizer/printing/calprintdefaultplugins.cpp #934006:934007
@@ -94,7 +94,6 @@
{
if ( mConfig ) {
KConfigGroup grp( mConfig, description() );
- mUseColors = grp.readEntry( "Use Colors", false );
mShowOptions = grp.readEntry( "Show Options", false );
mShowSubitemsNotes = grp.readEntry( "Show Subitems and Notes", false );
mShowAttendees = grp.readEntry( "Use Attendees", false );
@@ -444,17 +443,10 @@
attachmentsBox.setBottom( attendeesBox.bottom() );
}
}
-
- QString description;
- if ( (*it)->descriptionIsRich() ) {
- description = toPlainText( (*it)->description() );
- } else {
- description = (*it)->description();
- }
int newBottom = drawBoxWithCaption( p, descriptionBox, i18n( "Description:" ),
- description, /*sameLine=*/false,
- /*expand=*/false, captionFont, textFont );
-
+ (*it)->description(), /*sameLine=*/false,
+ /*expand=*/false, captionFont, textFont,
+ (*it)->descriptionIsRich() );
if ( mShowNoteLines ) {
drawNoteLines( p, descriptionBox, newBottom );
}
--- trunk/KDE/kdepim/korganizer/printing/calprintpluginbase.cpp #934006:934007
@@ -42,6 +42,9 @@
#include <QLabel>
#include <QtAlgorithms>
#include <QTextDocumentFragment>
+#include <QTextDocument>
+#include <QTextCursor>
+#include <QAbstractTextDocumentLayout>
#include <qmath.h> // qCeil
#ifndef KORG_NOPRINTER
@@ -430,7 +433,8 @@
const QString &contents,
bool sameLine, bool expand,
const QFont &captionFont,
- const QFont &textFont )
+ const QFont &textFont,
+ bool richContents )
{
QFont oldFont( p.font() );
// QFont captionFont( "sans-serif", 11, QFont::Bold );
@@ -443,7 +447,9 @@
// Bounding rectangle for caption, single-line, clip on the right
QRect captionBox( box.left() + padding(), box.top() + padding(), 0, 0 );
p.setFont( captionFont );
- captionBox = p.boundingRect( captionBox, Qt::AlignLeft | Qt::AlignTop | Qt::SingleLine, caption );
+ captionBox = p.boundingRect( captionBox,
+ Qt::AlignLeft | Qt::AlignTop | Qt::SingleLine,
+ caption );
p.setFont( oldFont );
if ( captionBox.right() > box.right() ) {
captionBox.setRight( box.right() );
@@ -452,39 +458,50 @@
box.setBottom( captionBox.bottom() + padding() );
}
- QString contentText = contents;
-
// Bounding rectangle for the contents (if any), word break, clip on the bottom
QRect textBox( captionBox );
- if ( !contentText.isEmpty() ) {
+ if ( !contents.isEmpty() ) {
if ( sameLine ) {
textBox.setLeft( captionBox.right() + padding() );
} else {
textBox.setTop( captionBox.bottom() + padding() );
}
textBox.setRight( box.right() );
- textBox.setHeight( 0 );
- p.setFont( textFont );
- textBox = p.boundingRect( textBox,
- Qt::WordBreak | Qt::AlignTop | Qt::AlignLeft,
- contentText );
- p.setFont( oldFont );
- if ( textBox.bottom() + padding() > box.bottom() ) {
- if ( expand ) {
- box.setBottom( textBox.bottom() + padding() );
+ }
+ drawBox( p, BOX_BORDER_WIDTH, box );
+ p.setFont( captionFont );
+ p.drawText( captionBox, Qt::AlignLeft | Qt::AlignTop | Qt::SingleLine,
+ caption );
+
+ if ( !contents.isEmpty() ) {
+ if ( sameLine ) {
+ QString contentText = toPlainText( contents );
+ p.setFont( textFont );
+ p.drawText( textBox, Qt::AlignLeft | Qt::AlignTop | Qt::SingleLine,
+ contents );
+ } else {
+ QTextDocument rtb;
+ int borderWidth = 2 * BOX_BORDER_WIDTH;
+ if ( richContents ) {
+ rtb.setHtml( contents );
} else {
- textBox.setBottom( box.bottom() );
+ rtb.setPlainText( contents );
}
+ int boxHeight = allbox.height();
+ if ( !sameLine ) {
+ boxHeight -= captionBox.height();
+ }
+ rtb.setPageSize( QSize( textBox.width(), boxHeight ) );
+ rtb.setDefaultFont( textFont );
+ p.save();
+ p.translate( textBox.x() - borderWidth, textBox.y() );
+ QRect clipBox( 0, 0, box.width(), boxHeight );
+ rtb.drawContents( &p, clipBox );
+ p.restore();
+ textBox.setBottom( textBox.y() +
+ rtb.documentLayout()->documentSize().height() );
}
}
-
- drawBox( p, BOX_BORDER_WIDTH, box );
- p.setFont( captionFont );
- p.drawText( captionBox, Qt::AlignLeft | Qt::AlignTop | Qt::SingleLine, caption );
- if ( !contentText.isEmpty() ) {
- p.setFont( textFont );
- p.drawText( textBox, Qt::WordBreak | Qt::AlignTop | Qt::AlignLeft, contentText );
- }
p.setFont( oldFont );
if ( expand ) {
@@ -582,7 +599,7 @@
// 3 Pixel after month name, 2 after day names, 1 after the calendar
double cellHeight = ( box.height() - 5 ) / rownr;
QFont oldFont( p.font() );
- p.setFont( QFont( "sans-serif", int(cellHeight-1), QFont::Normal ) );
+ p.setFont( QFont( "sans-serif", int(cellHeight-2), QFont::Normal ) );
// draw the title
if ( mCalSys ) {
@@ -1008,10 +1025,6 @@
Event::List::ConstIterator it;
for ( it=eventList.constBegin(); it != eventList.constEnd() && textY < box.height(); ++it ) {
- if ( textY >= box.height() ) {
- break;
- }
-
Event *currEvent = *it;
if ( ( !printRecurDaily && currEvent->recurrenceType() == Recurrence::rDaily ) ||
( !printRecurWeekly && currEvent->recurrenceType() == Recurrence::rWeekly ) ) {
@@ -1028,15 +1041,10 @@
}
p.save();
setCategoryColors( p, currEvent );
- QString description;
- if ( currEvent->descriptionIsRich() ) {
- description = toPlainText( currEvent->description() );
- } else {
- description = currEvent->description();
- }
drawIncidence( p, box, timeText,
- currEvent->summary(), description,
- textY, singleLineLimit, includeDescription );
+ currEvent->summary(), currEvent->description(),
+ textY, singleLineLimit, includeDescription,
+ currEvent->descriptionIsRich() );
p.restore();
}
@@ -1044,9 +1052,6 @@
Todo::List todos = mCalendar->todos( qd );
Todo::List::ConstIterator it2;
for ( it2=todos.constBegin(); it2 != todos.constEnd() && textY < box.height(); ++it2 ) {
- if ( textY >= box.height() ) {
- break;
- }
Todo *todo = *it2;
if ( ( !printRecurDaily && todo->recurrenceType() == Recurrence::rDaily ) ||
( !printRecurWeekly && todo->recurrenceType() == Recurrence::rWeekly ) ) {
@@ -1063,15 +1068,10 @@
}
p.save();
setCategoryColors( p, todo );
- QString description;
- if ( todo->descriptionIsRich() ) {
- description = toPlainText( todo->description() );
- } else {
- description = todo->description();
- }
drawIncidence( p, box, timeText,
- i18n( "To-do: %1", todo->summary() ), description,
- textY, singleLineLimit, includeDescription );
+ i18n( "To-do: %1", todo->summary() ), todo->description(),
+ textY, singleLineLimit, includeDescription,
+ todo->descriptionIsRich() );
p.restore();
}
}
@@ -1087,7 +1087,8 @@
const QString &summary,
const QString &description,
int &textY, bool singleLineLimit,
- bool includeDescription )
+ bool includeDescription,
+ bool richDescription )
{
kDebug() << "summary =" << summary << ", singleLineLimit=" << singleLineLimit;
@@ -1095,8 +1096,8 @@
QFontMetrics fm = p.fontMetrics();
const int borderWidth = p.pen().width() + 1;
QRect timeBound = p.boundingRect( dayBox.x() + borderWidth,
- dayBox.y() + textY + 1,
- dayBox.width()/* - 10*/, fm.lineSpacing(),
+ dayBox.y() + textY,
+ dayBox.width(), fm.lineSpacing(),
flags, time );
int summaryWidth = time.isEmpty() ? 0 : timeBound.width() + 3;
@@ -1106,55 +1107,82 @@
dayBox.height() - textY );
QString summaryText = summary;
+ bool boxOverflow = false;
- int lineCount = 1;
- QString lineText;
if ( singleLineLimit ) {
+ QString lineText;
lineText = summaryText;
if ( includeDescription ) {
- lineText += ", " + description;
+ lineText += ", " + toPlainText( description );
}
+ int totalHeight = fm.lineSpacing() + borderWidth;
+ int textBoxHeight = ( totalHeight > ( dayBox.height() - textY ) ) ?
+ dayBox.height() - textY : totalHeight;
+ summaryBound.setHeight(textBoxHeight);
+ QRect lineRect( dayBox.x() + borderWidth, dayBox.y() + textY,
+ dayBox.width() - ( borderWidth * 2 ), textBoxHeight );
+ drawBox( p, -1, lineRect );
+ if ( !time.isEmpty() ) {
+ p.drawText( timeBound, flags, time );
+ }
+ p.drawText( summaryBound, flags, lineText );
} else {
- if ( includeDescription ) {
- summaryText += " \n" + description;
+ QTextDocument textDoc;
+ QTextCursor textCursor( &textDoc );
+ if ( richDescription ) {
+ QTextCursor textCursor( &textDoc );
+ textCursor.insertText( summaryText );
+ if ( includeDescription ) {
+ textCursor.insertText( "\n" );
+ textCursor.insertHtml( description );
+ }
+ } else {
+ textCursor.insertText( summaryText );
+ if ( includeDescription ) {
+ textCursor.insertText( "\n" );
+ textCursor.insertText( description );
+ }
}
- while ( summaryText.endsWith( '\n' ) ) {
- summaryText.resize( summaryText.length() - 1 );
+ textDoc.setPageSize( QSize( summaryBound.width(), summaryBound.height() ) );
+ p.save();
+ QRect clipBox( 0, 0, summaryBound.width(), summaryBound.height() );
+ p.setFont( p.font() );
+ p.translate( summaryBound.x(), summaryBound.y() - 6 );
+ textDoc.drawContents( &p, clipBox );
+ summaryBound.setHeight( textDoc.documentLayout()->documentSize().height()- 9 );
+ if ( summaryBound.bottom() > dayBox.bottom() ) {
+ summaryBound.setBottom( dayBox.bottom() );
}
- KWordWrap *ww = KWordWrap::formatText( fm, summaryBound, flags, summaryText );
- lineText = ww->wrappedString();
- delete ww;
- for ( int i=0; i<lineText.size(); ++i ) {
- if ( lineText[i] == '\n' ) {
- ++lineCount;
+ clipBox.setHeight( summaryBound.height() );
+ p.restore();
+
+ p.save();
+ QRect backBox( timeBound.x(), timeBound.y(),
+ dayBox.width() - ( borderWidth * 2 ), clipBox.height() );
+ drawBox( p, -1, backBox );
+
+ if ( !time.isEmpty() ) {
+ if ( timeBound.bottom() > dayBox.bottom() ) {
+ timeBound.setBottom( dayBox.bottom() );
}
+ p.drawText( timeBound, flags, time );
}
+ p.translate( summaryBound.x(), summaryBound.y() - 6 );
+ textDoc.drawContents( &p, clipBox );
+ p.restore();
+ boxOverflow = textDoc.pageCount() > 1;
}
-
- int totalHeight = ( fm.lineSpacing() * lineCount ) + borderWidth;
- int textBoxHeight = ( totalHeight > ( dayBox.height() - textY ) ) ?
- dayBox.height() - textY : totalHeight;
- summaryBound.setHeight(textBoxHeight);
- QRect lineRect( dayBox.x() + borderWidth, dayBox.y() + textY,
- dayBox.width() - ( borderWidth * 2 ), textBoxHeight );
- drawBox( p, -1, lineRect );
-
- if ( !time.isEmpty() ) {
- p.drawText( timeBound, flags, time );
+ if ( summaryBound.bottom() < dayBox.bottom() ) {
+ QPen oldPen( p.pen() );
+ p.setPen( QPen() );
+ p.drawLine( dayBox.x(), summaryBound.bottom(),
+ dayBox.x() + dayBox.width(), summaryBound.bottom() );
+ p.setPen( oldPen );
}
+ textY += summaryBound.height();
- p.drawText( summaryBound, flags, lineText );
-
- QPen oldPen( p.pen() );
- p.setPen( QPen() );
- p.drawLine( lineRect.x(), lineRect.y() + textBoxHeight,
- lineRect.x() + dayBox.width(), lineRect.y() + textBoxHeight );
- p.setPen( oldPen );
-
- textY += totalHeight;
-
// show that we have overflowed the box
- if ( textY > dayBox.height() ) {
+ if ( boxOverflow ) {
QPolygon poly(3);
int x = dayBox.x() + dayBox.width();
int y = dayBox.y() + dayBox.height();
@@ -1165,6 +1193,7 @@
p.setBrush( QBrush( Qt::black ) );
p.drawPolygon(poly);
p.setBrush( oldBrush );
+ textY = dayBox.height();
}
}
--- trunk/KDE/kdepim/korganizer/printing/calprintpluginbase.h #934006:934007
@@ -226,6 +226,7 @@
next line (no indentation of the contents)
@param expand Whether to expand the box vertically to fit the
whole text in it.
+ @param rickContents Whether contents contains rich text.
@return The bottom of the printed box. If expand==true, the bottom of
the drawn box is returned, if expand==false, the vertical
end of the printed contents inside the box is returned.
@@ -235,7 +236,8 @@
*/
int drawBoxWithCaption( QPainter &p, const QRect &box, const QString &caption,
const QString &contents, bool sameLine, bool expand,
- const QFont &captionFont, const QFont &textFont );
+ const QFont &captionFont, const QFont &textFont,
+ bool richContents = false );
/**
Draw the gray header bar of the printout to the QPainter.
@@ -585,7 +587,7 @@
void drawIncidence( QPainter &p, const QRect &dayBox, const QString &time,
const QString &summary, const QString &description,
int &textY, bool singleLineLimit,
- bool includeDescription );
+ bool includeDescription, bool richDescription );
QString toPlainText( const QString &htmlText );
protected:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic