25 #ifndef KORG_NOPRINTER
27 #include "calprintyearconfig_base.h"
28 #include "yearprint.h"
32 #include <tdeconfig.h>
34 #include <kcalendarsystem.h>
35 #include <tdelocale.h>
37 #include <tqcheckbox.h>
38 #include <tqspinbox.h>
39 #include <tqcombobox.h>
40 #include <tqpainter.h>
42 class YearPrintFactory :
public KOrg::PrintPluginFactory {
47 K_EXPORT_COMPONENT_FACTORY( libkorg_yearlyprint, YearPrintFactory )
54 TQWidget *CalPrintYear::createConfigWidget( TQWidget *w )
56 return new CalPrintYearConfig_Base( w );
59 void CalPrintYear::readSettingsWidget()
61 CalPrintYearConfig_Base *cfg =
62 dynamic_cast<CalPrintYearConfig_Base*
>( mConfigWidget );
64 mYear = cfg->mYear->value();
65 mPages = cfg->mPages->currentText().toInt();
66 mSubDaysEvents = (cfg->mSubDays->currentItem()==0)?Text:TimeBoxes;
67 mHolidaysEvents = (cfg->mHolidays->currentItem()==0)?Text:TimeBoxes;
71 void CalPrintYear::setSettingsWidget()
73 CalPrintYearConfig_Base *cfg =
74 dynamic_cast<CalPrintYearConfig_Base*
>( mConfigWidget );
76 const KCalendarSystem *calsys = calendarSystem();
78 calsys->setYMD( start, mYear, 1, 1 );
79 int months = calsys->monthsInYear( start );
80 int pages=0, prevPages=0;
81 for (
int i=1; i<= months; ++i ) {
82 pages = (months-1)/i + 1;
83 if ( pages != prevPages ) {
85 cfg->mPages->insertItem( TQString::number( pages ), 0 );
89 cfg->mYear->setValue( mYear );
90 cfg->mPages->setCurrentText( TQString::number( mPages ) );
92 cfg->mSubDays->setCurrentItem( (mSubDaysEvents==Text)?0:1 );
93 cfg->mHolidays->setCurrentItem( (mHolidaysEvents==Text)?0:1 );
97 void CalPrintYear::loadConfig()
100 mYear = mConfig->readNumEntry(
"Year", 2007 );
101 mPages = mConfig->readNumEntry(
"Pages", 1 );
102 mSubDaysEvents = mConfig->readNumEntry(
"ShowSubDayEventsAs", TimeBoxes );
103 mHolidaysEvents = mConfig->readNumEntry(
"ShowHolidaysAs", Text );
108 void CalPrintYear::saveConfig()
110 kdDebug(5850) <<
"CalPrintYear::saveConfig()" << endl;
112 readSettingsWidget();
114 mConfig->writeEntry(
"Year", mYear );
115 mConfig->writeEntry(
"Pages", mPages );
116 mConfig->writeEntry(
"Pages", mPages );
117 mConfig->writeEntry(
"ShowSubDayEventsAs", mSubDaysEvents );
118 mConfig->writeEntry(
"ShowHolidaysAs", mHolidaysEvents );
122 KPrinter::Orientation CalPrintYear::defaultOrientation()
124 return ( mPages == 1 )?(KPrinter::Landscape):(KPrinter::Portrait);
128 void CalPrintYear::setDateRange(
const TQDate& from,
const TQDate& to )
131 CalPrintYearConfig_Base *cfg =
132 dynamic_cast<CalPrintYearConfig_Base*
>( mConfigWidget );
134 cfg->mYear->setValue( from.year() );
138 void CalPrintYear::print( TQPainter &p,
int width,
int height )
140 const KCalendarSystem *calsys = calendarSystem();
141 TDELocale *locale = TDEGlobal::locale();
142 if ( !calsys || !locale )
return;
144 TQRect headerBox( 0, 0, width, headerHeight() );
145 TQRect footerBox( 0, height - footerHeight(), width, footerHeight() );
146 height -= footerHeight();
149 calsys->setYMD( start, mYear, 1, 1 );
153 TQDate temp( start );
154 int months = calsys->monthsInYear( start );
156 for (
int i = 1; i< months; ++i ) {
157 maxdays = TQMAX( maxdays, temp.daysInMonth() );
158 temp = calsys->addMonths( temp, 1 );
163 int monthsPerPage = (months-1) / mPages + 1;
164 int pages = (months-1) / monthsPerPage + 1;
167 for (
int page = 0; page < pages; ++page ) {
171 TQDate end( calsys->addMonths( start, monthsPerPage ) );
172 end = calsys->addDays( end, -1 );
174 if ( orientation() == KPrinter::Landscape ) {
175 title = i18n(
"date from - to",
"%1 - %2");
177 title = i18n(
"date from -\nto",
"%1 -\n%2");
180 .arg( locale->formatDate( start ) )
181 .arg( locale->formatDate( end ) ),
182 calsys->addMonths( start, -1), calsys->addMonths( start, monthsPerPage ),
185 TQRect monthesBox( headerBox );
186 monthesBox.setTop( monthesBox.bottom() + padding() );
187 monthesBox.setBottom( height );
189 drawBox( p, BOX_BORDER_WIDTH, monthesBox );
190 float monthwidth = float(monthesBox.width()) / float( monthsPerPage );
192 for (
int j=0; j<monthsPerPage; ++j ) {
193 if ( ++thismonth > months )
break;
194 int xstart = int(j*monthwidth + 0.5);
195 int xend = int((j+1)*monthwidth + 0.5);
196 TQRect monthBox( xstart, monthesBox.top(), xend-xstart, monthesBox.height() );
197 drawMonth( p, temp, monthBox, maxdays, mSubDaysEvents, mHolidaysEvents );
199 temp = calsys->addMonths( temp, 1 );
202 drawFooter( p, footerBox );
203 start = calsys->addMonths( start, monthsPerPage );
Base class for KOrganizer printing classes.
virtual void setDateRange(const TQDate &from, const TQDate &to)
Set date range which should be printed.