korganizer
journalprint.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef KORG_NOPRINTER
00026
00027 #include "journalprint.h"
00028
00029 #include "calprintpluginbase.h"
00030 #include <libkcal/journal.h>
00031 #include <libkcal/calendar.h>
00032 #include <libkdepim/kdateedit.h>
00033 #include <kconfig.h>
00034 #include <kdebug.h>
00035
00036 #include <qbuttongroup.h>
00037
00038 #include "calprintjournalconfig_base.h"
00039
00040
00041 class JournalPrintFactory : public KOrg::PrintPluginFactory {
00042 public:
00043 KOrg::PrintPlugin *create() { return new CalPrintJournal; }
00044 };
00045
00046 K_EXPORT_COMPONENT_FACTORY( libkorg_journalprint, JournalPrintFactory )
00047
00048
00049
00050
00051
00052
00053 QWidget *CalPrintJournal::createConfigWidget( QWidget *w )
00054 {
00055 return new CalPrintJournalConfig_Base( w );
00056 }
00057
00058 void CalPrintJournal::readSettingsWidget()
00059 {
00060 CalPrintJournalConfig_Base *cfg =
00061 dynamic_cast<CalPrintJournalConfig_Base*>( mConfigWidget );
00062 if ( cfg ) {
00063 mFromDate = cfg->mFromDate->date();
00064 mToDate = cfg->mToDate->date();
00065 mUseDateRange = (cfg->mDateRangeGroup->selectedId() == 1);
00066 }
00067 }
00068
00069 void CalPrintJournal::setSettingsWidget()
00070 {
00071 CalPrintJournalConfig_Base *cfg =
00072 dynamic_cast<CalPrintJournalConfig_Base*>( mConfigWidget );
00073 if ( cfg ) {
00074 cfg->mFromDate->setDate( mFromDate );
00075 cfg->mToDate->setDate( mToDate );
00076
00077 cfg->mDateRangeGroup->setButton( (mUseDateRange)?1:0 );
00078 }
00079 }
00080
00081 void CalPrintJournal::loadConfig()
00082 {
00083 if ( mConfig ) {
00084 mUseDateRange = mConfig->readBoolEntry( "JournalsInRange", false );
00085 }
00086 setSettingsWidget();
00087 }
00088
00089 void CalPrintJournal::saveConfig()
00090 {
00091 kdDebug(5850) << "CalPrintJournal::saveConfig()" << endl;
00092
00093 readSettingsWidget();
00094 if ( mConfig ) {
00095 mConfig->writeEntry( "JournalsInRange", mUseDateRange );
00096 }
00097 }
00098
00099 void CalPrintJournal::setDateRange( const QDate& from, const QDate& to )
00100 {
00101 CalPrintPluginBase::setDateRange( from, to );
00102 CalPrintJournalConfig_Base *cfg =
00103 dynamic_cast<CalPrintJournalConfig_Base*>( mConfigWidget );
00104 if ( cfg ) {
00105 cfg->mFromDate->setDate( from );
00106 cfg->mToDate->setDate( to );
00107 }
00108 }
00109
00110 void CalPrintJournal::print( QPainter &p, int width, int height )
00111 {
00112 int x=0, y=0;
00113 Journal::List journals( mCalendar->journals() );
00114 if ( mUseDateRange ) {
00115 Journal::List allJournals = journals;
00116 journals.clear();
00117 Journal::List::Iterator it = allJournals.begin();
00118 for ( ; it != allJournals.end(); ++it ) {
00119 QDate dt = (*it)->dtStart().date();
00120 if ( mFromDate <= dt && dt <= mToDate ) {
00121 journals.append( *it );
00122 }
00123 }
00124 }
00125
00126 drawHeader( p, i18n("Journal entries"), QDate(), QDate(), QRect( 0, 0, width, headerHeight() ) );
00127 y = headerHeight() + 15;
00128
00129 Journal::List::Iterator it = journals.begin();
00130 for ( ; it != journals.end(); ++it ) {
00131 drawJournal( *it, p, x, y, width, height );
00132 }
00133 }
00134
00135 #endif
|