diff --git a/CMakeLists.txt b/CMakeLists.txt index f75623eac..ca85d2a52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ set(okularcore_SRCS core/textdocumentgenerator.cpp core/textpage.cpp core/utils.cpp + core/view.cpp core/fileprinter.cpp ) diff --git a/core/document.cpp b/core/document.cpp index 14737d2d4..406a50629 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -65,6 +65,8 @@ #include "scripter.h" #include "settings.h" #include "sourcereference.h" +#include "view.h" +#include "view_p.h" #include @@ -1209,6 +1211,13 @@ Document::~Document() // delete generator, pages, and related stuff closeDocument(); + QSet< View * >::const_iterator viewIt = d->m_views.begin(), viewEnd = d->m_views.end(); + for ( ; viewIt != viewEnd; ++viewIt ) + { + View *v = *viewIt; + v->d_func()->document = 0; + } + // delete the bookmark manager delete d->m_bookmarkManager; @@ -2852,6 +2861,38 @@ bool Document::saveChanges( const QString &fileName ) return saveIface->save( fileName, SaveInterface::SaveChanges ); } +void Document::registerView( View *view ) +{ + if ( !view ) + return; + + Document *viewDoc = view->viewDocument(); + if ( viewDoc ) + { + // check if already registered for this document + if ( viewDoc == this ) + return; + + viewDoc->unregisterView( view ); + } + + d->m_views.insert( view ); + view->d_func()->document = d; +} + +void Document::unregisterView( View *view ) +{ + if ( !view ) + return; + + Document *viewDoc = view->viewDocument(); + if ( !viewDoc || viewDoc != this ) + return; + + view->d_func()->document = 0; + d->m_views.remove( view ); +} + void DocumentPrivate::requestDone( PixmapRequest * req ) { if ( !req ) diff --git a/core/document.h b/core/document.h index 2c35ec558..78f4fde34 100644 --- a/core/document.h +++ b/core/document.h @@ -48,6 +48,7 @@ class Action; class Page; class PixmapRequest; class SourceReference; +class View; class VisiblePageRect; /** IDs for seaches. Globally defined here. **/ @@ -534,6 +535,22 @@ class OKULAR_EXPORT Document : public QObject */ bool saveChanges( const QString &fileName ); + /** + * Register the specified @p view for the current document. + * + * It is unregistered from the previous document, if any. + * + * @since 0.7 (KDE 4.1) + */ + void registerView( View *view ); + + /** + * Unregister the specified @p view from the current document. + * + * @since 0.7 (KDE 4.1) + */ + void unregisterView( View *view ); + public Q_SLOTS: /** * This slot is called whenever the user changes the @p rotation of diff --git a/core/document_p.h b/core/document_p.h index 65eb1aeee..31203702d 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -37,6 +37,7 @@ namespace Okular { class ConfigInterface; class SaveInterface; class Scripter; +class View; } struct GeneratorInfo @@ -196,6 +197,8 @@ class DocumentPrivate QPointer< FontExtractionThread > m_fontThread; bool m_fontsCached; FontInfo::List m_fontsCache; + + QSet< View * > m_views; }; } diff --git a/core/view.cpp b/core/view.cpp new file mode 100644 index 000000000..2c7c4ba59 --- /dev/null +++ b/core/view.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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. * + ***************************************************************************/ + +#include "view.h" +#include "view_p.h" + +// local includes +#include "document_p.h" + +using namespace Okular; + +ViewPrivate::ViewPrivate() + : document( 0 ) +{ +} + +ViewPrivate::~ViewPrivate() +{ +} + + +View::View( const QString &name ) + : d_ptr( new ViewPrivate() ) +{ + d_ptr->name = name; +} + +View::~View() +{ + if ( d_ptr->document ) + { + d_ptr->document->m_views.remove( this ); + } + + delete d_ptr; +} + +Document* View::viewDocument() const +{ + return d_ptr->document ? d_ptr->document->m_parent : 0; +} + +QString View::name() const +{ + return d_ptr->name; +} + +bool View::supportsCapability( View::ViewCapability capability ) const +{ + Q_UNUSED( capability ) + return false; +} + +View::CapabilityFlags View::capabilityFlags( View::ViewCapability capability ) const +{ + Q_UNUSED( capability ) + return 0; +} + +QVariant View::capability( View::ViewCapability capability ) const +{ + Q_UNUSED( capability ) + return QVariant(); +} + +void View::setCapability( View::ViewCapability capability, const QVariant &option ) +{ + Q_UNUSED( capability ) + Q_UNUSED( option ) +} + diff --git a/core/view.h b/core/view.h new file mode 100644 index 000000000..017545248 --- /dev/null +++ b/core/view.h @@ -0,0 +1,111 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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_VIEW_H +#define OKULAR_VIEW_H + +#include "okular_export.h" + +class QString; +class QVariant; + +namespace Okular { + +class Document; +class DocumentPrivate; +class ViewPrivate; + +/** + * @short View on the document + * + * The View class represents a "view" on a document. + * A view can be registered with only a document at a time. + * + * @since 0.7 (KDE 4.1) + */ +class OKULAR_EXPORT View +{ + /// @cond PRIVATE + friend class Document; + friend class DocumentPrivate; + /// @endcond + + public: + /** + * The capabilities of a view + */ + enum ViewCapability + { + Zoom ///< Possibility to get/set the zoom of the view + }; + + /** + * The access type of a capability + */ + enum CapabilityFlag + { + NoFlag = 0, + CapabilityRead = 0x01, ///< Possibility to read a capability + CapabilityWrite = 0x02 ///< Possibility to write a capability + }; + Q_DECLARE_FLAGS( CapabilityFlags, CapabilityFlag ) + + virtual ~View(); + + /** + * Return the document which this view is associated to, + * or null if it is not associated with any document. + */ + Document* viewDocument() const; + + /** + * Return the name of this view. + */ + QString name() const; + + /** + * Query whether the view support the specified @p capability. + */ + virtual bool supportsCapability( ViewCapability capability ) const; + + /** + * Query the flags for the specified @p capability. + */ + virtual CapabilityFlags capabilityFlags( ViewCapability capability ) const; + + /** + * Query the value of the specified @p capability. + */ + virtual QVariant capability( ViewCapability capability ) const; + + /** + * Sets a new value for the specified @p capability. + */ + virtual void setCapability( ViewCapability capability, const QVariant &option ); + + protected: + /** + * Construct a new view with the specified @p name. + */ + View( const QString &name ); + + /// @cond PRIVATE + Q_DECLARE_PRIVATE( View ) + ViewPrivate *d_ptr; + /// @endcond + + private: + Q_DISABLE_COPY( View ) +}; + +} + +Q_DECLARE_OPERATORS_FOR_FLAGS( Okular::View::CapabilityFlags ) + +#endif diff --git a/core/view_p.h b/core/view_p.h new file mode 100644 index 000000000..17a8b6999 --- /dev/null +++ b/core/view_p.h @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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_VIEW_P_H +#define OKULAR_VIEW_P_H + +#include +#include + +namespace Okular { + +class DocumentPrivate; +class View; + +class ViewPrivate +{ + public: + ViewPrivate(); + virtual ~ViewPrivate(); + + QString name; + DocumentPrivate *document; +}; + +} + +#endif