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

kate

  • kate
  • part
kateprinter.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001-2002 Michael Goffioul <tdeprint@swing.be>
4  * Complete rewrite on Sat Jun 15 2002 (c) Anders Lund <anders@alweb.dk>
5  * Copyright (c) 2002, 2003 Anders Lund <anders@alweb.dk>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License version 2 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  **/
21 
22 #include "kateprinter.h"
23 
24 #include <kateconfig.h>
25 #include <katedocument.h>
26 #include <katefactory.h>
27 #include <katehighlight.h>
28 #include <katelinerange.h>
29 #include <katerenderer.h>
30 #include <kateschema.h>
31 #include <katetextline.h>
32 
33 #include <tdeapplication.h>
34 #include <kcolorbutton.h>
35 #include <kdebug.h>
36 #include <kdialog.h> // for spacingHint()
37 #include <tdefontdialog.h>
38 #include <tdelocale.h>
39 #include <kprinter.h>
40 #include <kurl.h>
41 #include <kuser.h> // for loginName
42 
43 #include <tqpainter.h>
44 #include <tqpopupmenu.h>
45 #include <tqpaintdevicemetrics.h>
46 #include <tqcheckbox.h>
47 #include <tqcombobox.h>
48 #include <tqgroupbox.h>
49 #include <tqhbox.h>
50 #include <tqlabel.h>
51 #include <tqlayout.h>
52 #include <tqlineedit.h>
53 #include <tqspinbox.h>
54 #include <tqstringlist.h>
55 #include <tqwhatsthis.h>
56 
57 //BEGIN KatePrinter
58 bool KatePrinter::print (KateDocument *doc)
59 {
60 #ifndef Q_WS_WIN //TODO: reenable
61  KPrinter printer;
62 
63  // docname is now always there, including the right Untitled name
64  printer.setDocName(doc->docName());
65 
66  KatePrintTextSettings *kpts = new KatePrintTextSettings(&printer, NULL);
67  kpts->enableSelection( doc->hasSelection() );
68  printer.addDialogPage( kpts );
69  printer.addDialogPage( new KatePrintHeaderFooter(&printer, NULL) );
70  printer.addDialogPage( new KatePrintLayout(&printer, NULL) );
71 
72  if ( printer.setup( kapp->mainWidget(), i18n("Print %1").arg(printer.docName()) ) )
73  {
74  KateRenderer renderer(doc);
75  //renderer.config()->setSchema (1);
76  renderer.setPrinterFriendly(true);
77 
78  TQPainter paint( &printer );
79  TQPaintDeviceMetrics pdm( &printer );
80  /*
81  We work in tree cycles:
82  1) initialize variables and retrieve print settings
83  2) prepare data according to those settings
84  3) draw to the printer
85  */
86  uint pdmWidth = pdm.width();
87  uint y = 0;
88  uint xstart = 0; // beginning point for painting lines
89  uint lineCount = 0;
90  uint maxWidth = pdmWidth;
91  uint headerWidth = pdmWidth;
92  int startCol = 0;
93  int endCol = 0;
94  bool needWrap = true;
95  bool pageStarted = true;
96 
97  // Text Settings Page
98  bool selectionOnly = ( doc->hasSelection() &&
99  ( printer.option("app-kate-printselection") == "true" ) );
100  int selStartCol = 0;
101  int selEndCol = 0;
102 
103  bool useGuide = ( printer.option("app-kate-printguide") == "true" );
104  int guideHeight = 0;
105  int guideCols = 0;
106 
107  bool printLineNumbers = ( printer.option("app-kate-printlinenumbers") == "true" );
108  uint lineNumberWidth( 0 );
109 
110  // Header/Footer Page
111  TQFont headerFont; // used for header/footer
112  TQString f = printer.option("app-kate-hffont");
113  if (!f.isEmpty())
114  headerFont.fromString( f );
115 
116  bool useHeader = (printer.option("app-kate-useheader") == "true");
117  TQColor headerBgColor(printer.option("app-kate-headerbg"));
118  TQColor headerFgColor(printer.option("app-kate-headerfg"));
119  uint headerHeight( 0 ); // further init only if needed
120  TQStringList headerTagList; // do
121  bool headerDrawBg = false; // do
122 
123  bool useFooter = (printer.option("app-kate-usefooter") == "true");
124  TQColor footerBgColor(printer.option("app-kate-footerbg"));
125  TQColor footerFgColor(printer.option("app-kate-footerfg"));
126  uint footerHeight( 0 ); // further init only if needed
127  TQStringList footerTagList = 0; // do
128  bool footerDrawBg = 0; // do
129 
130  // Layout Page
131  renderer.config()->setSchema( KateFactory::self()->schemaManager()->number(
132  printer.option("app-kate-colorscheme") ) );
133  bool useBackground = ( printer.option("app-kate-usebackground") == "true" );
134  bool useBox = (printer.option("app-kate-usebox") == "true");
135  int boxWidth(printer.option("app-kate-boxwidth").toInt());
136  TQColor boxColor(printer.option("app-kate-boxcolor"));
137  int innerMargin = useBox ? printer.option("app-kate-boxmargin").toInt() : 6;
138 
139  // Post initialization
140  uint maxHeight = (useBox ? pdm.height()-innerMargin : pdm.height());
141  uint currentPage( 1 );
142  uint lastline = doc->lastLine(); // nessecary to print selection only
143  uint firstline( 0 );
144 
145  KateHlItemDataList ilist;
146 
147  if (useGuide)
148  doc->highlight()->getKateHlItemDataListCopy (renderer.config()->schema(), ilist);
149 
150  /*
151  Now on for preparations...
152  during preparations, variable names starting with a "_" means
153  those variables are local to the enclosing block.
154  */
155  {
156  if ( selectionOnly )
157  {
158  // set a line range from the first selected line to the last
159  firstline = doc->selStartLine();
160  selStartCol = doc->selStartCol();
161  lastline = doc->selEndLine();
162  selEndCol = doc->selEndCol();
163 
164  lineCount = firstline;
165  }
166 
167  if ( printLineNumbers )
168  {
169  // figure out the horiizontal space required
170  TQString s( TQString("%1 ").arg( doc->numLines() ) );
171  s.fill('5', -1); // some non-fixed fonts haven't equally wide numbers
172  // FIXME calculate which is actually the widest...
173  lineNumberWidth = renderer.currentFontMetrics()->width( s );
174  // a small space between the line numbers and the text
175  int _adj = renderer.currentFontMetrics()->width( "5" );
176  // adjust available width and set horizontal start point for data
177  maxWidth -= (lineNumberWidth + _adj);
178  xstart += lineNumberWidth + _adj;
179  }
180 
181  if ( useHeader || useFooter )
182  {
183  // Set up a tag map
184  // This retrieves all tags, ued or not, but
185  // none of theese operations should be expensive,
186  // and searcing each tag in the format strings is avoided.
187  TQDateTime dt = TQDateTime::currentDateTime();
188  TQMap<TQString,TQString> tags;
189 
190  KUser u (KUser::UseRealUserID);
191  tags["u"] = u.loginName();
192 
193  tags["d"] = TDEGlobal::locale()->formatDateTime(dt, true, false);
194  tags["D"] = TDEGlobal::locale()->formatDateTime(dt, false, false);
195  tags["h"] = TDEGlobal::locale()->formatTime(TQT_TQTIME_OBJECT(dt.time()), false);
196  tags["y"] = TDEGlobal::locale()->formatDate(TQT_TQDATE_OBJECT(dt.date()), true);
197  tags["Y"] = TDEGlobal::locale()->formatDate(TQT_TQDATE_OBJECT(dt.date()), false);
198  tags["f"] = doc->url().fileName();
199  tags["U"] = doc->url().prettyURL();
200  if ( selectionOnly )
201  {
202  TQString s( i18n("(Selection of) ") );
203  tags["f"].prepend( s );
204  tags["U"].prepend( s );
205  }
206 
207  TQRegExp reTags( "%([dDfUhuyY])" ); // TODO tjeck for "%%<TAG>"
208 
209  if (useHeader)
210  {
211  headerDrawBg = ( printer.option("app-kate-headerusebg") == "true" );
212  headerHeight = TQFontMetrics( headerFont ).height();
213  if ( useBox || headerDrawBg )
214  headerHeight += innerMargin * 2;
215  else
216  headerHeight += 1 + TQFontMetrics( headerFont ).leading();
217 
218  TQString headerTags = printer.option("app-kate-headerformat");
219  int pos = reTags.search( headerTags );
220  TQString rep;
221  while ( pos > -1 )
222  {
223  rep = tags[reTags.cap( 1 )];
224  headerTags.replace( (uint)pos, 2, rep );
225  pos += rep.length();
226  pos = reTags.search( headerTags, pos );
227  }
228  headerTagList = TQStringList::split('|', headerTags, true);
229 
230  if (!headerBgColor.isValid())
231  headerBgColor = Qt::lightGray;
232  if (!headerFgColor.isValid())
233  headerFgColor = Qt::black;
234  }
235 
236  if (useFooter)
237  {
238  footerDrawBg = ( printer.option("app-kate-footerusebg") == "true" );
239  footerHeight = TQFontMetrics( headerFont ).height();
240  if ( useBox || footerDrawBg )
241  footerHeight += 2*innerMargin;
242  else
243  footerHeight += 1; // line only
244 
245  TQString footerTags = printer.option("app-kate-footerformat");
246  int pos = reTags.search( footerTags );
247  TQString rep;
248  while ( pos > -1 )
249  {
250  rep = tags[reTags.cap( 1 )];
251  footerTags.replace( (uint)pos, 2, rep );
252  pos += rep.length();
253  pos = reTags.search( footerTags, pos );
254  }
255 
256  footerTagList = TQStringList::split('|', footerTags, true);
257  if (!footerBgColor.isValid())
258  footerBgColor = Qt::lightGray;
259  if (!footerFgColor.isValid())
260  footerFgColor = Qt::black;
261  // adjust maxheight, so we can know when/where to print footer
262  maxHeight -= footerHeight;
263  }
264  } // if ( useHeader || useFooter )
265 
266  if ( useBackground )
267  {
268  if ( ! useBox )
269  {
270  xstart += innerMargin;
271  maxWidth -= innerMargin * 2;
272  }
273  }
274 
275  if ( useBox )
276  {
277  if (!boxColor.isValid())
278  boxColor = Qt::black;
279  if (boxWidth < 1) // shouldn't be pssible no more!
280  boxWidth = 1;
281  // set maxwidth to something sensible
282  maxWidth -= ( ( boxWidth + innerMargin ) * 2 );
283  xstart += boxWidth + innerMargin;
284  // maxheight too..
285  maxHeight -= boxWidth;
286  }
287  else
288  boxWidth = 0;
289 
290  if ( useGuide )
291  {
292  // calculate the height required
293  // the number of columns is a side effect, saved for drawing time
294  // first width is needed
295  int _w = pdmWidth - innerMargin * 2;
296  if ( useBox )
297  _w -= boxWidth * 2;
298  else
299  {
300  if ( useBackground )
301  _w -= ( innerMargin * 2 );
302  _w -= 2; // 1 px line on each side
303  }
304 
305  // base of height: margins top/bottom, above and below tetle sep line
306  guideHeight = ( innerMargin * 4 ) + 1;
307 
308  // get a title and add the height required to draw it
309  TQString _title = i18n("Typographical Conventions for %1").arg(doc->highlight()->name());
310  guideHeight += paint.boundingRect( 0, 0, _w, 1000, Qt::AlignTop|Qt::AlignHCenter, _title ).height();
311 
312  // see how many columns we can fit in
313  int _widest( 0 );
314 
315  TQPtrListIterator<KateHlItemData> it( ilist );
316  KateHlItemData *_d;
317 
318  int _items ( 0 );
319  while ( ( _d = it.current()) != 0 )
320  {
321  _widest = kMax( _widest, ((TQFontMetrics)(
322  _d->bold() ?
323  _d->italic() ?
324  renderer.config()->fontStruct()->myFontMetricsBI :
325  renderer.config()->fontStruct()->myFontMetricsBold :
326  _d->italic() ?
327  renderer.config()->fontStruct()->myFontMetricsItalic :
328  renderer.config()->fontStruct()->myFontMetrics
329  ) ).width( _d->name ) );
330  _items++;
331  ++it;
332  }
333  guideCols = _w/( _widest + innerMargin );
334  // add height for required number of lines needed given columns
335  guideHeight += renderer.fontHeight() * ( _items/guideCols );
336  if ( _items%guideCols )
337  guideHeight += renderer.fontHeight();
338  }
339 
340  // now that we know the vertical amount of space needed,
341  // it is possible to calculate the total number of pages
342  // if needed, that is if any header/footer tag contains "%P".
343  if ( headerTagList.grep("%P").count() || footerTagList.grep("%P").count() )
344  {
345  kdDebug(13020)<<"'%P' found! calculating number of pages..."<<endl;
346  uint _pages = 0;
347  uint _ph = maxHeight;
348  if ( useHeader )
349  _ph -= ( headerHeight + innerMargin );
350  if ( useFooter )
351  _ph -= innerMargin;
352  int _lpp = _ph / renderer.fontHeight();
353  uint _lt = 0, _c=0;
354 
355  // add space for guide if required
356  if ( useGuide )
357  _lt += (guideHeight + (renderer.fontHeight() /2)) / renderer.fontHeight();
358  long _lw;
359  for ( uint i = firstline; i < lastline; i++ )
360  {
361  _lw = renderer.textWidth( doc->kateTextLine( i ), -1 );
362  while ( _lw >= 0 )
363  {
364  _c++;
365  _lt++;
366  if ( (int)_lt == _lpp )
367  {
368  _pages++;
369  _lt = 0;
370  }
371  _lw -= maxWidth;
372  if ( ! _lw ) _lw--; // skip lines matching exactly!
373  }
374  }
375  if ( _lt ) _pages++; // last page
376 
377  // substitute both tag lists
378  TQString re("%P");
379  TQStringList::Iterator it;
380  for ( it=headerTagList.begin(); it!=headerTagList.end(); ++it )
381  (*it).replace( re, TQString( "%1" ).arg( _pages ) );
382  for ( it=footerTagList.begin(); it!=footerTagList.end(); ++it )
383  (*it).replace( re, TQString( "%1" ).arg( _pages ) );
384  }
385  } // end prepare block
386 
387  /*
388  On to draw something :-)
389  */
390  uint _count = 0;
391  while ( lineCount <= lastline )
392  {
393  startCol = 0;
394  endCol = 0;
395  needWrap = true;
396 
397  while (needWrap)
398  {
399  if ( y + renderer.fontHeight() >= (uint)(maxHeight) )
400  {
401  kdDebug(13020)<<"Starting new page, "<<_count<<" lines up to now."<<endl;
402  printer.newPage();
403  currentPage++;
404  pageStarted = true;
405  y=0;
406  }
407 
408  if ( pageStarted )
409  {
410 
411  if ( useHeader )
412  {
413  paint.setPen(headerFgColor);
414  paint.setFont(headerFont);
415  if ( headerDrawBg )
416  paint.fillRect(0, 0, headerWidth, headerHeight, headerBgColor);
417  if (headerTagList.count() == 3)
418  {
419  int valign = ( (useBox||headerDrawBg||useBackground) ?
420  Qt::AlignVCenter : Qt::AlignTop );
421  int align = valign|Qt::AlignLeft;
422  int marg = ( useBox || headerDrawBg ) ? innerMargin : 0;
423  if ( useBox ) marg += boxWidth;
424  TQString s;
425  for (int i=0; i<3; i++)
426  {
427  s = headerTagList[i];
428  if (s.find("%p") != -1) s.replace("%p", TQString::number(currentPage));
429  paint.drawText(marg, 0, headerWidth-(marg*2), headerHeight, align, s);
430  align = valign|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
431  }
432  }
433  if ( ! ( headerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate header from contents
434  {
435  paint.drawLine( 0, headerHeight-1, headerWidth, headerHeight-1 );
436  //y += 1; now included in headerHeight
437  }
438  y += headerHeight + innerMargin;
439  }
440 
441  if ( useFooter )
442  {
443  if ( ! ( footerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate footer from contents
444  paint.drawLine( 0, maxHeight + innerMargin - 1, headerWidth, maxHeight + innerMargin - 1 );
445  if ( footerDrawBg )
446  paint.fillRect(0, maxHeight+innerMargin+boxWidth, headerWidth, footerHeight, footerBgColor);
447  if (footerTagList.count() == 3)
448  {
449  int align = Qt::AlignVCenter|Qt::AlignLeft;
450  int marg = ( useBox || footerDrawBg ) ? innerMargin : 0;
451  if ( useBox ) marg += boxWidth;
452  TQString s;
453  for (int i=0; i<3; i++)
454  {
455  s = footerTagList[i];
456  if (s.find("%p") != -1) s.replace("%p", TQString::number(currentPage));
457  paint.drawText(marg, maxHeight+innerMargin, headerWidth-(marg*2), footerHeight, align, s);
458  align = Qt::AlignVCenter|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
459  }
460  }
461  } // done footer
462 
463  if ( useBackground )
464  {
465  // If we have a box, or the header/footer has backgrounds, we want to paint
466  // to the border of those. Otherwise just the contents area.
467  int _y = y, _h = maxHeight - y;
468  if ( useBox )
469  {
470  _y -= innerMargin;
471  _h += 2 * innerMargin;
472  }
473  else
474  {
475  if ( headerDrawBg )
476  {
477  _y -= innerMargin;
478  _h += innerMargin;
479  }
480  if ( footerDrawBg )
481  {
482  _h += innerMargin;
483  }
484  }
485  paint.fillRect( 0, _y, pdmWidth, _h, renderer.config()->backgroundColor());
486  }
487 
488  if ( useBox )
489  {
490  paint.setPen(TQPen(boxColor, boxWidth));
491  paint.drawRect(0, 0, pdmWidth, pdm.height());
492  if (useHeader)
493  paint.drawLine(0, headerHeight, headerWidth, headerHeight);
494  else
495  y += innerMargin;
496 
497  if ( useFooter ) // drawline is not trustable, grr.
498  paint.fillRect( 0, maxHeight+innerMargin, headerWidth, boxWidth, boxColor );
499  }
500 
501  if ( useGuide && currentPage == 1 )
502  { // FIXME - this may span more pages...
503  // draw a box unless we have boxes, in which case we end with a box line
504 
505  // use color of dsNormal for the title string and the hline
506  KateAttributeList _dsList;
507  KateHlManager::self()->getDefaults ( renderer.config()->schema(), _dsList );
508  paint.setPen( _dsList.at(0)->textColor() );
509  int _marg = 0; // this could be available globally!??
510  if ( useBox )
511  {
512  _marg += (2*boxWidth) + (2*innerMargin);
513  paint.fillRect( 0, y+guideHeight-innerMargin-boxWidth, headerWidth, boxWidth, boxColor );
514  }
515  else
516  {
517  if ( useBackground )
518  _marg += 2*innerMargin;
519  paint.drawRect( _marg, y, pdmWidth-(2*_marg), guideHeight );
520  _marg += 1;
521  y += 1 + innerMargin;
522  }
523  // draw a title string
524  paint.setFont( renderer.config()->fontStruct()->myFontBold );
525  TQRect _r;
526  paint.drawText( _marg, y, pdmWidth-(2*_marg), maxHeight - y,
527  Qt::AlignTop|Qt::AlignHCenter,
528  i18n("Typographical Conventions for %1").arg(doc->highlight()->name()), -1, &_r );
529  int _w = pdmWidth - (_marg*2) - (innerMargin*2);
530  int _x = _marg + innerMargin;
531  y += _r.height() + innerMargin;
532  paint.drawLine( _x, y, _x + _w, y );
533  y += 1 + innerMargin;
534  // draw attrib names using their styles
535 
536  TQPtrListIterator<KateHlItemData> _it( ilist );
537  KateHlItemData *_d;
538  int _cw = _w/guideCols;
539  int _i(0);
540 
541  while ( ( _d = _it.current() ) != 0 )
542  {
543  paint.setPen( renderer.attribute(_i)->textColor() );
544  paint.setFont( renderer.attribute(_i)->font( *renderer.currentFont() ) );
545  paint.drawText(( _x + ((_i%guideCols)*_cw)), y, _cw, renderer.fontHeight(),
546  Qt::AlignVCenter|Qt::AlignLeft, _d->name, -1, &_r );
547  _i++;
548  if ( _i && ! ( _i%guideCols ) ) y += renderer.fontHeight();
549  ++_it;
550  }
551  if ( _i%guideCols ) y += renderer.fontHeight();// last row not full
552  y += ( useBox ? boxWidth : 1 ) + (innerMargin*2);
553  }
554 
555  pageStarted = false;
556  } // pageStarted; move on to contents:)
557 
558  if ( printLineNumbers && ! startCol ) // don't repeat!
559  {
560  paint.setFont( renderer.config()->fontStruct()->font( false, false ) );
561  paint.setPen( renderer.config()->lineNumberColor() );
562  paint.drawText( (( useBox || useBackground ) ? innerMargin : 0), y,
563  lineNumberWidth, renderer.fontHeight(),
564  Qt::AlignRight, TQString("%1").arg( lineCount + 1 ) );
565  }
566  endCol = renderer.textWidth(doc->kateTextLine(lineCount), startCol, maxWidth, &needWrap);
567 
568  if ( endCol < startCol )
569  {
570  //kdDebug(13020)<<"--- Skipping garbage, line: "<<lineCount<<" start: "<<startCol<<" end: "<<endCol<<" real EndCol; "<< buffer->line(lineCount)->length()<< " !?"<<endl;
571  lineCount++;
572  continue; // strange case...
573  // Happens if the line fits exactly.
574  // When it happens, a line of garbage would be printed.
575  // FIXME Most likely this is an error in textWidth(),
576  // failing to correctly set needWrap to false in this case?
577  }
578 
579  // if we print only selection:
580  // print only selected range of chars.
581  bool skip = false;
582  if ( selectionOnly )
583  {
584  bool inBlockSelection = ( doc->blockSelectionMode() && lineCount >= firstline && lineCount <= lastline );
585  if ( lineCount == firstline || inBlockSelection )
586  {
587  if ( startCol < selStartCol )
588  startCol = selStartCol;
589  }
590  if ( lineCount == lastline || inBlockSelection )
591  {
592  if ( endCol > selEndCol )
593  {
594  endCol = selEndCol;
595  skip = true;
596  }
597  }
598  }
599 
600  // HA! this is where we print [part of] a line ;]]
601  // FIXME Convert this function + related functionality to a separate KatePrintView
602  KateLineRange range;
603  range.line = lineCount;
604  range.startCol = startCol;
605  range.endCol = endCol;
606  range.wrap = needWrap;
607  paint.translate(xstart, y);
608  renderer.paintTextLine(paint, &range, 0, maxWidth);
609  paint.resetXForm();
610  if ( skip )
611  {
612  needWrap = false;
613  startCol = 0;
614  }
615  else
616  {
617  startCol = endCol;
618  }
619 
620  y += renderer.fontHeight();
621  _count++;
622  } // done while ( needWrap )
623 
624  lineCount++;
625  } // done lineCount <= lastline
626  return true;
627  }
628 
629 #endif
630  return false;
631 }
632 //END KatePrinter
633 
634 #ifndef Q_WS_WIN //TODO: reenable
635 //BEGIN KatePrintTextSettings
636 KatePrintTextSettings::KatePrintTextSettings( KPrinter * /*printer*/, TQWidget *parent, const char *name )
637  : KPrintDialogPage( parent, name )
638 {
639  setTitle( i18n("Te&xt Settings") );
640 
641  TQVBoxLayout *lo = new TQVBoxLayout ( this );
642  lo->setSpacing( KDialog::spacingHint() );
643 
644  cbSelection = new TQCheckBox( i18n("Print &selected text only"), this );
645  lo->addWidget( cbSelection );
646 
647  cbLineNumbers = new TQCheckBox( i18n("Print &line numbers"), this );
648  lo->addWidget( cbLineNumbers );
649 
650  cbGuide = new TQCheckBox( i18n("Print syntax &guide"), this );
651  lo->addWidget( cbGuide );
652 
653  lo->addStretch( 1 );
654 
655  // set defaults - nothing to do :-)
656 
657  // whatsthis
658  TQWhatsThis::add( cbSelection, i18n(
659  "<p>This option is only available if some text is selected in the document.</p>"
660  "<p>If available and enabled, only the selected text is printed.</p>") );
661  TQWhatsThis::add( cbLineNumbers, i18n(
662  "<p>If enabled, line numbers will be printed on the left side of the page(s).</p>") );
663  TQWhatsThis::add( cbGuide, i18n(
664  "<p>Print a box displaying typographical conventions for the document type, as "
665  "defined by the syntax highlighting being used.") );
666 }
667 
668 void KatePrintTextSettings::getOptions( TQMap<TQString,TQString>& opts, bool )
669 {
670  opts["app-kate-printselection"] = cbSelection->isChecked() ? "true" : "false";
671  opts["app-kate-printlinenumbers"] = cbLineNumbers->isChecked() ? "true" : "false";
672  opts["app-kate-printguide"] = cbGuide->isChecked() ? "true" : "false" ;
673 }
674 
675 void KatePrintTextSettings::setOptions( const TQMap<TQString,TQString>& opts )
676 {
677  TQString v;
678  v = opts["app-kate-printselection"];
679  if ( ! v.isEmpty() )
680  cbSelection->setChecked( v == "true" );
681  v = opts["app-kate-printlinenumbers"];
682  if ( ! v.isEmpty() )
683  cbLineNumbers->setChecked( v == "true" );
684  v = opts["app-kate-printguide"];
685  if ( ! v.isEmpty() )
686  cbGuide->setChecked( v == "true" );
687 }
688 
689 void KatePrintTextSettings::enableSelection( bool enable )
690 {
691  cbSelection->setEnabled( enable );
692 }
693 
694 //END KatePrintTextSettings
695 
696 //BEGIN KatePrintHeaderFooter
697 KatePrintHeaderFooter::KatePrintHeaderFooter( KPrinter * /*printer*/, TQWidget *parent, const char *name )
698  : KPrintDialogPage( parent, name )
699 {
700  setTitle( i18n("Hea&der && Footer") );
701 
702  TQVBoxLayout *lo = new TQVBoxLayout ( this );
703  uint sp = KDialog::spacingHint();
704  lo->setSpacing( sp );
705 
706  // enable
707  TQHBoxLayout *lo1 = new TQHBoxLayout ( lo );
708  cbEnableHeader = new TQCheckBox( i18n("Pr&int header"), this );
709  lo1->addWidget( cbEnableHeader );
710  cbEnableFooter = new TQCheckBox( i18n("Pri&nt footer"), this );
711  lo1->addWidget( cbEnableFooter );
712 
713  // font
714  TQHBoxLayout *lo2 = new TQHBoxLayout( lo );
715  lo2->addWidget( new TQLabel( i18n("Header/footer font:"), this ) );
716  lFontPreview = new TQLabel( this );
717  lFontPreview->setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
718  lo2->addWidget( lFontPreview );
719  lo2->setStretchFactor( lFontPreview, 1 );
720  TQPushButton *btnChooseFont = new TQPushButton( i18n("Choo&se Font..."), this );
721  lo2->addWidget( btnChooseFont );
722  connect( btnChooseFont, TQT_SIGNAL(clicked()), this, TQT_SLOT(setHFFont()) );
723  // header
724  gbHeader = new TQGroupBox( 2, Qt::Horizontal, i18n("Header Properties"), this );
725  lo->addWidget( gbHeader );
726 
727  TQLabel *lHeaderFormat = new TQLabel( i18n("&Format:"), gbHeader );
728  TQHBox *hbHeaderFormat = new TQHBox( gbHeader );
729  hbHeaderFormat->setSpacing( sp );
730  leHeaderLeft = new TQLineEdit( hbHeaderFormat );
731  leHeaderCenter = new TQLineEdit( hbHeaderFormat );
732  leHeaderRight = new TQLineEdit( hbHeaderFormat );
733  lHeaderFormat->setBuddy( leHeaderLeft );
734  new TQLabel( i18n("Colors:"), gbHeader );
735  TQHBox *hbHeaderColors = new TQHBox( gbHeader );
736  hbHeaderColors->setSpacing( sp );
737  TQLabel *lHeaderFgCol = new TQLabel( i18n("Foreground:"), hbHeaderColors );
738  kcbtnHeaderFg = new KColorButton( hbHeaderColors );
739  lHeaderFgCol->setBuddy( kcbtnHeaderFg );
740  cbHeaderEnableBgColor = new TQCheckBox( i18n("Bac&kground"), hbHeaderColors );
741  kcbtnHeaderBg = new KColorButton( hbHeaderColors );
742 
743  gbFooter = new TQGroupBox( 2, Qt::Horizontal, i18n("Footer Properties"), this );
744  lo->addWidget( gbFooter );
745 
746  // footer
747  TQLabel *lFooterFormat = new TQLabel( i18n("For&mat:"), gbFooter );
748  TQHBox *hbFooterFormat = new TQHBox( gbFooter );
749  hbFooterFormat->setSpacing( sp );
750  leFooterLeft = new TQLineEdit( hbFooterFormat );
751  leFooterCenter = new TQLineEdit( hbFooterFormat );
752  leFooterRight = new TQLineEdit( hbFooterFormat );
753  lFooterFormat->setBuddy( leFooterLeft );
754 
755  new TQLabel( i18n("Colors:"), gbFooter );
756  TQHBox *hbFooterColors = new TQHBox( gbFooter );
757  hbFooterColors->setSpacing( sp );
758  TQLabel *lFooterBgCol = new TQLabel( i18n("Foreground:"), hbFooterColors );
759  kcbtnFooterFg = new KColorButton( hbFooterColors );
760  lFooterBgCol->setBuddy( kcbtnFooterFg );
761  cbFooterEnableBgColor = new TQCheckBox( i18n("&Background"), hbFooterColors );
762  kcbtnFooterBg = new KColorButton( hbFooterColors );
763 
764  lo->addStretch( 1 );
765 
766  // user friendly
767  connect( cbEnableHeader, TQT_SIGNAL(toggled(bool)), gbHeader, TQT_SLOT(setEnabled(bool)) );
768  connect( cbEnableFooter, TQT_SIGNAL(toggled(bool)), gbFooter, TQT_SLOT(setEnabled(bool)) );
769  connect( cbHeaderEnableBgColor, TQT_SIGNAL(toggled(bool)), kcbtnHeaderBg, TQT_SLOT(setEnabled(bool)) );
770  connect( cbFooterEnableBgColor, TQT_SIGNAL(toggled(bool)), kcbtnFooterBg, TQT_SLOT(setEnabled(bool)) );
771 
772  // set defaults
773  cbEnableHeader->setChecked( true );
774  leHeaderLeft->setText( "%y" );
775  leHeaderCenter->setText( "%f" );
776  leHeaderRight->setText( "%p" );
777  kcbtnHeaderFg->setColor( TQColor("black") );
778  cbHeaderEnableBgColor->setChecked( true );
779  kcbtnHeaderBg->setColor( TQColor("lightgrey") );
780 
781  cbEnableFooter->setChecked( true );
782  leFooterRight->setText( "%U" );
783  kcbtnFooterFg->setColor( TQColor("black") );
784  cbFooterEnableBgColor->setChecked( true );
785  kcbtnFooterBg->setColor( TQColor("lightgrey") );
786 
787  // whatsthis
788  TQString s = i18n("<p>Format of the page header. The following tags are supported:</p>");
789  TQString s1 = i18n(
790  "<ul><li><tt>%u</tt>: current user name</li>"
791  "<li><tt>%d</tt>: complete date/time in short format</li>"
792  "<li><tt>%D</tt>: complete date/time in long format</li>"
793  "<li><tt>%h</tt>: current time</li>"
794  "<li><tt>%y</tt>: current date in short format</li>"
795  "<li><tt>%Y</tt>: current date in long format</li>"
796  "<li><tt>%f</tt>: file name</li>"
797  "<li><tt>%U</tt>: full URL of the document</li>"
798  "<li><tt>%p</tt>: page number</li>"
799  "</ul><br>"
800  "<u>Note:</u> Do <b>not</b> use the '|' (vertical bar) character.");
801  TQWhatsThis::add(leHeaderRight, s + s1 );
802  TQWhatsThis::add(leHeaderCenter, s + s1 );
803  TQWhatsThis::add(leHeaderLeft, s + s1 );
804  s = i18n("<p>Format of the page footer. The following tags are supported:</p>");
805  TQWhatsThis::add(leFooterRight, s + s1 );
806  TQWhatsThis::add(leFooterCenter, s + s1 );
807  TQWhatsThis::add(leFooterLeft, s + s1 );
808 
809 
810 }
811 
812 void KatePrintHeaderFooter::getOptions(TQMap<TQString,TQString>& opts, bool )
813 {
814  opts["app-kate-hffont"] = strFont;
815 
816  opts["app-kate-useheader"] = (cbEnableHeader->isChecked() ? "true" : "false");
817  opts["app-kate-headerfg"] = kcbtnHeaderFg->color().name();
818  opts["app-kate-headerusebg"] = (cbHeaderEnableBgColor->isChecked() ? "true" : "false");
819  opts["app-kate-headerbg"] = kcbtnHeaderBg->color().name();
820  opts["app-kate-headerformat"] = leHeaderLeft->text() + "|" + leHeaderCenter->text() + "|" + leHeaderRight->text();
821 
822  opts["app-kate-usefooter"] = (cbEnableFooter->isChecked() ? "true" : "false");
823  opts["app-kate-footerfg"] = kcbtnFooterFg->color().name();
824  opts["app-kate-footerusebg"] = (cbFooterEnableBgColor->isChecked() ? "true" : "false");
825  opts["app-kate-footerbg"] = kcbtnFooterBg->color().name();
826  opts["app-kate-footerformat"] = leFooterLeft->text() + "|" + leFooterCenter->text() + "|" + leFooterRight->text();
827 }
828 
829 void KatePrintHeaderFooter::setOptions( const TQMap<TQString,TQString>& opts )
830 {
831  TQString v;
832  v = opts["app-kate-hffont"];
833  strFont = v;
834  TQFont f = font();
835  if ( ! v.isEmpty() )
836  {
837  if (!strFont.isEmpty())
838  f.fromString( strFont );
839 
840  lFontPreview->setFont( f );
841  }
842  lFontPreview->setText( (f.family() + ", %1pt").arg( f.pointSize() ) );
843 
844  v = opts["app-kate-useheader"];
845  if ( ! v.isEmpty() )
846  cbEnableHeader->setChecked( v == "true" );
847  v = opts["app-kate-headerfg"];
848  if ( ! v.isEmpty() )
849  kcbtnHeaderFg->setColor( TQColor( v ) );
850  v = opts["app-kate-headerusebg"];
851  if ( ! v.isEmpty() )
852  cbHeaderEnableBgColor->setChecked( v == "true" );
853  v = opts["app-kate-headerbg"];
854  if ( ! v.isEmpty() )
855  kcbtnHeaderBg->setColor( TQColor( v ) );
856 
857  TQStringList tags = TQStringList::split('|', opts["app-kate-headerformat"], "true");
858  if (tags.count() == 3)
859  {
860  leHeaderLeft->setText(tags[0]);
861  leHeaderCenter->setText(tags[1]);
862  leHeaderRight->setText(tags[2]);
863  }
864 
865  v = opts["app-kate-usefooter"];
866  if ( ! v.isEmpty() )
867  cbEnableFooter->setChecked( v == "true" );
868  v = opts["app-kate-footerfg"];
869  if ( ! v.isEmpty() )
870  kcbtnFooterFg->setColor( TQColor( v ) );
871  v = opts["app-kate-footerusebg"];
872  if ( ! v.isEmpty() )
873  cbFooterEnableBgColor->setChecked( v == "true" );
874  v = opts["app-kate-footerbg"];
875  if ( ! v.isEmpty() )
876  kcbtnFooterBg->setColor( TQColor( v ) );
877 
878  tags = TQStringList::split('|', opts["app-kate-footerformat"], "true");
879  if (tags.count() == 3)
880  {
881  leFooterLeft->setText(tags[0]);
882  leFooterCenter->setText(tags[1]);
883  leFooterRight->setText(tags[2]);
884  }
885 }
886 
887 void KatePrintHeaderFooter::setHFFont()
888 {
889  TQFont fnt( lFontPreview->font() );
890  // display a font dialog
891  if ( TDEFontDialog::getFont( fnt, false, this ) == TDEFontDialog::Accepted )
892  {
893  // change strFont
894  strFont = fnt.toString();
895  // set preview
896  lFontPreview->setFont( fnt );
897  lFontPreview->setText( (fnt.family() + ", %1pt").arg( fnt.pointSize() ) );
898  }
899 }
900 
901 //END KatePrintHeaderFooter
902 
903 //BEGIN KatePrintLayout
904 
905 KatePrintLayout::KatePrintLayout( KPrinter * /*printer*/, TQWidget *parent, const char *name )
906  : KPrintDialogPage( parent, name )
907 {
908  setTitle( i18n("L&ayout") );
909 
910  TQVBoxLayout *lo = new TQVBoxLayout ( this );
911  lo->setSpacing( KDialog::spacingHint() );
912 
913  TQHBox *hb = new TQHBox( this );
914  lo->addWidget( hb );
915  TQLabel *lSchema = new TQLabel( i18n("&Schema:"), hb );
916  cmbSchema = new TQComboBox( false, hb );
917  lSchema->setBuddy( cmbSchema );
918 
919  cbDrawBackground = new TQCheckBox( i18n("Draw bac&kground color"), this );
920  lo->addWidget( cbDrawBackground );
921 
922  cbEnableBox = new TQCheckBox( i18n("Draw &boxes"), this );
923  lo->addWidget( cbEnableBox );
924 
925  gbBoxProps = new TQGroupBox( 2, Qt::Horizontal, i18n("Box Properties"), this );
926  lo->addWidget( gbBoxProps );
927 
928  TQLabel *lBoxWidth = new TQLabel( i18n("W&idth:"), gbBoxProps );
929  sbBoxWidth = new TQSpinBox( 1, 100, 1, gbBoxProps );
930  lBoxWidth->setBuddy( sbBoxWidth );
931 
932  TQLabel *lBoxMargin = new TQLabel( i18n("&Margin:"), gbBoxProps );
933  sbBoxMargin = new TQSpinBox( 0, 100, 1, gbBoxProps );
934  lBoxMargin->setBuddy( sbBoxMargin );
935 
936  TQLabel *lBoxColor = new TQLabel( i18n("Co&lor:"), gbBoxProps );
937  kcbtnBoxColor = new KColorButton( gbBoxProps );
938  lBoxColor->setBuddy( kcbtnBoxColor );
939 
940  connect( cbEnableBox, TQT_SIGNAL(toggled(bool)), gbBoxProps, TQT_SLOT(setEnabled(bool)) );
941 
942  lo->addStretch( 1 );
943  // set defaults:
944  sbBoxMargin->setValue( 6 );
945  gbBoxProps->setEnabled( false );
946  cmbSchema->insertStringList (KateFactory::self()->schemaManager()->list ());
947  cmbSchema->setCurrentItem( 1 );
948 
949  // whatsthis
950  // FIXME uncomment when string freeze is over
951 // TQWhatsThis::add ( cmbSchema, i18n(
952 // "Select the color scheme to use for the print." ) );
953  TQWhatsThis::add( cbDrawBackground, i18n(
954  "<p>If enabled, the background color of the editor will be used.</p>"
955  "<p>This may be useful if your color scheme is designed for a dark background.</p>") );
956  TQWhatsThis::add( cbEnableBox, i18n(
957  "<p>If enabled, a box as defined in the properties below will be drawn "
958  "around the contents of each page. The Header and Footer will be separated "
959  "from the contents with a line as well.</p>") );
960  TQWhatsThis::add( sbBoxWidth, i18n(
961  "The width of the box outline" ) );
962  TQWhatsThis::add( sbBoxMargin, i18n(
963  "The margin inside boxes, in pixels") );
964  TQWhatsThis::add( kcbtnBoxColor, i18n(
965  "The line color to use for boxes") );
966 }
967 
968 void KatePrintLayout::getOptions(TQMap<TQString,TQString>& opts, bool )
969 {
970  opts["app-kate-colorscheme"] = cmbSchema->currentText();
971  opts["app-kate-usebackground"] = cbDrawBackground->isChecked() ? "true" : "false";
972  opts["app-kate-usebox"] = cbEnableBox->isChecked() ? "true" : "false";
973  opts["app-kate-boxwidth"] = sbBoxWidth->cleanText();
974  opts["app-kate-boxmargin"] = sbBoxMargin->cleanText();
975  opts["app-kate-boxcolor"] = kcbtnBoxColor->color().name();
976 }
977 
978 void KatePrintLayout::setOptions( const TQMap<TQString,TQString>& opts )
979 {
980  TQString v;
981  v = opts["app-kate-colorscheme"];
982  if ( ! v.isEmpty() )
983  cmbSchema->setCurrentItem( KateFactory::self()->schemaManager()->number( v ) );
984  v = opts["app-kate-usebackground"];
985  if ( ! v.isEmpty() )
986  cbDrawBackground->setChecked( v == "true" );
987  v = opts["app-kate-usebox"];
988  if ( ! v.isEmpty() )
989  cbEnableBox->setChecked( v == "true" );
990  v = opts["app-kate-boxwidth"];
991  if ( ! v.isEmpty() )
992  sbBoxWidth->setValue( v.toInt() );
993  v = opts["app-kate-boxmargin"];
994  if ( ! v.isEmpty() )
995  sbBoxMargin->setValue( v.toInt() );
996  v = opts["app-kate-boxcolor"];
997  if ( ! v.isEmpty() )
998  kcbtnBoxColor->setColor( TQColor( v ) );
999 }
1000 //END KatePrintLayout
1001 
1002 #include "kateprinter.moc"
1003 #endif
KUser::UseRealUserID
kdDebug
kdbgstream kdDebug(int area=0)
KUser
KateRenderer
Handles all of the work of rendering the text (used for the views and printing)
Definition: katerenderer.h:42
tdelocale.h
TDEFontDialog::getFont
static int getFont(TQFont &theFont, bool onlyFixed=false, TQWidget *parent=0L, bool makeFrame=true, TQButton::ToggleState *sizeIsRelativeState=0L)
TDEGlobal::locale
static TDELocale * locale()
KColorButton
TDELocale::formatDate
TQString formatDate(const TQDate &pDate, bool shortFormat=false) const
TDELocale::formatTime
TQString formatTime(const TQTime &pTime, bool includeSecs, bool isDuration) const
TDELocale::formatDateTime
TQString formatDateTime(const TQDateTime &pDateTime, bool shortFormat=true, bool includeSecs=false) const
endl
kndbgstream & endl(kndbgstream &s)

kate

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

kate

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