27 #include "calprinter.moc"
31 #include <KMessageBox>
32 #include <KPrintPreview>
33 #include <KStandardGuiItem>
35 #include <kdeprintdialog.h>
37 #include <QButtonGroup>
38 #include <QGridLayout>
40 #include <QPrintDialog>
42 #include <QStackedWidget>
43 #include <QVBoxLayout>
47 :
QObject( parent ), mUniqItem( uniqItem )
50 mConfig =
new KConfig( QLatin1String(
"korganizer_printing.rc"), KConfig::SimpleConfig );
80 (*it)->setConfig( mConfig );
81 (*it)->setCalendar( mCalendar );
82 (*it)->setKOrgCoreHelper( mCoreHelper );
83 (*it)->doLoadConfig();
92 (*it)->setDateRange( fd, td );
97 Incidence::List selectedIncidences,
bool preview )
99 KOrg::PrintPlugin::List::Iterator it;
101 (*it)->setSelectedIncidences( selectedIncidences );
103 QPointer<CalPrintDialog> printDialog =
106 KConfigGroup grp( mConfig,
"" );
108 printDialog->setPreview( preview );
111 if ( printDialog->exec() == QDialog::Accepted ) {
112 grp.writeEntry(
"Orientation", (
int)printDialog->orientation() );
116 (*it)->doSaveConfig();
118 doPrint( printDialog->selectedPlugin(), printDialog->orientation(), preview );
123 (*it)->setSelectedIncidences( Incidence::List() );
130 if ( !selectedStyle ) {
133 i18nc(
"@info",
"Unable to print, an invalid print style was specified." ),
134 i18nc(
"@title:window",
"Printing error" ) );
139 switch ( dlgorientation ) {
144 printer.setOrientation( QPrinter::Portrait );
147 printer.setOrientation( QPrinter::Landscape );
155 QPointer<KPrintPreview> printPreview =
new KPrintPreview( &printer );
156 selectedStyle->
doPrint( &printer );
157 printPreview->exec();
160 QPointer<QPrintDialog> printDialog = KdePrint::createPrintDialog( &printer, mParent );
161 if ( printDialog->exec() == QDialog::Accepted ) {
162 selectedStyle->
doPrint( &printer );
173 QWidget *parent,
bool uniqItem )
176 setCaption( i18nc(
"@title:window",
"Print" ) );
177 setButtons( Ok | Cancel );
179 KVBox *page =
new KVBox(
this );
180 setMainWidget( page );
182 QSplitter *splitter =
new QSplitter( page );
183 splitter->setOrientation( Qt::Horizontal );
184 splitter->setChildrenCollapsible(
false );
185 QGroupBox *typeBox =
new QGroupBox( i18nc(
"@title:group",
"Print Style" ), splitter );
186 QBoxLayout *typeLayout =
new QVBoxLayout( typeBox );
187 mTypeGroup =
new QButtonGroup( typeBox );
190 QGridLayout *splitterRightLayout =
new QGridLayout( splitterRight );
191 splitterRightLayout->setMargin( marginHint() );
192 splitterRightLayout->setSpacing( spacingHint() );
194 mConfigArea =
new QStackedWidget( splitterRight );
195 splitterRightLayout->addWidget( mConfigArea, 0, 0, 1, 2 );
196 QLabel *orientationLabel =
new QLabel( i18nc(
"@label",
"Page &orientation:" ), splitterRight );
197 orientationLabel->setAlignment( Qt::AlignRight );
198 splitterRightLayout->addWidget( orientationLabel, 1, 0 );
200 mOrientationSelection =
new KComboBox( splitterRight );
201 mOrientationSelection->setToolTip(
202 i18nc(
"@info:tooltip",
"Set the print orientation" ) );
203 mOrientationSelection->setWhatsThis(
204 i18nc(
"@info:whatsthis",
205 "Choose if you want your output to be printed in \"portrait\" or "
206 "\"landscape\". You can also default to the orientation best suited to "
207 "the selected style or to your printer's default setting." ) );
208 mOrientationSelection->addItem( i18nc(
"@item:inlistbox",
209 "Use Default Orientation of Selected Style" ) );
210 mOrientationSelection->addItem( i18nc(
"@item:inlistbox",
211 "Use Printer Default" ) );
212 mOrientationSelection->addItem( i18nc(
"@item:inlistbox",
214 mOrientationSelection->addItem( i18nc(
"@item:inlistbox",
216 splitterRightLayout->addWidget( mOrientationSelection, 1, 1 );
219 connect( mTypeGroup, SIGNAL(buttonClicked(
int)), SLOT(
setPrintType(
int)) );
220 orientationLabel->setBuddy( mOrientationSelection );
225 for ( KOrg::PrintPlugin::List::ConstIterator it=plugins.constBegin();
226 it != plugins.constEnd(); ++it ) {
227 int newid = mConfigArea->insertWidget( (*it)->sortID(), (*it)->configWidget( mConfigArea ) );
228 mPluginIDs[newid] = (*it);
231 QMap<int, KOrg::PrintPlugin*>::ConstIterator mapit;
232 int firstButton =
true;
234 for ( mapit = mPluginIDs.constBegin(); mapit != mPluginIDs.constEnd(); ++mapit ) {
236 QRadioButton *radioButton =
new QRadioButton( p->
description() );
237 radioButton->setEnabled( p->
enabled() );
238 radioButton->setToolTip(
239 i18nc(
"@info:tooltip",
"Select the type of print" ) );
240 radioButton->setWhatsThis(
241 i18nc(
"@info:whatsthis",
242 "Select one of the following types of prints you want to make. "
243 "You may want to print an individual item, or all the items for a "
244 "specific time range (like a day, week or month), or you may want "
245 "to print your to-do list." ) );
248 if ( ( firstButton || p->
sortID() == initialPrintType ) && p->
enabled() ) {
250 radioButton->setChecked(
true );
253 mTypeGroup->addButton( radioButton, mapit.key() );
254 typeLayout->addWidget( radioButton );
260 typeLayout->insertStretch( -1, 100 );
261 connect(
this, SIGNAL(okClicked()), SLOT(
slotOk()) );
262 setMinimumSize( minimumSizeHint() );
263 resize( minimumSizeHint() );
273 setButtonText( Ok, i18nc(
"@action:button",
"&Preview" ) );
275 setButtonText( Ok, KStandardGuiItem::print().text() );
281 mConfigArea->setCurrentIndex( i );
282 mConfigArea->currentWidget()->raise();
283 QAbstractButton *btn = mTypeGroup->button( i );
285 btn->setChecked(
true );
292 mOrientationSelection->setCurrentIndex( mOrientation );
297 int id = mConfigArea->currentIndex();
298 if ( mPluginIDs.contains(
id ) ) {
299 return mPluginIDs[id];
310 QMap<int, KOrg::PrintPlugin*>::ConstIterator it = mPluginIDs.constBegin();
311 for ( ; it != mPluginIDs.constEnd(); ++it ) {
313 it.value()->readSettingsWidget();
CalPrinter::ePrintOrientation orientation()
virtual QString description()=0
Returns short description of print format.
CalPrintDialog(int initialPrintType, KOrg::PrintPlugin::List plugins, QWidget *parent=0, bool mUniqItem=false)
virtual void doPrint(QPrinter *printer)=0
Actually do the printing.
QList< PrintPlugin * > List
CalPrinter(QWidget *par, const Akonadi::ETMCalendar::Ptr &calendar, KOrg::CoreHelper *helper, bool uniqItem=false)
void setOrientation(CalPrinter::ePrintOrientation orientation)
KOrg::PrintPlugin * selectedPlugin()
void init(const Akonadi::ETMCalendar::Ptr &calendar)
Base class for KOrganizer printing classes.
void setDateRange(const QDate &start, const QDate &end)
Set date range to be printed.
virtual KOrg::PrintPlugin::List loadPrintPlugins()=0
KOrg::PrintPlugin::List mPrintPlugins
virtual int sortID()
Returns the sort ID of the plugin.
virtual QPrinter::Orientation defaultOrientation()
Orientation of printout.
void print(int type, const QDate &fd, const QDate &td, Incidence::List selectedIncidences=Incidence::List(), bool preview=false)
virtual ~CalPrintDialog()
virtual bool enabled()
Returns true if the plugin should be enabled; false otherwise.
Akonadi::ETMCalendar::Ptr calendar() const