journalprint.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 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 <libtdepim/kdateedit.h> 00033 #include <tdeconfig.h> 00034 #include <kdebug.h> 00035 00036 #include <tqbuttongroup.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 * Print Journal 00051 **************************************************************/ 00052 00053 TQWidget *CalPrintJournal::createConfigWidget( TQWidget *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 TQDate& from, const TQDate& 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( TQPainter &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 TQDate dt = (*it)->dtStart().date(); 00120 if ( mFromDate <= dt && dt <= mToDate ) { 00121 journals.append( *it ); 00122 } 00123 } 00124 } 00125 00126 TQRect headerBox( 0, 0, width, headerHeight() ); 00127 TQRect footerBox( 0, height - footerHeight(), width, footerHeight() ); 00128 height -= footerHeight(); 00129 00130 drawHeader( p, i18n("Journal entries"), TQDate(), TQDate(), headerBox ); 00131 y = headerHeight() + 15; 00132 00133 Journal::List::Iterator it = journals.begin(); 00134 for ( ; it != journals.end(); ++it ) { 00135 drawJournal( *it, p, x, y, width, height ); 00136 } 00137 00138 drawFooter( p, footerBox ); 00139 } 00140 00141 #endif