kword

KWPage.cpp
1/* This file is part of the KOffice project
2 * Copyright (C) 2005 Thomas Zander <zander@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; version 2.
7
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#include "KWPage.h"
20#include "KoZoomHandler.h"
21
22#include <tqrect.h>
23
24KWPage::KWPage(KWPageManager *parent, int pageNum) {
25 m_parent = parent;
26 m_pageNum = pageNum;
27 m_pageLayout.ptWidth = -1.0;
28 m_pageLayout.ptHeight = -1.0;
29 m_pageLayout.ptLeft = -1.0;
30 m_pageLayout.ptRight = -1.0;
31 m_pageLayout.ptBottom = -1.0;
32 m_pageLayout.ptTop = -1.0;
33 m_pageLayout.ptPageEdge = -1.0;
34 m_pageLayout.ptBindingSide = -1.0;
35 m_pageSide = pageNum%2==0 ? Left : Right;
36}
37
38double KWPage::width() const {
39 if(m_pageLayout.ptWidth != -1)
40 return m_pageLayout.ptWidth;
41 return m_parent->m_defaultPageLayout.ptWidth;
42}
43
44double KWPage::height() const {
45 if(m_pageLayout.ptHeight != -1)
46 return m_pageLayout.ptHeight;
47 return m_parent->m_defaultPageLayout.ptHeight;
48}
49
50void KWPage::setWidth(const double &x) {
51 m_pageLayout.ptWidth = x == m_parent->m_defaultPageLayout.ptWidth ? -1 : x;
52}
53void KWPage::setHeight(const double &y) {
54 m_pageLayout.ptHeight = y == m_parent->m_defaultPageLayout.ptHeight ? -1 : y;
55}
56void KWPage::setTopMargin(const double &t) {
57 m_pageLayout.ptTop = t == m_parent->m_defaultPageLayout.ptTop ? -1 : t;
58}
59void KWPage::setBottomMargin(const double &b) {
60 m_pageLayout.ptBottom = b == m_parent->m_defaultPageLayout.ptBottom ? -1 : b;
61}
62void KWPage::setPageEdgeMargin(const double &m) {
63 m_pageLayout.ptPageEdge = m == m_parent->m_defaultPageLayout.ptPageEdge ? -1 : m;
64 m_pageLayout.ptLeft = -1;
65 m_pageLayout.ptRight = -1;
66}
67void KWPage::setMarginClosestBinding(const double &m) {
68 m_pageLayout.ptBindingSide = m == m_parent->m_defaultPageLayout.ptBindingSide ? -1 : m;
69 m_pageLayout.ptLeft = -1;
70 m_pageLayout.ptRight = -1;
71}
72void KWPage::setLeftMargin(const double &l) {
73 m_pageLayout.ptLeft = l == m_parent->m_defaultPageLayout.ptLeft ? -1 : l;
74 m_pageLayout.ptBindingSide = -1;
75 m_pageLayout.ptPageEdge = -1;
76 if(rightMargin() == -1)
77 m_pageLayout.ptRight = 0; // never leave this object in an illegal state
78}
79void KWPage::setRightMargin(const double &r) {
80 m_pageLayout.ptRight = r == m_parent->m_defaultPageLayout.ptRight ? -1 : r;
81 m_pageLayout.ptBindingSide = -1;
82 m_pageLayout.ptPageEdge = -1;
83 if(leftMargin() == -1)
84 m_pageLayout.ptLeft = 0; // never leave this object in an illegal state
85}
86
87double KWPage::topMargin() const {
88 if(m_pageLayout.ptTop != -1)
89 return m_pageLayout.ptTop;
90 return m_parent->m_defaultPageLayout.ptTop;
91}
92double KWPage::bottomMargin() const {
93 if(m_pageLayout.ptBottom != -1)
94 return m_pageLayout.ptBottom;
95 return m_parent->m_defaultPageLayout.ptBottom;
96}
97double KWPage::leftMargin() const {
98 // first try local left.
99 if(m_pageLayout.ptLeft != -1)
100 return m_pageLayout.ptLeft;
101
102 // then see if the margin is in use.
103 double answer = m_pageSide == Right ? marginClosestBinding() : pageEdgeMargin();
104 if(answer != -1)
105 return answer;
106 return m_parent->m_defaultPageLayout.ptLeft;
107}
108double KWPage::rightMargin() const {
109 if(m_pageLayout.ptRight != -1)
110 return m_pageLayout.ptRight;
111
112 double answer = m_pageSide == Left ? marginClosestBinding() : pageEdgeMargin();
113 if(answer != -1)
114 return answer;
115 return m_parent->m_defaultPageLayout.ptRight;
116}
118 if(m_pageLayout.ptPageEdge != -1)
119 return m_pageLayout.ptPageEdge;
120 return m_parent->m_defaultPageLayout.ptPageEdge;
121}
123 if(m_pageLayout.ptBindingSide != -1)
124 return m_pageLayout.ptBindingSide;
125 return m_parent->m_defaultPageLayout.ptBindingSide;
126}
127
128double KWPage::offsetInDocument() const { // the y coordinate
129 return m_parent->topOfPage(m_pageNum);
130}
131
132TQRect KWPage::zoomedRect(KoZoomHandler *zoomHandler) {
133 return TQRect(0, zoomHandler->zoomItY(offsetInDocument()),
134 zoomHandler->zoomItX(width()), zoomHandler->zoomItY(height()));
135}
136
137const KoRect KWPage::rect() const {
138 return KoRect(0, offsetInDocument(), width(), height());
139}
The Page Manager manages all the pages a document contains and separates all the frames the document ...
void setMarginClosestBinding(const double &y)
set width of the margin that is the closest to the binding, i.e.
Definition KWPage.cpp:67
void setRightMargin(const double &r)
set width of the right margin.
Definition KWPage.cpp:79
void setTopMargin(const double &x)
set height of the top margin in pt
Definition KWPage.cpp:56
void setBottomMargin(const double &y)
set height of the bottom margin in pt
Definition KWPage.cpp:59
double height() const
return the height of this page (in pt)
Definition KWPage.cpp:44
void setLeftMargin(const double &l)
set width of the left margin.
Definition KWPage.cpp:72
double leftMargin() const
return the width of the margin at left (in pt);
Definition KWPage.cpp:97
void setHeight(const double &y)
set the height of the page in pt
Definition KWPage.cpp:53
void setWidth(const double &x)
set the width of the page in pt
Definition KWPage.cpp:50
double topMargin() const
return the height of the margin at top (in pt);
Definition KWPage.cpp:87
double bottomMargin() const
return the height of the margin at bottom (in pt);
Definition KWPage.cpp:92
void setPageEdgeMargin(const double &x)
set width of the margin that is the closest to the page edge, i.e.
Definition KWPage.cpp:62
double pageEdgeMargin() const
return width of the margin that is the closest to the page edge, i.e. left for even pages
Definition KWPage.cpp:117
double marginClosestBinding() const
return width of the margin that is the closest to the binding, i.e. right for even pages
Definition KWPage.cpp:122
double width() const
return the width of this page (in pt)
Definition KWPage.cpp:38
double rightMargin() const
return the width of the margin at left (in pt);
Definition KWPage.cpp:108
double offsetInDocument() const
All Pages are in a document-wide coordinate system that simply puts every page under the next page an...
Definition KWPage.cpp:128
TQRect zoomedRect(KoZoomHandler *zoomHandler)
return a TQRect with the size of this page in pixels.
Definition KWPage.cpp:132
const KoRect rect() const
return a KoRect with the (pt) sizes of this page. Margins are ignored for this function.
Definition KWPage.cpp:137