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