26 #include <tqvbuttongroup.h>
27 #include <tqwidgetstack.h>
28 #include <tqradiobutton.h>
30 #include <tqpushbutton.h>
31 #include <tqcombobox.h>
34 #include <tqsplitter.h>
37 #include <ksimpleconfig.h>
39 #include <tdeversion.h>
41 #include "korganizer/corehelper.h"
43 #include "calprinter.h"
44 #ifndef KORG_NOPRINTER
45 #include "calprinter.moc"
47 #include "calprintdefaultplugins.h"
50 : TQObject( parent,
"CalPrinter" )
53 mConfig =
new KSimpleConfig(
"korganizer_printing.rc" );
59 CalPrinter::~CalPrinter()
61 kdDebug(5850) <<
"~CalPrinter()" << endl;
63 mPrintPlugins.clear();
68 void CalPrinter::init(
Calendar *calendar )
72 mPrintPlugins.clear();
73 mPrintPlugins.setAutoDelete(
true );
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() );
82 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
83 for ( ; it != mPrintPlugins.end(); ++it ) {
85 (*it)->setConfig( mConfig );
86 (*it)->setCalendar( mCalendar );
87 (*it)->setKOrgCoreHelper( mCoreHelper );
88 (*it)->doLoadConfig();
95 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
96 for ( ; it != mPrintPlugins.end(); ++it ) {
97 (*it)->setDateRange( fd, td );
101 void CalPrinter::print(
int type,
const TQDate &fd,
const TQDate &td,
102 Incidence::List selectedIncidences,
bool preview )
104 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
105 for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
106 (*it)->setSelectedIncidences( selectedIncidences );
108 CalPrintDialog printDialog( mPrintPlugins, mParent );
109 printDialog.setOrientation( CalPrinter::ePrintOrientation( mConfig->readNumEntry(
"Orientation", 1 ) ) );
110 printDialog.setPreview( preview );
111 printDialog.setPrintType( type );
114 if ( printDialog.exec() == TQDialog::Accepted ) {
115 mConfig->writeEntry(
"Orientation", printDialog.orientation() );
118 for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
119 (*it)->doSaveConfig();
121 doPrint( printDialog.selectedPlugin(), printDialog.orientation(), preview );
123 for ( it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it ) {
124 (*it)->setSelectedIncidences( Incidence::List() );
129 CalPrinter::ePrintOrientation dlgorientation,
bool preview )
131 if ( !selectedStyle ) {
132 KMessageBox::error( mParent,
133 i18n(
"Unable to print, no valid print style was returned."),
134 i18n(
"Printing error") );
139 printer.setPreviewOnly( preview );
140 switch ( dlgorientation ) {
144 case eOrientPortrait:
145 printer.setOrientation( KPrinter::Portrait );
147 case eOrientLandscape:
148 printer.setOrientation( KPrinter::Landscape );
155 if ( preview || printer.setup( mParent, i18n(
"Print Calendar") ) ) {
156 selectedStyle->
doPrint( &printer );
162 void CalPrinter::updateConfig()
170 CalPrintDialog::CalPrintDialog( KOrg::PrintPlugin::List plugins,
171 TQWidget *parent,
const char *name )
172 : KDialogBase( parent, name, true, i18n(
"Print"), Ok | Cancel )
174 TQVBox *page = makeVBoxMainWidget();
176 TQSplitter *splitter =
new TQSplitter( page );
177 splitter->setOrientation( TQt::Horizontal );
179 mTypeGroup =
new TQVButtonGroup( i18n(
"Print Style"), splitter,
"buttonGroup" );
185 TQWidget *splitterRight =
new TQWidget( splitter,
"splitterRight" );
186 TQGridLayout *splitterRightLayout =
new TQGridLayout( splitterRight );
187 splitterRightLayout->setMargin( marginHint() );
188 splitterRightLayout->setSpacing( spacingHint() );
190 mConfigArea =
new TQWidgetStack( splitterRight,
"configWidgetStack" );
191 splitterRightLayout->addMultiCellWidget( mConfigArea, 0,0, 0,1 );
193 TQLabel *orientationLabel =
new TQLabel( i18n(
"Page &orientation:"),
194 splitterRight,
"orientationLabel" );
195 splitterRightLayout->addWidget( orientationLabel, 1, 0 );
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 );
205 connect( mTypeGroup, TQ_SIGNAL( clicked(
int ) ), TQ_SLOT( setPrintType(
int ) ) );
206 orientationLabel->setBuddy( mOrientationSelection );
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);
217 TQMap<int, KOrg::PrintPlugin*>::ConstIterator mapit;
218 for ( mapit = mPluginIDs.begin(); mapit != mPluginIDs.end(); ++mapit ) {
220 TQRadioButton *radioButton =
new TQRadioButton( p->
description(), mTypeGroup );
221 radioButton->setEnabled( p->
enabled() );
222 mTypeGroup->insert( radioButton, mapit.key() );
226 setMinimumSize( minimumSizeHint() );
227 resize( minimumSizeHint() );
230 CalPrintDialog::~CalPrintDialog()
234 void CalPrintDialog::setPreview(
bool preview)
236 #if KDE_IS_VERSION( 3, 1, 93 )
237 setButtonOK( preview ? i18n(
"&Preview") : KStdGuiItem::print() );
239 setButtonOKText( preview ? i18n(
"&Preview") : i18n(
"&Print...") );
243 void CalPrintDialog::setPrintType(
int i )
245 mTypeGroup->setButton( i );
246 mConfigArea->raiseWidget( i );
249 void CalPrintDialog::setOrientation( CalPrinter::ePrintOrientation orientation )
251 mOrientation = orientation;
252 mOrientationSelection->setCurrentItem( mOrientation );
257 int id = mTypeGroup->selectedId();
258 if ( mPluginIDs.contains(
id ) ) {
259 return mPluginIDs[id];
265 void CalPrintDialog::slotOk()
267 mOrientation = (CalPrinter::ePrintOrientation)mOrientationSelection->currentItem();
269 TQMap<int, KOrg::PrintPlugin*>::Iterator it = mPluginIDs.begin();
270 for ( ; it != mPluginIDs.end(); ++it ) {
275 KDialogBase::slotOk();
CalPrinter(TQWidget *par, Calendar *cal, KOrg::CoreHelper *helper)
void setDateRange(const TQDate &start, const TQDate &end)
Set date range to be printed.
Base class for KOrganizer printing classes.
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.
virtual bool enabled()
Returns true if the plugin should be enabled; false otherwise.
virtual void readSettingsWidget()
Read settings from configuration widget and apply them to current object.