~adamreichold/qpdfview/trunk

« back to all changes in this revision

Viewing changes to sources/documentlayout.cpp

  • Committer: Adam Reichold
  • Date: 2013-10-27 10:31:24 UTC
  • mto: This revision was merged to the branch mainline in revision 1349.
  • Revision ID: adamreichold@myopera.com-20131027103124-tzfrbr1k9sfcc0v2
actually remove layout implementation from document view and adjust document layout interface accordingly

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "settings.h"
25
25
#include "pageitem.h"
26
26
 
27
 
int SinglePageLayout::currentPageForPage(int page) const
 
27
qreal DocumentLayout::visibleHeight(int viewportHeight) const
 
28
{
 
29
    const qreal pageSpacing = Settings::instance()->documentView().pageSpacing();
 
30
 
 
31
    return viewportHeight - 2.0 * pageSpacing;
 
32
}
 
33
 
 
34
 
 
35
int SinglePageLayout::currentPage(int page) const
28
36
{
29
37
    return page;
30
38
}
31
39
 
32
 
int SinglePageLayout::leftIndexForIndex(int index) const
 
40
int SinglePageLayout::previousPage(int page) const
 
41
{
 
42
    return qMax(page - 1, 1);
 
43
}
 
44
 
 
45
int SinglePageLayout::nextPage(int page, int count) const
 
46
{
 
47
    return qMin(page + 1, count);
 
48
}
 
49
 
 
50
QPair< int, int > SinglePageLayout::prefetchRange(int page, int count) const
 
51
{
 
52
    const int prefetchDistance = Settings::instance()->documentView().prefetchDistance();
 
53
 
 
54
    return qMakePair(qMax(page - prefetchDistance / 2, 1),
 
55
                     qMin(page + prefetchDistance, count));
 
56
}
 
57
 
 
58
int SinglePageLayout::leftIndex(int index) const
33
59
{
34
60
    return index;
35
61
}
36
62
 
37
 
int SinglePageLayout::rightIndexForIndex(int index, int count) const
 
63
int SinglePageLayout::rightIndex(int index, int count) const
38
64
{
39
65
    Q_UNUSED(count);
40
66
 
69
95
}
70
96
 
71
97
 
72
 
int TwoPagesLayout::currentPageForPage(int page) const
 
98
int TwoPagesLayout::currentPage(int page) const
73
99
{
74
100
    return page % 2 != 0 ? page : page - 1;
75
101
}
76
102
 
77
 
int TwoPagesLayout::leftIndexForIndex(int index) const
 
103
int TwoPagesLayout::previousPage(int page) const
 
104
{
 
105
    return qMax(page - 2, 1);
 
106
}
 
107
 
 
108
int TwoPagesLayout::nextPage(int page, int count) const
 
109
{
 
110
    return qMin(page + 2, count);
 
111
}
 
112
 
 
113
QPair< int, int > TwoPagesLayout::prefetchRange(int page, int count) const
 
114
{
 
115
    const int prefetchDistance = Settings::instance()->documentView().prefetchDistance();
 
116
 
 
117
    return qMakePair(qMax(page - prefetchDistance, 1),
 
118
                     qMin(page + 2 * prefetchDistance + 1, count));
 
119
}
 
120
 
 
121
int TwoPagesLayout::leftIndex(int index) const
78
122
{
79
123
    return index % 2 == 0 ? index : index - 1;
80
124
}
81
125
 
82
 
int TwoPagesLayout::rightIndexForIndex(int index, int count) const
 
126
int TwoPagesLayout::rightIndex(int index, int count) const
83
127
{
84
128
    return qMin(index % 2 == 0 ? index + 1 : index, count - 1);
85
129
}
98
142
    const qreal pageSpacing = Settings::instance()->documentView().pageSpacing();
99
143
    const QRectF boundingRect = page->boundingRect();
100
144
 
101
 
    if(index == leftIndexForIndex(index))
 
145
    if(index == leftIndex(index))
102
146
    {
103
147
        page->setPos(-boundingRect.left() - boundingRect.width() - 0.5 * pageSpacing, height - boundingRect.top());
104
148
 
108
152
 
109
153
        left = qMin(left, -boundingRect.width() - 1.5f * pageSpacing);
110
154
 
111
 
        if(index == rightIndexForIndex(index, count))
 
155
        if(index == rightIndex(index, count))
112
156
        {
113
157
            right = qMax(right, 0.5f * pageSpacing);
114
158
            height += pageHeight + pageSpacing;
126
170
}
127
171
 
128
172
 
129
 
int TwoPagesWithCoverPageLayout::currentPageForPage(int page) const
 
173
int TwoPagesWithCoverPageLayout::currentPage(int page) const
130
174
{
131
175
    return page == 1 ? page : (page % 2 == 0 ? page : page - 1);
132
176
}
133
177
 
134
 
int TwoPagesWithCoverPageLayout::leftIndexForIndex(int index) const
 
178
int TwoPagesWithCoverPageLayout::leftIndex(int index) const
135
179
{
136
180
    return index == 0 ? index : (index % 2 != 0 ? index : index - 1);
137
181
}
138
182
 
139
 
int TwoPagesWithCoverPageLayout::rightIndexForIndex(int index, int count) const
 
183
int TwoPagesWithCoverPageLayout::rightIndex(int index, int count) const
140
184
{
141
185
    return qMin(index % 2 != 0 ? index + 1 : index, count - 1);
142
186
}
143
187
 
144
188
 
145
 
int MultiplePagesLayout::currentPageForPage(int page) const
 
189
int MultiplePagesLayout::currentPage(int page) const
146
190
{
147
191
    const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
148
192
 
149
193
    return page - ((page - 1) % pagesPerRow);
150
194
}
151
195
 
152
 
int MultiplePagesLayout::leftIndexForIndex(int index) const
 
196
int MultiplePagesLayout::previousPage(int page) const
 
197
{
 
198
    const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
 
199
 
 
200
    return qMax(page - pagesPerRow, 1);
 
201
}
 
202
 
 
203
int MultiplePagesLayout::nextPage(int page, int count) const
 
204
{
 
205
    const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
 
206
 
 
207
    return qMin(page + pagesPerRow, count);
 
208
}
 
209
 
 
210
QPair<int, int> MultiplePagesLayout::prefetchRange(int page, int count) const
 
211
{
 
212
    const int prefetchDistance = Settings::instance()->documentView().prefetchDistance();
 
213
    const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
 
214
 
 
215
    return qMakePair(qMax(page - pagesPerRow * (prefetchDistance / 2), 1),
 
216
                     qMin(page + pagesPerRow * (prefetchDistance + 1) - 1, count));
 
217
}
 
218
 
 
219
int MultiplePagesLayout::leftIndex(int index) const
153
220
{
154
221
    const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
155
222
 
156
223
    return index - (index % pagesPerRow);
157
224
}
158
225
 
159
 
int MultiplePagesLayout::rightIndexForIndex(int index, int count) const
 
226
int MultiplePagesLayout::rightIndex(int index, int count) const
160
227
{
161
228
    const int pagesPerRow = Settings::instance()->documentView().pagesPerRow();
162
229
 
183
250
    pageHeight = qMax(pageHeight, boundingRect.height());
184
251
    left += boundingRect.width() + pageSpacing;
185
252
 
186
 
    if(index == leftIndexForIndex(index))
 
253
    if(index == leftIndex(index))
187
254
    {
188
255
        heightToIndex.insert(-height + pageSpacing + 0.3 * pageHeight, index);
189
256
    }
190
257
 
191
 
    if(index == rightIndexForIndex(index, count))
 
258
    if(index == rightIndex(index, count))
192
259
    {
193
260
        height += pageHeight + pageSpacing;
194
261
        pageHeight = 0.0;