1 /* This file is part of the Calligra project
2  * Copyright (C) 2006 Sebastian Sauer <mail@dipe.org>
3  * Copyright (C) 2005, 2007-2009 Thomas Zander <zander@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef SCRIPTING_PAGE_H
22 #define SCRIPTING_PAGE_H
23 
24 #include <QObject>
25 #include <KWPage.h>
26 
27 #include "Module.h"
28 
29 namespace Scripting
30 {
31 
32 /**
33 * The Page class represents a printed page in the document.
34 */
35 class Page : public QObject
36 {
37     Q_OBJECT
38 public:
Page(Module * module,KWPage & page)39     Page(Module* module, KWPage &page)
40             : QObject(module), m_page(page) {}
~Page()41     virtual ~Page() {}
42 
43 public Q_SLOTS:
44 
45     /** Return the number of this page as it will be shown to the user. */
pageNumber()46     int pageNumber() const {
47         return m_page.pageNumber();
48     }
49 
50     /** Return the pageside of this page.
51     *
52     * The returned string could be one of the following;
53     * \li "Left" for left page used for even-numbered pages.
54     * \li "Right" for right page used for odd numbered pages.
55     * \li "Spread" for page spread which is one page that represents 2 pagenumbers.
56     */
pageSide()57     QString pageSide() const {
58         switch (m_page.pageSide()) {
59         case KWPage::Left: return "Left";
60         case KWPage::Right: return "Right";
61         case KWPage::PageSpread: return "Spread";
62         }
63         return QString();
64     }
65     /** Set the pageside of this page. See the pageSide() method above for a
66     list of valid arguments. */
setPageSide(const QString & ps)67     void setPageSide(const QString& ps) {
68         if (ps == "Left") m_page.setPageSide(KWPage::Left);
69         else if (ps == "Right") m_page.setPageSide(KWPage::Right);
70         else if (ps == "Spread") m_page.setPageSide(KWPage::PageSpread);
71     }
72 
73     /** Return the width of this page in pt. */
width()74     qreal width() const {
75         return m_page.width();
76     }
77 
78     /** Return the height of this page in pt. */
height()79     qreal height() const {
80         return m_page.height();
81     }
82 
83     /** Return the height of the margin at top in pt. */
topMargin()84     qreal topMargin() const {
85         return m_page.topMargin();
86     }
87 
88     /** Return the height of the margin at bottom in pt. */
bottomMargin()89     qreal bottomMargin() const {
90         return m_page.bottomMargin();
91     }
92 
93     /** Return the width of the margin at left in pt. */
leftMargin()94     qreal leftMargin() const {
95         return m_page.leftMargin();
96     }
97 
98     /** Return the width of the margin at right in pt. */
rightMargin()99     qreal rightMargin() const {
100         return m_page.rightMargin();
101     }
102 
103 private:
104     KWPage m_page;
105 };
106 
107 }
108 
109 #endif
110