summaryrefslogtreecommitdiffstats
path: root/kviewshell/documentRenderer.cpp
blob: f9837fa2d41b2ed4e086b1616aaeb886cdf6ccf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// Class: documentRenderer
//
// Abstract Widget for displaying document types
// Needs to be implemented from the actual parts
// using kviewshell 
// Part of KViewshell - A generic interface for document viewers.
//
// (C) 2004-2005 Wilfried Huss, Stefan Kebekus. Distributed under the GPL.

#include <config.h>

#include <kdebug.h>

#include "documentRenderer.h"
#include "renderedDocumentPage.h"


DocumentRenderer::DocumentRenderer(QWidget* par)
  : mutex(true), parentWidget(par), accessibilityBackground(false),
    accessibilityBackgroundColor(QColor(255,255,255))
{
  numPages = 0;
  _isModified = false;
}


DocumentRenderer::~DocumentRenderer()
{
  // Wait for all access to this DocumentRenderer to finish
  QMutexLocker lock(&mutex);
  
  clear();
}


void DocumentRenderer::clear()
{
  // Wait for all access to this DocumentRenderer to finish
  QMutexLocker lock(&mutex);

  numPages = 0;
  pageSizes.clear();
  anchorList.clear();
  bookmarks.clear();
  _isModified = false;
}

void DocumentRenderer::setAccessibleBackground(bool accessibleMode, const QColor& background)
{
  // Wait for all access to this DocumentRenderer to finish
  QMutexLocker lock(&mutex);
  
  accessibilityBackground = accessibleMode;
  accessibilityBackgroundColor = background;
}

SimplePageSize DocumentRenderer::sizeOfPage(const PageNumber& page)
{
  // Wait for all access to this DocumentRenderer to finish
  QMutexLocker locker(&mutex);
  
  if (!page.isValid())
    return SimplePageSize();
  if (page > totalPages()) 
    return SimplePageSize();
  if (page > pageSizes.size())
    return SimplePageSize();
  
  return pageSizes[page-1];
}


void DocumentRenderer::drawThumbnail(double resolution, RenderedDocumentPage* page)
{
  // Wait for all access to this DocumentRenderer to finish
  QMutexLocker locker(&mutex);

  drawPage(resolution, page);
}

void DocumentRenderer::getText(RenderedDocumentPage* page)
{
  // We are only interrested in the textual data, so we can use a dummy value for the resolution.
  drawPage(100.0, page);
}

bool DocumentRenderer::isValidFile(const QString&) const
{
  return true;
}


Anchor DocumentRenderer::parseReference(const QString &reference)
{
  // Wait for all access to this documentRenderer to finish
  QMutexLocker locker(&mutex);

  if (isEmpty())
    return Anchor();

  // If the reference is a number, which we'll interpret as a
  // page number.
  bool ok;
  int page = reference.toInt(&ok);
  if (ok == true)
  {
    if (page < 1)
      page = 1;
    if (page > totalPages())
      page = totalPages();

    return Anchor(page, Length());
  }

  // If the reference is not a number, return an empty anchor.
  return Anchor();
}

Anchor DocumentRenderer::findAnchor(const QString &locallink)
{
  // Wait for all access to this DocumentRenderer to finish
  QMutexLocker locker(&mutex);

  QMap<QString,Anchor>::Iterator it = anchorList.find(locallink);
  if (it != anchorList.end()) 
    return *it;
  else 
    return Anchor();
}


#include "documentRenderer.moc"