summaryrefslogtreecommitdiffstats
path: root/kdeprint/cups/kptextpage.cpp
blob: 25cfb888d16ef1b19d173c681b0f6498f3d57fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include "kptextpage.h"
#include "marginwidget.h"
#include "driver.h"
#include "kprinter.h"

#include <tqbuttongroup.h>
#include <tqgroupbox.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqradiobutton.h>
#include <tqwhatsthis.h>
#include <knuminput.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kseparator.h>
#include <kdebug.h>

KPTextPage::KPTextPage(DrMain *driver, TQWidget *parent, const char *name)
: KPrintDialogPage(0, driver, parent, name)
{
	//WhatsThis strings.... (added by pfeifle@kde.org)
	TQString whatsThisCPITextPage = i18n( " <qt> "
			" <p><b>Characters Per Inch</b></p> "
			" <p>This setting controls the horizontal size of characters when printing a text file. </p>"
			" <p>The default value is 10, meaning that the font is scaled in a way that 10 characters "
			" per inch will be printed. </p> "
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"    -o cpi=...          # example: \"8\" or \"12\" "
			" </pre>"
			" </p> "
			" </qt>" );

	TQString whatsThisLPITextPage = i18n( " <qt> "
			" <p><b>Lines Per Inch</b></p> "
			" <p>This setting controls the vertical size of characters when printing a text file. </p>"
			" <p>The default value is 6, meaning that the font is scaled in a way that 6 lines "
			" per inch will be printed. </p> "
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"    -o lpi=...         # example \"5\" or \"7\" "
			" </pre>"
			" </p> "
			" </qt>" );

	TQString whatsThisColumnsTextPage = i18n( " <qt> "
			" <p><b>Columns</b></p> "
			" <p>This setting controls how many columns of text will be printed on each page when."
			" printing text files. </p> "
			" <p>The default value is 1, meaning that only one column of text per page "
			" will be printed. </p> "
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"    -o columns=...     # example: \"2\" or \"4\" "
			" </pre>"
			" </p> "
			" </qt>" );

	TQString whatsThisPrettyprintPreviewIconTextPage = i18n( " <qt> "
			" Preview icon changes when you turn on or off prettyprint. "
			" </qt>" );
	TQString whatsThisFormatTextPage = i18n( " <qt> "
			" <p><b>Text Formats</b></p> "
			" <p>These settings control the appearance of text on printouts. They are only valid for "
			" printing text files or input directly through kprinter. </p> "
			" <p><b>Note:</b> These settings have no effect whatsoever for other input formats than "
			" text, or for printing from applications such as the KDE Advanced Text Editor. (Applications "
			" in general send PostScript to the print system, and 'kate' in particular has its own "
			" knobs to control the print output. </p>."
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"     -o cpi=...         # example: \"8\" or \"12\" "
			" <br> "
			"    -o lpi=...         # example: \"5\" or \"7\" "
			" <br> "
			"    -o columns=...     # example: \"2\" or \"4\" "
			" </pre>"
			" </p> "
			" </qt>" );

	TQString whatsThisMarginsTextPage = i18n( " <qt> "
			" <p><b>Margins</b></p> "
			" <p>These settings control the margins of printouts on the paper. They are not valid for "
			" jobs originating from applications which define their own page layout internally and "
			" send PostScript to KDEPrint (such as KOffice or OpenOffice.org). </p> "
			" <p>When printing from KDE applications, such as KMail and Konqueror, or printing an ASCII text "
			" file through kprinter, you can choose your preferred margin settings here. </p> "
			" <p>Margins may be set individually for each edge of the paper. The combo box at the bottom lets you change "
			" the units of measurement between Pixels, Millimeters, Centimeters, and Inches. </p> "
			" <p>You can even use the mouse to grab one margin and drag it to the intended position (see the "
			" preview picture on the right side). </p> "
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"     -o page-top=...      # example: \"72\" "
			" <br> "
			"    -o page-bottom=...   # example: \"24\" "
			" <br> "
			"    -o page-left=...     # example: \"36\" "
			" <br> "
			"    -o page-right=...    # example: \"12\" "
			" </pre>"
			" </p> "
			" </qt>" );

	TQString whatsThisPrettyprintButtonOnTextPage = i18n( " <qt> "
			" <p><b>Turn Text Printing with Syntax Highlighting (Prettyprint) On!</b></p> "
			" <p>ASCII text file printouts can be 'prettyfied' by enabling this option. If you do so, "
			" a header is printed at the top of each page. The header contains "
			" the page number, job title (usually the filename), and the date. In addition, C and "
			" C++ keywords are highlighted, and comment lines are italicized.</p>"
			" <p>This prettyprint option is handled by CUPS.</p> "
			" <p>If you prefer another 'plaintext-to-prettyprint' converter, look for the <em>enscript</em> "
			" pre-filter on the <em>Filters</em> tab. </p>"
			" <br> "
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"     -o prettyprint=true. "
			" </pre>"
			" </p> "
			" </qt>" );

	TQString whatsThisPrettyprintButtonOffTextPage = i18n( " <qt> "
			" <p><b>Turn Text Printing with Syntax Highlighting (Prettyprint) Off! </b></p> "
			" <p>ASCII text file printing with this option turned off are appearing without a page "
			" header and without syntax highlighting. (You can still set the page margins, though.) </p> "
			" <br> "
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"    -o prettyprint=false "
			" </pre>"
			" </p> "
			" </qt>" );

	TQString whatsThisPrettyprintFrameTextPage = i18n( " <qt> "
			" <p><b>Print Text with Syntax Highlighting (Prettyprint)</b></p> "
			" <p>ASCII file printouts can be 'prettyfied' by enabling this option. If you do so, "
			" a header is printed at the top of each page. The header contains "
			" the page number, job title (usually the filename), and the date. In addition, C and "
			" C++ keywords are highlighted, and comment lines are italicized.</p>"
			" <p>This prettyprint option is handled by CUPS.</p> "
			" <p>If you prefer another 'plaintext-to-prettyprint' converter, look for the <em>enscript</em> "
			" pre-filter on the <em>Filters</em> tab. </p> "
			" <br> "
			" <hr> "
			" <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
			" with the CUPS commandline job option parameter:</em> "
			" <pre>"
			"     -o prettyprint=true. "
			" <br> "
			"    -o prettyprint=false "
			" </pre>"
			" </p> "
			" </qt>" );

	setTitle(i18n("Text"));
	m_block = false;

	TQGroupBox	*formatbox = new TQGroupBox(0, Qt::Vertical, i18n("Text Format"), this);
	  TQWhatsThis::add(formatbox, whatsThisFormatTextPage);
	TQGroupBox	*prettybox = new TQGroupBox(0, Qt::Vertical, i18n("Syntax Highlighting"), this);
	  TQWhatsThis::add(prettybox, whatsThisPrettyprintFrameTextPage);
	TQGroupBox	*marginbox = new TQGroupBox(0, Qt::Vertical, i18n("Margins"), this);
	  TQWhatsThis::add(marginbox, whatsThisMarginsTextPage);

	m_cpi = new KIntNumInput(10, formatbox);
	  TQWhatsThis::add(m_cpi, whatsThisCPITextPage);
	m_cpi->setLabel(i18n("&Chars per inch:"), Qt::AlignLeft|Qt::AlignVCenter);
	m_cpi->setRange(1, 999, 1, false);
	m_lpi = new KIntNumInput(m_cpi, 6, formatbox);
	  TQWhatsThis::add(m_lpi, whatsThisLPITextPage);
	m_lpi->setLabel(i18n("&Lines per inch:"), Qt::AlignLeft|Qt::AlignVCenter);
	m_lpi->setRange(1, 999, 1, false);
	m_columns = new KIntNumInput(m_lpi, 1, formatbox);
	  TQWhatsThis::add(m_columns, whatsThisColumnsTextPage);
	m_columns->setLabel(i18n("C&olumns:"), Qt::AlignLeft|Qt::AlignVCenter);
	m_columns->setRange(1, 10, 1, false);
	KSeparator	*sep = new KSeparator(Qt::Horizontal, formatbox);
	connect(m_columns, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotColumnsChanged(int)));

	m_prettypix = new TQLabel(prettybox);
	  TQWhatsThis::add(m_prettypix, whatsThisPrettyprintPreviewIconTextPage);
	m_prettypix->tqsetAlignment(Qt::AlignCenter);
	TQRadioButton	*off = new TQRadioButton(i18n("&Disabled"), prettybox);
	  TQWhatsThis::add(off, whatsThisPrettyprintButtonOffTextPage);
	TQRadioButton	*on = new TQRadioButton(i18n("&Enabled"), prettybox);
	  TQWhatsThis::add(on, whatsThisPrettyprintButtonOnTextPage);
	m_prettyprint = new TQButtonGroup(prettybox);
	m_prettyprint->hide();
	m_prettyprint->insert(off, 0);
	m_prettyprint->insert(on, 1);
	m_prettyprint->setButton(0);
	connect(m_prettyprint, TQT_SIGNAL(clicked(int)), TQT_SLOT(slotPrettyChanged(int)));
	slotPrettyChanged(0);

	m_margin = new MarginWidget(marginbox);
	  TQWhatsThis::add(m_margin, whatsThisMarginsTextPage);
	m_margin->setPageSize(595, 842);

	TQGridLayout	*l0 = new TQGridLayout(this, 2, 2, 0, 10);
	l0->addWidget(formatbox, 0, 0);
	l0->addWidget(prettybox, 0, 1);
	l0->addMultiCellWidget(marginbox, 1, 1, 0, 1);
	TQVBoxLayout	*l1 = new TQVBoxLayout(TQT_TQLAYOUT(formatbox->layout()), 5);
	l1->addWidget(m_cpi);
	l1->addWidget(m_lpi);
	l1->addWidget(sep);
	l1->addWidget(m_columns);
	TQGridLayout	*l2 = new TQGridLayout(TQT_TQLAYOUT(prettybox->layout()), 2, 2, 10);
	l2->addWidget(off, 0, 0);
	l2->addWidget(on, 1, 0);
	l2->addMultiCellWidget(m_prettypix, 0, 1, 1, 1);
	TQVBoxLayout	*l3 = new TQVBoxLayout(TQT_TQLAYOUT(marginbox->layout()), 10);
	l3->addWidget(m_margin);
}

KPTextPage::~KPTextPage()
{
}

void KPTextPage::setOptions(const TQMap<TQString,TQString>& opts)
{
	TQString	value;

	if (!(value=opts["cpi"]).isEmpty())
		m_cpi->setValue(value.toInt());
	if (!(value=opts["lpi"]).isEmpty())
		m_lpi->setValue(value.toInt());
	if (!(value=opts["columns"]).isEmpty())
		m_columns->setValue(value.toInt());
	int	ID(0);
	if (opts.tqcontains("prettyprint") && (opts["prettyprint"].isEmpty() || opts["prettyprint"] == "true"))
		ID = 1;
	m_prettyprint->setButton(ID);
	slotPrettyChanged(ID);

	// get default margins
	m_currentps = opts["PageSize"];
	TQString	orient = opts["orientation-requested"];
	bool	landscape = (orient == "4" || orient == "5");
	initPageSize(landscape);

	bool	marginset(false);
	if (!(value=opts["page-top"]).isEmpty() && value.toFloat() != m_margin->top())
	{
		marginset = true;
		m_margin->setTop(value.toFloat());
	}
	if (!(value=opts["page-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
	{
		marginset = true;
		m_margin->setBottom(value.toFloat());
	}
	if (!(value=opts["page-left"]).isEmpty() && value.toFloat() != m_margin->left())
	{
		marginset = true;
		m_margin->setLeft(value.toFloat());
	}
	if (!(value=opts["page-right"]).isEmpty() && value.toFloat() != m_margin->right())
	{
		marginset = true;
		m_margin->setRight(value.toFloat());
	}
	m_margin->setCustomEnabled(marginset);
}

void KPTextPage::getOptions(TQMap<TQString,TQString>& opts, bool incldef)
{
	if (incldef || m_cpi->value() != 10)
		opts["cpi"] = TQString::number(m_cpi->value());
	if (incldef || m_lpi->value() != 6)
		opts["lpi"] = TQString::number(m_lpi->value());
	if (incldef || m_columns->value() != 1)
		opts["columns"] = TQString::number(m_columns->value());

	//if (m_margin->isCustomEnabled() || incldef)
	if (m_margin->isCustomEnabled())
	{
		opts["page-top"] = TQString::number(( int )( m_margin->top()+0.5 ));
		opts["page-bottom"] = TQString::number(( int )( m_margin->bottom()+0.5 ));
		opts["page-left"] = TQString::number(( int )( m_margin->left()+0.5 ));
		opts["page-right"] = TQString::number(( int )( m_margin->right()+0.5 ));
	}
	else
	{
		opts.remove("page-top");
		opts.remove("page-bottom");
		opts.remove("page-left");
		opts.remove("page-right");
	}

	if (m_prettyprint->id(m_prettyprint->selected()) == 1)
		opts["prettyprint"] = "true";
	else if (incldef)
		opts["prettyprint"] = "false";
	else
		opts.remove("prettyprint");
}

void KPTextPage::slotPrettyChanged(int ID)
{
	TQString	iconstr = (ID == 0 ? "kdeprint_nup1" : "kdeprint_prettyprint");
	m_prettypix->setPixmap(UserIcon(iconstr));
}

void KPTextPage::slotColumnsChanged(int)
{
	// TO BE IMPLEMENTED
}

void KPTextPage::initPageSize(bool landscape)
{
	float w( -1 ), h( -1 );
	float mt( 36 ), mb( mt ), ml( 18 ), mr( ml );
	if (driver())
	{
		if (m_currentps.isEmpty())
		{
			DrListOption	*o = (DrListOption*)driver()->findOption("PageSize");
			if (o)
				m_currentps = o->get("default");
		}
		if (!m_currentps.isEmpty())
		{
			DrPageSize	*ps = driver()->findPageSize(m_currentps);
			if (ps)
			{
				w = ps->pageWidth();
				h = ps->pageHeight();
				mt = ps->topMargin();
				ml = ps->leftMargin();
				mr = ps->rightMargin();
				mb = ps->bottomMargin();
			}
		}
	}
	m_margin->setPageSize(w, h);
	m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
	m_margin->setDefaultMargins( mt, mb, ml, mr );
	m_margin->setCustomEnabled(false);
}

#include "kptextpage.moc"