korganizer

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
41class JournalPrintFactory : public KOrg::PrintPluginFactory {
42 public:
43 KOrg::PrintPlugin *create() { return new CalPrintJournal; }
44};
45
46K_EXPORT_COMPONENT_FACTORY( libkorg_journalprint, JournalPrintFactory )
47
48
49/**************************************************************
50 * Print Journal
51 **************************************************************/
52
53TQWidget *CalPrintJournal::createConfigWidget( TQWidget *w )
54{
55 return new CalPrintJournalConfig_Base( w );
56}
57
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
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
82{
83 if ( mConfig ) {
84 mUseDateRange = mConfig->readBoolEntry( "JournalsInRange", false );
85 }
87}
88
90{
91 kdDebug(5850) << "CalPrintJournal::saveConfig()" << endl;
92
94 if ( mConfig ) {
95 mConfig->writeEntry( "JournalsInRange", mUseDateRange );
96 }
97}
98
99void 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
110void 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
virtual void loadConfig()=0
Load print format configuration from config file.
int footerHeight() const
Returns the height of the page footer.
int headerHeight() const
Returns the height of the page header.
void drawJournal(Journal *journal, TQPainter &p, int x, int &y, int width, int pageHeight)
Draws single journal item.
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 void readSettingsWidget()
Read settings from configuration widget and apply them to current object.