1 #include "knoteprinter.h"
3 #include <libkcal/journal.h>
9 #include <tqpaintdevicemetrics.h>
10 #include <tqpainter.h>
12 #include <tqsimplerichtext.h>
15 KNotePrinter::KNotePrinter() : m_styleSheet( 0 ), m_mimeSourceFactory( 0 )
19 void KNotePrinter::setContext(
const TQString& context )
24 TQString KNotePrinter::context()
const
29 void KNotePrinter::setMimeSourceFactory( TQMimeSourceFactory* factory )
31 m_mimeSourceFactory = factory;
34 TQMimeSourceFactory* KNotePrinter::mimeSourceFactory()
const
36 return m_mimeSourceFactory;
39 void KNotePrinter::setFont(
const TQFont& font )
44 TQFont KNotePrinter::font()
const
49 void KNotePrinter::setColorGroup(
const TQColorGroup& colorGroup )
51 m_colorGroup = colorGroup;
54 TQColorGroup KNotePrinter::colorGroup()
const
59 void KNotePrinter::setStyleSheet( TQStyleSheet* styleSheet )
61 m_styleSheet = styleSheet;
64 TQStyleSheet* KNotePrinter::styleSheet()
const
69 void KNotePrinter::doPrint( KPrinter& printer, TQPainter& painter,
70 const TQString& content )
const
72 const int margin = 40;
74 TQPaintDeviceMetrics metrics( painter.device() );
75 int marginX = margin * metrics.logicalDpiX() / 72;
76 int marginY = margin * metrics.logicalDpiY() / 72;
78 TQRect body( marginX, marginY,
79 metrics.width() - marginX * 2,
80 metrics.height() - marginY * 2 );
82 kdDebug()<<
" content :"<<content<<endl;
83 kdDebug()<<
" m_styleSheet :"<<m_styleSheet<<endl;
85 TQSimpleRichText text( content, m_font, m_context,
86 m_styleSheet, m_mimeSourceFactory,
89 text.setWidth( &painter, body.width() );
96 text.draw( &painter, body.left(), body.top(), view, m_colorGroup );
97 view.moveBy( 0, body.height() );
98 painter.translate( 0, -body.height() );
101 painter.setFont( m_font );
103 view.right() - painter.fontMetrics().width( TQString::number( page ) ),
104 view.bottom() + painter.fontMetrics().ascent() + 5, TQString::number( page )
107 if ( view.top() >= text.height() )
115 void KNotePrinter::printNote(
const TQString& name,
const TQString& content )
const
118 printer.setFullPage(
true );
120 if ( !printer.setup( 0, i18n(
"Print %1").arg(name) ) )
123 painter.begin( &printer );
124 doPrint( printer, painter, content );
128 void KNotePrinter::printNotes(
const TQValueList<KCal::Journal*>& journals )
const
130 if ( journals.isEmpty() )
134 printer.setFullPage(
true );
136 if ( !printer.setup( 0, i18n(
"Print Note",
"Print %n notes", journals.count() ) ) )
140 painter.begin( &printer );
142 TQValueListConstIterator<KCal::Journal*> it( journals.constBegin() );
143 TQValueListConstIterator<KCal::Journal*> end( journals.constEnd() );
144 while ( it != end ) {
145 KCal::Journal *j = *it;
147 content +=
"<h2>" + j->summary() +
"</h2>";
148 content += j->description();
152 doPrint( printer, painter, content );