24
24
#include "settings.h"
25
25
#include "pageitem.h"
27
int SinglePageLayout::currentPageForPage(int page) const
27
qreal DocumentLayout::visibleHeight(int viewportHeight) const
29
const qreal pageSpacing = Settings::instance()->documentView().pageSpacing();
31
return viewportHeight - 2.0 * pageSpacing;
35
int SinglePageLayout::currentPage(int page) const
32
int SinglePageLayout::leftIndexForIndex(int index) const
40
int SinglePageLayout::previousPage(int page) const
42
return qMax(page - 1, 1);
45
int SinglePageLayout::nextPage(int page, int count) const
47
return qMin(page + 1, count);
50
QPair< int, int > SinglePageLayout::prefetchRange(int page, int count) const
52
const int prefetchDistance = Settings::instance()->documentView().prefetchDistance();
54
return qMakePair(qMax(page - prefetchDistance / 2, 1),
55
qMin(page + prefetchDistance, count));
58
int SinglePageLayout::leftIndex(int index) const
37
int SinglePageLayout::rightIndexForIndex(int index, int count) const
63
int SinglePageLayout::rightIndex(int index, int count) const
72
int TwoPagesLayout::currentPageForPage(int page) const
98
int TwoPagesLayout::currentPage(int page) const
74
100
return page % 2 != 0 ? page : page - 1;
77
int TwoPagesLayout::leftIndexForIndex(int index) const
103
int TwoPagesLayout::previousPage(int page) const
105
return qMax(page - 2, 1);
108
int TwoPagesLayout::nextPage(int page, int count) const
110
return qMin(page + 2, count);
113
QPair< int, int > TwoPagesLayout::prefetchRange(int page, int count) const
115
const int prefetchDistance = Settings::instance()->documentView().prefetchDistance();
117
return qMakePair(qMax(page - prefetchDistance, 1),
118
qMin(page + 2 * prefetchDistance + 1, count));
121
int TwoPagesLayout::leftIndex(int index) const
79
123
return index % 2 == 0 ? index : index - 1;
82
int TwoPagesLayout::rightIndexForIndex(int index, int count) const
126
int TwoPagesLayout::rightIndex(int index, int count) const
84
128
return qMin(index % 2 == 0 ? index + 1 : index, count - 1);
98
142
const qreal pageSpacing = Settings::instance()->documentView().pageSpacing();
99
143
const QRectF boundingRect = page->boundingRect();
101
if(index == leftIndexForIndex(index))
145
if(index == leftIndex(index))
103
147
page->setPos(-boundingRect.left() - boundingRect.width() - 0.5 * pageSpacing, height - boundingRect.top());
109
153
left = qMin(left, -boundingRect.width() - 1.5f * pageSpacing);
111
if(index == rightIndexForIndex(index, count))
155
if(index == rightIndex(index, count))
113
157
right = qMax(right, 0.5f * pageSpacing);
114
158
height += pageHeight + pageSpacing;
129
int TwoPagesWithCoverPageLayout::currentPageForPage(int page) const
173
int TwoPagesWithCoverPageLayout::currentPage(int page) const
131
175
return page == 1 ? page : (page % 2 == 0 ? page : page - 1);
134
int TwoPagesWithCoverPageLayout::leftIndexForIndex(int index) const
178
int TwoPagesWithCoverPageLayout::leftIndex(int index) const
136
180
return index == 0 ? index : (index % 2 != 0 ? index : index - 1);
139
int TwoPagesWithCoverPageLayout::rightIndexForIndex(int index, int count) const
183
int TwoPagesWithCoverPageLayout::rightIndex(int index, int count) const
141
185
return qMin(index % 2 != 0 ? index + 1 : index, count - 1);
145
int MultiplePagesLayout::currentPageForPage(int page) const
189
int MultiplePagesLayout::currentPage(int page) const
147
191
const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
149
193
return page - ((page - 1) % pagesPerRow);
152
int MultiplePagesLayout::leftIndexForIndex(int index) const
196
int MultiplePagesLayout::previousPage(int page) const
198
const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
200
return qMax(page - pagesPerRow, 1);
203
int MultiplePagesLayout::nextPage(int page, int count) const
205
const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
207
return qMin(page + pagesPerRow, count);
210
QPair<int, int> MultiplePagesLayout::prefetchRange(int page, int count) const
212
const int prefetchDistance = Settings::instance()->documentView().prefetchDistance();
213
const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
215
return qMakePair(qMax(page - pagesPerRow * (prefetchDistance / 2), 1),
216
qMin(page + pagesPerRow * (prefetchDistance + 1) - 1, count));
219
int MultiplePagesLayout::leftIndex(int index) const
154
221
const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
156
223
return index - (index % pagesPerRow);
159
int MultiplePagesLayout::rightIndexForIndex(int index, int count) const
226
int MultiplePagesLayout::rightIndex(int index, int count) const
161
228
const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
183
250
pageHeight = qMax(pageHeight, boundingRect.height());
184
251
left += boundingRect.width() + pageSpacing;
186
if(index == leftIndexForIndex(index))
253
if(index == leftIndex(index))
188
255
heightToIndex.insert(-height + pageSpacing + 0.3 * pageHeight, index);
191
if(index == rightIndexForIndex(index, count))
258
if(index == rightIndex(index, count))
193
260
height += pageHeight + pageSpacing;
194
261
pageHeight = 0.0;