• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • utils
kateprinter.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2002-2010 Anders Lund <anders@alweb.dk>
4  *
5  * Rewritten based on code of Copyright (c) 2002 Michael Goffioul <kdeprint@swing.be>
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 as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include "kateprinter.h"
24 
25 #include "kateconfig.h"
26 #include "katedocument.h"
27 #include "kateglobal.h"
28 #include "katehighlight.h"
29 #include "katetextlayout.h"
30 #include "katerenderer.h"
31 #include "kateschema.h"
32 #include "katetextline.h"
33 #include "kateview.h"
34 #include "katebuffer.h"
35 #include "katetextfolding.h"
36 
37 #include <kapplication.h>
38 #include <kcolorbutton.h>
39 #include <kdebug.h>
40 #include <kfontdialog.h>
41 #include <klocale.h>
42 #include <kdeprintdialog.h>
43 #include <kurl.h>
44 #include <kuser.h> // for loginName
45 #include <klineedit.h>
46 #include <knuminput.h>
47 #include <kcombobox.h>
48 
49 #include <QtGui/QPainter>
50 #include <QtGui/QCheckBox>
51 #include <QtGui/QGroupBox>
52 #include <QtGui/QPrintDialog>
53 #include <QtGui/QPrinter>
54 #include <QtGui/QApplication>
55 
56 #include <QtGui/QLabel>
57 #include <QtGui/QLayout>
58 #include <QtCore/QStringList>
59 #include <kvbox.h>
60 
61 //BEGIN KatePrinter
62 void KatePrinter::readSettings(QPrinter& printer)
63 {
64  // NOTE: Saving & loading the margins works around QPrinter/QPrintDialog bugs:
65  // - https://bugreports.qt.nokia.com/browse/QTBUG-15351
66  // - https://bugs.kde.org/show_bug.cgi?id=205802
67  // - https://bugs.kde.org/show_bug.cgi?id=180051
68  // Changing the margins now works. However, when you reopen the print dialog
69  // later, the WRONG margins are displayed. The correct ones are still used.
70  // This is a critical bug in Qt.
71 
72  KSharedConfigPtr config = KGlobal::config();
73  KConfigGroup group(config, "Kate Print Settings");
74  KConfigGroup margins(&group, "Margins");
75 
76  qreal left, right, top, bottom;
77  printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
78 
79  left = margins.readEntry("left", left);
80  top = margins.readEntry("top", top);
81  right = margins.readEntry("right", right);
82  bottom = margins.readEntry("bottom", bottom);
83 
84  printer.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
85 }
86 
87 void KatePrinter::writeSettings(QPrinter& printer)
88 {
89  KSharedConfigPtr config = KGlobal::config();
90  KConfigGroup group(config, "Kate Print Settings");
91  KConfigGroup margins(&group, "Margins");
92 
93  qreal left, right, top, bottom;
94  printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
95 
96  margins.writeEntry( "left", left);
97  margins.writeEntry( "top", top);
98  margins.writeEntry( "right", right);
99  margins.writeEntry( "bottom", bottom);
100 }
101 
102 bool KatePrinter::print (KateDocument *doc)
103 {
104  QPrinter printer;
105  readSettings(printer);
106 
107  // docname is now always there, including the right Untitled name
108  printer.setDocName(doc->documentName());
109 
110  KatePrintTextSettings *kpts = new KatePrintTextSettings;
111  KatePrintHeaderFooter *kphf = new KatePrintHeaderFooter;
112  KatePrintLayout *kpl = new KatePrintLayout;
113 
114  QList<QWidget*> tabs;
115  tabs << kpts;
116  tabs << kphf;
117  tabs << kpl;
118 
119  QWidget *parentWidget=doc->widget();
120 
121  if ( !parentWidget )
122  parentWidget=QApplication::activeWindow();
123 
124  QScopedPointer<QPrintDialog> printDialog(KdePrint::createPrintDialog(&printer, KdePrint::SystemSelectsPages, tabs, parentWidget));
125 
126  if ( doc->activeView()->selection() ) {
127  printer.setPrintRange(QPrinter::Selection);
128  printDialog->setOption(QAbstractPrintDialog::PrintSelection, true);
129  }
130 
131  if ( printDialog->exec() )
132  {
133  writeSettings(printer);
134 
135  Kate::TextFolding folding (doc->buffer());
136  KateRenderer renderer(doc, folding, doc->activeKateView());
137  renderer.config()->setSchema (kpl->colorScheme());
138  renderer.setPrinterFriendly(true);
139 
140  QPainter paint( &printer );
141  /*
142  * We work in tree cycles:
143  * 1) initialize variables and retrieve print settings
144  * 2) prepare data according to those settings
145  * 3) draw to the printer
146  */
147  uint pdmWidth = printer.width();
148  uint pdmHeight = printer.height();
149  int y = 0;
150  uint xstart = 0; // beginning point for painting lines
151  uint lineCount = 0;
152  uint maxWidth = pdmWidth;
153  int headerWidth = pdmWidth;
154  bool pageStarted = true;
155  int remainder = 0; // remaining sublines from a wrapped line (for the top of a new page)
156 
157  // Text Settings Page
158  bool selectionOnly = (printDialog->printRange() == QAbstractPrintDialog::Selection);
159  bool useGuide = kpts->printGuide();
160 
161  bool printLineNumbers = kpts->printLineNumbers();
162  uint lineNumberWidth( 0 );
163 
164  // Header/Footer Page
165  QFont headerFont(kphf->font()); // used for header/footer
166 
167  bool useHeader = kphf->useHeader();
168  QColor headerBgColor(kphf->headerBackground());
169  QColor headerFgColor(kphf->headerForeground());
170  uint headerHeight( 0 ); // further init only if needed
171  QStringList headerTagList; // do
172  bool headerDrawBg = false; // do
173 
174  bool useFooter = kphf->useFooter();
175  QColor footerBgColor(kphf->footerBackground());
176  QColor footerFgColor(kphf->footerForeground());
177  uint footerHeight( 0 ); // further init only if needed
178  QStringList footerTagList; // do
179  bool footerDrawBg = false; // do
180 
181  // Layout Page
182  renderer.config()->setSchema( kpl->colorScheme() );
183  bool useBackground = kpl->useBackground();
184  bool useBox = kpl->useBox();
185  int boxWidth(kpl->boxWidth());
186  QColor boxColor(kpl->boxColor());
187  int innerMargin = useBox ? kpl->boxMargin() : 6;
188 
189  // Post initialization
190  int maxHeight = (useBox ? pdmHeight-innerMargin : pdmHeight);
191  uint currentPage( 1 );
192  uint lastline = doc->lastLine(); // necessary to print selection only
193  uint firstline( 0 );
194  const int fontHeight = renderer.fontHeight();
195  KTextEditor::Range selectionRange;
196 
197  /*
198  * Now on for preparations...
199  * during preparations, variable names starting with a "_" means
200  * those variables are local to the enclosing block.
201  */
202  {
203  if ( selectionOnly )
204  {
205  // set a line range from the first selected line to the last
206  selectionRange = doc->activeView()->selectionRange();
207  firstline = selectionRange.start().line();
208  lastline = selectionRange.end().line();
209  lineCount = firstline;
210  }
211 
212  if ( printLineNumbers )
213  {
214  // figure out the horiizontal space required
215  QString s( QString("%1 ").arg( doc->lines() ) );
216  s.fill('5', -1); // some non-fixed fonts haven't equally wide numbers
217  // FIXME calculate which is actually the widest...
218  lineNumberWidth = renderer.currentFontMetrics().width( s );
219  // a small space between the line numbers and the text
220  int _adj = renderer.currentFontMetrics().width( "5" );
221  // adjust available width and set horizontal start point for data
222  maxWidth -= (lineNumberWidth + _adj);
223  xstart += lineNumberWidth + _adj;
224  }
225 
226  if ( useHeader || useFooter )
227  {
228  // Set up a tag map
229  // This retrieves all tags, ued or not, but
230  // none of theese operations should be expensive,
231  // and searcing each tag in the format strings is avoided.
232  QDateTime dt = QDateTime::currentDateTime();
233  QMap<QString,QString> tags;
234 
235  KUser u (KUser::UseRealUserID);
236  tags["u"] = u.loginName();
237 
238  tags["d"] = KGlobal::locale()->formatDateTime(dt, KLocale::ShortDate);
239  tags["D"] = KGlobal::locale()->formatDateTime(dt, KLocale::LongDate);
240  tags["h"] = KGlobal::locale()->formatTime(dt.time(), false);
241  tags["y"] = KGlobal::locale()->formatDate(dt.date(), KLocale::ShortDate);
242  tags["Y"] = KGlobal::locale()->formatDate(dt.date(), KLocale::LongDate);
243  tags["f"] = doc->url().fileName();
244  tags["U"] = doc->url().pathOrUrl();
245  if ( selectionOnly )
246  {
247  QString s( i18n("(Selection of) ") );
248  tags["f"].prepend( s );
249  tags["U"].prepend( s );
250  }
251 
252  QRegExp reTags( "%([dDfUhuyY])" ); // TODO tjeck for "%%<TAG>"
253 
254  if (useHeader)
255  {
256  headerDrawBg = kphf->useHeaderBackground();
257  headerHeight = QFontMetrics( headerFont ).height();
258  if ( useBox || headerDrawBg )
259  headerHeight += innerMargin * 2;
260  else
261  headerHeight += 1 + QFontMetrics( headerFont ).leading();
262 
263  headerTagList = kphf->headerFormat();
264  QMutableStringListIterator it(headerTagList);
265  while ( it.hasNext() ) {
266  QString tag = it.next();
267  int pos = reTags.indexIn( tag );
268  QString rep;
269  while ( pos > -1 )
270  {
271  rep = tags[reTags.cap( 1 )];
272  tag.replace( (uint)pos, 2, rep );
273  pos += rep.length();
274  pos = reTags.indexIn( tag, pos );
275  }
276  it.setValue( tag );
277  }
278 
279  if (!headerBgColor.isValid())
280  headerBgColor = Qt::lightGray;
281  if (!headerFgColor.isValid())
282  headerFgColor = Qt::black;
283  }
284 
285  if (useFooter)
286  {
287  footerDrawBg = kphf->useFooterBackground();
288  footerHeight = QFontMetrics( headerFont ).height();
289  if ( useBox || footerDrawBg )
290  footerHeight += 2*innerMargin;
291  else
292  footerHeight += 1; // line only
293 
294  footerTagList = kphf->footerFormat();
295  QMutableStringListIterator it(footerTagList);
296  while ( it.hasNext() ) {
297  QString tag = it.next();
298  int pos = reTags.indexIn( tag );
299  QString rep;
300  while ( pos > -1 )
301  {
302  rep = tags[reTags.cap( 1 )];
303  tag.replace( (uint)pos, 2, rep );
304  pos += rep.length();
305  pos = reTags.indexIn( tag, pos );
306  }
307  it.setValue( tag );
308  }
309 
310  if (!footerBgColor.isValid())
311  footerBgColor = Qt::lightGray;
312  if (!footerFgColor.isValid())
313  footerFgColor = Qt::black;
314  // adjust maxheight, so we can know when/where to print footer
315  maxHeight -= footerHeight;
316  }
317  } // if ( useHeader || useFooter )
318 
319  if ( useBackground )
320  {
321  if ( ! useBox )
322  {
323  xstart += innerMargin;
324  maxWidth -= innerMargin * 2;
325  }
326  }
327 
328  if ( useBox )
329  {
330  if (!boxColor.isValid())
331  boxColor = Qt::black;
332  if (boxWidth < 1) // shouldn't be pssible no more!
333  boxWidth = 1;
334  // set maxwidth to something sensible
335  maxWidth -= ( ( boxWidth + innerMargin ) * 2 );
336  xstart += boxWidth + innerMargin;
337  // maxheight too..
338  maxHeight -= boxWidth;
339  }
340  else
341  boxWidth = 0;
342 
343  // now that we know the vertical amount of space needed,
344  // it is possible to calculate the total number of pages
345  // if needed, that is if any header/footer tag contains "%P".
346  if ( !headerTagList.filter("%P").isEmpty() || !footerTagList.filter("%P").isEmpty() )
347  {
348  kDebug(13020)<<"'%P' found! calculating number of pages...";
349  int pageHeight = maxHeight;
350  if ( useHeader )
351  pageHeight -= ( headerHeight + innerMargin );
352  if ( useFooter )
353  pageHeight -= innerMargin;
354  const int linesPerPage = pageHeight / fontHeight;
355 // kDebug() << "Lines per page:" << linesPerPage;
356 
357  // calculate total layouted lines in the document
358  int totalLines = 0;
359  // TODO: right now ignores selection printing
360  for (unsigned int i = firstline; i <= lastline; ++i) {
361  KateLineLayoutPtr rangeptr(new KateLineLayout(renderer));
362  rangeptr->setLine(i);
363  renderer.layoutLine(rangeptr, (int)maxWidth, false);
364  totalLines += rangeptr->viewLineCount();
365  }
366  int totalPages = (totalLines / linesPerPage)
367  + ((totalLines % linesPerPage) > 0 ? 1 : 0);
368 // kDebug() << "_______ pages:" << (totalLines / linesPerPage);
369 // kDebug() << "________ rest:" << (totalLines % linesPerPage);
370 
371  // TODO: add space for guide if required
372 // if ( useGuide )
373 // _lt += (guideHeight + (fontHeight /2)) / fontHeight;
374 
375  // substitute both tag lists
376  QString re("%P");
377  QStringList::Iterator it;
378  for ( it=headerTagList.begin(); it!=headerTagList.end(); ++it )
379  (*it).replace( re, QString( "%1" ).arg( totalPages ) );
380  for ( it=footerTagList.begin(); it!=footerTagList.end(); ++it )
381  (*it).replace( re, QString( "%1" ).arg( totalPages ) );
382  }
383  } // end prepare block
384 
385  /*
386  On to draw something :-)
387  */
388  while ( lineCount <= lastline )
389  {
390  if ( y + fontHeight > maxHeight )
391  {
392  kDebug(13020)<<"Starting new page,"<<lineCount<<"lines up to now.";
393  printer.newPage();
394  paint.resetTransform();
395  currentPage++;
396  pageStarted = true;
397  y=0;
398  }
399 
400  if ( pageStarted )
401  {
402  if ( useHeader )
403  {
404  paint.setPen(headerFgColor);
405  paint.setFont(headerFont);
406  if ( headerDrawBg )
407  paint.fillRect(0, 0, headerWidth, headerHeight, headerBgColor);
408  if (headerTagList.count() == 3)
409  {
410  int valign = ( (useBox||headerDrawBg||useBackground) ?
411  Qt::AlignVCenter : Qt::AlignTop );
412  int align = valign|Qt::AlignLeft;
413  int marg = ( useBox || headerDrawBg ) ? innerMargin : 0;
414  if ( useBox ) marg += boxWidth;
415  QString s;
416  for (int i=0; i<3; i++)
417  {
418  s = headerTagList[i];
419  if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage));
420  paint.drawText(marg, 0, headerWidth-(marg*2), headerHeight, align, s);
421  align = valign|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
422  }
423  }
424  if ( ! ( headerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate header from contents
425  {
426  paint.drawLine( 0, headerHeight-1, headerWidth, headerHeight-1 );
427  //y += 1; now included in headerHeight
428  }
429  y += headerHeight + innerMargin;
430  }
431 
432  if ( useFooter )
433  {
434  paint.setPen(footerFgColor);
435  if ( ! ( footerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate footer from contents
436  paint.drawLine( 0, maxHeight + innerMargin - 1, headerWidth, maxHeight + innerMargin - 1 );
437  if ( footerDrawBg )
438  paint.fillRect(0, maxHeight+innerMargin+boxWidth, headerWidth, footerHeight, footerBgColor);
439  if (footerTagList.count() == 3)
440  {
441  int align = Qt::AlignVCenter|Qt::AlignLeft;
442  int marg = ( useBox || footerDrawBg ) ? innerMargin : 0;
443  if ( useBox ) marg += boxWidth;
444  QString s;
445  for (int i=0; i<3; i++)
446  {
447  s = footerTagList[i];
448  if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage));
449  paint.drawText(marg, maxHeight+innerMargin, headerWidth-(marg*2), footerHeight, align, s);
450  align = Qt::AlignVCenter|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
451  }
452  }
453  } // done footer
454 
455  if ( useBackground )
456  {
457  // If we have a box, or the header/footer has backgrounds, we want to paint
458  // to the border of those. Otherwise just the contents area.
459  int _y = y, _h = maxHeight - y;
460  if ( useBox )
461  {
462  _y -= innerMargin;
463  _h += 2 * innerMargin;
464  }
465  else
466  {
467  if ( headerDrawBg )
468  {
469  _y -= innerMargin;
470  _h += innerMargin;
471  }
472  if ( footerDrawBg )
473  {
474  _h += innerMargin;
475  }
476  }
477  paint.fillRect( 0, _y, pdmWidth, _h, renderer.config()->backgroundColor());
478  }
479 
480  if ( useBox )
481  {
482  paint.setPen(QPen(boxColor, boxWidth));
483  paint.drawRect(0, 0, pdmWidth, pdmHeight);
484  if (useHeader)
485  paint.drawLine(0, headerHeight, headerWidth, headerHeight);
486  else
487  y += innerMargin;
488 
489  if ( useFooter ) // drawline is not trustable, grr.
490  paint.fillRect( 0, maxHeight+innerMargin, headerWidth, boxWidth, boxColor );
491  }
492 
493  if ( useGuide && currentPage == 1 )
494  { // FIXME - this may span more pages...
495  // draw a box unless we have boxes, in which case we end with a box line
496  int _ystart = y;
497  QString _hlName = doc->highlight()->name();
498 
499  QList<KateExtendedAttribute::Ptr> _attributes; // list of highlight attributes for the legend
500  doc->highlight()->getKateExtendedAttributeList(kpl->colorScheme(), _attributes);
501 
502  KateAttributeList _defaultAttributes;
503  KateHlManager::self()->getDefaults ( renderer.config()->schema(), _defaultAttributes );
504 
505  QColor _defaultPen = _defaultAttributes.at(0)->foreground().color();
506  paint.setPen(_defaultPen);
507 
508  int _marg = 0;
509  if ( useBox )
510  _marg += (2*boxWidth) + (2*innerMargin);
511  else
512  {
513  if ( useBackground )
514  _marg += 2*innerMargin;
515  _marg += 1;
516  y += 1 + innerMargin;
517  }
518 
519  // draw a title string
520  QFont _titleFont = renderer.config()->font();
521  _titleFont.setBold(true);
522  paint.setFont( _titleFont );
523  QRect _r;
524  paint.drawText( QRect(_marg, y, pdmWidth-(2*_marg), maxHeight - y),
525  Qt::AlignTop|Qt::AlignHCenter,
526  i18n("Typographical Conventions for %1", _hlName ), &_r );
527  int _w = pdmWidth - (_marg*2) - (innerMargin*2);
528  int _x = _marg + innerMargin;
529  y += _r.height() + innerMargin;
530  paint.drawLine( _x, y, _x + _w, y );
531  y += 1 + innerMargin;
532 
533  int _widest( 0 );
534  foreach (const KateExtendedAttribute::Ptr &attribute, _attributes)
535  _widest = qMax(QFontMetrics(attribute->font()).width(attribute->name().section(':',1,1)), _widest);
536 
537  int _guideCols = _w/( _widest + innerMargin );
538 
539  // draw attrib names using their styles
540  int _cw = _w/_guideCols;
541  int _i(0);
542 
543  _titleFont.setUnderline(true);
544  QString _currentHlName;
545  foreach (const KateExtendedAttribute::Ptr &attribute, _attributes)
546  {
547  QString _hl = attribute->name().section(':',0,0);
548  QString _name = attribute->name().section(':',1,1);
549  if ( _hl != _hlName && _hl != _currentHlName ) {
550  _currentHlName = _hl;
551  if ( _i%_guideCols )
552  y += fontHeight;
553  y += innerMargin;
554  paint.setFont(_titleFont);
555  paint.setPen(_defaultPen);
556  paint.drawText( _x, y, _w, fontHeight, Qt::AlignTop, _hl + ' ' + i18n("text") );
557  y += fontHeight;
558  _i = 0;
559  }
560 
561  KTextEditor::Attribute _attr = *_defaultAttributes[attribute->defaultStyleIndex()];
562  _attr += *attribute;
563  paint.setPen( _attr.foreground().color() );
564  paint.setFont( _attr.font() );
565 
566  if (_attr.hasProperty(QTextFormat::BackgroundBrush) ) {
567  QRect _rect = QFontMetrics(_attr.font()).boundingRect(_name);
568  _rect.moveTo(_x + ((_i%_guideCols)*_cw), y);
569  paint.fillRect(_rect, _attr.background() );
570  }
571 
572  paint.drawText(( _x + ((_i%_guideCols)*_cw)), y, _cw, fontHeight, Qt::AlignTop, _name );
573 
574  _i++;
575  if ( _i && ! ( _i%_guideCols ) )
576  y += fontHeight;
577  }
578 
579  if ( _i%_guideCols )
580  y += fontHeight;// last row not full
581 
582  // draw a box around the legend
583  paint.setPen ( _defaultPen );
584  if ( useBox )
585  paint.fillRect( 0, y+innerMargin, headerWidth, boxWidth, boxColor );
586  else
587  {
588  _marg -=1;
589  paint.drawRect( _marg, _ystart, pdmWidth-(2*_marg), y-_ystart+innerMargin );
590  }
591 
592  y += ( useBox ? boxWidth : 1 ) + (innerMargin*2);
593  } // useGuide
594 
595  paint.translate(xstart,y);
596  pageStarted = false;
597  } // pageStarted; move on to contents:)
598 
599  if ( printLineNumbers /*&& ! startCol*/ ) // don't repeat!
600  {
601  paint.setFont( renderer.config()->font() );
602  paint.setPen( renderer.config()->lineNumberColor() );
603  paint.drawText( (( useBox || useBackground ) ? innerMargin : 0)-xstart, 0,
604  lineNumberWidth, fontHeight,
605  Qt::AlignRight, QString("%1").arg( lineCount + 1 ) );
606  }
607 
608  // HA! this is where we print [part of] a line ;]]
609  // FIXME Convert this function + related functionality to a separate KatePrintView
610  KateLineLayoutPtr rangeptr(new KateLineLayout(renderer));
611  rangeptr->setLine(lineCount);
612  renderer.layoutLine(rangeptr, (int)maxWidth, false);
613 
614  // selectionOnly: clip non-selection parts and adjust painter position if needed
615  int _xadjust = 0;
616  if (selectionOnly) {
617  if (doc->activeView()->blockSelection()) {
618  int _x = renderer.cursorToX(rangeptr->viewLine(0), selectionRange.start());
619  int _x1 = renderer.cursorToX(rangeptr->viewLine(rangeptr->viewLineCount()-1), selectionRange.end());
620  _xadjust = _x;
621  paint.translate(-_xadjust, 0);
622  paint.setClipRegion(QRegion( _x, 0, _x1 - _x, rangeptr->viewLineCount()*fontHeight));
623  }
624 
625  else if (lineCount == firstline || lineCount == lastline) {
626  QRegion region(0, 0, maxWidth, rangeptr->viewLineCount()*fontHeight);
627 
628  if ( lineCount == firstline) {
629  region = region.subtracted(QRegion(0, 0, renderer.cursorToX(rangeptr->viewLine(0), selectionRange.start()), fontHeight));
630  }
631 
632  if (lineCount == lastline) {
633  int _x = renderer.cursorToX(rangeptr->viewLine(rangeptr->viewLineCount()-1), selectionRange.end());
634  region = region.subtracted(QRegion(_x, 0, maxWidth-_x, fontHeight));
635  }
636 
637  paint.setClipRegion(region);
638  }
639  }
640 
641  // If the line is too long (too many 'viewlines') to fit the remaining vertical space,
642  // clip and adjust the painter position as necessary
643  int _lines = rangeptr->viewLineCount(); // number of "sublines" to paint.
644 
645  int proceedLines = _lines;
646  if (remainder) {
647  proceedLines = qMin((maxHeight - y) / fontHeight, remainder);
648 
649  paint.translate(0, -(_lines-remainder)*fontHeight+1);
650  paint.setClipRect(0, (_lines-remainder)*fontHeight+1, maxWidth, proceedLines*fontHeight); //### drop the crosspatch in printerfriendly mode???
651  remainder -= proceedLines;
652  }
653  else if (y + fontHeight * _lines > maxHeight) {
654  remainder = _lines - ((maxHeight-y)/fontHeight);
655  paint.setClipRect(0, 0, maxWidth, (_lines-remainder)*fontHeight+1); //### drop the crosspatch in printerfriendly mode???
656  }
657 
658  renderer.paintTextLine(paint, rangeptr, 0, (int)maxWidth);
659 
660  paint.setClipping(false);
661  paint.translate(_xadjust, (fontHeight * (_lines-remainder)));
662 
663  y += fontHeight * proceedLines;
664 
665  if ( ! remainder )
666  lineCount++;
667  } // done lineCount <= lastline
668 
669  paint.end();
670  return true;
671  }
672  return false;
673 }
674 //END KatePrinter
675 
676 //BEGIN KatePrintTextSettings
677 KatePrintTextSettings::KatePrintTextSettings( QWidget *parent )
678  : QWidget( parent )
679 {
680  setWindowTitle( i18n("Te&xt Settings") );
681 
682  QVBoxLayout *lo = new QVBoxLayout ( this );
683 
684  cbLineNumbers = new QCheckBox( i18n("Print line &numbers"), this );
685  lo->addWidget( cbLineNumbers );
686 
687  cbGuide = new QCheckBox( i18n("Print &legend"), this );
688  lo->addWidget( cbGuide );
689 
690  lo->addStretch( 1 );
691 
692  // set defaults - nothing to do :-)
693 
694  // whatsthis
695  cbLineNumbers->setWhatsThis(i18n(
696  "<p>If enabled, line numbers will be printed on the left side of the page(s).</p>") );
697  cbGuide->setWhatsThis(i18n(
698  "<p>Print a box displaying typographical conventions for the document type, as "
699  "defined by the syntax highlighting being used.</p>") );
700 
701  readSettings();
702 }
703 
704 KatePrintTextSettings::~KatePrintTextSettings()
705 {
706  writeSettings();
707 }
708 
709 bool KatePrintTextSettings::printLineNumbers()
710 {
711  return cbLineNumbers->isChecked();
712 }
713 
714 bool KatePrintTextSettings::printGuide()
715 {
716  return cbGuide->isChecked();
717 }
718 
719 void KatePrintTextSettings::readSettings()
720 {
721  KSharedConfigPtr config = KGlobal::config();
722  KConfigGroup printGroup( config, "Kate Print Settings" );
723 
724  KConfigGroup textGroup( &printGroup, "Text" );
725  bool isLineNumbersChecked = textGroup.readEntry( "LineNumbers", false );
726  cbLineNumbers->setChecked( isLineNumbersChecked );
727 
728  bool isLegendChecked = textGroup.readEntry( "Legend", false );
729  cbGuide->setChecked( isLegendChecked );
730 }
731 
732 void KatePrintTextSettings::writeSettings()
733 {
734  KSharedConfigPtr config = KGlobal::config();
735  KConfigGroup printGroup( config, "Kate Print Settings" );
736 
737  KConfigGroup textGroup( &printGroup, "Text" );
738  textGroup.writeEntry( "LineNumbers", printLineNumbers() );
739  textGroup.writeEntry( "Legend", printGuide() );
740 
741  config->sync();
742 }
743 
744 //END KatePrintTextSettings
745 
746 //BEGIN KatePrintHeaderFooter
747 KatePrintHeaderFooter::KatePrintHeaderFooter( QWidget *parent )
748  : QWidget( parent )
749 {
750  setWindowTitle( i18n("Hea&der && Footer") );
751 
752  QVBoxLayout *lo = new QVBoxLayout ( this );
753 
754  // enable
755  QHBoxLayout *lo1 = new QHBoxLayout ();
756  lo->addLayout( lo1 );
757  cbEnableHeader = new QCheckBox( i18n("Pr&int header"), this );
758  lo1->addWidget( cbEnableHeader );
759  cbEnableFooter = new QCheckBox( i18n("Pri&nt footer"), this );
760  lo1->addWidget( cbEnableFooter );
761 
762  // font
763  QHBoxLayout *lo2 = new QHBoxLayout();
764  lo->addLayout( lo2 );
765  lo2->addWidget( new QLabel( i18n("Header/footer font:"), this ) );
766  lFontPreview = new QLabel( this );
767  lFontPreview->setFrameStyle( QFrame::Panel|QFrame::Sunken );
768  lo2->addWidget( lFontPreview );
769  lo2->setStretchFactor( lFontPreview, 1 );
770  QPushButton *btnChooseFont = new QPushButton( i18n("Choo&se Font..."), this );
771  lo2->addWidget( btnChooseFont );
772  connect( btnChooseFont, SIGNAL(clicked()), this, SLOT(setHFFont()) );
773 
774  // header
775  gbHeader = new QGroupBox( this );
776  gbHeader->setTitle(i18n("Header Properties"));
777  QGridLayout* grid = new QGridLayout(gbHeader);
778  lo->addWidget( gbHeader );
779 
780  QLabel *lHeaderFormat = new QLabel( i18n("&Format:"), gbHeader );
781  grid->addWidget(lHeaderFormat, 0, 0);
782 
783  KHBox *hbHeaderFormat = new KHBox( gbHeader );
784  grid->addWidget(hbHeaderFormat, 0, 1);
785 
786  leHeaderLeft = new KLineEdit( hbHeaderFormat );
787  leHeaderCenter = new KLineEdit( hbHeaderFormat );
788  leHeaderRight = new KLineEdit( hbHeaderFormat );
789  lHeaderFormat->setBuddy( leHeaderLeft );
790 
791  leHeaderLeft->setContextMenuPolicy(Qt::CustomContextMenu);
792  leHeaderCenter->setContextMenuPolicy(Qt::CustomContextMenu);
793  leHeaderRight->setContextMenuPolicy(Qt::CustomContextMenu);
794  connect(leHeaderLeft, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
795  connect(leHeaderCenter, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
796  connect(leHeaderRight, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
797 
798  grid->addWidget(new QLabel( i18n("Colors:"), gbHeader ), 1, 0);
799 
800  KHBox *hbHeaderColors = new KHBox( gbHeader );
801  grid->addWidget(hbHeaderColors, 1, 1);
802 
803  hbHeaderColors->setSpacing( -1 );
804  QLabel *lHeaderFgCol = new QLabel( i18n("Foreground:"), hbHeaderColors );
805  kcbtnHeaderFg = new KColorButton( hbHeaderColors );
806  lHeaderFgCol->setBuddy( kcbtnHeaderFg );
807  cbHeaderEnableBgColor = new QCheckBox( i18n("Bac&kground"), hbHeaderColors );
808  kcbtnHeaderBg = new KColorButton( hbHeaderColors );
809 
810  gbFooter = new QGroupBox( this );
811  gbFooter->setTitle(i18n("Footer Properties"));
812  grid = new QGridLayout(gbFooter);
813  lo->addWidget( gbFooter );
814 
815  // footer
816  QLabel *lFooterFormat = new QLabel( i18n("For&mat:"), gbFooter );
817  grid->addWidget(lFooterFormat, 0, 0);
818 
819  KHBox *hbFooterFormat = new KHBox( gbFooter );
820  grid->addWidget(hbFooterFormat, 0, 1);
821 
822  hbFooterFormat->setSpacing( -1 );
823  leFooterLeft = new KLineEdit( hbFooterFormat );
824  leFooterCenter = new KLineEdit( hbFooterFormat );
825  leFooterRight = new KLineEdit( hbFooterFormat );
826  lFooterFormat->setBuddy( leFooterLeft );
827 
828  leFooterLeft->setContextMenuPolicy(Qt::CustomContextMenu);
829  leFooterCenter->setContextMenuPolicy(Qt::CustomContextMenu);
830  leFooterRight->setContextMenuPolicy(Qt::CustomContextMenu);
831  connect(leFooterLeft, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
832  connect(leFooterCenter, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
833  connect(leFooterRight, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
834 
835  grid->addWidget(new QLabel( i18n("Colors:"), gbFooter ), 1, 0);
836 
837  KHBox *hbFooterColors = new KHBox( gbFooter );
838  grid->addWidget(hbFooterColors, 1, 1);
839 
840  hbFooterColors->setSpacing( -1 );
841  QLabel *lFooterBgCol = new QLabel( i18n("Foreground:"), hbFooterColors );
842  kcbtnFooterFg = new KColorButton( hbFooterColors );
843  lFooterBgCol->setBuddy( kcbtnFooterFg );
844  cbFooterEnableBgColor = new QCheckBox( i18n("&Background"), hbFooterColors );
845  kcbtnFooterBg = new KColorButton( hbFooterColors );
846 
847  lo->addStretch( 1 );
848 
849  // user friendly
850  connect( cbEnableHeader, SIGNAL(toggled(bool)), gbHeader, SLOT(setEnabled(bool)) );
851  connect( cbEnableFooter, SIGNAL(toggled(bool)), gbFooter, SLOT(setEnabled(bool)) );
852  connect( cbHeaderEnableBgColor, SIGNAL(toggled(bool)), kcbtnHeaderBg, SLOT(setEnabled(bool)) );
853  connect( cbFooterEnableBgColor, SIGNAL(toggled(bool)), kcbtnFooterBg, SLOT(setEnabled(bool)) );
854 
855  // set defaults
856  cbEnableHeader->setChecked( true );
857  leHeaderLeft->setText( "%y" );
858  leHeaderCenter->setText( "%f" );
859  leHeaderRight->setText( "%p" );
860  kcbtnHeaderFg->setColor( QColor("black") );
861  cbHeaderEnableBgColor->setChecked( false );
862  kcbtnHeaderBg->setColor( QColor("lightgrey") );
863 
864  cbEnableFooter->setChecked( true );
865  leFooterRight->setText( "%U" );
866  kcbtnFooterFg->setColor( QColor("black") );
867  cbFooterEnableBgColor->setChecked( false );
868  kcbtnFooterBg->setColor( QColor("lightgrey") );
869 
870  // whatsthis
871  QString s = i18n("<p>Format of the page header. The following tags are supported:</p>");
872  QString s1 = i18n(
873  "<ul><li><tt>%u</tt>: current user name</li>"
874  "<li><tt>%d</tt>: complete date/time in short format</li>"
875  "<li><tt>%D</tt>: complete date/time in long format</li>"
876  "<li><tt>%h</tt>: current time</li>"
877  "<li><tt>%y</tt>: current date in short format</li>"
878  "<li><tt>%Y</tt>: current date in long format</li>"
879  "<li><tt>%f</tt>: file name</li>"
880  "<li><tt>%U</tt>: full URL of the document</li>"
881  "<li><tt>%p</tt>: page number</li>"
882  "<li><tt>%P</tt>: total amount of pages</li>"
883  "</ul><br />");
884  leHeaderRight->setWhatsThis(s + s1 );
885  leHeaderCenter->setWhatsThis(s + s1 );
886  leHeaderLeft->setWhatsThis(s + s1 );
887  s = i18n("<p>Format of the page footer. The following tags are supported:</p>");
888  leFooterRight->setWhatsThis(s + s1 );
889  leFooterCenter->setWhatsThis(s + s1 );
890  leFooterLeft->setWhatsThis(s + s1 );
891 
892  readSettings();
893 }
894 
895 KatePrintHeaderFooter::~KatePrintHeaderFooter()
896 {
897  writeSettings();
898 }
899 
900 QFont KatePrintHeaderFooter::font()
901 {
902  return lFontPreview->font();
903 }
904 
905 bool KatePrintHeaderFooter::useHeader()
906 {
907  return cbEnableHeader->isChecked();
908 }
909 
910 QStringList KatePrintHeaderFooter::headerFormat()
911 {
912  QStringList l;
913  l << leHeaderLeft->text() << leHeaderCenter->text() << leHeaderRight->text();
914  return l;
915 }
916 
917 QColor KatePrintHeaderFooter::headerForeground()
918 {
919  return kcbtnHeaderFg->color();
920 }
921 
922 QColor KatePrintHeaderFooter::headerBackground()
923 {
924  return kcbtnHeaderBg->color();
925 }
926 
927 bool KatePrintHeaderFooter::useHeaderBackground()
928 {
929  return cbHeaderEnableBgColor->isChecked();
930 }
931 
932 bool KatePrintHeaderFooter::useFooter()
933 {
934  return cbEnableFooter->isChecked();
935 }
936 
937 QStringList KatePrintHeaderFooter::footerFormat()
938 {
939  QStringList l;
940  l<< leFooterLeft->text() << leFooterCenter->text() << leFooterRight->text();
941  return l;
942 }
943 
944 QColor KatePrintHeaderFooter::footerForeground()
945 {
946  return kcbtnFooterFg->color();
947 }
948 
949 QColor KatePrintHeaderFooter::footerBackground()
950 {
951  return kcbtnFooterBg->color();
952 }
953 
954 bool KatePrintHeaderFooter::useFooterBackground()
955 {
956  return cbFooterEnableBgColor->isChecked();
957 }
958 
959 void KatePrintHeaderFooter::setHFFont()
960 {
961  QFont fnt( lFontPreview->font() );
962  // display a font dialog
963  if ( KFontDialog::getFont( fnt, KFontChooser::NoDisplayFlags, this ) == KFontDialog::Accepted )
964  {
965  // set preview
966  lFontPreview->setFont( fnt );
967  lFontPreview->setText( QString(fnt.family() + ", %1pt").arg( fnt.pointSize() ) );
968  }
969 }
970 
971 void KatePrintHeaderFooter::showContextMenu(const QPoint& pos)
972 {
973  QLineEdit* lineEdit = qobject_cast<QLineEdit*>(sender());
974  if (!lineEdit) {
975  return;
976  }
977 
978  QMenu* const contextMenu = lineEdit->createStandardContextMenu();
979  if (contextMenu == NULL) {
980  return;
981  }
982  contextMenu->addSeparator();
983 
984  // create original context menu
985  QMenu* menu = contextMenu->addMenu(i18n("Add Placeholder..."));
986  menu->setIcon(KIcon("list-add"));
987  QAction* a = menu->addAction(i18n("Current User Name") + "\t%u");
988  a->setData("%u");
989  a = menu->addAction(i18n("Complete Date/Time (short format)") + "\t%d");
990  a->setData("%d");
991  a = menu->addAction(i18n("Complete Date/Time (long format)") + "\t%D");
992  a->setData("%D");
993  a = menu->addAction(i18n("Current Time") + "\t%h");
994  a->setData("%h");
995  a = menu->addAction(i18n("Current Date (short format)") + "\t%y");
996  a->setData("%y");
997  a = menu->addAction(i18n("Current Date (long format)") + "\t%Y");
998  a->setData("%Y");
999  a = menu->addAction(i18n("File Name") + "\t%f");
1000  a->setData("%f");
1001  a = menu->addAction(i18n("Full document URL") + "\t%U");
1002  a->setData("%U");
1003  a = menu->addAction(i18n("Page Number") + "\t%p");
1004  a->setData("%p");
1005  a = menu->addAction(i18n("Total Amount of Pages") + "\t%P");
1006  a->setData("%P");
1007 
1008  QAction* const result = contextMenu->exec(lineEdit->mapToGlobal(pos));
1009  if (result) {
1010  QString placeHolder = result->data().toString();
1011  if (!placeHolder.isEmpty()) {
1012  lineEdit->insert(placeHolder);
1013  }
1014  }
1015 }
1016 
1017 void KatePrintHeaderFooter::readSettings()
1018 {
1019  KSharedConfigPtr config = KGlobal::config();
1020  KConfigGroup printGroup( config, "Kate Print Settings" );
1021 
1022  // Header
1023  KConfigGroup headerFooterGroup( &printGroup, "HeaderFooter" );
1024  bool isHeaderEnabledChecked = headerFooterGroup.readEntry( "HeaderEnabled", true );
1025  cbEnableHeader->setChecked( isHeaderEnabledChecked );
1026 
1027  QString headerFormatLeft = headerFooterGroup.readEntry( "HeaderFormatLeft", "%y" );
1028  leHeaderLeft->setText( headerFormatLeft );
1029 
1030  QString headerFormatCenter = headerFooterGroup.readEntry( "HeaderFormatCenter", "%f" );
1031  leHeaderCenter->setText( headerFormatCenter );
1032 
1033  QString headerFormatRight = headerFooterGroup.readEntry( "HeaderFormatRight", "%p" );
1034  leHeaderRight->setText( headerFormatRight );
1035 
1036  QColor headerForeground = headerFooterGroup.readEntry( "HeaderForeground", QColor("black") );
1037  kcbtnHeaderFg->setColor( headerForeground );
1038 
1039  bool isHeaderBackgroundChecked = headerFooterGroup.readEntry( "HeaderBackgroundEnabled", false );
1040  cbHeaderEnableBgColor->setChecked( isHeaderBackgroundChecked );
1041 
1042  QColor headerBackground = headerFooterGroup.readEntry( "HeaderBackground", QColor("lightgrey") );
1043  kcbtnHeaderBg->setColor( headerBackground );
1044 
1045  // Footer
1046  bool isFooterEnabledChecked = headerFooterGroup.readEntry( "FooterEnabled", true );
1047  cbEnableFooter->setChecked( isFooterEnabledChecked );
1048 
1049  QString footerFormatLeft = headerFooterGroup.readEntry( "FooterFormatLeft", QString() );
1050  leFooterLeft->setText( footerFormatLeft );
1051 
1052  QString footerFormatCenter = headerFooterGroup.readEntry( "FooterFormatCenter", QString() );
1053  leFooterCenter->setText( footerFormatCenter );
1054 
1055  QString footerFormatRight = headerFooterGroup.readEntry( "FooterFormatRight", "%U" );
1056  leFooterRight->setText( footerFormatRight );
1057 
1058  QColor footerForeground = headerFooterGroup.readEntry( "FooterForeground", QColor("black") );
1059  kcbtnFooterFg->setColor( footerForeground );
1060 
1061  bool isFooterBackgroundChecked = headerFooterGroup.readEntry( "FooterBackgroundEnabled", false );
1062  cbFooterEnableBgColor->setChecked( isFooterBackgroundChecked );
1063 
1064  QColor footerBackground = headerFooterGroup.readEntry( "FooterBackground", QColor("lightgrey") );
1065  kcbtnFooterBg->setColor( footerBackground );
1066 
1067  // Font
1068  QFont headerFooterFont = headerFooterGroup.readEntry( "HeaderFooterFont", QFont() );
1069  lFontPreview->setFont( headerFooterFont );
1070  lFontPreview->setText( QString(headerFooterFont.family() + ", %1pt").arg( headerFooterFont.pointSize() ) );
1071 }
1072 
1073 void KatePrintHeaderFooter::writeSettings()
1074 {
1075  KSharedConfigPtr config = KGlobal::config();
1076  KConfigGroup printGroup( config, "Kate Print Settings" );
1077 
1078  // Header
1079  KConfigGroup headerFooterGroup( &printGroup, "HeaderFooter" );
1080  headerFooterGroup.writeEntry( "HeaderEnabled", useHeader() );
1081 
1082  QStringList format = headerFormat();
1083  headerFooterGroup.writeEntry( "HeaderFormatLeft", format[0] );
1084  headerFooterGroup.writeEntry( "HeaderFormatCenter", format[1] );
1085  headerFooterGroup.writeEntry( "HeaderFormatRight", format[2] );
1086  headerFooterGroup.writeEntry( "HeaderForeground", headerForeground() );
1087  headerFooterGroup.writeEntry( "HeaderBackgroundEnabled", useHeaderBackground() );
1088  headerFooterGroup.writeEntry( "HeaderBackground", headerBackground() );
1089 
1090  // Footer
1091  headerFooterGroup.writeEntry( "FooterEnabled", useFooter() );
1092 
1093  format = footerFormat();
1094  headerFooterGroup.writeEntry( "FooterFormatLeft", format[0] );
1095  headerFooterGroup.writeEntry( "FooterFormatCenter", format[1] );
1096  headerFooterGroup.writeEntry( "FooterFormatRight", format[2] );
1097  headerFooterGroup.writeEntry( "FooterForeground", footerForeground() );
1098  headerFooterGroup.writeEntry( "FooterBackgroundEnabled", useFooterBackground() );
1099  headerFooterGroup.writeEntry( "FooterBackground", footerBackground() );
1100 
1101  // Font
1102  headerFooterGroup.writeEntry( "HeaderFooterFont", font() );
1103 
1104  config->sync();
1105 }
1106 
1107 //END KatePrintHeaderFooter
1108 
1109 //BEGIN KatePrintLayout
1110 
1111 KatePrintLayout::KatePrintLayout( QWidget *parent)
1112  : QWidget( parent )
1113 {
1114  setWindowTitle( i18n("L&ayout") );
1115 
1116  QVBoxLayout *lo = new QVBoxLayout ( this );
1117 
1118  KHBox *hb = new KHBox( this );
1119  lo->addWidget( hb );
1120  QLabel *lSchema = new QLabel( i18n("&Schema:"), hb );
1121  cmbSchema = new KComboBox( hb );
1122  cmbSchema->setEditable( false );
1123  lSchema->setBuddy( cmbSchema );
1124 
1125  cbDrawBackground = new QCheckBox( i18n("Draw bac&kground color"), this );
1126  lo->addWidget( cbDrawBackground );
1127 
1128  cbEnableBox = new QCheckBox( i18n("Draw &boxes"), this );
1129  lo->addWidget( cbEnableBox );
1130 
1131  gbBoxProps = new QGroupBox( this );
1132  gbBoxProps->setTitle(i18n("Box Properties"));
1133  QGridLayout* grid = new QGridLayout(gbBoxProps);
1134  lo->addWidget( gbBoxProps );
1135 
1136  QLabel *lBoxWidth = new QLabel( i18n("W&idth:"), gbBoxProps );
1137  grid->addWidget(lBoxWidth, 0, 0);
1138  sbBoxWidth = new KIntSpinBox( gbBoxProps );
1139  sbBoxWidth->setRange( 1, 100 );
1140  sbBoxWidth->setSingleStep( 1 );
1141  grid->addWidget(sbBoxWidth, 0, 1);
1142  lBoxWidth->setBuddy( sbBoxWidth );
1143 
1144  QLabel *lBoxMargin = new QLabel( i18n("&Margin:"), gbBoxProps );
1145  grid->addWidget(lBoxMargin, 1, 0);
1146  sbBoxMargin = new KIntSpinBox( gbBoxProps );
1147  sbBoxMargin->setRange( 0, 100 );
1148  sbBoxMargin->setSingleStep( 1 );
1149  grid->addWidget(sbBoxMargin, 1, 1);
1150  lBoxMargin->setBuddy( sbBoxMargin );
1151 
1152  QLabel *lBoxColor = new QLabel( i18n("Co&lor:"), gbBoxProps );
1153  grid->addWidget(lBoxColor, 2, 0);
1154  kcbtnBoxColor = new KColorButton( gbBoxProps );
1155  grid->addWidget(kcbtnBoxColor, 2, 1);
1156  lBoxColor->setBuddy( kcbtnBoxColor );
1157 
1158  connect( cbEnableBox, SIGNAL(toggled(bool)), gbBoxProps, SLOT(setEnabled(bool)) );
1159 
1160  lo->addStretch( 1 );
1161  // set defaults:
1162  sbBoxMargin->setValue( 6 );
1163  gbBoxProps->setEnabled( false );
1164 
1165  Q_FOREACH (const KateSchema &schema, KateGlobal::self()->schemaManager()->list())
1166  cmbSchema->addItem (schema.translatedName(), QVariant (schema.rawName));
1167 
1168  // default is printing, MUST BE THERE
1169  cmbSchema->setCurrentIndex (cmbSchema->findData (QVariant("Printing")));
1170 
1171  // whatsthis
1172  cmbSchema->setWhatsThis(i18n(
1173  "Select the color scheme to use for the print." ) );
1174  cbDrawBackground->setWhatsThis(i18n(
1175  "<p>If enabled, the background color of the editor will be used.</p>"
1176  "<p>This may be useful if your color scheme is designed for a dark background.</p>") );
1177  cbEnableBox->setWhatsThis(i18n(
1178  "<p>If enabled, a box as defined in the properties below will be drawn "
1179  "around the contents of each page. The Header and Footer will be separated "
1180  "from the contents with a line as well.</p>") );
1181  sbBoxWidth->setWhatsThis(i18n(
1182  "The width of the box outline" ) );
1183  sbBoxMargin->setWhatsThis(i18n(
1184  "The margin inside boxes, in pixels") );
1185  kcbtnBoxColor->setWhatsThis(i18n(
1186  "The line color to use for boxes") );
1187 
1188  readSettings();
1189 }
1190 
1191 KatePrintLayout::~KatePrintLayout()
1192 {
1193  writeSettings();
1194 }
1195 
1196 QString KatePrintLayout::colorScheme()
1197 {
1198  return cmbSchema->itemData(cmbSchema->currentIndex()).toString();
1199 }
1200 
1201 bool KatePrintLayout::useBackground()
1202 {
1203  return cbDrawBackground->isChecked();
1204 }
1205 
1206 bool KatePrintLayout::useBox()
1207 {
1208  return cbEnableBox->isChecked();
1209 }
1210 
1211 int KatePrintLayout::boxWidth()
1212 {
1213  return sbBoxWidth->value();
1214 }
1215 
1216 int KatePrintLayout::boxMargin()
1217 {
1218  return sbBoxMargin->value();
1219 }
1220 
1221 QColor KatePrintLayout::boxColor()
1222 {
1223  return kcbtnBoxColor->color();
1224 }
1225 
1226 void KatePrintLayout::readSettings()
1227 {
1228  KSharedConfigPtr config = KGlobal::config();
1229  KConfigGroup printGroup(config, "Kate Print Settings");
1230 
1231  KConfigGroup layoutGroup(&printGroup, "Layout");
1232 
1233  // get color schema back
1234  QString colorScheme = layoutGroup.readEntry( "ColorScheme", "Printing" );
1235  int index = cmbSchema->findData (QVariant (colorScheme));
1236  if (index != -1)
1237  cmbSchema->setCurrentIndex ( index );
1238 
1239  bool isBackgroundChecked = layoutGroup.readEntry( "BackgroundColorEnabled", false );
1240  cbDrawBackground->setChecked( isBackgroundChecked );
1241 
1242  bool isBoxChecked = layoutGroup.readEntry( "BoxEnabled", false );
1243  cbEnableBox->setChecked( isBoxChecked );
1244 
1245  int boxWidth = layoutGroup.readEntry( "BoxWidth", 1 );
1246  sbBoxWidth->setValue( boxWidth );
1247 
1248  int boxMargin = layoutGroup.readEntry( "BoxMargin", 6 );
1249  sbBoxMargin->setValue( boxMargin );
1250 
1251  QColor boxColor = layoutGroup.readEntry( "BoxColor", QColor() );
1252  kcbtnBoxColor->setColor( boxColor );
1253 }
1254 
1255 void KatePrintLayout::writeSettings()
1256 {
1257  KSharedConfigPtr config = KGlobal::config();
1258  KConfigGroup printGroup(config, "Kate Print Settings");
1259 
1260  KConfigGroup layoutGroup(&printGroup, "Layout");
1261  layoutGroup.writeEntry( "ColorScheme", colorScheme() );
1262  layoutGroup.writeEntry( "BackgroundColorEnabled", useBackground() );
1263  layoutGroup.writeEntry( "BoxEnabled", useBox() );
1264  layoutGroup.writeEntry( "BoxWidth", boxWidth() );
1265  layoutGroup.writeEntry( "BoxMargin", boxMargin() );
1266  layoutGroup.writeEntry( "BoxColor", boxColor() );
1267 
1268  config->sync();
1269 }
1270 
1271 //END KatePrintLayout
1272 
1273 #include "kateprinter.moc"
1274 
1275 // kate: space-indent on; indent-width 2; replace-tabs on;
QWidget::customContextMenuRequested
void customContextMenuRequested(const QPoint &pos)
KateDocument::documentName
virtual const QString & documentName() const
Definition: katedocument.h:828
KateDocument::buffer
KateBuffer & buffer()
Get access to buffer of this document.
Definition: katedocument.h:946
KatePrintTextSettings::printLineNumbers
bool printLineNumbers()
Definition: kateprinter.cpp:709
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QWidget
KateRendererConfig::setSchema
void setSchema(const QString &schema)
Definition: kateconfig.cpp:2183
katehighlight.h
katetextline.h
KatePrintHeaderFooter::headerFormat
QStringList headerFormat()
Definition: kateprinter.cpp:910
QRegExp::cap
QString cap(int nth) const
kateview.h
Kate::Script::i18n
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
QPainter::end
bool end()
QString::fill
QString & fill(QChar ch, int size)
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
KateSchema
Definition: kateschema.h:33
katerenderer.h
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
KateDocument::highlight
KateHighlighting * highlight() const
Definition: katedocument.cpp:4701
QPrinter
KateDocument::activeView
virtual KTextEditor::View * activeView() const
Definition: katedocument.h:156
QObject::sender
QObject * sender() const
KatePrintLayout::colorScheme
QString colorScheme()
Definition: kateprinter.cpp:1196
QAction::data
QVariant data() const
QFont
KateExtendedAttribute::Ptr
KSharedPtr< KateExtendedAttribute > Ptr
Definition: kateextendedattribute.h:38
QPainter::setClipping
void setClipping(bool enable)
QList::at
const T & at(int i) const
QMap< QString, QString >
QMenu::addAction
void addAction(QAction *action)
QFont::setUnderline
void setUnderline(bool enable)
katedocument.h
katetextfolding.h
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
QLineEdit::createStandardContextMenu
QMenu * createStandardContextMenu()
QHBoxLayout
QDateTime::time
QTime time() const
QRect::height
int height() const
QGridLayout
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:465
QPoint
QFontMetrics
QPainter::setClipRegion
void setClipRegion(const QRegion &region, Qt::ClipOperation operation)
QFrame::setFrameStyle
void setFrameStyle(int style)
QPainter::drawLine
void drawLine(const QLineF &line)
KateLineLayout
Definition: katelinelayout.h:34
KateSchema::translatedName
QString translatedName() const
construct translated name for shipped schemas
Definition: kateschema.h:42
KatePrintLayout::boxColor
QColor boxColor()
Definition: kateprinter.cpp:1221
katebuffer.h
KateDocument::widget
virtual QWidget * widget()
Definition: katedocument.cpp:273
KateDocument::lastLine
int lastLine() const
gets the last line number (lines() - 1)
Definition: katedocument.h:691
QRect::moveTo
void moveTo(int x, int y)
KatePrintLayout::boxWidth
int boxWidth()
Definition: kateprinter.cpp:1211
QPaintDevice::width
int width() const
QLabel::setBuddy
void setBuddy(QWidget *buddy)
QFont::setBold
void setBold(bool enable)
QPainter::resetTransform
void resetTransform()
KateSchema::rawName
QString rawName
Definition: kateschema.h:36
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QPainter::drawRect
void drawRect(const QRectF &rectangle)
KateRenderer
Handles all of the work of rendering the text (used for the views and printing)
Definition: katerenderer.h:50
QRegExp
QRect
QPainter::setFont
void setFont(const QFont &font)
QApplication::activeWindow
QWidget * activeWindow()
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
KatePrintLayout::KatePrintLayout
KatePrintLayout(QWidget *parent=0)
Definition: kateprinter.cpp:1111
QMenu::setIcon
void setIcon(const QIcon &icon)
QGroupBox
KatePrintHeaderFooter::setHFFont
void setHFFont()
Definition: kateprinter.cpp:959
kateschema.h
KateRenderer::config
KateRendererConfig * config() const
Configuration.
Definition: katerenderer.h:362
KatePrintHeaderFooter
Definition: kateprinter.h:81
KatePrintLayout::useBox
bool useBox()
Definition: kateprinter.cpp:1206
QRegion::subtracted
QRegion subtracted(const QRegion &r) const
QPainter::setPen
void setPen(const QColor &color)
QCheckBox
kateglobal.h
QScopedPointer
KatePrintLayout::useBackground
bool useBackground()
Definition: kateprinter.cpp:1201
KatePrintHeaderFooter::useFooter
bool useFooter()
Definition: kateprinter.cpp:932
QList::isEmpty
bool isEmpty() const
QPainter
QString::isEmpty
bool isEmpty() const
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
QVBoxLayout
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QPrinter::setDocName
void setDocName(const QString &name)
QList::Iterator
typedef Iterator
KatePrintTextSettings::~KatePrintTextSettings
~KatePrintTextSettings()
Definition: kateprinter.cpp:704
KatePrintTextSettings::printGuide
bool printGuide()
Definition: kateprinter.cpp:714
QLabel::setText
void setText(const QString &)
Kate::TextFolding
Class representing the folding information for a TextBuffer.
Definition: katetextfolding.h:42
QMenu::addSeparator
QAction * addSeparator()
QString
kateprinter.h
QList
KatePrintHeaderFooter::showContextMenu
void showContextMenu(const QPoint &pos)
Definition: kateprinter.cpp:971
QColor
KatePrintHeaderFooter::useHeader
bool useHeader()
Definition: kateprinter.cpp:905
QMenu::exec
QAction * exec()
QStringList
QAction::setData
void setData(const QVariant &userData)
QList::end
iterator end()
QMenu
QLineEdit::insert
void insert(const QString &newText)
KatePrintHeaderFooter::KatePrintHeaderFooter
KatePrintHeaderFooter(QWidget *parent=0)
Definition: kateprinter.cpp:747
KateDocument
Definition: katedocument.h:74
QWidget::font
font
KatePrintHeaderFooter::headerForeground
QColor headerForeground()
Definition: kateprinter.cpp:917
QPrinter::setPageMargins
void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit)
KatePrintHeaderFooter::footerFormat
QStringList footerFormat()
Definition: kateprinter.cpp:937
KateHighlighting::getKateExtendedAttributeList
void getKateExtendedAttributeList(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0)
Definition: katehighlight.cpp:619
QFontMetrics::leading
int leading() const
KatePrintHeaderFooter::headerBackground
QColor headerBackground()
Definition: kateprinter.cpp:922
QPrinter::newPage
bool newPage()
QAbstractButton::isChecked
bool isChecked() const
QPrinter::getPageMargins
void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const
katetextlayout.h
QString::replace
QString & replace(int position, int n, QChar after)
KLineEdit
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QDateTime::currentDateTime
QDateTime currentDateTime()
QPainter::setClipRect
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
QDateTime::date
QDate date() const
KatePrinter::writeSettings
static void writeSettings(QPrinter &printer)
Definition: kateprinter.cpp:87
QBoxLayout::addStretch
void addStretch(int stretch)
KatePrintHeaderFooter::font
QFont font()
Definition: kateprinter.cpp:900
QGroupBox::setTitle
void setTitle(const QString &title)
KatePrintHeaderFooter::useFooterBackground
bool useFooterBackground()
Definition: kateprinter.cpp:954
QFont::family
QString family() const
QMenu::addMenu
QAction * addMenu(QMenu *menu)
QWidget::setWindowTitle
void setWindowTitle(const QString &)
QAction
KatePrintTextSettings::KatePrintTextSettings
KatePrintTextSettings(QWidget *parent=0)
Definition: kateprinter.cpp:677
QFontMetrics::height
int height() const
QString::length
int length() const
QPainter::translate
void translate(const QPointF &offset)
KateHlManager::getDefaults
void getDefaults(const QString &schema, KateAttributeList &, KConfig *cfg=0)
Definition: katesyntaxmanager.cpp:177
QString::section
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
KatePrintLayout
Definition: kateprinter.h:133
QPen
KatePrintHeaderFooter::~KatePrintHeaderFooter
~KatePrintHeaderFooter()
Definition: kateprinter.cpp:895
QPrinter::setPrintRange
void setPrintRange(PrintRange range)
QPushButton
QLineEdit
KatePrintHeaderFooter::footerBackground
QColor footerBackground()
Definition: kateprinter.cpp:949
KatePrinter::print
static bool print(KateDocument *doc)
Definition: kateprinter.cpp:102
KatePrinter::readSettings
static void readSettings(QPrinter &printer)
Definition: kateprinter.cpp:62
KateHighlighting::name
const QString & name() const
Definition: katehighlight.h:161
QPaintDevice::height
int height() const
QStringList::filter
QStringList filter(const QString &str, Qt::CaseSensitivity cs) const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KatePrintHeaderFooter::footerForeground
QColor footerForeground()
Definition: kateprinter.cpp:944
QLabel
kateconfig.h
QVariant::toString
QString toString() const
KateDocument::activeKateView
KateView * activeKateView() const
Definition: katedocument.cpp:4676
KateLineLayoutPtr
KSharedPtr< KateLineLayout > KateLineLayoutPtr
Definition: katelinelayout.h:120
KatePrintHeaderFooter::useHeaderBackground
bool useHeaderBackground()
Definition: kateprinter.cpp:927
QList::begin
iterator begin()
KateHlManager::self
static KateHlManager * self()
Definition: katesyntaxmanager.cpp:103
QBoxLayout::setStretchFactor
bool setStretchFactor(QWidget *widget, int stretch)
QFont::pointSize
int pointSize() const
KatePrintTextSettings
Definition: kateprinter.h:53
QRegion
QDateTime
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
KatePrintLayout::~KatePrintLayout
~KatePrintLayout()
Definition: kateprinter.cpp:1191
QVariant
KatePrintLayout::boxMargin
int boxMargin()
Definition: kateprinter.cpp:1216
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal