korganizer

calprinter.cpp
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 As a special exception, permission is given to link this program
22 with any edition of TQt, and distribute the resulting executable,
23 without including the source code for TQt in the source distribution.
24*/
25
26#include <tqvbuttongroup.h>
27#include <tqwidgetstack.h>
28#include <tqradiobutton.h>
29#include <tqlayout.h>
30#include <tqpushbutton.h>
31#include <tqcombobox.h>
32#include <tqlabel.h>
33#include <tqvbox.h>
34#include <tqsplitter.h>
35
36#include <kprinter.h>
37#include <ksimpleconfig.h>
38#include <kdebug.h>
39#include <tdeversion.h>
40
41#include "korganizer/corehelper.h"
42
43#include "calprinter.h"
44#ifndef KORG_NOPRINTER
45#include "calprinter.moc"
46
47#include "calprintdefaultplugins.h"
48
49CalPrinter::CalPrinter( TQWidget *parent, Calendar *calendar, KOrg::CoreHelper *helper )
50 : TQObject( parent, "CalPrinter" )
51{
52 mParent = parent;
53 mConfig = new KSimpleConfig( "korganizer_printing.rc" );
54 mCoreHelper = helper;
55
56 init( calendar );
57}
58
59CalPrinter::~CalPrinter()
60{
61 kdDebug(5850) << "~CalPrinter()" << endl;
62
63 mPrintPlugins.clear();
64
65 delete mConfig;
66}
67
68void CalPrinter::init( Calendar *calendar )
69{
70 mCalendar = calendar;
71
72 mPrintPlugins.clear();
73 mPrintPlugins.setAutoDelete( true );
74
75 mPrintPlugins = mCoreHelper->loadPrintPlugins();
76 mPrintPlugins.prepend( new CalPrintTodos() );
77 mPrintPlugins.prepend( new CalPrintMonth() );
78 mPrintPlugins.prepend( new CalPrintWeek() );
79 mPrintPlugins.prepend( new CalPrintDay() );
80 mPrintPlugins.prepend( new CalPrintIncidence() );
81
82 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
83 for ( ; it != mPrintPlugins.end(); ++it ) {
84 if ( *it ) {
85 (*it)->setConfig( mConfig );
86 (*it)->setCalendar( mCalendar );
87 (*it)->setKOrgCoreHelper( mCoreHelper );
88 (*it)->doLoadConfig();
89 }
90 }
91}
92
93void CalPrinter::setDateRange( const TQDate &fd, const TQDate &td )
94{
95 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
96 for ( ; it != mPrintPlugins.end(); ++it ) {
97 (*it)->setDateRange( fd, td );
98 }
99}
100
101void CalPrinter::print( int type, const TQDate &fd, const TQDate &td,
102 Incidence::List selectedIncidences, bool preview )
103{
104 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
105 for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
106 (*it)->setSelectedIncidences( selectedIncidences );
107 }
108 CalPrintDialog printDialog( mPrintPlugins, mParent );
109 printDialog.setOrientation( CalPrinter::ePrintOrientation( mConfig->readNumEntry("Orientation", 1 ) ) );
110 printDialog.setPreview( preview );
111 printDialog.setPrintType( type );
112 setDateRange( fd, td );
113
114 if ( printDialog.exec() == TQDialog::Accepted ) {
115 mConfig->writeEntry( "Orientation", printDialog.orientation() );
116
117 // Save all changes in the dialog
118 for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
119 (*it)->doSaveConfig();
120 }
121 doPrint( printDialog.selectedPlugin(), printDialog.orientation(), preview );
122 }
123 for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
124 (*it)->setSelectedIncidences( Incidence::List() );
125 }
126}
127
128void CalPrinter::doPrint( KOrg::PrintPlugin *selectedStyle,
129 CalPrinter::ePrintOrientation dlgorientation, bool preview )
130{
131 if ( !selectedStyle ) {
132 KMessageBox::error( mParent,
133 i18n("Unable to print, no valid print style was returned."),
134 i18n("Printing error") );
135 return;
136 }
137 KPrinter printer;
138
139 printer.setPreviewOnly( preview );
140 switch ( dlgorientation ) {
141 case eOrientPlugin:
142 printer.setOrientation( selectedStyle->defaultOrientation() );
143 break;
144 case eOrientPortrait:
145 printer.setOrientation( KPrinter::Portrait );
146 break;
147 case eOrientLandscape:
148 printer.setOrientation( KPrinter::Landscape );
149 break;
150 case eOrientPrinter:
151 default:
152 break;
153 }
154
155 if ( preview || printer.setup( mParent, i18n("Print Calendar") ) ) {
156 selectedStyle->doPrint( &printer );
157 }
158}
159
161
162void CalPrinter::updateConfig()
163{
164}
165
166
167
168/****************************************************************************/
169
170CalPrintDialog::CalPrintDialog( KOrg::PrintPlugin::List plugins,
171 TQWidget *parent, const char *name )
172 : KDialogBase( parent, name, /*modal*/true, i18n("Print"), Ok | Cancel )
173{
174 TQVBox *page = makeVBoxMainWidget();
175
176 TQSplitter *splitter = new TQSplitter( page );
177 splitter->setOrientation( TQt::Horizontal );
178
179 mTypeGroup = new TQVButtonGroup( i18n("Print Style"), splitter, "buttonGroup" );
180 // use the minimal width possible = max width of the radio buttons, not extensible
181/* mTypeGroup->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)4,
182 (TQSizePolicy::SizeType)5, 0, 0,
183 mTypeGroup->sizePolicy().hasHeightForWidth() ) );*/
184
185 TQWidget *splitterRight = new TQWidget( splitter, "splitterRight" );
186 TQGridLayout *splitterRightLayout = new TQGridLayout( splitterRight );
187 splitterRightLayout->setMargin( marginHint() );
188 splitterRightLayout->setSpacing( spacingHint() );
189
190 mConfigArea = new TQWidgetStack( splitterRight, "configWidgetStack" );
191 splitterRightLayout->addMultiCellWidget( mConfigArea, 0,0, 0,1 );
192
193 TQLabel *orientationLabel = new TQLabel( i18n("Page &orientation:"),
194 splitterRight, "orientationLabel" );
195 splitterRightLayout->addWidget( orientationLabel, 1, 0 );
196
197 mOrientationSelection = new TQComboBox( splitterRight, "orientationCombo" );
198 mOrientationSelection->insertItem( i18n("Use Default Orientation of Selected Style") );
199 mOrientationSelection->insertItem( i18n("Use Printer Default") );
200 mOrientationSelection->insertItem( i18n("Portrait") );
201 mOrientationSelection->insertItem( i18n("Landscape") );
202 splitterRightLayout->addWidget( mOrientationSelection, 1, 1 );
203
204 // signals and slots connections
205 connect( mTypeGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( setPrintType( int ) ) );
206 orientationLabel->setBuddy( mOrientationSelection );
207
208 // First insert the config widgets into the widget stack. This possibly assigns
209 // proper ids (when two plugins have the same sortID), so store them in a map
210 // and use these new IDs to later sort the plugins for the type selection.
211 for ( KOrg::PrintPlugin::List::Iterator it = plugins.begin();
212 it != plugins.end(); ++it ) {
213 int newid = mConfigArea->addWidget( (*it)->configWidget( mConfigArea ), (*it)->sortID() );
214 mPluginIDs[newid] = (*it);
215 }
216 // Insert all plugins with in sorted order; plugins with clashing IDs will be first...
217 TQMap<int, KOrg::PrintPlugin*>::ConstIterator mapit;
218 for ( mapit = mPluginIDs.begin(); mapit != mPluginIDs.end(); ++mapit ) {
219 KOrg::PrintPlugin *p = mapit.data();
220 TQRadioButton *radioButton = new TQRadioButton( p->description(), mTypeGroup );
221 radioButton->setEnabled( p->enabled() );
222 mTypeGroup->insert( radioButton, mapit.key() );
223// radioButton->setMinimumHeight( radioButton->sizeHint().height() - 5 );
224 }
225
226 setMinimumSize( minimumSizeHint() );
227 resize( minimumSizeHint() );
228}
229
230CalPrintDialog::~CalPrintDialog()
231{
232}
233
234void CalPrintDialog::setPreview(bool preview)
235{
236#if KDE_IS_VERSION( 3, 1, 93 )
237 setButtonOK( preview ? i18n("&Preview") : KStdGuiItem::print() );
238#else
239 setButtonOKText( preview ? i18n("&Preview") : i18n("&Print...") );
240#endif
241}
242
243void CalPrintDialog::setPrintType( int i )
244{
245 mTypeGroup->setButton( i );
246 mConfigArea->raiseWidget( i );
247}
248
249void CalPrintDialog::setOrientation( CalPrinter::ePrintOrientation orientation )
250{
251 mOrientation = orientation;
252 mOrientationSelection->setCurrentItem( mOrientation );
253}
254
255KOrg::PrintPlugin *CalPrintDialog::selectedPlugin()
256{
257 int id = mTypeGroup->selectedId();
258 if ( mPluginIDs.contains( id ) ) {
259 return mPluginIDs[id];
260 } else {
261 return 0;
262 }
263}
264
265void CalPrintDialog::slotOk()
266{
267 mOrientation = (CalPrinter::ePrintOrientation)mOrientationSelection->currentItem();
268
269 TQMap<int, KOrg::PrintPlugin*>::Iterator it = mPluginIDs.begin();
270 for ( ; it != mPluginIDs.end(); ++it ) {
271 if ( it.data() )
272 it.data()->readSettingsWidget();
273 }
274
275 KDialogBase::slotOk();
276}
277
278#endif
CalPrinter(TQWidget *par, Calendar *cal, KOrg::CoreHelper *helper)
Definition: calprinter.cpp:49
void setDateRange(const TQDate &start, const TQDate &end)
Set date range to be printed.
Definition: calprinter.cpp:93
Base class for KOrganizer printing classes.
Definition: printplugin.h:52
virtual void doPrint(KPrinter *printer)=0
Actually do the printing.
virtual TQString description()=0
Returns short description of print format.
virtual KPrinter::Orientation defaultOrientation()
Orientation of printout.
Definition: printplugin.h:116
virtual bool enabled()
Returns true if the plugin should be enabled; false otherwise.
Definition: printplugin.h:91
virtual void readSettingsWidget()
Read settings from configuration widget and apply them to current object.
Definition: printplugin.h:132