18#include "KWPageManager.h"
24KWPageManager::KWPageManager() {
26 m_onlyAllowAppend =
false;
27 m_pageList.setAutoDelete(
true);
28 m_defaultPageLayout = KoPageLayout::standardLayout();
33 double startOfpage = 0.0;
34 TQPtrListIterator<KWPage> pages(m_pageList);
35 while(pages.current() && startOfpage < frame.top()) {
36 startOfpage += pages.current()->height();
37 if(startOfpage >= frame.top())
45 if ( !pages.current() )
46 page = m_firstPage + m_pageList.count() - 1;
48 if(!pages.current() || frame.right() > pages.current()->width() ||
49 frame.top() > pages.current()->height() + startOfpage) {
52 kdDebug(31001) <<
" KWPageManager::pageNumber of "<< frame <<
" is too high, no page there\n";
53 else if(frame.right() > pages.current()->width())
54 kdDebug(31001) <<
" KWPageManager::pageNumber right of "<< frame <<
" is out of bounds\n";
55 else if(frame.top() > pages.current()->height() + startOfpage)
56 kdDebug(31001) <<
" KWPageManager::pageNumber "<< frame <<
" spans multiple pages\n";
58kdDebug(31001) << kdBacktrace() << endl;
77 return m_pageList.count();
81 TQPtrListIterator<KWPage> pages(m_pageList);
82 while(pages.current()) {
83 if(pages.current()->pageNumber() == pageNum)
84 return pages.current();
87 kdWarning(31001) <<
"KWPageManager::page(" << pageNum <<
") failed; Requested page does not exist ["<< m_firstPage <<
"-"<<
lastPageNumber() <<
"]"<< endl;
89 kdDebug(31001) << kdBacktrace();
109 bool switchSides =
startPage % 2 != m_firstPage % 2;
110 for(TQPtrListIterator<KWPage> pages(m_pageList); pages.current(); ++pages) {
112 page->m_pageNum =
page->m_pageNum + offset;
114 page->m_pageSide =
page->m_pageSide == KWPage::Left ? KWPage::Right : KWPage::Left;
124 if(m_onlyAllowAppend)
127 TQPtrListIterator<KWPage> pages(m_pageList);
128 while(pages.current() && pages.current()->pageNumber() < index)
130 while(pages.current()) {
131 pages.current()->m_pageNum++;
134 m_pageList.inSort(
page);
140 m_pageList.append(
page);
145 KoPageLayout lay = m_defaultPageLayout;
159 return pageOffset(pageNum,
false);
162 return pageOffset(pageNum,
true);
165double KWPageManager::pageOffset(
int pageNum,
bool bottom)
const {
166 if(pageNum < m_firstPage)
168 TQPtrListIterator<KWPage> pages(m_pageList);
170 while(pages.current()) {
171 if(pages.current()->pageNumber() == pageNum) {
173 offset += pages.current()->height();
176 offset += pages.current()->height();
188 TQPtrListIterator<KWPage> pages(m_pageList);
189 while(pages.current() && pages.current()->pageNumber() <=
page->
pageNumber())
191 while(pages.current()) {
192 pages.current()->m_pageNum--;
196 m_pageList.remove(
page);
199void KWPageManager::setDefaultPage(
const KoPageLayout &layout) {
200 m_defaultPageLayout = layout;
202 if(m_defaultPageLayout.ptLeft < 0 || m_defaultPageLayout.ptRight < 0) {
203 m_defaultPageLayout.ptLeft = -1;
204 m_defaultPageLayout.ptRight = -1;
206 m_defaultPageLayout.ptPageEdge = -1;
207 m_defaultPageLayout.ptBindingSide = -1;
208 m_defaultPageLayout.ptLeft = TQMAX(m_defaultPageLayout.ptLeft, 0);
209 m_defaultPageLayout.ptRight = TQMAX(m_defaultPageLayout.ptRight, 0);
215 int page=m_firstPage;
216 double startOfpage = 0.0;
217 TQPtrListIterator<KWPage> pages(m_pageList);
218 while(pages.current()) {
219 startOfpage += pages.current()->height();
220 if(startOfpage >= point.y())
226 KoRect rect = this->
page(page)->
rect();
227 if(rect.contains(point))
231 if(rect.top() > rc.y())
233 else if(rect.bottom() < rc.y())
234 rc.setY(rect.bottom());
236 if(rect.left() > rc.x())
237 rc.setX(rect.left());
238 else if(rect.right() < rc.x())
239 rc.setX(rect.right());
244int KWPageManager::PageList::compareItems(TQPtrCollection::Item a, TQPtrCollection::Item b)
246 int pa = ((
KWPage *)a)->pageNumber();
247 int pb = ((
KWPage *)b)->pageNumber();
248 if (pa == pb)
return 0;
249 if (pa < pb)
return -1;
const KoPageLayout pageLayout(int pageNumber) const
return the effective pageLayout of pageNumber combining the default and the page specific ones
double topOfPage(int pageNumber) const
Return the y-offset in this document of the top of page with pageNumber Note that pageNumber is NOT a...
KWPage * insertPage(int pageNumber)
Inserts a new page at the specified position in the document.
KoPoint clipToDocument(const KoPoint &point)
Returns the argument point, with altered coordinats if the point happens to be outside all pages.
void setStartPage(int startPage)
Set a new startpage for this document, renumbering all pages already added.
int pageNumber(const KoRect *rect) const
return pageNumber of frame, pagenumbers for a normal document start at 1.
KWPage * page(int pageNumber) const
return the KWPage of a specific page number. Returns 0 if page does not exist.
KWPage * appendPage()
Append a new page at the end of the document.
int pageCount() const
return total number of pages in this document.
void removePage(int pageNumber)
Remove the page with pageNumber renumbering all pages after pages already added.
double bottomOfPage(int pageNumber) const
Return the y-offset in this document of the bottom of page with pageNumber Note that pageNumber is NO...
int startPage() const
return the first pagenumber of this document
int lastPageNumber() const
return the highest page number we have in this document.
This class represents a printed page of the document.
double height() const
return the height of this page (in pt)
double leftMargin() const
return the width of the margin at left (in pt);
int pageNumber() const
returns the number of this page as it will be shown to the user.
double topMargin() const
return the height of the margin at top (in pt);
double bottomMargin() const
return the height of the margin at bottom (in pt);
double width() const
return the width of this page (in pt)
double rightMargin() const
return the width of the margin at left (in pt);
const KoRect rect() const
return a KoRect with the (pt) sizes of this page. Margins are ignored for this function.