Commit 36b894c7 authored by Pino Toscano's avatar Pino Toscano

Create a (private) PageController that handles the rotation jobs from all the pages.

This removes the needs for Page to be a QObject (it's the PageController that connects to the jobs and emits the right signals), so it again a "cheap" object.

svn path=/trunk/playground/graphics/okular/; revision=646010
parent 5d5eb0f2
......@@ -32,6 +32,7 @@ set(okularcore_SRCS
core/misc.cpp
core/observer.cpp
core/page.cpp
core/pagecontroller.cpp
core/pagesize.cpp
core/pagetransition.cpp
core/rotationjob.cpp
......
......@@ -46,6 +46,7 @@
#include "link.h"
#include "observer.h"
#include "page.h"
#include "pagecontroller_p.h"
#include "settings.h"
#include "sourcereference.h"
......@@ -689,6 +690,9 @@ Document::Document()
: d( new Private( this ) )
{
d->m_bookmarkManager = new BookmarkManager( this );
connect( PageController::self(), SIGNAL( rotationFinished( int ) ),
this, SLOT( rotationFinished( int ) ) );
}
Document::~Document()
......@@ -847,10 +851,6 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi
}
}
for ( int i = 0; i < d->m_pagesVector.count(); ++i )
connect( d->m_pagesVector.at(i), SIGNAL( rotationFinished( int ) ),
this, SLOT( rotationFinished( int ) ) );
QApplication::restoreOverrideCursor();
if ( !openOk || d->m_pagesVector.size() <= 0 )
{
......
......@@ -23,6 +23,7 @@
#include "link.h"
#include "page.h"
#include "page_p.h"
#include "pagecontroller_p.h"
#include "pagesize.h"
#include "pagetransition.h"
#include "rotationjob.h"
......@@ -68,10 +69,8 @@ PagePrivate::~PagePrivate()
}
void PagePrivate::imageRotationDone()
void PagePrivate::imageRotationDone( RotationJob * job )
{
RotationJob *job = static_cast<RotationJob*>( m_page->sender() );
QMap< int, Page::PixmapObject >::iterator it = m_page->m_pixmaps.find( job->id() );
if ( it != m_page->m_pixmaps.end() )
{
......@@ -85,10 +84,6 @@ void PagePrivate::imageRotationDone()
m_page->m_pixmaps.insert( job->id(), object );
}
emit m_page->rotationFinished( m_number );
job->deleteLater();
}
QMatrix PagePrivate::rotationMatrix() const
......@@ -116,7 +111,7 @@ QMatrix PagePrivate::rotationMatrix() const
/** class Page **/
Page::Page( uint page, double w, double h, Rotation o )
: QObject( 0 ), d( new PagePrivate( this, page, w, h, o ) ),
: d( new PagePrivate( this, page, w, h, o ) ),
m_textSelections( 0 )
{
}
......@@ -288,7 +283,8 @@ void Page::rotateAt( Rotation orientation )
const PixmapObject &object = it.value();
RotationJob *job = new RotationJob( object.m_pixmap->toImage(), object.m_rotation, d->m_rotation, it.key() );
connect( job, SIGNAL( finished() ), this, SLOT( imageRotationDone() ) );
job->setPage( d );
QObject::connect( job, SIGNAL( finished() ), PageController::self(), SLOT( imageRotationDone() ) );
job->start();
}
......@@ -371,7 +367,8 @@ void Page::setPixmap( int id, QPixmap *pixmap )
it.value().m_rotation = d->m_rotation;
} else {
RotationJob *job = new RotationJob( pixmap->toImage(), Rotation0, d->m_rotation, id );
connect( job, SIGNAL( finished() ), this, SLOT( imageRotationDone() ) );
job->setPage( d );
QObject::connect( job, SIGNAL( finished() ), PageController::self(), SLOT( imageRotationDone() ) );
job->start();
delete pixmap;
......@@ -734,5 +731,3 @@ void Page::saveLocalContents( QDomNode & parentNode, QDomDocument & document ) c
if ( pageElement.hasChildNodes() )
parentNode.appendChild( pageElement );
}
#include "page.moc"
......@@ -46,10 +46,8 @@ class TextSelection;
*
* Note: The class takes ownership of all objects.
*/
class OKULAR_EXPORT Page : public QObject
class OKULAR_EXPORT Page
{
Q_OBJECT
public:
/**
* An action to be executed when particular events happen.
......@@ -346,9 +344,6 @@ class OKULAR_EXPORT Page : public QObject
*/
void saveLocalContents( QDomNode & parentNode, QDomDocument & document ) const;
Q_SIGNALS:
void rotationFinished( int page );
private:
PagePrivate* const d;
friend class PagePrivate;
......@@ -373,8 +368,6 @@ class OKULAR_EXPORT Page : public QObject
HighlightAreaRect *m_textSelections;
Q_DISABLE_COPY( Page )
Q_PRIVATE_SLOT( d, void imageRotationDone() )
};
}
......
......@@ -25,6 +25,7 @@ class FormField;
class Link;
class Page;
class PageTransition;
class RotationJob;
class TextPage;
class PagePrivate
......@@ -33,7 +34,7 @@ class PagePrivate
PagePrivate( Page *page, uint n, double w, double h, Rotation o );
~PagePrivate();
void imageRotationDone();
void imageRotationDone( RotationJob * job );
QMatrix rotationMatrix() const;
Page *m_page;
......
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
// qt/kde includes
#include <kglobal.h>
// local includes
#include "page_p.h"
#include "pagecontroller_p.h"
#include "rotationjob.h"
K_GLOBAL_STATIC( Okular::PageController, page_controller_self )
using namespace Okular;
PageController::PageController()
: QObject()
{
}
PageController::~PageController()
{
}
PageController * PageController::self()
{
return page_controller_self;
}
void PageController::imageRotationDone()
{
RotationJob *job = sender() ? qobject_cast< RotationJob * >( sender() ) : 0;
if ( !job )
return;
if ( job->page() )
{
job->page()->imageRotationDone( job );
emit rotationFinished( job->page()->m_number );
}
job->deleteLater();
}
#include "pagecontroller_p.moc"
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef _OKULAR_PAGECONTROLLER_P_H_
#define _OKULAR_PAGECONTROLLER_P_H_
#include <QtCore/QObject>
namespace Okular {
class Page;
class PagePrivate;
class PageController : public QObject
{
Q_OBJECT
public:
/**
* Constructor. No NOT use this, NEVER! Use the static self() instead.
*/
PageController();
~PageController();
static PageController * self();
signals:
void rotationFinished( int page );
private slots:
void imageRotationDone();
};
}
#endif
......@@ -14,10 +14,15 @@
using namespace Okular;
RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, int id )
: mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mId( id )
: mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mId( id ), m_pd( 0 )
{
}
void RotationJob::setPage( PagePrivate * pd )
{
m_pd = pd;
}
QImage RotationJob::image() const
{
return mRotatedImage;
......@@ -33,6 +38,11 @@ int RotationJob::id() const
return mId;
}
PagePrivate * RotationJob::page() const
{
return m_pd;
}
void RotationJob::run()
{
QMatrix matrix;
......@@ -74,3 +84,5 @@ void RotationJob::run()
mRotatedImage = mImage.transformed( matrix );
}
#include "rotationjob.moc"
......@@ -17,14 +17,21 @@
namespace Okular {
class PagePrivate;
class RotationJob : public QThread
{
Q_OBJECT
public:
RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, int id );
void setPage( PagePrivate * pd );
QImage image() const;
Rotation rotation() const;
int id() const;
PagePrivate * page() const;
protected:
virtual void run();
......@@ -35,6 +42,7 @@ class RotationJob : public QThread
Rotation mNewRotation;
int mId;
QImage mRotatedImage;
PagePrivate * m_pd;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment