2012-05-14 19:16:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 by Marco Martin <mart@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Library General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-05-14 18:37:22 +00:00
|
|
|
#ifndef QDOCUMENTITEM_H
|
|
|
|
#define QDOCUMENTITEM_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
2012-05-15 15:23:15 +00:00
|
|
|
#include <core/document.h>
|
|
|
|
#include <core/observer.h>
|
2012-05-14 18:37:22 +00:00
|
|
|
|
|
|
|
namespace Okular {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Observer;
|
2012-07-31 14:28:54 +00:00
|
|
|
class TOCModel;
|
2012-05-14 18:37:22 +00:00
|
|
|
|
|
|
|
class DocumentItem : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2012-10-02 11:25:34 +00:00
|
|
|
/**
|
|
|
|
* Absolute path of the document file to open
|
|
|
|
*/
|
2012-05-14 18:37:22 +00:00
|
|
|
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Current displaying page for the document
|
|
|
|
*/
|
2012-05-15 11:50:16 +00:00
|
|
|
Q_PROPERTY(int currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True if this DocumentItem instance has a document file opened
|
|
|
|
*/
|
2012-05-14 18:37:22 +00:00
|
|
|
Q_PROPERTY(bool opened READ isOpened NOTIFY openedChanged)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How many pages there are in the document
|
|
|
|
*/
|
2012-05-14 18:37:22 +00:00
|
|
|
Q_PROPERTY(int pageCount READ pageCount NOTIFY pageCountChanged)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the document is able to perform full text searches in its contents
|
|
|
|
*/
|
2012-05-15 11:56:08 +00:00
|
|
|
Q_PROPERTY(bool supportsSearching READ supportsSearching NOTIFY supportsSearchingChanged)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True if a search is currently in progress and results didn't arrive yet
|
|
|
|
*/
|
2012-05-15 10:12:56 +00:00
|
|
|
Q_PROPERTY(bool searchInProgress READ isSearchInProgress NOTIFY searchInProgressChanged)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of all pages that contain a match for the search terms. If no text has been searched, all pages are returned.
|
|
|
|
*/
|
2012-05-15 10:12:56 +00:00
|
|
|
Q_PROPERTY(QList<int> matchingPages READ matchingPages NOTIFY matchingPagesChanged)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table of contents for the document, if available
|
|
|
|
*/
|
2012-07-31 14:28:54 +00:00
|
|
|
Q_PROPERTY(TOCModel *tableOfContents READ tableOfContents CONSTANT)
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of pages that contain a bookmark
|
|
|
|
*/
|
2012-08-01 16:00:56 +00:00
|
|
|
Q_PROPERTY(QList<int> bookmarks READ bookmarks NOTIFY bookmarksChanged)
|
2012-05-14 18:37:22 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DocumentItem(QObject *parent=0);
|
|
|
|
~DocumentItem();
|
|
|
|
|
|
|
|
void setPath(const QString &path);
|
|
|
|
QString path() const;
|
|
|
|
|
2012-05-15 11:50:16 +00:00
|
|
|
void setCurrentPage(int page);
|
|
|
|
int currentPage() const;
|
|
|
|
|
2012-05-14 18:37:22 +00:00
|
|
|
bool isOpened() const;
|
|
|
|
|
|
|
|
int pageCount() const;
|
|
|
|
|
2012-05-15 11:56:08 +00:00
|
|
|
bool supportsSearching() const;
|
|
|
|
|
2012-05-15 10:12:56 +00:00
|
|
|
bool isSearchInProgress() const;
|
|
|
|
|
|
|
|
QList<int> matchingPages() const;
|
|
|
|
|
2012-07-31 14:28:54 +00:00
|
|
|
TOCModel *tableOfContents() const;
|
|
|
|
|
2012-08-01 16:00:56 +00:00
|
|
|
QList<int> bookmarks() const;
|
|
|
|
|
2012-10-02 11:25:34 +00:00
|
|
|
//This could be a property, but maybe we want to have parameter for searchText
|
|
|
|
/**
|
|
|
|
* Performs a search in the document
|
|
|
|
*
|
|
|
|
* @param text the string to search in the document
|
|
|
|
*/
|
2012-05-15 10:12:56 +00:00
|
|
|
Q_INVOKABLE void searchText(const QString &text);
|
2012-10-02 11:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the search over the document.
|
|
|
|
*/
|
2012-05-15 10:12:56 +00:00
|
|
|
Q_INVOKABLE void resetSearch();
|
|
|
|
|
2012-05-14 18:37:22 +00:00
|
|
|
//Internal, not binded to qml
|
|
|
|
Okular::Document *document();
|
|
|
|
Observer *observerFor(int id);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void pathChanged();
|
|
|
|
void pageCountChanged();
|
|
|
|
void openedChanged();
|
2012-05-15 10:12:56 +00:00
|
|
|
void searchInProgressChanged();
|
|
|
|
void matchingPagesChanged();
|
2012-05-15 11:50:16 +00:00
|
|
|
void currentPageChanged();
|
2012-05-15 11:56:08 +00:00
|
|
|
void supportsSearchingChanged();
|
2012-08-01 16:00:56 +00:00
|
|
|
void bookmarksChanged();
|
2012-05-15 10:12:56 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void searchFinished(int id, Okular::Document::SearchStatus endStatus);
|
2012-05-14 18:37:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Okular::Document *m_document;
|
2012-07-31 14:28:54 +00:00
|
|
|
TOCModel *m_tocModel;
|
2012-05-14 18:37:22 +00:00
|
|
|
QHash <int, Observer *> m_observers;
|
2012-05-15 10:12:56 +00:00
|
|
|
QList<int> m_matchingPages;
|
|
|
|
bool m_searchInProgress;
|
2012-05-14 18:37:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Observer : public QObject, public Okular::DocumentObserver
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
Observer(DocumentItem *parent, int observerId);
|
|
|
|
~Observer();
|
|
|
|
|
|
|
|
// inherited from DocumentObserver
|
|
|
|
uint observerId() const { return m_observerId; }
|
|
|
|
void notifyPageChanged(int page, int flags);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void pageChanged(int page, int flags);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_observerId;
|
|
|
|
DocumentItem *m_document;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|