Commit bf673495 authored by Saheb Preet Singh's avatar Saheb Preet Singh

added layers on the left sidebar

parent 146c6d85
......@@ -204,6 +204,7 @@ set(okularpart_SRCS
ui/toolaction.cpp
ui/tts.cpp
ui/videowidget.cpp
ui/layers.cpp
)
kde4_add_ui_files(okularpart_SRCS
......
......@@ -36,6 +36,7 @@
#include <QtGui/QPrintDialog>
#include <QStack>
#include <QUndoCommand>
#include <QAbstractItemModel>
#include <kaboutdata.h>
#include <kauthorized.h>
......@@ -3737,6 +3738,13 @@ void Document::editFormButtons( int pageNumber, const QList< FormFieldButton* >&
d->m_undoStack->push( uc );
}
void Document::reloadDocument() const
{
const int numOfPages = pages();
for( int i = 0; i < numOfPages; i ++ )
d->refreshPixmaps( i );
}
BookmarkManager * Document::bookmarkManager() const
{
return d->m_bookmarkManager;
......@@ -4563,6 +4571,11 @@ void Document::walletDataForFile( const QString &fileName, QString *walletName,
}
}
QAbstractItemModel * Document::layersModel() const
{
return d->m_generator ? d->m_generator->layersModel() : NULL;
}
void DocumentPrivate::requestDone( PixmapRequest * req )
{
if ( !req )
......
......@@ -31,6 +31,7 @@ class KConfigDialog;
class KXMLGUIClient;
class KUrl;
class DocumentItem;
class QAbstractItemModel;
namespace Okular {
......@@ -842,6 +843,11 @@ class OKULAR_EXPORT Document : public QObject
*/
void walletDataForFile( const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey ) const;
/**
* Returns the model for rendering layer or NULL if no layer is present
*/
QAbstractItemModel * layersModel() const;
public Q_SLOTS:
/**
* This slot is called whenever the user changes the @p rotation of
......@@ -918,6 +924,11 @@ class OKULAR_EXPORT Document : public QObject
const QList< Okular::FormFieldButton* > & formButtons,
const QList< bool > & newButtonStates );
/**
* This slot is called to reload the pixmaps for whole document
*/
void reloadDocument() const;
Q_SIGNALS:
/**
* This signal is emitted whenever an action requests a
......
......@@ -432,6 +432,12 @@ class OKULAR_EXPORT Generator : public QObject
*/
void setDPI(const QSizeF &dpi);
/**
* Returns the 'layers model' object of the document or NULL if
* layers model is not available.
*/
virtual QAbstractItemModel * layersModel() const;
Q_SIGNALS:
/**
* This signal should be emitted whenever an error occurred in the generator.
......
......@@ -776,6 +776,11 @@ const QList<Okular::EmbeddedFile*> *PDFGenerator::embeddedFiles() const
return &docEmbeddedFiles;
}
QAbstractItemModel* PDFGenerator::layersModel() const
{
return pdfdoc->hasOptionalContent() ? pdfdoc->optionalContentModel() : NULL;
}
bool PDFGenerator::isAllowed( Okular::Permission permission ) const
{
bool b = true;
......
......@@ -67,6 +67,7 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface, p
Okular::FontInfo::List fontsForPage( int page );
const QList<Okular::EmbeddedFile*> * embeddedFiles() const;
PageSizeMetric pagesSizeMetric() const { return Pixels; }
QAbstractItemModel * layersModel() const;
// [INHERITED] document information
bool isAllowed( Okular::Permission permission ) const;
......
......@@ -85,6 +85,7 @@
#include "ui/sidebar.h"
#include "ui/fileprinterpreview.h"
#include "ui/guiutils.h"
#include "ui/layers.h"
#include "conf/preferencesdialog.h"
#include "settings.h"
#include "core/action.h"
......@@ -379,6 +380,12 @@ m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentW
tbIndex = m_sidebar->addItem( m_toc, KIcon(QApplication::isLeftToRight() ? "format-justify-left" : "format-justify-right"), i18n("Contents") );
enableTOC( false );
// [left toolbox: Layers] | []
m_layers = new Layers( 0, m_document );
connect( m_layers, SIGNAL(hasLayers(bool)), this, SLOT(enableLayers(bool)) );
tbIndex = m_sidebar->addItem( m_layers, KIcon( "draw-freehand" ), i18n( "Layers" ) );
enableLayers( false );
// [left toolbox: Thumbnails and Bookmarks] | []
KVBox * thumbsBox = new ThumbnailsBox( 0 );
thumbsBox->setSpacing( 6 );
......@@ -854,6 +861,7 @@ Part::~Part()
Part::closeUrl( false );
delete m_toc;
delete m_layers;
delete m_pageView;
delete m_thumbnailList;
delete m_miniBar;
......@@ -1935,6 +1943,11 @@ void Part::slotRebuildBookmarkMenu()
rebuildBookmarkMenu();
}
void Part::enableLayers(bool enable)
{
m_sidebar->setItemEnabled( 1, enable );
}
void Part::slotShowFindBar()
{
m_findBar->show();
......
......@@ -64,6 +64,7 @@ class MiniBarLogic;
class FileKeeper;
class Reviews;
class BookmarkList;
class Layers;
namespace Okular
{
......@@ -219,6 +220,7 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
void updateBookmarksActions();
void enableTOC(bool enable);
void slotRebuildBookmarkMenu();
void enableLayers( bool enable );
public slots:
// connected to Shell action (and browserExtension), not local one
......@@ -278,6 +280,7 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
QPointer<PageSizeLabel> m_pageSizeLabel;
QPointer<Reviews> m_reviewsWidget;
QPointer<BookmarkList> m_bookmarkList;
QPointer<Layers> m_layers;
// document watcher (and reloader) variables
KDirWatch *m_watcher;
......
#include "layers.h"
#include "settings.h"
// qt/kde includes
#include <QVBoxLayout>
#include <QTreeView>
#include <qheaderview.h>
// local includes
#include "core/document.h"
#include "ktreeviewsearchline.h"
Layers::Layers(QWidget *parent, Okular::Document *document) : QWidget(parent), m_document(document)
{
QVBoxLayout * const mainlay = new QVBoxLayout( this );
mainlay->setMargin( 0 );
mainlay->setSpacing( 6 );
m_document->addObserver( this );
m_searchLine = new KTreeViewSearchLine( this );
mainlay->addWidget( m_searchLine );
m_searchLine->setCaseSensitivity( Okular::Settings::self()->contentsSearchCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive );
m_searchLine->setRegularExpression( Okular::Settings::self()->contentsSearchRegularExpression() );
connect( m_searchLine, SIGNAL(searchOptionsChanged()), this, SLOT(saveSearchOptions()) );
m_treeView = new QTreeView( this );
mainlay->addWidget( m_treeView );
QAbstractItemModel * layersModel = m_document->layersModel();
if( layersModel )
{
m_treeView->setModel( layersModel );
m_searchLine->addTreeView( m_treeView );
emit hasLayers( true );
connect( layersModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), m_document, SLOT(reloadDocument()) );
}
else
{
emit hasLayers( false );
}
m_treeView->setSortingEnabled( false );
m_treeView->setRootIsDecorated( true );
m_treeView->setAlternatingRowColors( true );
m_treeView->header()->hide();
}
Layers::~Layers()
{
m_document->removeObserver( this );
}
void Layers::notifySetup( const QVector< Okular::Page * > & /*pages*/, int /*setupFlags*/ )
{
QAbstractItemModel * layersModel = m_document->layersModel();
if( layersModel )
{
m_treeView->setModel( layersModel );
m_searchLine->addTreeView( m_treeView );
emit hasLayers( true );
connect( layersModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), m_document, SLOT(reloadDocument()) );
}
else
{
emit hasLayers( false );
}
}
void Layers::saveSearchOptions()
{
Okular::Settings::setContentsSearchRegularExpression( m_searchLine->regularExpression() );
Okular::Settings::setContentsSearchCaseSensitive( m_searchLine->caseSensitivity() == Qt::CaseSensitive ? true : false );
Okular::Settings::self()->writeConfig();
}
#include "layers.moc"
#ifndef _OKULAR_LAYERS_H_
#define _OKULAR_LAYERS_H_
#include <qwidget.h>
#include "core/observer.h"
#include "okular_part_export.h"
class QModelIndex;
class QTreeView;
class KTreeViewSearchLine;
namespace Okular {
class Document;
class PartTest;
}
class OKULAR_PART_EXPORT Layers : public QWidget, public Okular::DocumentObserver
{
Q_OBJECT
friend class Okular::PartTest;
public:
Layers(QWidget *parent, Okular::Document *document);
~Layers();
// inherited from DocumentObserver
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
signals:
void hasLayers(bool has);
private slots:
void saveSearchOptions();
private:
Okular::Document *m_document;
QTreeView *m_treeView;
KTreeViewSearchLine *m_searchLine;
};
#endif
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