1 /* This file is part of the KDE project
2    Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3    Copyright 2003 Philipp Müller <philipp.mueller@gmx.de>
4    Copyright 1998, 1999 Torben Weis <weis@kde.org>,
5 
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10 
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15 
16    You should have received a copy of the GNU Library General Public License
17    along with this library; see the file COPYING.LIB.  If not, write to
18    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19    Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef CALLIGRA_SHEETS_HEADER_FOOTER
23 #define CALLIGRA_SHEETS_HEADER_FOOTER
24 
25 #include <KoPageLayout.h>
26 
27 #include <QString>
28 
29 #include "sheets_odf_export.h"
30 
31 namespace Calligra
32 {
33 namespace Sheets
34 {
35 class Sheet;
36 
37 class CALLIGRA_SHEETS_ODF_EXPORT HeaderFooter
38 {
39 public:
40     explicit HeaderFooter(Sheet* sheet);
41     ~HeaderFooter();
42 
headLeft(int _p,const QString & _t)43     QString headLeft(int _p, const QString &_t)const {
44         if (m_headLeft.isNull()) return "";
45         return completeHeading(m_headLeft, _p, _t);
46     }
headMid(int _p,const QString & _t)47     QString headMid(int _p, const QString &_t)const {
48         if (m_headMid.isNull()) return "";
49         return completeHeading(m_headMid, _p, _t);
50     }
headRight(int _p,const QString & _t)51     QString headRight(int _p, const QString &_t)const {
52         if (m_headRight.isNull()) return "";
53         return completeHeading(m_headRight, _p, _t);
54     }
footLeft(int _p,const QString & _t)55     QString footLeft(int _p, const QString &_t)const {
56         if (m_footLeft.isNull()) return "";
57         return completeHeading(m_footLeft, _p, _t);
58     }
footMid(int _p,const QString & _t)59     QString footMid(int _p, const QString &_t)const {
60         if (m_footMid.isNull()) return "";
61         return completeHeading(m_footMid, _p, _t);
62     }
footRight(int _p,const QString & _t)63     QString footRight(int _p, const QString &_t)const {
64         if (m_footRight.isNull()) return "";
65         return completeHeading(m_footRight, _p, _t);
66     }
67 
headLeft()68     QString headLeft()const {
69         if (m_headLeft.isNull()) return "";
70         return m_headLeft;
71     }
headMid()72     QString headMid()const {
73         if (m_headMid.isNull()) return "";
74         return m_headMid;
75     }
headRight()76     QString headRight()const {
77         if (m_headRight.isNull()) return "";
78         return m_headRight;
79     }
footLeft()80     QString footLeft()const {
81         if (m_footLeft.isNull()) return "";
82         return m_footLeft;
83     }
footMid()84     QString footMid()const {
85         if (m_footMid.isNull()) return "";
86         return m_footMid;
87     }
footRight()88     QString footRight()const {
89         if (m_footRight.isNull()) return "";
90         return m_footRight;
91     }
92 
93     /**
94      * Replaces in _text all _search text parts by _replace text parts.
95      * Included is a test to not change if _search == _replace.
96      * The arguments should not include neither the beginning "<" nor the leading ">", this is already
97      * included internally.
98      */
99     void replaceHeadFootLineMacro(QString &_text, const QString &_search, const QString &_replace) const;
100 
101     /**
102      * Replaces in _text all page macros by the i18n-version of the macros
103      */
104     QString localizeHeadFootLine(const QString &_text) const;
105 
106     /**
107      * Replaces in _text all i18n-versions of the page macros by the internal version of the macros
108      */
109     QString delocalizeHeadFootLine(const QString &_text) const;
110 
111     /**
112      * Sets the head and foot line of the print out
113      */
114     void setHeadFootLine(const QString &_headl, const QString &_headm, const QString &_headr,
115                          const QString &_footl, const QString &_footm, const QString &_footr);
116 
117 private:
118     /**
119      * Replaces macros like <name>, <file>, <date> etc. in the string and
120      * returns the modified one.
121      *
122      * @param _page is the page number for which the heading is produced.
123      * @param _Sheet is the name of the Sheet for which we generate the headings.
124      */
125     QString completeHeading(const QString &_data, int _page, const QString &_sheet) const ;
126 
127     Sheet *m_pSheet;
128 
129     /**
130      * Header string. The string may contains makros. That means
131      * it has to be processed before printing.
132      */
133     QString m_headLeft;
134 
135     /**
136      * Header string. The string may contains makros. That means
137      * it has to be processed before printing.
138      */
139     QString m_headRight;
140 
141     /**
142      * Header string. The string may contains makros. That means
143      * it has to be processed before printing.
144      */
145     QString m_headMid;
146 
147     /**
148      * Footer string. The string may contains makros. That means
149      * it has to be processed before printing.
150      */
151     QString m_footLeft;
152 
153     /**
154      * Footer string. The string may contains makros. That means
155      * it has to be processed before printing.
156      */
157     QString m_footRight;
158 
159     /**
160      * Footer string. The string may contains makros. That means
161      * it has to be processed before printing.
162      */
163     QString m_footMid;
164 };
165 
166 } // namespace Sheets
167 } // namespace Calligra
168 
169 #endif // CALLIGRA_SHEETS_HEADER_FOOTER
170