mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-27 11:40:07 +00:00
Improve a bit the image generator, even if it's just a toy:
- use QImage instead of QPixmap, and save some QPixmap <-> QImage conversions - make it able to read from raw data (read from stdin) as a simple example of the functionality svn path=/trunk/playground/graphics/okular/; revision=622775
This commit is contained in:
parent
24ec1e37c5
commit
4f8724b62b
|
@ -8,7 +8,6 @@
|
|||
***************************************************************************/
|
||||
|
||||
#include <qpainter.h>
|
||||
#include <qimage.h>
|
||||
#include <kprinter.h>
|
||||
|
||||
#include <okular/core/page.h>
|
||||
|
@ -27,11 +26,25 @@ KIMGIOGenerator::~KIMGIOGenerator()
|
|||
|
||||
bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector )
|
||||
{
|
||||
m_pix = new QPixmap(fileName);
|
||||
if ( !m_img.load( fileName ) )
|
||||
return false;
|
||||
|
||||
pagesVector.resize( 1 );
|
||||
|
||||
Okular::Page * page = new Okular::Page( 0, m_pix->width(), m_pix->height(), Okular::Rotation0 );
|
||||
Okular::Page * page = new Okular::Page( 0, m_img.width(), m_img.height(), Okular::Rotation0 );
|
||||
pagesVector[0] = page;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KIMGIOGenerator::loadDocumentFromData( const QByteArray & fileData, QVector<Okular::Page*> & pagesVector )
|
||||
{
|
||||
if ( !m_img.loadFromData( fileData ) )
|
||||
return false;
|
||||
|
||||
pagesVector.resize( 1 );
|
||||
|
||||
Okular::Page * page = new Okular::Page( 0, m_img.width(), m_img.height(), Okular::Rotation0 );
|
||||
pagesVector[0] = page;
|
||||
|
||||
return true;
|
||||
|
@ -39,8 +52,7 @@ bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<Okular::Pa
|
|||
|
||||
bool KIMGIOGenerator::closeDocument()
|
||||
{
|
||||
delete m_pix;
|
||||
m_pix = 0;
|
||||
m_img = QImage();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -57,7 +69,7 @@ void KIMGIOGenerator::generatePixmap( Okular::PixmapRequest * request )
|
|||
int height = request->height();
|
||||
if ( request->page()->rotation() % 2 == 1 )
|
||||
qSwap( width, height );
|
||||
QImage image = m_pix->toImage().scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||
QImage image = m_img.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||
request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( image ) ) );
|
||||
|
||||
// signal that the request has been accomplished
|
||||
|
@ -67,9 +79,14 @@ void KIMGIOGenerator::generatePixmap( Okular::PixmapRequest * request )
|
|||
bool KIMGIOGenerator::print( KPrinter& printer )
|
||||
{
|
||||
QPainter p( &printer );
|
||||
p.drawPixmap( 0, 0, *m_pix );
|
||||
p.drawImage( 0, 0, m_img );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KIMGIOGenerator::hasFeature( GeneratorFeature feature ) const
|
||||
{
|
||||
return feature == Okular::Generator::ReadRawData;
|
||||
}
|
||||
|
||||
#include "generator_kimgio.moc"
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include <okular/core/generator.h>
|
||||
|
||||
#include <qimage.h>
|
||||
|
||||
class KIMGIOGenerator : public Okular::Generator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -21,6 +23,7 @@ class KIMGIOGenerator : public Okular::Generator
|
|||
|
||||
// [INHERITED] load a document and fill up the pagesVector
|
||||
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
|
||||
bool loadDocumentFromData( const QByteArray & fileData, QVector<Okular::Page*> & pagesVector );
|
||||
bool closeDocument();
|
||||
|
||||
// [INHERITED] perform actions on document / pages
|
||||
|
@ -30,8 +33,10 @@ class KIMGIOGenerator : public Okular::Generator
|
|||
// [INHERITED] print document using already configured kprinter
|
||||
bool print( KPrinter& printer );
|
||||
|
||||
bool hasFeature( GeneratorFeature feature ) const;
|
||||
|
||||
private:
|
||||
QPixmap *m_pix;
|
||||
QImage m_img;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue