• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • cups
kptextpage.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "kptextpage.h"
21 #include "marginwidget.h"
22 #include "driver.h"
23 #include "kprinter.h"
24 
25 #include <tqbuttongroup.h>
26 #include <tqgroupbox.h>
27 #include <tqlayout.h>
28 #include <tqlabel.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>
35 #include <kdebug.h>
36 
37 KPTextPage::KPTextPage(DrMain *driver, TQWidget *parent, const char *name)
38 : KPrintDialogPage(0, driver, parent, name)
39 {
40  //WhatsThis strings.... (added by pfeifle@kde.org)
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> "
46  " <hr> "
47  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
48  " with the CUPS commandline job option parameter:</em> "
49  " <pre>"
50  " -o cpi=... # example: \"8\" or \"12\" "
51  " </pre>"
52  " </p> "
53  " </qt>" );
54 
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> "
60  " <hr> "
61  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
62  " with the CUPS commandline job option parameter:</em> "
63  " <pre>"
64  " -o lpi=... # example \"5\" or \"7\" "
65  " </pre>"
66  " </p> "
67  " </qt>" );
68 
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> "
75  " <hr> "
76  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
77  " with the CUPS commandline job option parameter:</em> "
78  " <pre>"
79  " -o columns=... # example: \"2\" or \"4\" "
80  " </pre>"
81  " </p> "
82  " </qt>" );
83 
84  TQString whatsThisPrettyprintPreviewIconTextPage = i18n( " <qt> "
85  " Preview icon changes when you turn on or off prettyprint. "
86  " </qt>" );
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>."
95  " <hr> "
96  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
97  " with the CUPS commandline job option parameter:</em> "
98  " <pre>"
99  " -o cpi=... # example: \"8\" or \"12\" "
100  " <br> "
101  " -o lpi=... # example: \"5\" or \"7\" "
102  " <br> "
103  " -o columns=... # example: \"2\" or \"4\" "
104  " </pre>"
105  " </p> "
106  " </qt>" );
107 
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> "
119  " <hr> "
120  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
121  " with the CUPS commandline job option parameter:</em> "
122  " <pre>"
123  " -o page-top=... # example: \"72\" "
124  " <br> "
125  " -o page-bottom=... # example: \"24\" "
126  " <br> "
127  " -o page-left=... # example: \"36\" "
128  " <br> "
129  " -o page-right=... # example: \"12\" "
130  " </pre>"
131  " </p> "
132  " </qt>" );
133 
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>"
143  " <br> "
144  " <hr> "
145  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
146  " with the CUPS commandline job option parameter:</em> "
147  " <pre>"
148  " -o prettyprint=true. "
149  " </pre>"
150  " </p> "
151  " </qt>" );
152 
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> "
157  " <br> "
158  " <hr> "
159  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
160  " with the CUPS commandline job option parameter:</em> "
161  " <pre>"
162  " -o prettyprint=false "
163  " </pre>"
164  " </p> "
165  " </qt>" );
166 
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> "
176  " <br> "
177  " <hr> "
178  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
179  " with the CUPS commandline job option parameter:</em> "
180  " <pre>"
181  " -o prettyprint=true. "
182  " <br> "
183  " -o prettyprint=false "
184  " </pre>"
185  " </p> "
186  " </qt>" );
187 
188  setTitle(i18n("Text"));
189  m_block = false;
190 
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);
197 
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)));
212 
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);
227 
228  m_margin = new MarginWidget(marginbox);
229  TQWhatsThis::add(m_margin, whatsThisMarginsTextPage);
230  m_margin->setPageSize(595, 842);
231 
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);
239  l1->addWidget(sep);
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);
247 }
248 
249 KPTextPage::~KPTextPage()
250 {
251 }
252 
253 void KPTextPage::setOptions(const TQMap<TQString,TQString>& opts)
254 {
255  TQString value;
256 
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());
263  int ID(0);
264  if (opts.contains("prettyprint") && (opts["prettyprint"].isEmpty() || opts["prettyprint"] == "true"))
265  ID = 1;
266  m_prettyprint->setButton(ID);
267  slotPrettyChanged(ID);
268 
269  // get default margins
270  m_currentps = opts["PageSize"];
271  TQString orient = opts["orientation-requested"];
272  bool landscape = (orient == "4" || orient == "5");
273  initPageSize(landscape);
274 
275  bool marginset(false);
276  if (!(value=opts["page-top"]).isEmpty() && value.toFloat() != m_margin->top())
277  {
278  marginset = true;
279  m_margin->setTop(value.toFloat());
280  }
281  if (!(value=opts["page-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
282  {
283  marginset = true;
284  m_margin->setBottom(value.toFloat());
285  }
286  if (!(value=opts["page-left"]).isEmpty() && value.toFloat() != m_margin->left())
287  {
288  marginset = true;
289  m_margin->setLeft(value.toFloat());
290  }
291  if (!(value=opts["page-right"]).isEmpty() && value.toFloat() != m_margin->right())
292  {
293  marginset = true;
294  m_margin->setRight(value.toFloat());
295  }
296  m_margin->setCustomEnabled(marginset);
297 }
298 
299 void KPTextPage::getOptions(TQMap<TQString,TQString>& opts, bool incldef)
300 {
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());
307 
308  //if (m_margin->isCustomEnabled() || incldef)
309  if (m_margin->isCustomEnabled())
310  {
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 ));
315  }
316  else
317  {
318  opts.remove("page-top");
319  opts.remove("page-bottom");
320  opts.remove("page-left");
321  opts.remove("page-right");
322  }
323 
324  if (m_prettyprint->id(m_prettyprint->selected()) == 1)
325  opts["prettyprint"] = "true";
326  else if (incldef)
327  opts["prettyprint"] = "false";
328  else
329  opts.remove("prettyprint");
330 }
331 
332 void KPTextPage::slotPrettyChanged(int ID)
333 {
334  TQString iconstr = (ID == 0 ? "tdeprint_nup1" : "tdeprint_prettyprint");
335  m_prettypix->setPixmap(UserIcon(iconstr));
336 }
337 
338 void KPTextPage::slotColumnsChanged(int)
339 {
340  // TO BE IMPLEMENTED
341 }
342 
343 void KPTextPage::initPageSize(bool landscape)
344 {
345  float w( -1 ), h( -1 );
346  float mt( 36 ), mb( mt ), ml( 18 ), mr( ml );
347  if (driver())
348  {
349  if (m_currentps.isEmpty())
350  {
351  DrListOption *o = (DrListOption*)driver()->findOption("PageSize");
352  if (o)
353  m_currentps = o->get("default");
354  }
355  if (!m_currentps.isEmpty())
356  {
357  DrPageSize *ps = driver()->findPageSize(m_currentps);
358  if (ps)
359  {
360  w = ps->pageWidth();
361  h = ps->pageHeight();
362  mt = ps->topMargin();
363  ml = ps->leftMargin();
364  mr = ps->rightMargin();
365  mb = ps->bottomMargin();
366  }
367  }
368  }
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);
373 }
374 
375 #include "kptextpage.moc"
KPrintDialogPage
This class is intended to be used as base class for customized print dialog page.
Definition: kprintdialogpage.h:91

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.