00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <qvbuttongroup.h>
00027 #include <qwidgetstack.h>
00028 #include <qradiobutton.h>
00029 #include <qlayout.h>
00030 #include <qpushbutton.h>
00031 #include <qcombobox.h>
00032 #include <qlabel.h>
00033 #include <qvbox.h>
00034 #include <qsplitter.h>
00035
00036 #include <kprinter.h>
00037 #include <ksimpleconfig.h>
00038 #include <kdebug.h>
00039 #include <kdeversion.h>
00040
00041 #include "korganizer/corehelper.h"
00042
00043 #include "calprinthelper.h"
00044
00045 #include "calprinter.h"
00046 #ifndef KORG_NOPRINTER
00047 #include "calprinter.moc"
00048
00049 #include "calprintdefaultplugins.h"
00050
00051 CalPrinter::CalPrinter( QWidget *parent, Calendar *calendar, KOrg::CoreHelper *helper )
00052 : QObject( parent, "CalPrinter" ), mHelper( 0 )
00053 {
00054 mParent = parent;
00055 mConfig = new KSimpleConfig( "korganizer_printing.rc" );
00056 mCoreHelper = helper;
00057
00058 init( new KPrinter, calendar );
00059 }
00060
00061 CalPrinter::~CalPrinter()
00062 {
00063 kdDebug(5850) << "~CalPrinter()" << endl;
00064
00065 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00066 for ( ; it != mPrintPlugins.end(); ++it ) {
00067 (*it)->doSaveConfig();
00068 }
00069 mPrintPlugins.clear();
00070
00071 delete mConfig;
00072 delete mPrintDialog;
00073 delete mPrinter;
00074 if ( mHelper ) delete mHelper;
00075 }
00076
00077 void CalPrinter::init( KPrinter *printer, Calendar *calendar )
00078 {
00079 mCalendar = calendar;
00080 mPrinter = printer;
00081 mHelper = new CalPrintHelper( mPrinter, mCalendar, mConfig, mCoreHelper );
00082
00083 mPrintPlugins.clear();
00084 mPrintPlugins.setAutoDelete( true );
00085
00086 mPrintPlugins = mCoreHelper->loadPrintPlugins();
00087 mPrintPlugins.prepend( new CalPrintTodos() );
00088 mPrintPlugins.prepend( new CalPrintMonth() );
00089 mPrintPlugins.prepend( new CalPrintWeek() );
00090 mPrintPlugins.prepend( new CalPrintDay() );
00091
00092 mPrintDialog = new CalPrintDialog( mPrintPlugins, mPrinter, mParent );
00093
00094 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00095 for ( ; it != mPrintPlugins.end(); ++it ) {
00096 (*it)->setConfig( mConfig );
00097 (*it)->setCalendar( calendar );
00098 (*it)->setPrinter( printer );
00099 (*it)->setKOrgCoreHelper( mCoreHelper );
00100 (*it)->setCalPrintHelper( mHelper );
00101
00102 (*it)->doLoadConfig();
00103 }
00104 }
00105
00106 void CalPrinter::setDateRange( const QDate &fd, const QDate &td )
00107 {
00108 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00109 for ( ; it != mPrintPlugins.end(); ++it ) {
00110 (*it)->setDateRange( fd, td );
00111 }
00112 }
00113
00114 void CalPrinter::preview( PrintType type, const QDate &fd, const QDate &td )
00115 {
00116 mPrintDialog->setPreview( true );
00117 mPrintDialog->setPrintType( int( type ) );
00118 setDateRange( fd, td );
00119
00120 if ( mPrintDialog->exec() == QDialog::Accepted ) {
00121 doPrint( mPrintDialog->selectedPlugin(), true );
00122 }
00123 }
00124
00125 void CalPrinter::print( PrintType type, const QDate &fd, const QDate &td )
00126 {
00127 mPrintDialog->setPreview( false );
00128 mPrintDialog->setPrintType( int( type ) );
00129 setDateRange( fd, td );
00130
00131 if ( mPrintDialog->exec() == QDialog::Accepted ) {
00132 doPrint( mPrintDialog->selectedPlugin(), false );
00133 }
00134 }
00135
00136 void CalPrinter::doPrint( KOrg::PrintPlugin *selectedStyle, bool preview )
00137 {
00138 if ( mHelper ) delete mHelper;
00139 KPrinter::Orientation printerOrientation = mPrinter->orientation();
00140
00141 mHelper = new CalPrintHelper( mPrinter, mCalendar, mConfig, mCoreHelper );
00142 if ( preview ) mPrinter->setPreviewOnly( true );
00143 switch ( mPrintDialog->orientation() ) {
00144 case eOrientPlugin:
00145 mPrinter->setOrientation( selectedStyle->orientation() );
00146 break;
00147 case eOrientPortrait:
00148 mPrinter->setOrientation( KPrinter::Portrait );
00149 break;
00150 case eOrientLandscape:
00151 mPrinter->setOrientation( KPrinter::Landscape );
00152 break;
00153 case eOrientPrinter:
00154 default:
00155 break;
00156 }
00157
00158 if ( preview || mPrinter->setup( mParent, i18n("Print Calendar") ) ) {
00159 selectedStyle->setKOrgCoreHelper( mCoreHelper );
00160 selectedStyle->setCalPrintHelper( mHelper );
00161 selectedStyle->doPrint();
00162 }
00163 mPrinter->setPreviewOnly( false );
00164 mPrinter->setOrientation( printerOrientation );
00165 }
00166
00168
00169 void CalPrinter::updateConfig()
00170 {
00171 }
00172
00173
00174
00175
00176
00177 CalPrintDialog::CalPrintDialog( KOrg::PrintPlugin::List plugins, KPrinter *p,
00178 QWidget *parent, const char *name )
00179 : KDialogBase( parent, name, true, i18n("Print"), Ok | Cancel ),
00180 mPrinter( p ), mPrintPlugins( plugins )
00181 {
00182 QVBox *page = makeVBoxMainWidget();
00183
00184 QSplitter *splitter = new QSplitter( page );
00185 splitter->setOrientation( QSplitter::Horizontal );
00186
00187 mTypeGroup = new QVButtonGroup( i18n("Print Style"), splitter, "buttonGroup" );
00188
00189
00190
00191
00192
00193 QWidget *splitterRight = new QWidget( splitter, "splitterRight" );
00194 QGridLayout *splitterRightLayout = new QGridLayout( splitterRight );
00195 splitterRightLayout->setMargin( marginHint() );
00196 splitterRightLayout->setSpacing( spacingHint() );
00197
00198 mConfigArea = new QWidgetStack( splitterRight, "configWidgetStack" );
00199 splitterRightLayout->addMultiCellWidget( mConfigArea, 0,0, 0,1 );
00200
00201 QLabel *orientationLabel = new QLabel( i18n("Page &orientation:"),
00202 splitterRight, "orientationLabel" );
00203 splitterRightLayout->addWidget( orientationLabel, 1, 0 );
00204
00205 mOrientationSelection = new QComboBox( splitterRight, "orientationCombo" );
00206 mOrientationSelection->insertItem( i18n("Use Default Orientation of Selected Style") );
00207 mOrientationSelection->insertItem( i18n("Use Printer Default") );
00208 mOrientationSelection->insertItem( i18n("Portrait") );
00209 mOrientationSelection->insertItem( i18n("Landscape") );
00210 splitterRightLayout->addWidget( mOrientationSelection, 1, 1 );
00211
00212
00213 connect( mTypeGroup, SIGNAL( clicked( int ) ), SLOT( setPrintType( int ) ) );
00214
00215
00216 orientationLabel->setBuddy( mOrientationSelection );
00217
00218 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00219 QRadioButton *radioButton;
00220 int id = 0;
00221 for ( ; it != mPrintPlugins.end(); ++it ) {
00222 radioButton = new QRadioButton( (*it)->description(), mTypeGroup );
00223 mTypeGroup->insert( radioButton, id );
00224 radioButton->setMinimumHeight( radioButton->sizeHint().height() - 5 );
00225
00226 mConfigArea->addWidget( (*it)->configWidget( mConfigArea ), id );
00227 id++;
00228 }
00229
00230 setMinimumSize( minimumSizeHint() );
00231 resize( minimumSizeHint() );
00232 }
00233
00234 CalPrintDialog::~CalPrintDialog()
00235 {
00236 }
00237
00238 void CalPrintDialog::setPreview(bool preview)
00239 {
00240 #if KDE_IS_VERSION( 3, 1, 93 )
00241 setButtonOK( preview ? i18n("&Preview") : KStdGuiItem::print() );
00242 #else
00243 setButtonOKText( preview ? i18n("&Preview") : i18n("&Print...") );
00244 #endif
00245 }
00246
00247 void CalPrintDialog::setPrintType( int i )
00248 {
00249
00250
00251 mTypeGroup->setButton( i );
00252 mConfigArea->raiseWidget( i );
00253 }
00254
00255 KOrg::PrintPlugin *CalPrintDialog::selectedPlugin()
00256 {
00257 int pos = mTypeGroup->id( mTypeGroup->selected() );
00258 if ( pos < 0 ) return 0;
00259 KOrg::PrintPlugin *retval = mPrintPlugins.at( pos );
00260 return retval;
00261 }
00262
00263 void CalPrintDialog::slotOk()
00264 {
00265 mOrientation = (CalPrinter::ePrintOrientation)mOrientationSelection->currentItem();
00266
00267 KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00268 for ( ; it != mPrintPlugins.end(); ++it ) {
00269 (*it)->readSettingsWidget();
00270 }
00271
00272 KDialogBase::slotOk();
00273 }
00274
00275 #endif