27#include "calprintyearconfig_base.h"
34#include <kcalendarsystem.h>
37#include <tqcheckbox.h>
39#include <tqcombobox.h>
42class YearPrintFactory :
public KOrg::PrintPluginFactory {
44 KOrg::PrintPlugin *create() {
return new CalPrintYear; }
47K_EXPORT_COMPONENT_FACTORY( libkorg_yearlyprint, YearPrintFactory )
54TQWidget *CalPrintYear::createConfigWidget( TQWidget *w )
56 return new CalPrintYearConfig_Base( w );
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;
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 );
100 mYear = mConfig->readNumEntry(
"Year", 2007 );
101 mPages = mConfig->readNumEntry(
"Pages", 1 );
102 mSubDaysEvents = mConfig->readNumEntry(
"ShowSubDayEventsAs", TimeBoxes );
103 mHolidaysEvents = mConfig->readNumEntry(
"ShowHolidaysAs", Text );
110 kdDebug(5850) <<
"CalPrintYear::saveConfig()" << endl;
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 );
124 return ( mPages == 1 )?(KPrinter::Landscape):(KPrinter::Portrait);
128void CalPrintYear::setDateRange(
const TQDate& from,
const TQDate& to )
131 CalPrintYearConfig_Base *cfg =
132 dynamic_cast<CalPrintYearConfig_Base*
>( mConfigWidget );
134 cfg->mYear->setValue( from.year() );
138void CalPrintYear::print( TQPainter &p,
int width,
int height )
140 const KCalendarSystem *calsys = calendarSystem();
141 TDELocale *locale = TDEGlobal::locale();
142 if ( !calsys || !locale )
return;
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 );
203 start = calsys->addMonths( start, monthsPerPage );
virtual void loadConfig()=0
Load print format configuration from config file.
int footerHeight() const
Returns the height of the page footer.
void drawMonth(TQPainter &p, const TQDate &dt, const TQRect &box, int maxdays=-1, int subDailyFlags=TimeBoxes, int holidaysFlags=Text)
Draw a vertical representation of the month containing the date dt.
static void drawBox(TQPainter &p, int linewidth, const TQRect &rect)
Draw a box with given width at the given coordinates.
int headerHeight() const
Returns the height of the page header.
int drawHeader(TQPainter &p, TQString title, const TQDate &month1, const TQDate &month2, const TQRect &box, bool expand=false)
Draw the gray header bar of the printout to the TQPainter.
virtual void saveConfig()=0
Write print format configuration to config file.
int drawFooter(TQPainter &p, TQRect &box)
Draw a page footer containing the printing date and possibly other things, like a page number.
virtual void setSettingsWidget()
Set configuration widget to reflect settings of current object.
virtual void setDateRange(const TQDate &from, const TQDate &to)
Set date range which should be printed.
virtual KPrinter::Orientation defaultOrientation()
Orientation of printout.
KPrinter * mPrinter
The printer object.
virtual void readSettingsWidget()
Read settings from configuration widget and apply them to current object.