-rw-r--r-- | korganizer/calprintbase.h | 379 |
1 files changed, 379 insertions, 0 deletions
diff --git a/korganizer/calprintbase.h b/korganizer/calprintbase.h new file mode 100644 index 0000000..7409143 --- a/dev/null +++ b/korganizer/calprintbase.h | |||
@@ -0,0 +1,379 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | |||
4 | Copyright (c) 1998 Preston Brown | ||
5 | Copyright (c) 2003 Reinhold Kainhofer <reinhold@kainhofer.com> | ||
6 | |||
7 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | ||
11 | |||
12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software | ||
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
20 | |||
21 | As a special exception, permission is given to link this program | ||
22 | with any edition of Qt, and distribute the resulting executable, | ||
23 | without including the source code for Qt in the source distribution. | ||
24 | */ | ||
25 | #ifndef CALPRINTBASE_H | ||
26 | #define CALPRINTBASE_H | ||
27 | // #define KORG_NOPRINTER | ||
28 | |||
29 | #ifndef KORG_NOPRINTER | ||
30 | |||
31 | #include <qwidget.h> | ||
32 | #include <qdatetime.h> | ||
33 | #include <kprinter.h> | ||
34 | #include <kconfig.h> | ||
35 | #include <libkcal/event.h> | ||
36 | |||
37 | class PrintCellItem; | ||
38 | |||
39 | namespace KCal { | ||
40 | class Calendar; | ||
41 | class Todo; | ||
42 | } | ||
43 | |||
44 | using namespace KCal; | ||
45 | |||
46 | /** | ||
47 | Base class for KOrganizer printing classes. Each sub class represents one | ||
48 | calendar print format. | ||
49 | */ | ||
50 | class CalPrintBase : public QObject | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | public: | ||
54 | /** | ||
55 | Constructor | ||
56 | |||
57 | \param pr KPrinter object used to print. | ||
58 | \param cal Calendar to be printed. | ||
59 | \param cfg KConfig object for reading/writing printing configuration | ||
60 | */ | ||
61 | CalPrintBase( KPrinter *pr, Calendar *cal, KConfig *cfg ); | ||
62 | virtual ~CalPrintBase(); | ||
63 | |||
64 | /** | ||
65 | Returns short description of print format. | ||
66 | */ | ||
67 | virtual QString description() = 0; | ||
68 | /** | ||
69 | Returns long description of print format. | ||
70 | */ | ||
71 | virtual QString longDescription() = 0; | ||
72 | |||
73 | /** | ||
74 | Returns widget for configuring the print format. | ||
75 | */ | ||
76 | virtual QWidget *configWidget( QWidget * ); | ||
77 | |||
78 | /** | ||
79 | Actually do the printing. | ||
80 | |||
81 | \param p QPainter the print result is painted to | ||
82 | \param width Width of printable area | ||
83 | \param height Height of printable area | ||
84 | */ | ||
85 | virtual void print( QPainter &p, int width, int height ) = 0; | ||
86 | /** | ||
87 | Start printing. | ||
88 | */ | ||
89 | virtual void doPrint(); | ||
90 | |||
91 | /** | ||
92 | Orientation of printout. Default is Portrait. If your plugin wants | ||
93 | to use some other orientation as default (e.g. depending on some | ||
94 | config settings), implement this function in your subclass and | ||
95 | return the desired orientation. | ||
96 | */ | ||
97 | virtual KPrinter::Orientation orientation() { return KPrinter::Portrait; } | ||
98 | |||
99 | /** | ||
100 | Load print format configuration from config file. | ||
101 | */ | ||
102 | virtual void loadConfig() = 0; | ||
103 | /** | ||
104 | Write print format configuration to config file. | ||
105 | */ | ||
106 | virtual void saveConfig() = 0; | ||
107 | |||
108 | /** | ||
109 | Load complete config. This also calls loadConfig() of the derived class. | ||
110 | */ | ||
111 | void doLoadConfig(); | ||
112 | /** | ||
113 | Save complete config. This also calls saveConfig() of the derived class. | ||
114 | */ | ||
115 | void doSaveConfig(); | ||
116 | |||
117 | |||
118 | public slots: | ||
119 | /** | ||
120 | Read settings from configuration widget and apply them to current object. | ||
121 | */ | ||
122 | virtual void readSettingsWidget() {} | ||
123 | /** | ||
124 | Set configuration widget to reflect settings of current object. | ||
125 | */ | ||
126 | virtual void setSettingsWidget() {} | ||
127 | |||
128 | /** | ||
129 | Set date range which should be printed. | ||
130 | */ | ||
131 | virtual void setDateRange( const QDate &from, const QDate &to ) | ||
132 | { | ||
133 | mFromDate = from; | ||
134 | mToDate = to; | ||
135 | } | ||
136 | |||
137 | protected: | ||
138 | int weekdayColumn( int weekday ); | ||
139 | |||
140 | QDate mFromDate; | ||
141 | QDate mToDate; | ||
142 | bool mUseColors; | ||
143 | |||
144 | public: | ||
145 | /** | ||
146 | Internal class representing the start of a todo. | ||
147 | */ | ||
148 | class TodoParentStart; | ||
149 | |||
150 | protected: | ||
151 | /** | ||
152 | Draw the gray header bar of the printout to the QPainter. | ||
153 | It prints the given text and optionally one or two small | ||
154 | month views, as specified by the two QDate. The printed | ||
155 | text can also contain a line feed. | ||
156 | If month2 is invalid, only the month that contains month1 | ||
157 | is printed. | ||
158 | E.g. the filofax week view draws just the current month, | ||
159 | while the month view draws the previous and the next month. | ||
160 | \param p QPainter of the printout | ||
161 | \param title The string printed as the title of the page | ||
162 | (e.g. the date, date range or todo list title) | ||
163 | \param month1 Date specifying the month for the left one of | ||
164 | the small month views in the title bar. If left | ||
165 | empty, only month2 will be printed (or none, | ||
166 | it that is invalid as well). | ||
167 | \param month2 Date specifying the month for the right one of | ||
168 | the small month views in the title bar. If left | ||
169 | empty, only month1 will be printed (or none, | ||
170 | it that is invalid as well). | ||
171 | \param x x-coordinate of the upper left coordinate of the title bar | ||
172 | \param y y-coordinate of the upper left coordinate of the title bar | ||
173 | \param width width of the title bar | ||
174 | \param height height of the title bar | ||
175 | */ | ||
176 | void drawHeader( QPainter &p, QString title, | ||
177 | const QDate &month1, const QDate &month2, | ||
178 | int x, int y, int width, int height ); | ||
179 | /** | ||
180 | Draw a small calendar with the days of a month into the given area. | ||
181 | Used for example in the title bar of the sheet. | ||
182 | \param p QPainter of the printout | ||
183 | \param qd Arbitrary Date within the month to be printed. | ||
184 | \param x x-coordinate of the upper left coordinate of the small calendar | ||
185 | \param y y-coordinate of the upper left coordinate of the small calendar | ||
186 | \param width width of the small calendar | ||
187 | \param height height of the small calendar | ||
188 | */ | ||
189 | void drawSmallMonth( QPainter &p, const QDate &qd, | ||
190 | int x, int y, int width, int height ); | ||
191 | |||
192 | /** | ||
193 | Draw a horizontal bar with the weekday names of the given date range | ||
194 | in the given area of the painter. | ||
195 | This is used for the weekday-bar on top of the timetable view and the month view. | ||
196 | \param p QPainter of the printout | ||
197 | \param fromDate First date of the printed dates | ||
198 | \param toDate Last date of the printed dates | ||
199 | */ | ||
200 | void drawDaysOfWeek( QPainter &p, | ||
201 | const QDate &fromDate, const QDate &toDate, | ||
202 | int x, int y, int width, int height ); | ||
203 | /** | ||
204 | Draw a single weekday name in a box inside the given area of the painter. | ||
205 | This is called in a loop by drawDaysOfWeek. | ||
206 | \param p QPainter of the printout | ||
207 | \param qd Date of the printed day | ||
208 | */ | ||
209 | void drawDaysOfWeekBox( QPainter &p, const QDate &qd, | ||
210 | int x, int y, int width, int height ); | ||
211 | /** | ||
212 | Draw a (vertical) time scale from time fromTime to toTime inside the given area of the painter. | ||
213 | Every hour will have a one-pixel line over the whole width, every | ||
214 | half-hour the line will only span the left half of the width. | ||
215 | This is used in the day and timetable print styles | ||
216 | \param p QPainter of the printout | ||
217 | \param fromTime Start time of the time range to display | ||
218 | \param toTime End time of the time range to display | ||
219 | */ | ||
220 | void drawTimeLine( QPainter &p, | ||
221 | const QTime &fromTime, const QTime &toTime, | ||
222 | int x, int y, int width, int height ); | ||
223 | /** | ||
224 | Draw the all-day box for the agenda print view (the box on top which | ||
225 | doesn't have a time on the time scale associated). If expandable is set, | ||
226 | height is the cell height of a single cell, and the returned height will | ||
227 | be the total height used for the all-day events. If !expandable, only one | ||
228 | cell will be used, and multiple events are concatenated using ", ". | ||
229 | \param p QPainter of the printout | ||
230 | \param eventList The list of all-day events that are supposed to be printed | ||
231 | inside this box | ||
232 | \param qd The date of the currently printed day | ||
233 | \param expandable If true, height is the height of one single cell, the printout | ||
234 | will use as many cells as events in the list and return the total height | ||
235 | needed for all of them. If false, height specifies the total height | ||
236 | allowed for all events, and the events are displayed in one cell, | ||
237 | with their summaries concatenated by ", ". | ||
238 | */ | ||
239 | void drawAllDayBox( QPainter &p, Event::List &eventList, | ||
240 | const QDate &qd, bool expandable, | ||
241 | int x, int y, int width, int &height ); | ||
242 | /** | ||
243 | Draw the agenda box for the day print style (the box showing all events of that day). | ||
244 | Also draws a grid with half-hour spacing of the grid lines. | ||
245 | \param p QPainter of the printout | ||
246 | \param eventList The list of the events that are supposed to be printed | ||
247 | inside this box | ||
248 | \param qd The date of the currently printed day | ||
249 | \param expandable If true, the start and end times are adjusted to include | ||
250 | the whole range of all events of that day, not just of the given time range. | ||
251 | The height of the box will not be affected by this (but the height | ||
252 | of one hour will be scaled down so that the whole range fits into | ||
253 | the box. fromTime and toTime receive the actual time range printed | ||
254 | by this function). | ||
255 | \param fromTime Start of the time range to be printed. Might be adjusted | ||
256 | to include all events if expandable==true | ||
257 | \param toTime End of the time range to be printed. Might be adjusted | ||
258 | to include all events if expandable==true | ||
259 | */ | ||
260 | void drawAgendaDayBox( QPainter &p, Event::List &eventList, | ||
261 | const QDate &qd, bool expandable, | ||
262 | QTime &fromTime, QTime &toTime, | ||
263 | int x, int y, int width, int height); | ||
264 | |||
265 | void drawAgendaItem( PrintCellItem *item, QPainter &p, const QDate &, | ||
266 | const QDateTime &startPrintDate, | ||
267 | const QDateTime &endPrintDate, | ||
268 | float minlen, int x, int y, int width ); | ||
269 | /** | ||
270 | Draw the box containing a list of all events of the given day (with their times, | ||
271 | of course). Used in the Filofax and the month print style. | ||
272 | \param p QPainter of the printout | ||
273 | \param qd The date of the currently printed day. All events of the calendar | ||
274 | that appear on that day will be printed. | ||
275 | \param fullDate Whether the title bar of the box should contain the full | ||
276 | date string or just a short. | ||
277 | */ | ||
278 | void drawDayBox( QPainter &p, const QDate &qd, | ||
279 | int x, int y, int width, int height, | ||
280 | bool fullDate = false ); | ||
281 | /** | ||
282 | Draw the week (filofax) table of the week containing the date qd. The first | ||
283 | three days of the week will be shown in the first column (using drawDayBox), | ||
284 | the remaining four in the second column, where the last two days of the week | ||
285 | (typically Saturday and Sunday) only get half the height of the other day boxes. | ||
286 | \param p QPainter of the printout | ||
287 | \param qd Arbitrary date within the week to be printed. | ||
288 | */ | ||
289 | void drawWeek( QPainter &p, const QDate &qd, | ||
290 | int x, int y, int width, int height ); | ||
291 | /** | ||
292 | Draw the timetable view of the given time range from fromDate to toDate. | ||
293 | On the left side the time scale is printed (using drawTimeLine), then each | ||
294 | day gets one column (printed using drawAgendaDayBox), | ||
295 | and the events are displayed as boxes (like in korganizer's day/week view). | ||
296 | The first cell of each column contains the all-day events (using | ||
297 | drawAllDayBox with expandable=false). | ||
298 | The given time range cannot be expanded to include all events. | ||
299 | \param p QPainter of the printout | ||
300 | \param fromDate First day to be included in the page | ||
301 | \param toDate Last day to be included in the page | ||
302 | \param fromTime Start time of the displayed time range | ||
303 | \param toTime End time of the displayed time range | ||
304 | */ | ||
305 | void drawTimeTable( QPainter &p, const QDate &fromDate, const QDate &toDate, | ||
306 | QTime &fromTime, QTime &toTime, | ||
307 | int x, int y, int width, int height ); | ||
308 | |||
309 | /** | ||
310 | Draw the month table of the month containing the date qd. Each day gets one | ||
311 | box (using drawDayBox) that contains a list of all events on that day. They are arranged | ||
312 | in a matrix, with the first column being the first day of the | ||
313 | week (so it might display some days of the previous and the next month). | ||
314 | Above the matrix there is a bar showing the weekdays (drawn using drawDaysOfWeek). | ||
315 | \param p QPainter of the printout | ||
316 | \param qd Arbitrary date within the month to be printed. | ||
317 | \param weeknumbers Whether the week numbers are printed left of each row of the matrix | ||
318 | */ | ||
319 | void drawMonth( QPainter &p, const QDate &qd, bool weeknumbers, | ||
320 | int x, int y, int width, int height ); | ||
321 | |||
322 | /** | ||
323 | Draws single todo item and its (intented) subitems, optionally connects them by a tree-like line, | ||
324 | and optionally shows due date, summary, description and priority. | ||
325 | \param count The number of the currently printed todo (count will be incremented for each drawn item) | ||
326 | \param item The item to be printed. It's subitems are recursively | ||
327 | drawn, so drawTodo should only be called on the | ||
328 | items of the highest level. | ||
329 | \param p QPainter of the printout | ||
330 | \param connectSubTodos Whether subtodos shall be connected with their parent by a line (tree-like). | ||
331 | \param desc Whether to print the whole description of the item (the summary is always printed). | ||
332 | \param pospriority x-coordinate where the priority is supposed to be printed. If <0, no priority will be printed. | ||
333 | \param possummary x-coordinate where the summary of the item is supposed to be printed. | ||
334 | \param posDueDt x-coordinate where the due date is supposed to the be printed. If <0, no due date will be printed. | ||
335 | \param level Level of the current item in the todo hierarchy (0 means highest | ||
336 | level of printed items, 1 are their subtodos, etc.) | ||
337 | \param x x-coordinate of the upper left coordinate of the first item | ||
338 | \param y y-coordinate of the upper left coordinate of the first item | ||
339 | \param width width of the whole todo list | ||
340 | \param height Space left on the first page of the todo list | ||
341 | \param pageHeight Total height allowed for the todo list on a page. The first page uses height, | ||
342 | but at each line break the current position is reset to 0 and the | ||
343 | height is set to pageHeight. | ||
344 | \param r Internal (used when printing sub items to give information about its parent) | ||
345 | */ | ||
346 | void drawTodo( bool completed, int &count, Todo * item, QPainter &p, bool connectSubTodos, | ||
347 | bool desc, int pospriority, int possummary, int posDueDt, | ||
348 | int level, int x, int &y, int width, int &height, | ||
349 | int pageHeight, TodoParentStart *r = 0 ); | ||
350 | |||
351 | void drawSplitWeek( QPainter &p, const QDate &fd, const QDate &td ); | ||
352 | void drawSplitHeaderRight( QPainter &p, const QDate &fd, const QDate &td, | ||
353 | const QDate &cd, int width, int height ); | ||
354 | void drawSplitDay( QPainter &p, const QDate &qd, int width, int height, | ||
355 | int offsetLeft ); | ||
356 | void drawSplitTimes( QPainter &p, int width, int timeWidth, int height ); | ||
357 | |||
358 | /** | ||
359 | Determines the column of the given weekday ( 1=Monday, 7=Sunday ), taking the | ||
360 | start of the week setting into account as given in kcontrol. | ||
361 | \param weekday Index of the weekday | ||
362 | */ | ||
363 | int weekDayColumn( int weekday ); | ||
364 | |||
365 | KPrinter *mPrinter; | ||
366 | Calendar *mCalendar; | ||
367 | KConfig *mConfig; | ||
368 | //QWidget *mConfigWidget; | ||
369 | |||
370 | protected: | ||
371 | // TODO_RK: move these to the appropriate subclasses or set them globally. | ||
372 | static int mSubHeaderHeight; | ||
373 | static int mHeaderHeight; | ||
374 | static int mMargin; | ||
375 | }; | ||
376 | |||
377 | #endif | ||
378 | |||
379 | #endif | ||