• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

okular

  • sources
  • kde-4.12
  • kdegraphics
  • okular
  • active
  • components
documentitem.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012 by Marco Martin <mart@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "documentitem.h"
21 
22 #include <QtDeclarative/qdeclarative.h>
23 
24 #include <core/document_p.h>
25 #include <core/page.h>
26 #include <core/bookmarkmanager.h>
27 
28 #include "ui/tocmodel.h"
29 
30 DocumentItem::DocumentItem(QObject *parent)
31  : QObject(parent),
32  m_thumbnailObserver(0),
33  m_pageviewObserver(0),
34  m_searchInProgress(false)
35 {
36  qmlRegisterUncreatableType<TOCModel>("org.kde.okular", 1, 0, "TOCModel", QLatin1String("Do not create objects of this type."));
37  Okular::Settings::instance("okularproviderrc");
38  m_document = new Okular::Document(0);
39  m_tocModel = new TOCModel(m_document, this);
40 
41  connect(m_document, SIGNAL(searchFinished(int,Okular::Document::SearchStatus)),
42  this, SLOT(searchFinished(int,Okular::Document::SearchStatus)));
43  connect(m_document->bookmarkManager(), SIGNAL(bookmarksChanged(KUrl)),
44  this, SIGNAL(bookmarkedPagesChanged()));
45  connect(m_document->bookmarkManager(), SIGNAL(bookmarksChanged(KUrl)),
46  this, SIGNAL(bookmarksChanged()));
47 }
48 
49 
50 DocumentItem::~DocumentItem()
51 {
52  delete m_document;
53 }
54 
55 void DocumentItem::setPath(const QString &path)
56 {
57  //TODO: remote urls
58  m_document->openDocument(path, KUrl(path), KMimeType::findByUrl(KUrl(path)));
59 
60  m_tocModel->fill(m_document->documentSynopsis());
61  m_tocModel->setCurrentViewport(m_document->viewport());
62 
63  m_matchingPages.clear();
64  for (uint i = 0; i < m_document->pages(); ++i) {
65  m_matchingPages << (int)i;
66  }
67  emit matchingPagesChanged();
68  emit pathChanged();
69  emit pageCountChanged();
70  emit openedChanged();
71  emit supportsSearchingChanged();
72  emit windowTitleForDocumentChanged();
73 }
74 
75 QString DocumentItem::windowTitleForDocument() const
76 {
77  // If 'DocumentTitle' should be used, check if the document has one. If
78  // either case is false, use the file name.
79  QString title = Okular::Settings::displayDocumentNameOrPath() == Okular::Settings::EnumDisplayDocumentNameOrPath::Path ? m_document->currentDocument().pathOrUrl() : m_document->currentDocument().fileName();
80 
81  if (Okular::Settings::displayDocumentTitle()) {
82  const QString docTitle = m_document->metaData( "DocumentTitle" ).toString();
83 
84  if (!docTitle.isEmpty() && !docTitle.trimmed().isEmpty()) {
85  title = docTitle;
86  }
87  }
88 
89  return title;
90 }
91 
92 QString DocumentItem::path() const
93 {
94  return m_document->currentDocument().prettyUrl();
95 }
96 
97 void DocumentItem::setCurrentPage(int page)
98 {
99  m_document->setViewportPage(page);
100  m_tocModel->setCurrentViewport(m_document->viewport());
101  emit currentPageChanged();
102 }
103 
104 int DocumentItem::currentPage() const
105 {
106  return m_document->currentPage();
107 }
108 
109 bool DocumentItem::isOpened() const
110 {
111  return m_document->isOpened();
112 }
113 
114 int DocumentItem::pageCount() const
115 {
116  return m_document->pages();
117 }
118 
119 QList<int> DocumentItem::matchingPages() const
120 {
121  return m_matchingPages;
122 }
123 
124 TOCModel *DocumentItem::tableOfContents() const
125 {
126  return m_tocModel;
127 }
128 
129 QList<int> DocumentItem::bookmarkedPages() const
130 {
131  QList<int> list;
132  QSet<int> pages;
133  foreach (const KBookmark &bookmark, m_document->bookmarkManager()->bookmarks()) {
134  Okular::DocumentViewport viewport(bookmark.url().htmlRef());
135  pages << viewport.pageNumber;
136  }
137  list = pages.toList();
138  qSort(list);
139  return list;
140 }
141 
142 QStringList DocumentItem::bookmarks() const
143 {
144  QStringList list;
145  foreach(const KBookmark &bookmark, m_document->bookmarkManager()->bookmarks()) {
146  list << bookmark.url().prettyUrl();
147  }
148  return list;
149 }
150 
151 bool DocumentItem::supportsSearching() const
152 {
153  return m_document->supportsSearching();
154 }
155 
156 bool DocumentItem::isSearchInProgress() const
157 {
158  return m_searchInProgress;
159 }
160 
161 void DocumentItem::searchText(const QString &text)
162 {
163  if (text.isEmpty()) {
164  resetSearch();
165  return;
166  }
167  m_document->cancelSearch();
168  m_document->resetSearch(PAGEVIEW_SEARCH_ID);
169  m_document->searchText(PAGEVIEW_SEARCH_ID, text, 1, Qt::CaseInsensitive,
170  Okular::Document::AllDocument, true, QColor(100,100,200,40), true);
171 
172  if (!m_searchInProgress) {
173  m_searchInProgress = true;
174  emit searchInProgressChanged();
175  }
176 }
177 
178 void DocumentItem::resetSearch()
179 {
180  m_document->resetSearch(PAGEVIEW_SEARCH_ID);
181  m_matchingPages.clear();
182  for (uint i = 0; i < m_document->pages(); ++i) {
183  m_matchingPages << (int)i;
184  }
185  if (m_searchInProgress) {
186  m_searchInProgress = false;
187  emit searchInProgressChanged();
188  }
189 
190  emit matchingPagesChanged();
191 }
192 
193 Okular::Document *DocumentItem::document()
194 {
195  return m_document;
196 }
197 
198 Observer *DocumentItem::thumbnailObserver()
199 {
200  if (!m_thumbnailObserver)
201  m_thumbnailObserver = new Observer(this);
202 
203  return m_thumbnailObserver;
204 }
205 
206 Observer *DocumentItem::pageviewObserver()
207 {
208  if (!m_pageviewObserver) {
209  m_pageviewObserver = new Observer(this);
210  m_document->d->m_tiledObserver = m_pageviewObserver;
211  }
212 
213  return m_pageviewObserver;
214 }
215 
216 void DocumentItem::searchFinished(int id, Okular::Document::SearchStatus endStatus)
217 {
218  Q_UNUSED(endStatus)
219 
220  if (id != PAGEVIEW_SEARCH_ID) {
221  return;
222  }
223 
224  m_matchingPages.clear();
225  for (uint i = 0; i < m_document->pages(); ++i) {
226  if (m_document->page(i)->hasHighlights(id)) {
227  m_matchingPages << (int)i;
228  }
229  }
230 
231  if (m_searchInProgress) {
232  m_searchInProgress = false;
233  emit searchInProgressChanged();
234  }
235  emit matchingPagesChanged();
236 }
237 
238 
239 //Observer
240 
241 Observer::Observer(DocumentItem *parent)
242  : QObject(parent),
243  m_document(parent)
244 {
245  parent->document()->addObserver(this);
246 }
247 
248 Observer::~Observer()
249 {
250 }
251 
252 void Observer::notifyPageChanged(int page, int flags)
253 {
254  emit pageChanged(page, flags);
255 }
256 
257 #include "documentitem.moc"
Observer::pageChanged
void pageChanged(int page, int flags)
DocumentItem::pageCountChanged
void pageCountChanged()
DocumentItem::pageviewObserver
Observer * pageviewObserver()
Definition: documentitem.cpp:206
Observer::notifyPageChanged
void notifyPageChanged(int page, int flags)
This method is called whenever the content on page described by the passed flags has been changed...
Definition: documentitem.cpp:252
bookmarkmanager.h
DocumentItem::windowTitleForDocument
QString windowTitleForDocument() const
DocumentItem::path
QString path() const
Okular::Document::bookmarkManager
BookmarkManager * bookmarkManager() const
Returns the bookmark manager of the document.
Definition: document.cpp:3493
Okular::Document::pages
uint pages() const
Returns the number of pages of the document.
Definition: document.cpp:2652
Okular::Document::currentDocument
KUrl currentDocument() const
Returns the url of the currently opened document.
Definition: document.cpp:2657
Okular::Document::AllDocument
Search complete document.
Definition: document.h:473
DocumentItem::tableOfContents
TOCModel * tableOfContents() const
DocumentItem::thumbnailObserver
Observer * thumbnailObserver()
Definition: documentitem.cpp:198
DocumentItem::bookmarksChanged
void bookmarksChanged()
documentitem.h
QObject
DocumentItem
Definition: documentitem.h:37
page.h
Okular::Document::openDocument
bool openDocument(const QString &docFile, const KUrl &url, const KMimeType::Ptr &mime)
Opens the document.
Definition: document.cpp:2060
DocumentItem::supportsSearching
bool supportsSearching() const
Okular::Document::isOpened
bool isOpened() const
Returns whether the document is currently opened.
Definition: document.cpp:2513
DocumentItem::pageCount
int pageCount() const
Observer::Observer
Observer(DocumentItem *parent)
Definition: documentitem.cpp:241
DocumentItem::bookmarkedPagesChanged
void bookmarkedPagesChanged()
PAGEVIEW_SEARCH_ID
#define PAGEVIEW_SEARCH_ID
Definition: document.h:62
Okular::Document::page
const Page * page(int number) const
Returns the page object for the given page number or 0 if the number is out of range.
Definition: document.cpp:2619
DocumentItem::isSearchInProgress
bool isSearchInProgress() const
Definition: documentitem.cpp:156
DocumentItem::setCurrentPage
void setCurrentPage(int page)
Definition: documentitem.cpp:97
DocumentItem::~DocumentItem
~DocumentItem()
Definition: documentitem.cpp:50
DocumentItem::currentPage
int currentPage() const
Okular::Document::SearchStatus
SearchStatus
Describes how search ended.
Definition: document.h:481
DocumentItem::pathChanged
void pathChanged()
Okular::Document
The Document.
Definition: document.h:84
DocumentItem::DocumentItem
DocumentItem(QObject *parent=0)
Definition: documentitem.cpp:30
DocumentItem::openedChanged
void openedChanged()
DocumentItem::resetSearch
Q_INVOKABLE void resetSearch()
Reset the search over the document.
Definition: documentitem.cpp:178
DocumentItem::bookmarkedPages
QList< int > bookmarkedPages() const
DocumentItem::matchingPagesChanged
void matchingPagesChanged()
DocumentItem::document
Okular::Document * document()
Definition: documentitem.cpp:193
Okular::DocumentViewport::pageNumber
int pageNumber
The number of the page nearest the center of the viewport.
Definition: document.h:1035
Observer
Definition: documentitem.h:167
Okular::Document::documentSynopsis
const DocumentSynopsis * documentSynopsis() const
Returns the table of content of the document or 0 if no table of content is available.
Definition: document.cpp:2567
DocumentItem::matchingPages
QList< int > matchingPages() const
Okular::Document::viewport
const DocumentViewport & viewport() const
Returns the current viewport of the document.
Definition: document.cpp:2624
DocumentItem::searchText
Q_INVOKABLE void searchText(const QString &text)
Performs a search in the document.
Definition: documentitem.cpp:161
Okular::Document::metaData
QVariant metaData(const QString &key, const QVariant &option=QVariant()) const
Returns the meta data for the given key and option or an empty variant if the key doesn't exists...
Definition: document.cpp:2746
Observer::~Observer
~Observer()
Definition: documentitem.cpp:248
Okular::BookmarkManager::bookmarks
KBookmark::List bookmarks(const KUrl &url) const
Returns the list of bookmarks for the specified url.
Definition: bookmarkmanager.cpp:248
Okular::Document::cancelSearch
void cancelSearch()
Cancels the current search.
Definition: document.cpp:3430
DocumentItem::isOpened
bool isOpened() const
Definition: documentitem.cpp:109
DocumentItem::windowTitleForDocumentChanged
void windowTitleForDocumentChanged()
document_p.h
Okular::Page::hasHighlights
bool hasHighlights(int id=-1) const
Returns whether the page provides highlighting for the observer with the given id.
Definition: page.cpp:278
Okular::Document::searchText
void searchText(int searchID, const QString &text, bool fromStart, Qt::CaseSensitivity caseSensitivity, SearchType type, bool moveViewport, const QColor &color, bool noDialogs=false)
Searches the given text in the document.
Definition: document.cpp:3237
DocumentItem::bookmarks
QStringList bookmarks() const
Okular::DocumentViewport
A view on the document.
Definition: document.h:1003
Okular::Document::addObserver
void addObserver(DocumentObserver *observer)
Registers a new observer for the document.
Definition: document.cpp:2431
Okular::Document::supportsSearching
bool supportsSearching() const
Returns whether the document supports searching.
Definition: document.cpp:2675
DocumentItem::setPath
void setPath(const QString &path)
Definition: documentitem.cpp:55
DocumentItem::supportsSearchingChanged
void supportsSearchingChanged()
Okular::DocumentPrivate::m_tiledObserver
DocumentObserver * m_tiledObserver
Definition: document_p.h:215
Okular::Document::resetSearch
void resetSearch(int searchID)
Resets the search for the given searchID.
Definition: document.cpp:3401
Okular::Document::setViewportPage
void setViewportPage(int page, DocumentObserver *excludeObserver=0, bool smoothMove=false)
Sets the current document viewport to the given page.
Definition: document.cpp:3116
DocumentItem::currentPageChanged
void currentPageChanged()
DocumentItem::searchInProgressChanged
void searchInProgressChanged()
Okular::Document::currentPage
uint currentPage() const
Returns the number of the current page.
Definition: document.cpp:2647
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:45:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okular

Skip menu "okular"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal