[Okular-devel] Generic Generator for QTextDocument

Tobias Koenig tokoe at kde.org
Wed Jan 10 17:54:45 CET 2007


Hi,

since we have two generators now which use a QTextDocument for layouting
text and images I thought about extracting the common used code and put
it into a class Okular::GenericGenerator which will be placed in core/
so that other 3rd party developer can make use of it as well.

The API would look like the following:

///////////////////////////////////////////////////////

namespace Okular {

class GenericGenerator;

class GenericConverter : public QObject
{
    Q_OBJECT

    public:
        /**
         * Creates a new generic converter.
         */
        GenericConverter();

        /**
         * Destroys the generic converter.
         */
        ~GenericConverter();

        /**
         * Returns the generated QTextDocument object.
         */
        virtual QTextDocument *convert( const QString &fileName ) = 0;

    Q_SIGNALS:
        /**
         * Adds a new link object which is located between cursorBegin and
         * cursorEnd to the generator.
         */
        void addLink( Link *link, int cursorBegin, int cursorEnd );

        /**
         * Adds a new title at the given level which is located as position to the generator.
         */
        void addTitle( int level, const QString &title, const QTextBlock &position );

        /**
         * Adds a set of meta data to the generator.
         */
        void addMetaData( const QString &key, const QString &value, const QString &title );

    private:
        class Private;
        Private* const d;
};

class GenericGenerator : public Generator
{
    friend class GenericConverter;

    Q_OBJECT

    public:
        GenericGenerator( GenericConverter *converter );
        virtual ~GenericGenerator();

        .
        .
        .
        .

    private:
        class Private;
        Private* const d;

        Q_PRIVATE_SLOT( d, void addLink( Link*, int, int ) )
        Q_PRIVATE_SLOT( d, void addTitle( int, const QString&, const QTextBlock& ) )
        Q_PRIVATE_SLOT( d, void addMetaData( const QString&, const QString&, const QString& ) )
};

}

///////////////////////////////////////////////////////

So to implement a new QTextDocument based generator you just have to do
the following:


class MyGenerator : public Okular::GenericGenerator
{
  public:
    MyGenerator()
      : Okular::GenericGenerator( new MyConverter )
    {
    }
}

and implementing the 'convert' method in MyConverter.


To make it as easy as possible to add links, titles (toc) and meta data
(annotations as well) the GenericConverter class can emit signals which
take the use data as arguments together with the cursor positions in the
QTextDocument. All the boring stuff (calculation positions -> normalized
coordinates, creating the toc, filling DocumentSynopsis) is done by
the GenericGenerator.

One issue that crossed my plans you can see in addLink( Link*, int, int ).
I want to pass the Link object here, so the developer can choose what
type of link he wants to use in the Converter. However the passed object
is use for an object rect which is deleted at every pixmapRequest, so
passing the link here once doesn't work, because a new object is needed
for every pixmapRequest.

Does somebody have an idea how to solve this problem?

Ciao,
Tobias
-- 
Separate politics from religion and economy!
The Council of the European Union is an undemocratic and illegal institution!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.kde.org/pipermail/okular-devel/attachments/20070110/2ace92c1/attachment.pgp 


More information about the Okular-devel mailing list