kviewshell
documentRenderer.h
Go to the documentation of this file.00001 // -*- C++ -*- 00002 // 00003 // Class: documentRenderer 00004 // 00005 // Abstract class for rendering document types. Needs to be 00006 // subclassed by the actual parts using kviewshell. Part of 00007 // KViewshell - A generic interface for document viewers. 00008 // 00009 // (C) 2004-2005 Wilfried Huss, Stefan Kebekus. Distributed under the GPL. 00010 // 00011 00012 #ifndef DOCUMENTRENDERER_H 00013 #define DOCUMENTRENDERER_H 00014 00015 #include "bookmark.h" 00016 #include "pageNumber.h" 00017 #include "pageSize.h" 00018 00019 #include <qguardedptr.h> 00020 #include <qcolor.h> 00021 #include <qmutex.h> 00022 #include <qobject.h> 00023 #include <qvaluevector.h> 00024 00025 class Anchor; 00026 class KURL; 00027 class RenderedDocumentPage; 00028 00029 00051 class DocumentRenderer : public QObject 00052 { 00053 Q_OBJECT 00054 00055 public: 00057 DocumentRenderer(QWidget* parent); 00058 00059 virtual ~DocumentRenderer(); 00060 00126 virtual bool setFile(const QString &fname, const KURL &base) = 0; 00127 00128 00151 virtual void clear(); 00152 00153 00154 /* Returns true if the current document contains 0 pages. */ 00155 bool isEmpty() const {return numPages == 0;} 00156 00157 /* Tells if the document was modified after is was loaded. */ 00158 bool isModified() const {return _isModified; } 00159 00160 /* Returns the number of pages in the document. This method can well 00161 return 0, e.g. if no document has been loaded yet, or if the 00162 current document is empty. */ 00163 PageNumber totalPages() const {return numPages; } 00164 00165 QPtrList<Bookmark> getBookmarks() const { return bookmarks; } 00166 00167 /* Returns the size of page 'page'. If the document is empty, if the 00168 page specified is not a page of the document or if the document 00169 does not specify a size (which happens, e.g., for some 00170 DVI-files), then an invalid page size is returned. */ 00171 SimplePageSize sizeOfPage(const PageNumber& page); 00172 00173 /* Returns true if the document specifies page sizes, and false 00174 otherwise. NOTE: the information returned by this method is not 00175 always 100% reliable. Although unlikely, it is theoretically 00176 possible that this method returns 'true', but still some of the 00177 sizes returned by sizeOfPage() are invalid. */ 00178 bool hasSpecifiedPageSizes() const {return !pageSizes.isEmpty();} 00179 00271 virtual void drawPage(double resolution, RenderedDocumentPage* page) = 0; 00272 00286 virtual void drawThumbnail(double resolution, RenderedDocumentPage* page); 00287 00305 virtual void getText(RenderedDocumentPage* page); 00306 00316 virtual bool supportsTextSearch() const {return false;} 00317 00318 /* This method will try to parse the reference part of the DVI 00319 file's URL, (either a number, which is supposed to be a page 00320 number, or src:(line)(filename)) and see if a corresponding 00321 section of the DVI file can be found. If so, it returns an anchor 00322 to that section. If not, it returns an invalid anchor. 00323 */ 00324 virtual Anchor parseReference(const QString &reference); 00325 00326 /* Looks up a anchor in the "anchorList". Returns the anchor found, 00327 or an invalid anchor otherwise. 00328 */ 00329 Anchor findAnchor(const QString &); 00330 00331 /* Quick file validity check 00332 00333 This method is used internally, to check if a file is valid before 00334 it is re-loaded. This is used e.g. by kdvi: when a the user TeXes a 00335 file, the file changes immediately. If the 'watch file' option is 00336 set, kdvi is informed immediately. At that time, however, the TeX 00337 typesetting program still writes to the dvi file, and reloading must 00338 be postphoned till TeX finishes, and the dvi file becomes vaild. If 00339 such considerations are not an issue for you, this method does not 00340 need to be re-implemented. 00341 00342 @warning Future versions of kviewshell will use threading to keep 00343 the GUI responsive while pages are rendered. As a result, IT IS 00344 ABSOLUTELY NECESSARY that your implementation is THREAD-SAFE, if 00345 not, this can result in infrequent and very hard-to-find crashes of 00346 your programm. Use the member mutex to make your implemetation 00347 thread-safe. 00348 00349 @param fileName name of the file that should be checked for validity 00350 00351 @returns 'false' if the file 'fileName' is obviously invalid, and 00352 true otherwise. The default implementation always returns 00353 'true'. 00354 */ 00355 virtual bool isValidFile(const QString& fileName) const; 00356 00357 void setAccessibleBackground(bool accessibleMode, const QColor& background = QColor(255, 255, 255)); 00358 00359 signals: 00371 void documentIsChanged(); 00372 00373 00380 void setStatusBarText( const QString& ); 00381 00382 protected: 00392 QMutex mutex; 00393 00394 00403 Q_UINT16 numPages; 00404 00420 QValueVector<SimplePageSize> pageSizes; 00421 00431 QPtrList<Bookmark> bookmarks; 00432 00442 QMap<QString, Anchor> anchorList; 00443 00449 QGuardedPtr<QWidget> parentWidget; 00450 00457 bool accessibilityBackground; 00458 00465 QColor accessibilityBackgroundColor; 00466 00475 bool _isModified; 00476 }; 00477 00478 #endif