kword

KWPage.cpp

00001 /* This file is part of the KOffice project
00002  * Copyright (C) 2005 Thomas Zander <zander@kde.org>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; version 2.
00007 
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public License
00014  * along with this library; see the file COPYING.LIB.  If not, write to
00015  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  * Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "KWPage.h"
00020 #include "KoZoomHandler.h"
00021 
00022 #include <qrect.h>
00023 
00024 KWPage::KWPage(KWPageManager *parent, int pageNum) {
00025     m_parent = parent;
00026     m_pageNum = pageNum;
00027     m_pageLayout.ptWidth = -1.0;
00028     m_pageLayout.ptHeight = -1.0;
00029     m_pageLayout.ptLeft = -1.0;
00030     m_pageLayout.ptRight = -1.0;
00031     m_pageLayout.ptBottom = -1.0;
00032     m_pageLayout.ptTop = -1.0;
00033     m_pageLayout.ptPageEdge = -1.0;
00034     m_pageLayout.ptBindingSide = -1.0;
00035     m_pageSide = pageNum%2==0 ? Left : Right;
00036 }
00037 
00038 double KWPage::width() const {
00039     if(m_pageLayout.ptWidth != -1)
00040         return m_pageLayout.ptWidth;
00041     return m_parent->m_defaultPageLayout.ptWidth;
00042 }
00043 
00044 double KWPage::height() const {
00045     if(m_pageLayout.ptHeight != -1)
00046         return m_pageLayout.ptHeight;
00047     return m_parent->m_defaultPageLayout.ptHeight;
00048 }
00049 
00050 void KWPage::setWidth(const double &x) {
00051     m_pageLayout.ptWidth = x == m_parent->m_defaultPageLayout.ptWidth ? -1 : x;
00052 }
00053 void KWPage::setHeight(const double &y) {
00054     m_pageLayout.ptHeight = y == m_parent->m_defaultPageLayout.ptHeight ? -1 : y;
00055 }
00056 void KWPage::setTopMargin(const double &t) {
00057     m_pageLayout.ptTop = t == m_parent->m_defaultPageLayout.ptTop ? -1 : t;
00058 }
00059 void KWPage::setBottomMargin(const double &b) {
00060     m_pageLayout.ptBottom = b == m_parent->m_defaultPageLayout.ptBottom ? -1 : b;
00061 }
00062 void KWPage::setPageEdgeMargin(const double &m) {
00063     m_pageLayout.ptPageEdge = m == m_parent->m_defaultPageLayout.ptPageEdge ? -1 : m;
00064     m_pageLayout.ptLeft = -1;
00065     m_pageLayout.ptRight = -1;
00066 }
00067 void KWPage::setMarginClosestBinding(const double &m) {
00068     m_pageLayout.ptBindingSide = m == m_parent->m_defaultPageLayout.ptBindingSide ? -1 : m;
00069     m_pageLayout.ptLeft = -1;
00070     m_pageLayout.ptRight = -1;
00071 }
00072 void KWPage::setLeftMargin(const double &l) {
00073     m_pageLayout.ptLeft = l == m_parent->m_defaultPageLayout.ptLeft ? -1 : l;
00074     m_pageLayout.ptBindingSide = -1;
00075     m_pageLayout.ptPageEdge = -1;
00076     if(rightMargin() == -1)
00077         m_pageLayout.ptRight = 0; // never leave this object in an illegal state
00078 }
00079 void KWPage::setRightMargin(const double &r) {
00080     m_pageLayout.ptRight = r == m_parent->m_defaultPageLayout.ptRight ? -1 : r;
00081     m_pageLayout.ptBindingSide = -1;
00082     m_pageLayout.ptPageEdge = -1;
00083     if(leftMargin() == -1)
00084         m_pageLayout.ptLeft = 0; // never leave this object in an illegal state
00085 }
00086 
00087 double KWPage::topMargin() const {
00088     if(m_pageLayout.ptTop != -1)
00089         return m_pageLayout.ptTop;
00090     return m_parent->m_defaultPageLayout.ptTop;
00091 }
00092 double KWPage::bottomMargin() const {
00093     if(m_pageLayout.ptBottom != -1)
00094         return m_pageLayout.ptBottom;
00095     return m_parent->m_defaultPageLayout.ptBottom;
00096 }
00097 double KWPage::leftMargin() const {
00098     // first try local left.
00099     if(m_pageLayout.ptLeft != -1)
00100         return m_pageLayout.ptLeft;
00101 
00102     // then see if the margin is in use.
00103     double answer = m_pageSide == Right ? marginClosestBinding() : pageEdgeMargin();
00104     if(answer != -1)
00105         return answer;
00106     return m_parent->m_defaultPageLayout.ptLeft;
00107 }
00108 double KWPage::rightMargin() const {
00109     if(m_pageLayout.ptRight != -1)
00110         return m_pageLayout.ptRight;
00111 
00112     double answer = m_pageSide == Left ? marginClosestBinding() : pageEdgeMargin();
00113     if(answer != -1)
00114         return answer;
00115     return m_parent->m_defaultPageLayout.ptRight;
00116 }
00117 double KWPage::pageEdgeMargin() const {
00118     if(m_pageLayout.ptPageEdge != -1)
00119         return m_pageLayout.ptPageEdge;
00120     return m_parent->m_defaultPageLayout.ptPageEdge;
00121 }
00122 double KWPage::marginClosestBinding() const {
00123     if(m_pageLayout.ptBindingSide != -1)
00124         return m_pageLayout.ptBindingSide;
00125     return m_parent->m_defaultPageLayout.ptBindingSide;
00126 }
00127 
00128 double KWPage::offsetInDocument() const { // the y coordinate
00129     return m_parent->topOfPage(m_pageNum);
00130 }
00131 
00132 QRect KWPage::zoomedRect(KoZoomHandler *zoomHandler) {
00133     return QRect(0, zoomHandler->zoomItY(offsetInDocument()),
00134                  zoomHandler->zoomItX(width()), zoomHandler->zoomItY(height()));
00135 }
00136 
00137 const KoRect KWPage::rect() const {
00138     return KoRect(0, offsetInDocument(), width(), height());
00139 }
KDE Home | KDE Accessibility Home | Description of Access Keys