20 #include "kptextpage.h"
21 #include "marginwidget.h"
25 #include <tqbuttongroup.h>
26 #include <tqgroupbox.h>
29 #include <tqradiobutton.h>
30 #include <tqwhatsthis.h>
31 #include <knuminput.h>
32 #include <tdelocale.h>
33 #include <kiconloader.h>
34 #include <kseparator.h>
37 KPTextPage::KPTextPage(DrMain *driver, TQWidget *parent,
const char *name)
41 TQString whatsThisCPITextPage = i18n(
" <qt> "
42 " <p><b>Characters Per Inch</b></p> "
43 " <p>This setting controls the horizontal size of characters when printing a text file. </p>"
44 " <p>The default value is 10, meaning that the font is scaled in a way that 10 characters "
45 " per inch will be printed. </p> "
47 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
48 " with the CUPS commandline job option parameter:</em> "
50 " -o cpi=... # example: \"8\" or \"12\" "
55 TQString whatsThisLPITextPage = i18n(
" <qt> "
56 " <p><b>Lines Per Inch</b></p> "
57 " <p>This setting controls the vertical size of characters when printing a text file. </p>"
58 " <p>The default value is 6, meaning that the font is scaled in a way that 6 lines "
59 " per inch will be printed. </p> "
61 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
62 " with the CUPS commandline job option parameter:</em> "
64 " -o lpi=... # example \"5\" or \"7\" "
69 TQString whatsThisColumnsTextPage = i18n(
" <qt> "
70 " <p><b>Columns</b></p> "
71 " <p>This setting controls how many columns of text will be printed on each page when."
72 " printing text files. </p> "
73 " <p>The default value is 1, meaning that only one column of text per page "
74 " will be printed. </p> "
76 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
77 " with the CUPS commandline job option parameter:</em> "
79 " -o columns=... # example: \"2\" or \"4\" "
84 TQString whatsThisPrettyprintPreviewIconTextPage = i18n(
" <qt> "
85 " Preview icon changes when you turn on or off prettyprint. "
87 TQString whatsThisFormatTextPage = i18n(
" <qt> "
88 " <p><b>Text Formats</b></p> "
89 " <p>These settings control the appearance of text on printouts. They are only valid for "
90 " printing text files or input directly through kprinter. </p> "
91 " <p><b>Note:</b> These settings have no effect whatsoever for other input formats than "
92 " text, or for printing from applications such as the TDE Advanced Text Editor. (Applications "
93 " in general send PostScript to the print system, and 'kate' in particular has its own "
94 " knobs to control the print output. </p>."
96 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
97 " with the CUPS commandline job option parameter:</em> "
99 " -o cpi=... # example: \"8\" or \"12\" "
101 " -o lpi=... # example: \"5\" or \"7\" "
103 " -o columns=... # example: \"2\" or \"4\" "
108 TQString whatsThisMarginsTextPage = i18n(
" <qt> "
109 " <p><b>Margins</b></p> "
110 " <p>These settings control the margins of printouts on the paper. They are not valid for "
111 " jobs originating from applications which define their own page layout internally and "
112 " send PostScript to TDEPrint (such as KOffice, OpenOffice or LibreOffice). </p> "
113 " <p>When printing from TDE applications, such as KMail and Konqueror, or printing an ASCII text "
114 " file through kprinter, you can choose your preferred margin settings here. </p> "
115 " <p>Margins may be set individually for each edge of the paper. The combo box at the bottom lets you change "
116 " the units of measurement between Pixels, Millimeters, Centimeters, and Inches. </p> "
117 " <p>You can even use the mouse to grab one margin and drag it to the intended position (see the "
118 " preview picture on the right side). </p> "
120 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
121 " with the CUPS commandline job option parameter:</em> "
123 " -o page-top=... # example: \"72\" "
125 " -o page-bottom=... # example: \"24\" "
127 " -o page-left=... # example: \"36\" "
129 " -o page-right=... # example: \"12\" "
134 TQString whatsThisPrettyprintButtonOnTextPage = i18n(
" <qt> "
135 " <p><b>Turn Text Printing with Syntax Highlighting (Prettyprint) On!</b></p> "
136 " <p>ASCII text file printouts can be 'prettyfied' by enabling this option. If you do so, "
137 " a header is printed at the top of each page. The header contains "
138 " the page number, job title (usually the filename), and the date. In addition, C and "
139 " C++ keywords are highlighted, and comment lines are italicized.</p>"
140 " <p>This prettyprint option is handled by CUPS.</p> "
141 " <p>If you prefer another 'plaintext-to-prettyprint' converter, look for the <em>enscript</em> "
142 " pre-filter on the <em>Filters</em> tab. </p>"
145 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
146 " with the CUPS commandline job option parameter:</em> "
148 " -o prettyprint=true. "
153 TQString whatsThisPrettyprintButtonOffTextPage = i18n(
" <qt> "
154 " <p><b>Turn Text Printing with Syntax Highlighting (Prettyprint) Off! </b></p> "
155 " <p>ASCII text file printing with this option turned off are appearing without a page "
156 " header and without syntax highlighting. (You can still set the page margins, though.) </p> "
159 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
160 " with the CUPS commandline job option parameter:</em> "
162 " -o prettyprint=false "
167 TQString whatsThisPrettyprintFrameTextPage = i18n(
" <qt> "
168 " <p><b>Print Text with Syntax Highlighting (Prettyprint)</b></p> "
169 " <p>ASCII file printouts can be 'prettyfied' by enabling this option. If you do so, "
170 " a header is printed at the top of each page. The header contains "
171 " the page number, job title (usually the filename), and the date. In addition, C and "
172 " C++ keywords are highlighted, and comment lines are italicized.</p>"
173 " <p>This prettyprint option is handled by CUPS.</p> "
174 " <p>If you prefer another 'plaintext-to-prettyprint' converter, look for the <em>enscript</em> "
175 " pre-filter on the <em>Filters</em> tab. </p> "
178 " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
179 " with the CUPS commandline job option parameter:</em> "
181 " -o prettyprint=true. "
183 " -o prettyprint=false "
188 setTitle(i18n(
"Text"));
191 TQGroupBox *formatbox =
new TQGroupBox(0, TQt::Vertical, i18n(
"Text Format"),
this);
192 TQWhatsThis::add(formatbox, whatsThisFormatTextPage);
193 TQGroupBox *prettybox =
new TQGroupBox(0, TQt::Vertical, i18n(
"Syntax Highlighting"),
this);
194 TQWhatsThis::add(prettybox, whatsThisPrettyprintFrameTextPage);
195 TQGroupBox *marginbox =
new TQGroupBox(0, TQt::Vertical, i18n(
"Margins"),
this);
196 TQWhatsThis::add(marginbox, whatsThisMarginsTextPage);
198 m_cpi =
new KIntNumInput(10, formatbox);
199 TQWhatsThis::add(m_cpi, whatsThisCPITextPage);
200 m_cpi->setLabel(i18n(
"&Chars per inch:"), TQt::AlignLeft|TQt::AlignVCenter);
201 m_cpi->setRange(1, 999, 1,
false);
202 m_lpi =
new KIntNumInput(m_cpi, 6, formatbox);
203 TQWhatsThis::add(m_lpi, whatsThisLPITextPage);
204 m_lpi->setLabel(i18n(
"&Lines per inch:"), TQt::AlignLeft|TQt::AlignVCenter);
205 m_lpi->setRange(1, 999, 1,
false);
206 m_columns =
new KIntNumInput(m_lpi, 1, formatbox);
207 TQWhatsThis::add(m_columns, whatsThisColumnsTextPage);
208 m_columns->setLabel(i18n(
"C&olumns:"), TQt::AlignLeft|TQt::AlignVCenter);
209 m_columns->setRange(1, 10, 1,
false);
210 KSeparator *sep =
new KSeparator(TQt::Horizontal, formatbox);
211 connect(m_columns, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(slotColumnsChanged(
int)));
213 m_prettypix =
new TQLabel(prettybox);
214 TQWhatsThis::add(m_prettypix, whatsThisPrettyprintPreviewIconTextPage);
215 m_prettypix->setAlignment(TQt::AlignCenter);
216 TQRadioButton *off =
new TQRadioButton(i18n(
"&Disabled"), prettybox);
217 TQWhatsThis::add(off, whatsThisPrettyprintButtonOffTextPage);
218 TQRadioButton *on =
new TQRadioButton(i18n(
"&Enabled"), prettybox);
219 TQWhatsThis::add(on, whatsThisPrettyprintButtonOnTextPage);
220 m_prettyprint =
new TQButtonGroup(prettybox);
221 m_prettyprint->hide();
222 m_prettyprint->insert(off, 0);
223 m_prettyprint->insert(on, 1);
224 m_prettyprint->setButton(0);
225 connect(m_prettyprint, TQ_SIGNAL(clicked(
int)), TQ_SLOT(slotPrettyChanged(
int)));
226 slotPrettyChanged(0);
228 m_margin =
new MarginWidget(marginbox);
229 TQWhatsThis::add(m_margin, whatsThisMarginsTextPage);
230 m_margin->setPageSize(595, 842);
232 TQGridLayout *l0 =
new TQGridLayout(
this, 2, 2, 0, 10);
233 l0->addWidget(formatbox, 0, 0);
234 l0->addWidget(prettybox, 0, 1);
235 l0->addMultiCellWidget(marginbox, 1, 1, 0, 1);
236 TQVBoxLayout *l1 =
new TQVBoxLayout(formatbox->layout(), 5);
237 l1->addWidget(m_cpi);
238 l1->addWidget(m_lpi);
240 l1->addWidget(m_columns);
241 TQGridLayout *l2 =
new TQGridLayout(prettybox->layout(), 2, 2, 10);
242 l2->addWidget(off, 0, 0);
243 l2->addWidget(on, 1, 0);
244 l2->addMultiCellWidget(m_prettypix, 0, 1, 1, 1);
245 TQVBoxLayout *l3 =
new TQVBoxLayout(marginbox->layout(), 10);
246 l3->addWidget(m_margin);
249 KPTextPage::~KPTextPage()
253 void KPTextPage::setOptions(
const TQMap<TQString,TQString>& opts)
257 if (!(value=opts[
"cpi"]).isEmpty())
258 m_cpi->setValue(value.toInt());
259 if (!(value=opts[
"lpi"]).isEmpty())
260 m_lpi->setValue(value.toInt());
261 if (!(value=opts[
"columns"]).isEmpty())
262 m_columns->setValue(value.toInt());
264 if (opts.contains(
"prettyprint") && (opts[
"prettyprint"].isEmpty() || opts[
"prettyprint"] ==
"true"))
266 m_prettyprint->setButton(ID);
267 slotPrettyChanged(ID);
270 m_currentps = opts[
"PageSize"];
271 TQString orient = opts[
"orientation-requested"];
272 bool landscape = (orient ==
"4" || orient ==
"5");
273 initPageSize(landscape);
275 bool marginset(
false);
276 if (!(value=opts[
"page-top"]).isEmpty() && value.toFloat() != m_margin->top())
279 m_margin->setTop(value.toFloat());
281 if (!(value=opts[
"page-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
284 m_margin->setBottom(value.toFloat());
286 if (!(value=opts[
"page-left"]).isEmpty() && value.toFloat() != m_margin->left())
289 m_margin->setLeft(value.toFloat());
291 if (!(value=opts[
"page-right"]).isEmpty() && value.toFloat() != m_margin->right())
294 m_margin->setRight(value.toFloat());
296 m_margin->setCustomEnabled(marginset);
299 void KPTextPage::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
301 if (incldef || m_cpi->value() != 10)
302 opts[
"cpi"] = TQString::number(m_cpi->value());
303 if (incldef || m_lpi->value() != 6)
304 opts[
"lpi"] = TQString::number(m_lpi->value());
305 if (incldef || m_columns->value() != 1)
306 opts[
"columns"] = TQString::number(m_columns->value());
309 if (m_margin->isCustomEnabled())
311 opts[
"page-top"] = TQString::number((
int )( m_margin->top()+0.5 ));
312 opts[
"page-bottom"] = TQString::number((
int )( m_margin->bottom()+0.5 ));
313 opts[
"page-left"] = TQString::number((
int )( m_margin->left()+0.5 ));
314 opts[
"page-right"] = TQString::number((
int )( m_margin->right()+0.5 ));
318 opts.remove(
"page-top");
319 opts.remove(
"page-bottom");
320 opts.remove(
"page-left");
321 opts.remove(
"page-right");
324 if (m_prettyprint->id(m_prettyprint->selected()) == 1)
325 opts[
"prettyprint"] =
"true";
327 opts[
"prettyprint"] =
"false";
329 opts.remove(
"prettyprint");
332 void KPTextPage::slotPrettyChanged(
int ID)
334 TQString iconstr = (ID == 0 ?
"tdeprint_nup1" :
"tdeprint_prettyprint");
335 m_prettypix->setPixmap(UserIcon(iconstr));
338 void KPTextPage::slotColumnsChanged(
int)
343 void KPTextPage::initPageSize(
bool landscape)
345 float w( -1 ), h( -1 );
346 float mt( 36 ), mb( mt ), ml( 18 ), mr( ml );
349 if (m_currentps.isEmpty())
351 DrListOption *o = (DrListOption*)driver()->findOption(
"PageSize");
353 m_currentps = o->get(
"default");
355 if (!m_currentps.isEmpty())
357 DrPageSize *ps = driver()->findPageSize(m_currentps);
361 h = ps->pageHeight();
362 mt = ps->topMargin();
363 ml = ps->leftMargin();
364 mr = ps->rightMargin();
365 mb = ps->bottomMargin();
369 m_margin->setPageSize(w, h);
370 m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
371 m_margin->setDefaultMargins( mt, mb, ml, mr );
372 m_margin->setCustomEnabled(
false);
375 #include "kptextpage.moc"
This class is intended to be used as base class for customized print dialog page.