-rw-r--r-- | korganizer/calprinter.cpp | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/korganizer/calprinter.cpp b/korganizer/calprinter.cpp new file mode 100644 index 0000000..6b5b0fe --- a/dev/null +++ b/korganizer/calprinter.cpp | |||
@@ -0,0 +1,299 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 1998 Preston Brown | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | |||
24 | #include <qvbuttongroup.h> | ||
25 | #include <qwidgetstack.h> | ||
26 | #include <qradiobutton.h> | ||
27 | #include <qlayout.h> | ||
28 | #include <qpushbutton.h> | ||
29 | #include <qcombobox.h> | ||
30 | #include <qlabel.h> | ||
31 | #include <qvbox.h> | ||
32 | #include <qsplitter.h> | ||
33 | |||
34 | #include <kprinter.h> | ||
35 | #include <kglobal.h> | ||
36 | #include <ksimpleconfig.h> | ||
37 | #include <kmessagebox.h> | ||
38 | #include <kdebug.h> | ||
39 | //#include <kdeversion.h> | ||
40 | |||
41 | #include "koprefsdialog.h" | ||
42 | |||
43 | #include "calprinter.h" | ||
44 | #ifndef KORG_NOPRINTER | ||
45 | //#include "calprinter.moc" | ||
46 | |||
47 | #include "calprintplugins.h" | ||
48 | |||
49 | CalPrinter::CalPrinter( QWidget *parent, Calendar *calendar ) | ||
50 | : QObject( parent, "CalPrinter" ) | ||
51 | { | ||
52 | mCalendar = calendar; | ||
53 | mParent = parent; | ||
54 | mPrinter = new KPrinter; | ||
55 | mPrinter->setOrientation( KPrinter::Portrait ); | ||
56 | mConfig = new KConfig(locateLocal("config","korganizer_printing.rc" )); | ||
57 | //KSimpleConfig( "korganizer_printing.rc" ); | ||
58 | |||
59 | init( mPrinter, calendar ); | ||
60 | } | ||
61 | |||
62 | CalPrinter::~CalPrinter() | ||
63 | { | ||
64 | kdDebug() << "~CalPrinter()" << endl; | ||
65 | |||
66 | CalPrintBase *plug = mPrintPlugins.first(); | ||
67 | while ( plug ) { | ||
68 | plug->doSaveConfig(); | ||
69 | plug = mPrintPlugins.next(); | ||
70 | } | ||
71 | mConfig->sync(); | ||
72 | delete mConfig; | ||
73 | delete mPrintDialog; | ||
74 | delete mPrinter; | ||
75 | } | ||
76 | |||
77 | void CalPrinter::init( KPrinter *printer, Calendar *calendar ) | ||
78 | { | ||
79 | mPrintPlugins.setAutoDelete( true ); | ||
80 | mPrintPlugins.append( new CalPrintDay( printer, calendar, mConfig ) ); | ||
81 | mPrintPlugins.append( new CalPrintWeek( printer, calendar, mConfig ) ); | ||
82 | mPrintPlugins.append( new CalPrintMonth( printer, calendar, mConfig ) ); | ||
83 | mPrintPlugins.append( new CalPrintTodos( printer, calendar, mConfig ) ); | ||
84 | |||
85 | // TODO_RK: Add a plugin interface here | ||
86 | mPrintDialog = new CalPrintDialog( mPrintPlugins, mPrinter, mParent ); | ||
87 | |||
88 | CalPrintBase *plug = mPrintPlugins.first(); | ||
89 | while ( plug ) { | ||
90 | connect( mPrintDialog, SIGNAL( okClicked() ), | ||
91 | plug, SLOT( readSettingsWidget() ) ); | ||
92 | |||
93 | plug->doLoadConfig(); | ||
94 | |||
95 | plug = mPrintPlugins.next(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void CalPrinter::setupPrinter() | ||
100 | { | ||
101 | KMessageBox::sorry( mParent, i18n("Not implemented.") ); | ||
102 | #if 0 | ||
103 | KOPrefsDialog *optionsDlg = new KOPrefsDialog(mParent); | ||
104 | optionsDlg->readConfig(); | ||
105 | optionsDlg->showPrinterTab(); | ||
106 | connect(optionsDlg, SIGNAL(configChanged()), | ||
107 | mParent, SLOT(updateConfig())); | ||
108 | optionsDlg->show(); | ||
109 | #endif | ||
110 | } | ||
111 | |||
112 | void CalPrinter::setDateRange( const QDate &fd, const QDate &td ) | ||
113 | { | ||
114 | CalPrintBase *plug = mPrintPlugins.first(); | ||
115 | while ( plug ) { | ||
116 | plug->setDateRange( fd, td ); | ||
117 | plug = mPrintPlugins.next(); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | void CalPrinter::preview( PrintType type, const QDate &fd, const QDate &td ) | ||
122 | { | ||
123 | mPrintDialog->setPreview( true ); | ||
124 | mPrintDialog->setPrintType( int( type ) ); | ||
125 | setDateRange( fd, td ); | ||
126 | |||
127 | if ( mPrintDialog->exec() == QDialog::Accepted ) { | ||
128 | doPrint( mPrintDialog->selectedPlugin(), true ); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | void CalPrinter::print( PrintType type, const QDate &fd, const QDate &td ) | ||
133 | { | ||
134 | mPrintDialog->resize( 640, 380 ); | ||
135 | mPrintDialog->setPreview( false ); | ||
136 | mPrintDialog->setPrintType( int( type ) ); | ||
137 | setDateRange( fd, td ); | ||
138 | |||
139 | if ( mPrintDialog->exec() == QDialog::Accepted ) { | ||
140 | doPrint( mPrintDialog->selectedPlugin(), false ); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | void CalPrinter::doPrint( CalPrintBase *selectedStyle, bool preview ) | ||
145 | { | ||
146 | // FIXME: add a better caption to the Printingdialog | ||
147 | //mPrinter->setPreviewOnly( preview ); | ||
148 | if ( preview || mPrinter->setup( mParent ) ) { | ||
149 | switch ( mPrintDialog->orientation() ) { | ||
150 | case eOrientPlugin: | ||
151 | mPrinter->setOrientation( selectedStyle->orientation()); | ||
152 | break; | ||
153 | case eOrientPortrait: | ||
154 | mPrinter->setOrientation( KPrinter::Portrait ); | ||
155 | break; | ||
156 | case eOrientLandscape: | ||
157 | mPrinter->setOrientation( KPrinter::Landscape ); | ||
158 | break; | ||
159 | case eOrientPrinter: | ||
160 | default: | ||
161 | break; | ||
162 | } | ||
163 | selectedStyle->doPrint(); | ||
164 | } | ||
165 | //mPrinter->setPreviewOnly( false ); | ||
166 | } | ||
167 | |||
168 | /////////////////////////////////////////////////////////////////////////////// | ||
169 | |||
170 | void CalPrinter::updateConfig() | ||
171 | { | ||
172 | } | ||
173 | |||
174 | |||
175 | /****************************************************************************/ | ||
176 | |||
177 | CalPrintDialog::CalPrintDialog( QPtrList<CalPrintBase> plugins, KPrinter *p, | ||
178 | QWidget *parent, const char *name ) | ||
179 | : KDialogBase( parent, name, /*modal*/true, i18n("Print"), Ok | Cancel ), | ||
180 | mPrinter( p ), mPrintPlugins( plugins ) | ||
181 | { | ||
182 | QVBox *page = new QVBox(this);//makeVBoxMainWidget(); | ||
183 | setMainWidget( page ); | ||
184 | QHBox *printerLayout = new QHBox( page ); | ||
185 | |||
186 | mPrinterLabel = new QLabel( printerLayout ); | ||
187 | QPushButton *setupButton = new QPushButton( i18n("&Setup Printer..."), | ||
188 | printerLayout ); | ||
189 | setupButton->setSizePolicy( QSizePolicy( | ||
190 | (QSizePolicy::SizeType)4, (QSizePolicy::SizeType)0, | ||
191 | 0, 0, setupButton->sizePolicy().hasHeightForWidth() ) ); | ||
192 | |||
193 | QSplitter *splitter = new QSplitter( page ); | ||
194 | splitter->setOrientation( QSplitter::Horizontal ); | ||
195 | |||
196 | mTypeGroup = new QVButtonGroup( i18n("View Type"), splitter, "buttonGroup" ); | ||
197 | // use the minimal width possible = max width of the radio buttons, not extensible | ||
198 | /* mTypeGroup->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)4, | ||
199 | (QSizePolicy::SizeType)5, 0, 0, | ||
200 | mTypeGroup->sizePolicy().hasHeightForWidth() ) );*/ | ||
201 | |||
202 | QWidget *splitterRight = new QWidget( splitter, "splitterRight" ); | ||
203 | QGridLayout *splitterRightLayout = new QGridLayout( splitterRight ); | ||
204 | splitterRightLayout->setMargin( marginHint() ); | ||
205 | splitterRightLayout->setSpacing( spacingHint() ); | ||
206 | |||
207 | mConfigArea = new QWidgetStack( splitterRight, "configWidgetStack" ); | ||
208 | splitterRightLayout->addMultiCellWidget( mConfigArea, 0,0, 0,1 ); | ||
209 | |||
210 | QLabel *orientationLabel = new QLabel( i18n("Page &orientation:"), | ||
211 | splitterRight, "orientationLabel" ); | ||
212 | splitterRightLayout->addWidget( orientationLabel, 1, 0 ); | ||
213 | |||
214 | mOrientationSelection = new QComboBox( splitterRight, "orientationCombo" ); | ||
215 | mOrientationSelection->insertItem( i18n("Use Default of Selected Style") ); | ||
216 | mOrientationSelection->insertItem( i18n("Use Default Setting of Printer") ); | ||
217 | mOrientationSelection->insertItem( i18n("Portrait") ); | ||
218 | mOrientationSelection->insertItem( i18n("Landscape") ); | ||
219 | splitterRightLayout->addWidget( mOrientationSelection, 1, 1 ); | ||
220 | |||
221 | // signals and slots connections | ||
222 | connect( setupButton, SIGNAL( clicked() ), SLOT( setupPrinter() ) ); | ||
223 | connect( mTypeGroup, SIGNAL( clicked( int ) ), SLOT( setPrintType( int ) ) ); | ||
224 | |||
225 | // buddies | ||
226 | orientationLabel->setBuddy( mOrientationSelection ); | ||
227 | |||
228 | CalPrintBase *plug = mPrintPlugins.first(); | ||
229 | QRadioButton *radioButton; | ||
230 | int id = 0; | ||
231 | while ( plug ) { | ||
232 | radioButton = new QRadioButton( plug->description(), mTypeGroup ); | ||
233 | mTypeGroup->insert( radioButton, id ); | ||
234 | //radioButton->setMinimumHeight( radioButton->sizeHint().height() - 5 ); | ||
235 | |||
236 | mConfigArea->addWidget( plug->configWidget( mConfigArea ), id ); | ||
237 | |||
238 | plug = mPrintPlugins.next(); | ||
239 | id++; | ||
240 | } | ||
241 | |||
242 | // setMinimumSize( minimumSizeHint() ); | ||
243 | //resize( minimumSizeHint() ); | ||
244 | } | ||
245 | |||
246 | CalPrintDialog::~CalPrintDialog() | ||
247 | { | ||
248 | } | ||
249 | |||
250 | void CalPrintDialog::setupPrinter() | ||
251 | { | ||
252 | if ( mPrinter->setup( this ) ) { | ||
253 | setPrinterLabel(); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | void CalPrintDialog::setPreview(bool preview) | ||
258 | { | ||
259 | |||
260 | setButtonText(KDialogBase::Ok, preview ? i18n("&Preview") : i18n("&Print...") ); | ||
261 | |||
262 | mPreviewText = preview ? i18n("<qt>Preview for printer <b>%1</b></qt>") | ||
263 | : i18n( "<qt>Printing on printer <b>%1</b></qt>"); | ||
264 | setPrinterLabel(); | ||
265 | } | ||
266 | |||
267 | void CalPrintDialog::setPrinterLabel() | ||
268 | { | ||
269 | QString printerName( mPrinter->printerName() ); | ||
270 | if ( printerName.isEmpty() ) | ||
271 | mPrinterLabel->setText( mPreviewText.arg( i18n("[Unconfigured]") ) ); | ||
272 | else | ||
273 | mPrinterLabel->setText( mPreviewText.arg( printerName ) ); | ||
274 | } | ||
275 | |||
276 | void CalPrintDialog::setPrintType( int i ) | ||
277 | { | ||
278 | // TODO: Make a safe correlation between type and the radio button | ||
279 | |||
280 | mTypeGroup->setButton( i ); | ||
281 | mConfigArea->raiseWidget( i ); | ||
282 | } | ||
283 | |||
284 | CalPrintBase *CalPrintDialog::selectedPlugin() | ||
285 | { | ||
286 | int pos = mTypeGroup->id( mTypeGroup->selected() ); | ||
287 | if ( pos < 0 ) return 0; | ||
288 | CalPrintBase *retval = mPrintPlugins.at( pos ); | ||
289 | return retval; | ||
290 | } | ||
291 | |||
292 | void CalPrintDialog::slotOk() | ||
293 | { | ||
294 | mOrientation = (CalPrinter::ePrintOrientation)mOrientationSelection->currentItem(); | ||
295 | KDialogBase::slotOk(); | ||
296 | emit okClicked(); | ||
297 | } | ||
298 | |||
299 | #endif | ||