korganizer

calprinter.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 1998 Preston Brown <pbrown@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
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 
00082   mPrintPlugins.clear();
00083   mPrintPlugins.setAutoDelete( true );
00084 
00085   mPrintPlugins = mCoreHelper->loadPrintPlugins();
00086   mPrintPlugins.prepend( new CalPrintTodos() );
00087   mPrintPlugins.prepend( new CalPrintMonth() );
00088   mPrintPlugins.prepend( new CalPrintWeek() );
00089   mPrintPlugins.prepend( new CalPrintDay() );
00090 
00091   mPrintDialog = new CalPrintDialog( mPrintPlugins, mPrinter, mParent );
00092 
00093   KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00094   for ( ; it != mPrintPlugins.end(); ++it ) {
00095     (*it)->setConfig( mConfig );
00096     (*it)->setCalendar( calendar );
00097     (*it)->setPrinter( printer );
00098 
00099     (*it)->doLoadConfig();
00100   }
00101 }
00102 
00103 void CalPrinter::setDateRange( const QDate &fd, const QDate &td )
00104 {
00105   KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00106   for ( ; it != mPrintPlugins.end(); ++it ) {
00107     (*it)->setDateRange( fd, td );
00108   }
00109 }
00110 
00111 void CalPrinter::preview( PrintType type, const QDate &fd, const QDate &td )
00112 {
00113   mPrintDialog->setPreview( true );
00114   mPrintDialog->setPrintType( int( type ) );
00115   setDateRange( fd, td );
00116 
00117   if ( mPrintDialog->exec() == QDialog::Accepted ) {
00118     doPrint( mPrintDialog->selectedPlugin(), true );
00119   }
00120 }
00121 
00122 void CalPrinter::print( PrintType type, const QDate &fd, const QDate &td )
00123 {
00124   mPrintDialog->setPreview( false );
00125   mPrintDialog->setPrintType( int( type ) );
00126   setDateRange( fd, td );
00127 
00128   if ( mPrintDialog->exec() == QDialog::Accepted ) {
00129     doPrint( mPrintDialog->selectedPlugin(), false );
00130   }
00131 }
00132 
00133 void CalPrinter::doPrint( KOrg::PrintPlugin *selectedStyle, bool preview )
00134 {
00135   if ( mHelper ) delete mHelper;
00136   KPrinter::Orientation printerOrientation = mPrinter->orientation();
00137 
00138   mHelper = new CalPrintHelper( mPrinter, mCalendar, mConfig, mCoreHelper );
00139   if ( preview ) mPrinter->setPreviewOnly( true );
00140   switch ( mPrintDialog->orientation() ) {
00141     case eOrientPlugin:
00142       mPrinter->setOrientation( selectedStyle->orientation() );
00143       break;
00144     case eOrientPortrait:
00145       mPrinter->setOrientation( KPrinter::Portrait );
00146       break;
00147     case eOrientLandscape:
00148       mPrinter->setOrientation( KPrinter::Landscape );
00149       break;
00150     case eOrientPrinter:
00151     default:
00152       break;
00153   }
00154 
00155   if ( preview || mPrinter->setup( mParent, i18n("Print Calendar") ) ) {
00156   selectedStyle->setKOrgCoreHelper( mCoreHelper );
00157   selectedStyle->setCalPrintHelper( mHelper );
00158     selectedStyle->doPrint();
00159   }
00160   mPrinter->setPreviewOnly( false );
00161   mPrinter->setOrientation( printerOrientation );
00162 }
00163 
00165 
00166 void CalPrinter::updateConfig()
00167 {
00168 }
00169 
00170 
00171 
00172 /****************************************************************************/
00173 
00174 CalPrintDialog::CalPrintDialog( KOrg::PrintPlugin::List plugins, KPrinter *p,
00175                                 QWidget *parent, const char *name )
00176   : KDialogBase( parent, name, /*modal*/true, i18n("Print"), Ok | Cancel ),
00177     mPrinter( p ), mPrintPlugins( plugins )
00178 {
00179   QVBox *page = makeVBoxMainWidget();
00180 
00181   QSplitter *splitter = new QSplitter( page );
00182   splitter->setOrientation( QSplitter::Horizontal );
00183 
00184   mTypeGroup = new QVButtonGroup( i18n("Print Style"), splitter, "buttonGroup" );
00185   // use the minimal width possible = max width of the radio buttons, not extensible
00186 /*  mTypeGroup->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)4,
00187     (QSizePolicy::SizeType)5, 0, 0,
00188       mTypeGroup->sizePolicy().hasHeightForWidth() ) );*/
00189 
00190   QWidget *splitterRight = new QWidget( splitter, "splitterRight" );
00191   QGridLayout *splitterRightLayout = new QGridLayout( splitterRight );
00192   splitterRightLayout->setMargin( marginHint() );
00193   splitterRightLayout->setSpacing( spacingHint() );
00194 
00195   mConfigArea = new QWidgetStack( splitterRight, "configWidgetStack" );
00196   splitterRightLayout->addMultiCellWidget( mConfigArea, 0,0, 0,1 );
00197 
00198   QLabel *orientationLabel = new QLabel( i18n("Page &orientation:"),
00199                                          splitterRight, "orientationLabel" );
00200   splitterRightLayout->addWidget( orientationLabel, 1, 0 );
00201 
00202   mOrientationSelection = new QComboBox( splitterRight, "orientationCombo" );
00203   mOrientationSelection->insertItem( i18n("Use Default Orientation of Selected Style") );
00204   mOrientationSelection->insertItem( i18n("Use Printer Default") );
00205   mOrientationSelection->insertItem( i18n("Portrait") );
00206   mOrientationSelection->insertItem( i18n("Landscape") );
00207   splitterRightLayout->addWidget( mOrientationSelection, 1, 1 );
00208 
00209   // signals and slots connections
00210   connect( mTypeGroup, SIGNAL( clicked( int ) ), SLOT( setPrintType( int ) ) );
00211 
00212   // buddies
00213   orientationLabel->setBuddy( mOrientationSelection );
00214 
00215   KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00216   QRadioButton *radioButton;
00217   int id = 0;
00218   for ( ; it != mPrintPlugins.end(); ++it ) {
00219     radioButton = new QRadioButton( (*it)->description(), mTypeGroup );
00220     mTypeGroup->insert( radioButton, id );
00221     radioButton->setMinimumHeight( radioButton->sizeHint().height() - 5 );
00222 
00223     mConfigArea->addWidget( (*it)->configWidget( mConfigArea ), id );
00224     id++;
00225   }
00226 
00227   setMinimumSize( minimumSizeHint() );
00228   resize( minimumSizeHint() );
00229 }
00230 
00231 CalPrintDialog::~CalPrintDialog()
00232 {
00233 }
00234 
00235 void CalPrintDialog::setPreview(bool preview)
00236 {
00237 #if KDE_IS_VERSION( 3, 1, 93 )
00238   setButtonOK( preview ? i18n("&Preview") : KStdGuiItem::print() );
00239 #else
00240   setButtonOKText( preview ? i18n("&Preview") : i18n("&Print...") );
00241 #endif
00242 }
00243 
00244 void CalPrintDialog::setPrintType( int i )
00245 {
00246   // FIXME: Make a safe correlation between type and the radio button
00247 
00248   mTypeGroup->setButton( i );
00249   mConfigArea->raiseWidget( i );
00250 }
00251 
00252 KOrg::PrintPlugin *CalPrintDialog::selectedPlugin()
00253 {
00254   int pos = mTypeGroup->id( mTypeGroup->selected() );
00255   if ( pos < 0 ) return 0;
00256   KOrg::PrintPlugin *retval = mPrintPlugins.at( pos );
00257   return retval;
00258 }
00259 
00260 void CalPrintDialog::slotOk()
00261 {
00262   mOrientation = (CalPrinter::ePrintOrientation)mOrientationSelection->currentItem();
00263 
00264   KOrg::PrintPlugin::List::Iterator it = mPrintPlugins.begin();
00265   for ( ; it != mPrintPlugins.end(); ++it ) {
00266     (*it)->readSettingsWidget();
00267   }
00268 
00269   KDialogBase::slotOk();
00270 }
00271 
00272 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys