1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/*
This file is part of KOrganizer.
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, permission is given to link this program
with any edition of TQt, and distribute the resulting executable,
without including the source code for TQt in the source distribution.
*/
#ifndef KORG_NOPRINTER
#include "calprintyearconfig_base.h"
#include "yearprint.h"
#include <libkcal/calendar.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <kcalendarsystem.h>
#include <tdelocale.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqcombobox.h>
#include <tqpainter.h>
class YearPrintFactory : public KOrg::PrintPluginFactory {
public:
KOrg::PrintPlugin *create() { return new CalPrintYear; }
};
K_EXPORT_COMPONENT_FACTORY( libkorg_yearlyprint, YearPrintFactory )
/**************************************************************
* Print Year
**************************************************************/
TQWidget *CalPrintYear::createConfigWidget( TQWidget *w )
{
return new CalPrintYearConfig_Base( w );
}
void CalPrintYear::readSettingsWidget()
{
CalPrintYearConfig_Base *cfg =
dynamic_cast<CalPrintYearConfig_Base*>( mConfigWidget );
if ( cfg ) {
mYear = cfg->mYear->value();
mPages = cfg->mPages->currentText().toInt();
mSubDaysEvents = (cfg->mSubDays->currentItem()==0)?Text:TimeBoxes;
mHolidaysEvents = (cfg->mHolidays->currentItem()==0)?Text:TimeBoxes;
}
}
void CalPrintYear::setSettingsWidget()
{
CalPrintYearConfig_Base *cfg =
dynamic_cast<CalPrintYearConfig_Base*>( mConfigWidget );
if ( cfg ) {
const KCalendarSystem *calsys = calendarSystem();
TQDate start;
calsys->setYMD( start, mYear, 1, 1 );
int months = calsys->monthsInYear( start );
int pages=0, prevPages=0;
for ( int i=1; i<= months; ++i ) {
pages = (months-1)/i + 1;
if ( pages != prevPages ) {
prevPages = pages;
cfg->mPages->insertItem( TQString::number( pages ), 0 );
}
}
cfg->mYear->setValue( mYear );
cfg->mPages->setCurrentText( TQString::number( mPages ) );
cfg->mSubDays->setCurrentItem( (mSubDaysEvents==Text)?0:1 );
cfg->mHolidays->setCurrentItem( (mHolidaysEvents==Text)?0:1 );
}
}
void CalPrintYear::loadConfig()
{
if ( mConfig ) {
mYear = mConfig->readNumEntry( "Year", 2007 );
mPages = mConfig->readNumEntry( "Pages", 1 );
mSubDaysEvents = mConfig->readNumEntry( "ShowSubDayEventsAs", TimeBoxes );
mHolidaysEvents = mConfig->readNumEntry( "ShowHolidaysAs", Text );
}
setSettingsWidget();
}
void CalPrintYear::saveConfig()
{
kdDebug(5850) << "CalPrintYear::saveConfig()" << endl;
readSettingsWidget();
if ( mConfig ) {
mConfig->writeEntry( "Year", mYear );
mConfig->writeEntry( "Pages", mPages );
mConfig->writeEntry( "Pages", mPages );
mConfig->writeEntry( "ShowSubDayEventsAs", mSubDaysEvents );
mConfig->writeEntry( "ShowHolidaysAs", mHolidaysEvents );
}
}
KPrinter::Orientation CalPrintYear::defaultOrientation()
{
return ( mPages == 1 )?(KPrinter::Landscape):(KPrinter::Portrait);
}
void CalPrintYear::setDateRange( const TQDate& from, const TQDate& to )
{
CalPrintPluginBase::setDateRange( from, to );
CalPrintYearConfig_Base *cfg =
dynamic_cast<CalPrintYearConfig_Base*>( mConfigWidget );
if ( cfg ) {
cfg->mYear->setValue( from.year() );
}
}
void CalPrintYear::print( TQPainter &p, int width, int height )
{
const KCalendarSystem *calsys = calendarSystem();
TDELocale *locale = TDEGlobal::locale();
if ( !calsys || !locale ) return;
TQRect headerBox( 0, 0, width, headerHeight() );
TQRect footerBox( 0, height - footerHeight(), width, footerHeight() );
height -= footerHeight();
TQDate start;
calsys->setYMD( start, mYear, 1, 1 );
// Determine the nr of months and the max nr of days per month (dependent on
// calendar system!!!!)
TQDate temp( start );
int months = calsys->monthsInYear( start );
int maxdays = 1;
for ( int i = 1; i< months; ++i ) {
maxdays = TQMAX( maxdays, temp.daysInMonth() );
temp = calsys->addMonths( temp, 1 );
}
// Now determine the months per page so that the printout fits on
// exactly mPages pages
int monthsPerPage = (months-1) / mPages + 1;
int pages = (months-1) / monthsPerPage + 1;
int thismonth = 0;
temp = start;
for ( int page = 0; page < pages; ++page ) {
if ( page > 0 ) {
mPrinter->newPage();
}
TQDate end( calsys->addMonths( start, monthsPerPage ) );
end = calsys->addDays( end, -1 );
TQString title;
if ( orientation() == KPrinter::Landscape ) {
title = i18n("date from - to", "%1 - %2");
} else {
title = i18n("date from -\nto", "%1 -\n%2");
}
drawHeader( p, title
.arg( locale->formatDate( start ) )
.arg( locale->formatDate( end ) ),
calsys->addMonths( start, -1), calsys->addMonths( start, monthsPerPage ),
headerBox );
TQRect monthesBox( headerBox );
monthesBox.setTop( monthesBox.bottom() + padding() );
monthesBox.setBottom( height );
drawBox( p, BOX_BORDER_WIDTH, monthesBox );
float monthwidth = float(monthesBox.width()) / float( monthsPerPage );
for ( int j=0; j<monthsPerPage; ++j ) {
if ( ++thismonth > months ) break;
int xstart = int(j*monthwidth + 0.5);
int xend = int((j+1)*monthwidth + 0.5);
TQRect monthBox( xstart, monthesBox.top(), xend-xstart, monthesBox.height() );
drawMonth( p, temp, monthBox, maxdays, mSubDaysEvents, mHolidaysEvents );
temp = calsys->addMonths( temp, 1 );
}
drawFooter( p, footerBox );
start = calsys->addMonths( start, monthsPerPage );
}
}
#endif
|