journalprint.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #ifndef KORG_NOPRINTER
26 
27 #include "journalprint.h"
28 
29 #include "calprintpluginbase.h"
30 #include <libkcal/journal.h>
31 #include <libkcal/calendar.h>
32 #include <libtdepim/kdateedit.h>
33 #include <tdeconfig.h>
34 #include <kdebug.h>
35 
36 #include <tqbuttongroup.h>
37 
38 #include "calprintjournalconfig_base.h"
39 
40 
41 class JournalPrintFactory : public KOrg::PrintPluginFactory {
42  public:
43  KOrg::PrintPlugin *create() { return new CalPrintJournal; }
44 };
45 
46 K_EXPORT_COMPONENT_FACTORY( libkorg_journalprint, JournalPrintFactory )
47 
48 
49 /**************************************************************
50  * Print Journal
51  **************************************************************/
52 
53 TQWidget *CalPrintJournal::createConfigWidget( TQWidget *w )
54 {
55  return new CalPrintJournalConfig_Base( w );
56 }
57 
58 void CalPrintJournal::readSettingsWidget()
59 {
60  CalPrintJournalConfig_Base *cfg =
61  dynamic_cast<CalPrintJournalConfig_Base*>( mConfigWidget );
62  if ( cfg ) {
63  mFromDate = cfg->mFromDate->date();
64  mToDate = cfg->mToDate->date();
65  mUseDateRange = (cfg->mDateRangeGroup->selectedId() == 1);
66  }
67 }
68 
69 void CalPrintJournal::setSettingsWidget()
70 {
71  CalPrintJournalConfig_Base *cfg =
72  dynamic_cast<CalPrintJournalConfig_Base*>( mConfigWidget );
73  if ( cfg ) {
74  cfg->mFromDate->setDate( mFromDate );
75  cfg->mToDate->setDate( mToDate );
76 
77  cfg->mDateRangeGroup->setButton( (mUseDateRange)?1:0 );
78  }
79 }
80 
81 void CalPrintJournal::loadConfig()
82 {
83  if ( mConfig ) {
84  mUseDateRange = mConfig->readBoolEntry( "JournalsInRange", false );
85  }
86  setSettingsWidget();
87 }
88 
89 void CalPrintJournal::saveConfig()
90 {
91  kdDebug(5850) << "CalPrintJournal::saveConfig()" << endl;
92 
93  readSettingsWidget();
94  if ( mConfig ) {
95  mConfig->writeEntry( "JournalsInRange", mUseDateRange );
96  }
97 }
98 
99 void CalPrintJournal::setDateRange( const TQDate& from, const TQDate& to )
100 {
102  CalPrintJournalConfig_Base *cfg =
103  dynamic_cast<CalPrintJournalConfig_Base*>( mConfigWidget );
104  if ( cfg ) {
105  cfg->mFromDate->setDate( from );
106  cfg->mToDate->setDate( to );
107  }
108 }
109 
110 void CalPrintJournal::print( TQPainter &p, int width, int height )
111 {
112  int x=0, y=0;
113  Journal::List journals( mCalendar->journals() );
114  if ( mUseDateRange ) {
115  Journal::List allJournals = journals;
116  journals.clear();
117  Journal::List::Iterator it = allJournals.begin();
118  for ( ; it != allJournals.end(); ++it ) {
119  TQDate dt = (*it)->dtStart().date();
120  if ( mFromDate <= dt && dt <= mToDate ) {
121  journals.append( *it );
122  }
123  }
124  }
125 
126  TQRect headerBox( 0, 0, width, headerHeight() );
127  TQRect footerBox( 0, height - footerHeight(), width, footerHeight() );
128  height -= footerHeight();
129 
130  drawHeader( p, i18n("Journal entries"), TQDate(), TQDate(), headerBox );
131  y = headerHeight() + 15;
132 
133  Journal::List::Iterator it = journals.begin();
134  for ( ; it != journals.end(); ++it ) {
135  drawJournal( *it, p, x, y, width, height );
136  }
137 
138  drawFooter( p, footerBox );
139 }
140 
141 #endif
Base class for KOrganizer printing classes.
Definition: printplugin.h:52
virtual void setDateRange(const TQDate &from, const TQDate &to)
Set date range which should be printed.
Definition: printplugin.h:141