okular/active/components/documentitem.h

178 lines
4.7 KiB
C
Raw Normal View History

/*
* Copyright 2012 by Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
2012-10-03 09:32:42 +00:00
* it under the terms of the GNU 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
2012-10-03 09:32:42 +00:00
* GNU General Public License for more details
*
2012-10-03 09:32:42 +00:00
* You should have received a copy of the GNU 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.
*/
#ifndef QDOCUMENTITEM_H
#define QDOCUMENTITEM_H
#include <QObject>
#include "settings.h"
#include <core/document.h>
#include <core/observer.h>
namespace Okular {
class Document;
}
class Observer;
class TOCModel;
class DocumentItem : public QObject
{
Q_OBJECT
2012-10-02 11:25:34 +00:00
/**
* Absolute path of the document file to open
*/
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
2012-10-02 11:25:34 +00:00
/**
* Suggested window title if a window represents this document. may be pathname or document title, dependeing from Okular settings.
*/
Q_PROPERTY(QString windowTitleForDocument READ windowTitleForDocument NOTIFY windowTitleForDocumentChanged)
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
*/
Q_PROPERTY(bool opened READ isOpened NOTIFY openedChanged)
2012-10-02 11:25:34 +00:00
/**
* How many pages there are in the document
*/
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
*/
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
*/
Q_PROPERTY(TOCModel *tableOfContents READ tableOfContents CONSTANT)
2012-10-02 11:25:34 +00:00
/**
* List of pages that contain a bookmark
*/
Q_PROPERTY(QList<int> bookmarkedPages READ bookmarkedPages NOTIFY bookmarkedPagesChanged)
public:
DocumentItem(QObject *parent=0);
~DocumentItem();
void setPath(const QString &path);
QString path() const;
QString windowTitleForDocument() const;
2012-05-15 11:50:16 +00:00
void setCurrentPage(int page);
int currentPage() const;
bool isOpened() const;
int pageCount() const;
bool supportsSearching() const;
2012-05-15 10:12:56 +00:00
bool isSearchInProgress() const;
QList<int> matchingPages() const;
TOCModel *tableOfContents() const;
QList<int> bookmarkedPages() const;
2012-08-01 16:00:56 +00:00
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();
//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();
void supportsSearchingChanged();
void bookmarkedPagesChanged();
void windowTitleForDocumentChanged();
2012-05-15 10:12:56 +00:00
private Q_SLOTS:
void searchFinished(int id, Okular::Document::SearchStatus endStatus);
private:
Okular::Document *m_document;
TOCModel *m_tocModel;
QHash <int, Observer *> m_observers;
2012-05-15 10:12:56 +00:00
QList<int> m_matchingPages;
bool m_searchInProgress;
};
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