[Okular-devel] playground/graphics/okular/generators/ooo
Tobias Koenig
tokoe at kde.org
Sun Nov 5 15:52:05 CET 2006
SVN commit 602249 by tokoe:
Applyed patch written by Leandro Emanuel Lopez which adds plain text and
pdf export to ooo generator.
CCMAIL:okular-devel at kde.org
M +42 -2 generator_ooo.cpp
M +4 -0 generator_ooo.h
--- trunk/playground/graphics/okular/generators/ooo/generator_ooo.cpp #602248:602249
@@ -7,14 +7,15 @@
* (at your option) any later version. *
***************************************************************************/
+#include <QtCore/QFile>
+#include <QtCore/QTextStream>
#include <QtGui/QAbstractTextDocumentLayout>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
#include <QtGui/QTextDocument>
-#include <QDebug>
-
#include <kprinter.h>
+#include <klocale.h>
#include "converter.h"
#include "core/link.h"
@@ -154,5 +155,44 @@
else
return &mDocumentSynopsis;
}
+
+Okular::ExportFormat::List KOOOGenerator::exportFormats( ) const
+{
+ static Okular::ExportFormat::List formats;
+ if ( formats.isEmpty() ) {
+ formats.append( Okular::ExportFormat( i18n( "PDF" ), KMimeType::mimeType( "application/pdf" ) ) );
+ formats.append( Okular::ExportFormat( i18n( "Plain Text" ), KMimeType::mimeType( "text/plain" ) ) );
+ }
+
+ return formats;
+}
+
+bool KOOOGenerator::exportTo( const QString &fileName, const Okular::ExportFormat &format )
+{
+ if ( format.mimeType()->name() == QLatin1String( "application/pdf" ) ) {
+ QFile file( fileName );
+ if ( !file.open( QIODevice::WriteOnly ) )
+ return false;
+
+ QPrinter printer( QPrinter::HighResolution );
+ printer.setOutputFormat( QPrinter::PdfFormat );
+ printer.setOutputFileName( fileName );
+ mDocument->print( &printer );
+
+ return true;
+ } else if ( format.mimeType()->name() == QLatin1String( "text/plain" ) ) {
+ QFile file( fileName );
+ if ( !file.open( QIODevice::WriteOnly ) )
+ return false;
+
+ QTextStream out( &file );
+ out << mDocument->toPlainText();
+
+ return true;
+ }
+
+ return false;
+}
+
#include "generator_ooo.moc"
--- trunk/playground/graphics/okular/generators/ooo/generator_ooo.h #602248:602249
@@ -37,6 +37,10 @@
// [INHERITED] print document using already configured kprinter
bool print( KPrinter& printer );
+ // [INHERITED] text exporting
+ Okular::ExportFormat::List exportFormats() const;
+ bool exportTo( const QString &fileName, const Okular::ExportFormat &format );
+
const Okular::DocumentInfo* generateDocumentInfo();
const Okular::DocumentSynopsis* generateDocumentSynopsis();
More information about the Okular-devel
mailing list