• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

kateprinter.cpp

Go to the documentation of this file.
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001-2002 Michael Goffioul <kdeprint@swing.be>
00004  *  Complete rewrite on Sat Jun 15 2002 (c) Anders Lund <anders@alweb.dk>
00005  *  Copyright (c) 2002, 2003 Anders Lund <anders@alweb.dk>
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Library General Public
00009  *  License version 2 as published by the Free Software Foundation.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA 02110-1301, USA.
00020  **/
00021 
00022 #include "kateprinter.h"
00023 
00024 #include "kateconfig.h"
00025 #include "katedocument.h"
00026 #include "kateglobal.h"
00027 #include "katehighlight.h"
00028 #include "katetextlayout.h"
00029 #include "katerenderer.h"
00030 #include "kateschema.h"
00031 #include "katetextline.h"
00032 #include "kateview.h"
00033 
00034 #include <kapplication.h>
00035 #include <kcolorbutton.h>
00036 #include <kdebug.h>
00037 #include <kfontdialog.h>
00038 #include <klocale.h>
00039 #include <kdeprintdialog.h>
00040 #include <kurl.h>
00041 #include <kuser.h> // for loginName
00042 #include <klineedit.h>
00043 #include <kcombobox.h>
00044 
00045 #include <QtGui/QPainter>
00046 #include <QtGui/QCheckBox>
00047 #include <QtGui/QComboBox>
00048 #include <QtGui/QGroupBox>
00049 #include <QtGui/QPrintDialog>
00050 #include <QtGui/QPrinter>
00051 #include <QtGui/QApplication>
00052 
00053 #include <QtGui/QLabel>
00054 #include <QtGui/QLayout>
00055 #include <QtGui/QSpinBox>
00056 #include <QtCore/QStringList>
00057 #include <kvbox.h>
00058 
00059 //BEGIN KatePrinter
00060 bool KatePrinter::print (KateDocument *doc)
00061 {
00062 
00063   QPrinter printer;
00064 
00065   // docname is now always there, including the right Untitled name
00066   printer.setDocName(doc->documentName());
00067 
00068   KatePrintTextSettings *kpts = new KatePrintTextSettings;
00069   KatePrintHeaderFooter *kphf = new KatePrintHeaderFooter;
00070   KatePrintLayout *kpl = new KatePrintLayout;
00071 
00072   QList<QWidget*> tabs;
00073   tabs << kpts;
00074   tabs << kphf;
00075   tabs << kpl;
00076 
00077   QWidget *parentWidget=doc->widget();
00078 
00079   if ( !parentWidget )
00080     parentWidget=QApplication::activeWindow();
00081 
00082   QScopedPointer<QPrintDialog> printDialog(KdePrint::createPrintDialog(&printer, tabs, parentWidget));
00083 
00084   printDialog->setOption( QAbstractPrintDialog::PrintPageRange, false);
00085 
00086   if ( doc->activeView()->selection() )
00087     printDialog->addEnabledOption(QAbstractPrintDialog::PrintSelection);
00088 
00089   if ( printDialog->exec() )
00090   {
00091     KateRenderer renderer(doc, doc->activeKateView());
00092     renderer.config()->setSchema (kpl->colorScheme());
00093     renderer.setPrinterFriendly(true);
00094 
00095     QPainter paint( &printer );
00096     /*
00097      *        We work in tree cycles:
00098      *        1) initialize variables and retrieve print settings
00099      *        2) prepare data according to those settings
00100      *        3) draw to the printer
00101      */
00102     uint pdmWidth = printer.width();
00103     uint pdmHeight = printer.height();
00104     int y = 0;
00105     uint xstart = 0; // beginning point for painting lines
00106     uint lineCount = 0;
00107     uint maxWidth = pdmWidth;
00108     int headerWidth = pdmWidth;
00109     int startCol = 0;
00110     int endCol = 0;
00111     bool pageStarted = true;
00112     int remainder = 0; // remaining sublines from a wrapped line (for the top of a new page)
00113 
00114     // Text Settings Page
00115     bool selectionOnly = (printDialog->printRange() == QAbstractPrintDialog::Selection);
00116     bool useGuide = kpts->printGuide();
00117 
00118     bool printLineNumbers = kpts->printLineNumbers();
00119     uint lineNumberWidth( 0 );
00120 
00121     // Header/Footer Page
00122     QFont headerFont(kphf->font()); // used for header/footer
00123 
00124     bool useHeader = kphf->useHeader();
00125     QColor headerBgColor(kphf->headerBackground());
00126     QColor headerFgColor(kphf->headerForeground());
00127     uint headerHeight( 0 ); // further init only if needed
00128     QStringList headerTagList; // do
00129     bool headerDrawBg = false; // do
00130 
00131     bool useFooter = kphf->useFooter();
00132     QColor footerBgColor(kphf->footerBackground());
00133     QColor footerFgColor(kphf->footerForeground());
00134     uint footerHeight( 0 ); // further init only if needed
00135     QStringList footerTagList; // do
00136     bool footerDrawBg = false; // do
00137 
00138     // Layout Page
00139     renderer.config()->setSchema( kpl->colorScheme() );
00140     bool useBackground = kpl->useBackground();
00141     bool useBox = kpl->useBox();
00142     int boxWidth(kpl->boxWidth());
00143     QColor boxColor(kpl->boxColor());
00144     int innerMargin = useBox ? kpl->boxMargin() : 6;
00145 
00146     // Post initialization
00147     int maxHeight = (useBox ? pdmHeight-innerMargin : pdmHeight);
00148     uint currentPage( 1 );
00149     uint lastline = doc->lastLine(); // necessary to print selection only
00150     uint firstline( 0 );
00151     int fontHeight = renderer.fontHeight();
00152     KTextEditor::Range selectionRange;
00153 
00154     /*
00155     *        Now on for preparations...
00156     *        during preparations, variable names starting with a "_" means
00157     *        those variables are local to the enclosing block.
00158     */
00159     {
00160       if ( selectionOnly )
00161       {
00162         // set a line range from the first selected line to the last
00163         selectionRange = doc->activeView()->selectionRange();
00164         firstline = selectionRange.start().line();
00165         lastline = selectionRange.end().line();
00166         lineCount = firstline;
00167       }
00168 
00169       if ( printLineNumbers )
00170       {
00171         // figure out the horiizontal space required
00172         QString s( QString("%1 ").arg( doc->lines() ) );
00173         s.fill('5', -1); // some non-fixed fonts haven't equally wide numbers
00174         // FIXME calculate which is actually the widest...
00175         lineNumberWidth = renderer.currentFontMetrics().width( s );
00176         // a small space between the line numbers and the text
00177         int _adj = renderer.currentFontMetrics().width( "5" );
00178         // adjust available width and set horizontal start point for data
00179         maxWidth -= (lineNumberWidth + _adj);
00180         xstart += lineNumberWidth + _adj;
00181       }
00182 
00183       if ( useHeader || useFooter )
00184       {
00185         // Set up a tag map
00186         // This retrieves all tags, ued or not, but
00187         // none of theese operations should be expensive,
00188         // and searcing each tag in the format strings is avoided.
00189         QDateTime dt = QDateTime::currentDateTime();
00190         QMap<QString,QString> tags;
00191 
00192         KUser u (KUser::UseRealUserID);
00193         tags["u"] = u.loginName();
00194 
00195         tags["d"] = KGlobal::locale()->formatDateTime(dt, KLocale::ShortDate);
00196         tags["D"] =  KGlobal::locale()->formatDateTime(dt, KLocale::LongDate);
00197         tags["h"] =  KGlobal::locale()->formatTime(dt.time(), false);
00198         tags["y"] =  KGlobal::locale()->formatDate(dt.date(), KLocale::ShortDate);
00199         tags["Y"] =  KGlobal::locale()->formatDate(dt.date(), KLocale::LongDate);
00200         tags["f"] =  doc->url().fileName();
00201         tags["U"] =  doc->url().prettyUrl();
00202         if ( selectionOnly )
00203         {
00204           QString s( i18n("(Selection of) ") );
00205           tags["f"].prepend( s );
00206           tags["U"].prepend( s );
00207         }
00208 
00209         QRegExp reTags( "%([dDfUhuyY])" ); // TODO tjeck for "%%<TAG>"
00210 
00211         if (useHeader)
00212         {
00213           headerDrawBg = kphf->useHeaderBackground();
00214           headerHeight = QFontMetrics( headerFont ).height();
00215           if ( useBox || headerDrawBg )
00216             headerHeight += innerMargin * 2;
00217           else
00218             headerHeight += 1 + QFontMetrics( headerFont ).leading();
00219 
00220           headerTagList = kphf->headerFormat();
00221           QMutableStringListIterator it(headerTagList);
00222           while ( it.hasNext() ) {
00223             QString tag = it.next();
00224             int pos = reTags.indexIn( tag );
00225             QString rep;
00226             while ( pos > -1 )
00227             {
00228               rep = tags[reTags.cap( 1 )];
00229               tag.replace( (uint)pos, 2, rep );
00230               pos += rep.length();
00231               pos = reTags.indexIn( tag, pos );
00232             }
00233             it.setValue( tag );
00234           }
00235 
00236           if (!headerBgColor.isValid())
00237             headerBgColor = Qt::lightGray;
00238           if (!headerFgColor.isValid())
00239             headerFgColor = Qt::black;
00240         }
00241 
00242         if (useFooter)
00243         {
00244           footerDrawBg = kphf->useFooterBackground();
00245           footerHeight = QFontMetrics( headerFont ).height();
00246           if ( useBox || footerDrawBg )
00247             footerHeight += 2*innerMargin;
00248           else
00249             footerHeight += 1; // line only
00250 
00251           footerTagList = kphf->footerFormat();
00252           QMutableStringListIterator it(footerTagList);
00253           while ( it.hasNext() ) {
00254             QString tag = it.next();
00255             int pos = reTags.indexIn( tag );
00256             QString rep;
00257             while ( pos > -1 )
00258             {
00259               rep = tags[reTags.cap( 1 )];
00260               tag.replace( (uint)pos, 2, rep );
00261               pos += rep.length();
00262               pos = reTags.indexIn( tag, pos );
00263             }
00264             it.setValue( tag );
00265           }
00266 
00267           if (!footerBgColor.isValid())
00268             footerBgColor = Qt::lightGray;
00269           if (!footerFgColor.isValid())
00270             footerFgColor = Qt::black;
00271           // adjust maxheight, so we can know when/where to print footer
00272           maxHeight -= footerHeight;
00273         }
00274       } // if ( useHeader || useFooter )
00275 
00276       if ( useBackground )
00277       {
00278         if ( ! useBox )
00279         {
00280           xstart += innerMargin;
00281           maxWidth -= innerMargin * 2;
00282         }
00283       }
00284 
00285       if ( useBox )
00286       {
00287         if (!boxColor.isValid())
00288           boxColor = Qt::black;
00289         if (boxWidth < 1) // shouldn't be pssible no more!
00290           boxWidth = 1;
00291         // set maxwidth to something sensible
00292         maxWidth -= ( ( boxWidth + innerMargin )  * 2 );
00293         xstart += boxWidth + innerMargin;
00294         // maxheight too..
00295         maxHeight -= boxWidth;
00296       }
00297       else
00298         boxWidth = 0;
00299 
00300       // now that we know the vertical amount of space needed,
00301       // it is possible to calculate the total number of pages
00302       // if needed, that is if any header/footer tag contains "%P".
00303 #if 0
00304       if ( !headerTagList.filter("%P").isEmpty() || !footerTagList.filter("%P").isEmpty() )
00305       {
00306         kDebug(13020)<<"'%P' found! calculating number of pages...";
00307         uint _pages = 0;
00308         uint _ph = maxHeight;
00309         if ( useHeader )
00310           _ph -= ( headerHeight + innerMargin );
00311         if ( useFooter )
00312           _ph -= innerMargin;
00313         int _lpp = _ph / fontHeight;
00314         uint _lt = 0, _c=0;
00315 
00316         // add space for guide if required
00317 //         if ( useGuide )
00318 //           _lt += (guideHeight + (fontHeight /2)) / fontHeight;
00319         long _lw;
00320         for ( uint i = firstline; i < lastline; i++ )
00321         {
00322           //FIXME: _lw = renderer.textWidth( doc->kateTextLine( i ), -1 );
00323           _lw = 80 * renderer.spaceWidth(); //FIXME: just a stand-in
00324           while ( _lw >= 0 )
00325           {
00326             _c++;
00327             _lt++;
00328             if ( (int)_lt  == _lpp )
00329             {
00330               _pages++;
00331               _lt = 0;
00332             }
00333             _lw -= maxWidth;
00334             if ( ! _lw ) _lw--; // skip lines matching exactly!
00335           }
00336         }
00337         if ( _lt ) _pages++; // last page
00338 
00339         // substitute both tag lists
00340         QString re("%P");
00341         QStringList::Iterator it;
00342         for ( it=headerTagList.begin(); it!=headerTagList.end(); ++it )
00343           (*it).replace( re, QString( "%1" ).arg( _pages ) );
00344         for ( it=footerTagList.begin(); it!=footerTagList.end(); ++it )
00345           (*it).replace( re, QString( "%1" ).arg( _pages ) );
00346       }
00347 #endif
00348     } // end prepare block
00349 
00350      /*
00351         On to draw something :-)
00352      */
00353     while (  lineCount <= lastline  )
00354     {
00355       startCol = 0;
00356       endCol = 0;
00357 
00358       if ( y + fontHeight >= maxHeight )
00359       {
00360         kDebug(13020)<<"Starting new page,"<<lineCount<<"lines up to now.";
00361         printer.newPage();
00362         paint.resetTransform();
00363         currentPage++;
00364         pageStarted = true;
00365         y=0;
00366       }
00367 
00368       if ( pageStarted )
00369       {
00370         if ( useHeader )
00371         {
00372           paint.setPen(headerFgColor);
00373           paint.setFont(headerFont);
00374           if ( headerDrawBg )
00375             paint.fillRect(0, 0, headerWidth, headerHeight, headerBgColor);
00376           if (headerTagList.count() == 3)
00377           {
00378             int valign = ( (useBox||headerDrawBg||useBackground) ?
00379             Qt::AlignVCenter : Qt::AlignTop );
00380             int align = valign|Qt::AlignLeft;
00381             int marg = ( useBox || headerDrawBg ) ? innerMargin : 0;
00382             if ( useBox ) marg += boxWidth;
00383             QString s;
00384             for (int i=0; i<3; i++)
00385             {
00386               s = headerTagList[i];
00387               if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage));
00388               paint.drawText(marg, 0, headerWidth-(marg*2), headerHeight, align, s);
00389               align = valign|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
00390             }
00391           }
00392           if ( ! ( headerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate header from contents
00393           {
00394             paint.drawLine( 0, headerHeight-1, headerWidth, headerHeight-1 );
00395             //y += 1; now included in headerHeight
00396           }
00397           y += headerHeight + innerMargin;
00398         }
00399 
00400         if ( useFooter )
00401         {
00402           paint.setPen(footerFgColor);
00403           if ( ! ( footerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate footer from contents
00404             paint.drawLine( 0, maxHeight + innerMargin - 1, headerWidth, maxHeight + innerMargin - 1 );
00405           if ( footerDrawBg )
00406             paint.fillRect(0, maxHeight+innerMargin+boxWidth, headerWidth, footerHeight, footerBgColor);
00407           if (footerTagList.count() == 3)
00408           {
00409             int align = Qt::AlignVCenter|Qt::AlignLeft;
00410             int marg = ( useBox || footerDrawBg ) ? innerMargin : 0;
00411             if ( useBox ) marg += boxWidth;
00412             QString s;
00413             for (int i=0; i<3; i++)
00414             {
00415               s = footerTagList[i];
00416               if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage));
00417               paint.drawText(marg, maxHeight+innerMargin, headerWidth-(marg*2), footerHeight, align, s);
00418               align = Qt::AlignVCenter|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
00419             }
00420           }
00421         } // done footer
00422 
00423         if ( useBackground )
00424         {
00425           // If we have a box, or the header/footer has backgrounds, we want to paint
00426           // to the border of those. Otherwise just the contents area.
00427           int _y = y, _h = maxHeight - y;
00428           if ( useBox )
00429           {
00430             _y -= innerMargin;
00431             _h += 2 * innerMargin;
00432           }
00433           else
00434           {
00435             if ( headerDrawBg )
00436             {
00437               _y -= innerMargin;
00438               _h += innerMargin;
00439             }
00440             if ( footerDrawBg )
00441             {
00442               _h += innerMargin;
00443             }
00444           }
00445           paint.fillRect( 0, _y, pdmWidth, _h, renderer.config()->backgroundColor());
00446         }
00447 
00448         if ( useBox )
00449         {
00450           paint.setPen(QPen(boxColor, boxWidth));
00451           paint.drawRect(0, 0, pdmWidth, pdmHeight);
00452           if (useHeader)
00453             paint.drawLine(0, headerHeight, headerWidth, headerHeight);
00454           else
00455             y += innerMargin;
00456 
00457           if ( useFooter ) // drawline is not trustable, grr.
00458             paint.fillRect( 0, maxHeight+innerMargin, headerWidth, boxWidth, boxColor );
00459         }
00460 
00461         if ( useGuide && currentPage == 1 )
00462         {  // FIXME - this may span more pages...
00463           // draw a box unless we have boxes, in which case we end with a box line
00464           int _ystart = y;
00465           QString _hlName = doc->highlight()->name();
00466 
00467           QList<KateExtendedAttribute::Ptr> _attributes; // list of highlight attributes for the legend
00468           doc->highlight()->getKateExtendedAttributeList(kpl->colorScheme(), _attributes);
00469 
00470           KateAttributeList _defaultAttributes;
00471           KateHlManager::self()->getDefaults ( renderer.config()->schema(), _defaultAttributes );
00472 
00473           QColor _defaultPen = _defaultAttributes.at(0)->foreground().color();
00474           paint.setPen(_defaultPen);
00475           paint.setBrush(_defaultPen);
00476 
00477           int _marg = 0;
00478           if ( useBox )
00479             _marg += (2*boxWidth) + (2*innerMargin);
00480           else
00481           {
00482             if ( useBackground )
00483               _marg += 2*innerMargin;
00484             _marg += 1;
00485             y += 1 + innerMargin;
00486           }
00487 
00488           // draw a title string
00489           QFont _titleFont = renderer.config()->font();
00490           _titleFont.setBold(true);
00491           paint.setFont( _titleFont );
00492           QRect _r;
00493           paint.drawText( QRect(_marg, y, pdmWidth-(2*_marg), maxHeight - y),
00494             Qt::AlignTop|Qt::AlignHCenter,
00495             i18n("Typographical Conventions for %1", _hlName ), &_r );
00496           int _w = pdmWidth - (_marg*2) - (innerMargin*2);
00497           int _x = _marg + innerMargin;
00498           y += _r.height() + innerMargin;
00499           paint.drawLine( _x, y, _x + _w, y );
00500           y += 1 + innerMargin;
00501 
00502           int _widest( 0 );
00503           foreach (KateExtendedAttribute::Ptr attribute, _attributes)
00504             _widest = qMax(QFontMetrics(attribute->font()).width(attribute->name().section(':',1,1)), _widest);
00505 
00506           int _guideCols = _w/( _widest + innerMargin );
00507 
00508           // draw attrib names using their styles
00509           int _cw = _w/_guideCols;
00510           int _i(0);
00511 
00512           _titleFont.setUnderline(true);
00513           QString _currentHlName;
00514           foreach (KateExtendedAttribute::Ptr attribute, _attributes)
00515           {
00516             QString _hl = attribute->name().section(':',0,0);
00517             QString _name = attribute->name().section(':',1,1);
00518             if ( _hl != _hlName && _hl != _currentHlName ) {
00519               _currentHlName = _hl;
00520               if ( _i%_guideCols )
00521                 y += fontHeight;
00522               y += innerMargin;
00523               paint.setFont(_titleFont);
00524               paint.setPen(_defaultPen);
00525               paint.drawText( _x, y, _w, fontHeight, Qt::AlignTop, _hl + ' ' + i18n("text") );
00526               y += fontHeight;
00527               _i = 0;
00528             }
00529 
00530             KTextEditor::Attribute _attr =  *_defaultAttributes[attribute->defaultStyleIndex()];
00531             _attr += *attribute;
00532             paint.setPen( _attr.foreground().color() );
00533             paint.setFont( _attr.font() );
00534 
00535             if (_attr.hasProperty(QTextFormat::BackgroundBrush) ) {
00536               QRect _rect = QFontMetrics(_attr.font()).boundingRect(_name);
00537               _rect.moveTo(_x + ((_i%_guideCols)*_cw), y);
00538                paint.fillRect(_rect, _attr.background() );
00539             }
00540 
00541             paint.drawText(( _x + ((_i%_guideCols)*_cw)), y, _cw, fontHeight, Qt::AlignTop, _name );
00542 
00543             _i++;
00544             if ( _i && ! ( _i%_guideCols ) )
00545               y += fontHeight;
00546           }
00547 
00548           if ( _i%_guideCols )
00549             y += fontHeight;// last row not full
00550 
00551           // draw a box around the legend
00552           paint.setPen ( _defaultPen );
00553           if ( useBox )
00554             paint.fillRect( 0, y+innerMargin, headerWidth, boxWidth, boxColor );
00555           else
00556           {
00557             _marg -=1;
00558             paint.setBrush(QBrush());
00559             paint.drawRect( _marg, _ystart, pdmWidth-(2*_marg), y-_ystart+innerMargin );
00560           }
00561 
00562           y += ( useBox ? boxWidth : 1 ) + (innerMargin*2);
00563         } // useGuide
00564 
00565         paint.translate(xstart,y);
00566         pageStarted = false;
00567       } // pageStarted; move on to contents:)
00568 
00569       if ( printLineNumbers /*&& ! startCol*/ ) // don't repeat!
00570       {
00571         paint.setFont( renderer.config()->font() );
00572         paint.setPen( renderer.config()->lineNumberColor() );
00573         paint.drawText( (( useBox || useBackground ) ? innerMargin : 0)-xstart, 0,
00574                     lineNumberWidth, fontHeight,
00575                     Qt::AlignRight, QString("%1").arg( lineCount + 1 ) );
00576       }
00577 
00578       // HA! this is where we print [part of] a line ;]]
00579       // FIXME Convert this function + related functionality to a separate KatePrintView
00580       KateLineLayout range(doc);
00581       range.setLine(lineCount);
00582       KateLineLayoutPtr *rangeptr = new KateLineLayoutPtr(&range);
00583       renderer.layoutLine(*rangeptr, (int)maxWidth, false);
00584 
00585       // selectionOnly: clip non-selection parts and adjust painter position if needed
00586       int _xadjust = 0;
00587       if (selectionOnly) {
00588         if (doc->activeView()->blockSelection()) {
00589           int _x = renderer.cursorToX((*rangeptr)->viewLine(0), selectionRange.start());
00590           int _x1 = renderer.cursorToX((*rangeptr)->viewLine((*rangeptr)->viewLineCount()-1), selectionRange.end());
00591            _xadjust = _x;
00592            paint.translate(-_xadjust, 0);
00593           paint.setClipRegion(QRegion( _x, 0, _x1 - _x, (*rangeptr)->viewLineCount()*fontHeight));
00594         }
00595 
00596         else if (lineCount == firstline || lineCount == lastline) {
00597           QRegion region(0, 0, maxWidth, (*rangeptr)->viewLineCount()*fontHeight);
00598 
00599           if ( lineCount == firstline) {
00600             region = region.subtracted(QRegion(0, 0, renderer.cursorToX((*rangeptr)->viewLine(0), selectionRange.start()), fontHeight));
00601           }
00602 
00603           if (lineCount == lastline) {
00604             int _x = renderer.cursorToX((*rangeptr)->viewLine((*rangeptr)->viewLineCount()-1), selectionRange.end());
00605             region = region.subtracted(QRegion(_x, 0, maxWidth-_x, fontHeight));
00606           }
00607 
00608           paint.setClipRegion(region);
00609         }
00610       }
00611 
00612       // If the line is too long (too many 'viewlines') to fit the remaining vertical space,
00613       // clip and adjust the painter position as necessary
00614       int _lines = (*rangeptr)->viewLineCount(); // number of "sublines" to paint.
00615 
00616       if (remainder) {
00617         int _height = (maxHeight-y)/fontHeight;
00618         _height = qMin(_height, remainder);        
00619 
00620         paint.translate(0, -(_lines-remainder)*fontHeight+1);
00621         paint.setClipRect(0, (_lines-remainder)*fontHeight+1, maxWidth, _height*fontHeight); //### drop the crosspatch in printerfriendly mode???
00622         remainder -= _height;
00623       }
00624       else if (fontHeight*_lines > maxHeight-y) {
00625         remainder = _lines - ((maxHeight-y)/fontHeight);
00626         paint.setClipRect(0, 0, maxWidth, (_lines-remainder)*fontHeight+1); //### drop the crosspatch in printerfriendly mode???
00627       }
00628 
00629       renderer.paintTextLine(paint, *rangeptr, 0, (int)maxWidth);
00630 
00631       paint.setClipping(false);
00632       paint.translate(_xadjust, (fontHeight * _lines));
00633 
00634       y += fontHeight*_lines;
00635 
00636       if ( ! remainder )
00637       lineCount++;
00638     } // done lineCount <= lastline
00639 
00640     paint.end();
00641     return true;
00642   }
00643   return false;
00644 }
00645 //END KatePrinter
00646 
00647 //BEGIN KatePrintTextSettings
00648 KatePrintTextSettings::KatePrintTextSettings( QWidget *parent )
00649   : QWidget( parent )
00650 {
00651   setWindowTitle( i18n("Te&xt Settings") );
00652 
00653   QVBoxLayout *lo = new QVBoxLayout ( this );
00654 
00655 //   cbSelection = new QCheckBox( i18n("Print &selected text only"), this );
00656 //   lo->addWidget( cbSelection );
00657 
00658   cbLineNumbers = new QCheckBox( i18n("Print line &numbers"), this );
00659   lo->addWidget( cbLineNumbers );
00660 
00661   cbGuide = new QCheckBox( i18n("Print &legend"), this );
00662   lo->addWidget( cbGuide );
00663 
00664   lo->addStretch( 1 );
00665 
00666   // set defaults - nothing to do :-)
00667 
00668   // whatsthis
00669 //   cbSelection->setWhatsThis(i18n(
00670 //         "<p>This option is only available if some text is selected in the document.</p>"
00671 //         "<p>If available and enabled, only the selected text is printed.</p>") );
00672   cbLineNumbers->setWhatsThis(i18n(
00673         "<p>If enabled, line numbers will be printed on the left side of the page(s).</p>") );
00674   cbGuide->setWhatsThis(i18n(
00675         "<p>Print a box displaying typographical conventions for the document type, as "
00676         "defined by the syntax highlighting being used.</p>") );
00677 
00678   readSettings();
00679 }
00680 
00681 KatePrintTextSettings::~KatePrintTextSettings()
00682 {
00683   writeSettings();
00684 }
00685 
00686 // bool KatePrintTextSettings::printSelection()
00687 // {
00688 //     return cbSelection->isChecked();
00689 // }
00690 
00691 void KatePrintTextSettings::readSettings()
00692 {
00693   KSharedConfigPtr config = KGlobal::config();
00694   KConfigGroup printGroup( config, "Kate Print Settings" );
00695   
00696   KConfigGroup textGroup( &printGroup, "Text" );
00697   bool isLineNumbersChecked = textGroup.readEntry( "LineNumbers", false );
00698   cbLineNumbers->setChecked( isLineNumbersChecked );
00699 
00700   bool isLegendChecked = textGroup.readEntry( "Legend", false );
00701   cbGuide->setChecked( isLegendChecked );
00702 }
00703     
00704 void KatePrintTextSettings::writeSettings()
00705 {
00706   KSharedConfigPtr config = KGlobal::config();
00707   KConfigGroup printGroup( config, "Kate Print Settings" );
00708   
00709   KConfigGroup textGroup( &printGroup, "Text" );
00710   textGroup.writeEntry( "LineNumbers", printLineNumbers() );
00711   textGroup.writeEntry( "Legend", printGuide() );
00712   
00713   config->sync();
00714 }
00715 
00716 bool KatePrintTextSettings::printLineNumbers()
00717 {
00718   return cbLineNumbers->isChecked();
00719 }
00720 
00721 bool KatePrintTextSettings::printGuide()
00722 {
00723   return cbGuide->isChecked();
00724 }
00725 
00726 // void KatePrintTextSettings::enableSelection( bool enable )
00727 // {
00728 //   cbSelection->setEnabled( enable );
00729 // }
00730 
00731 //END KatePrintTextSettings
00732 
00733 //BEGIN KatePrintHeaderFooter
00734 KatePrintHeaderFooter::KatePrintHeaderFooter( QWidget *parent )
00735   : QWidget( parent )
00736 {
00737   setWindowTitle( i18n("Hea&der && Footer") );
00738 
00739   QVBoxLayout *lo = new QVBoxLayout ( this );
00740 
00741   // enable
00742   QHBoxLayout *lo1 = new QHBoxLayout ();
00743   lo->addLayout( lo1 );
00744   cbEnableHeader = new QCheckBox( i18n("Pr&int header"), this );
00745   lo1->addWidget( cbEnableHeader );
00746   cbEnableFooter = new QCheckBox( i18n("Pri&nt footer"), this );
00747   lo1->addWidget( cbEnableFooter );
00748 
00749   // font
00750   QHBoxLayout *lo2 = new QHBoxLayout();
00751   lo->addLayout( lo2 );
00752   lo2->addWidget( new QLabel( i18n("Header/footer font:"), this ) );
00753   lFontPreview = new QLabel( this );
00754   lFontPreview->setFrameStyle( QFrame::Panel|QFrame::Sunken );
00755   lo2->addWidget( lFontPreview );
00756   lo2->setStretchFactor( lFontPreview, 1 );
00757   QPushButton *btnChooseFont = new QPushButton( i18n("Choo&se Font..."), this );
00758   lo2->addWidget( btnChooseFont );
00759   connect( btnChooseFont, SIGNAL(clicked()), this, SLOT(setHFFont()) );
00760 
00761   // header
00762   gbHeader = new QGroupBox( this );
00763   gbHeader->setTitle(i18n("Header Properties"));
00764   QGridLayout* grid = new QGridLayout(gbHeader);
00765   lo->addWidget( gbHeader );
00766 
00767   QLabel *lHeaderFormat = new QLabel( i18n("&Format:"), gbHeader );
00768   grid->addWidget(lHeaderFormat, 0, 0);
00769 
00770   KHBox *hbHeaderFormat = new KHBox( gbHeader );
00771   grid->addWidget(hbHeaderFormat, 0, 1);
00772 
00773   leHeaderLeft = new KLineEdit( hbHeaderFormat );
00774   leHeaderCenter = new KLineEdit( hbHeaderFormat );
00775   leHeaderRight = new KLineEdit( hbHeaderFormat );
00776   lHeaderFormat->setBuddy( leHeaderLeft );
00777 
00778   grid->addWidget(new QLabel( i18n("Colors:"), gbHeader ), 1, 0);
00779 
00780   KHBox *hbHeaderColors = new KHBox( gbHeader );
00781   grid->addWidget(hbHeaderColors, 1, 1);
00782 
00783   hbHeaderColors->setSpacing( -1 );
00784   QLabel *lHeaderFgCol = new QLabel( i18n("Foreground:"), hbHeaderColors );
00785   kcbtnHeaderFg = new KColorButton( hbHeaderColors );
00786   lHeaderFgCol->setBuddy( kcbtnHeaderFg );
00787   cbHeaderEnableBgColor = new QCheckBox( i18n("Bac&kground"), hbHeaderColors );
00788   kcbtnHeaderBg = new KColorButton( hbHeaderColors );
00789 
00790   gbFooter = new QGroupBox( this );
00791   gbFooter->setTitle(i18n("Footer Properties"));
00792   grid = new QGridLayout(gbFooter);
00793   lo->addWidget( gbFooter );
00794 
00795   // footer
00796   QLabel *lFooterFormat = new QLabel( i18n("For&mat:"), gbFooter );
00797   grid->addWidget(lFooterFormat, 0, 0);
00798 
00799   KHBox *hbFooterFormat = new KHBox( gbFooter );
00800   grid->addWidget(hbFooterFormat, 0, 1);
00801 
00802   hbFooterFormat->setSpacing( -1 );
00803   leFooterLeft = new KLineEdit( hbFooterFormat );
00804   leFooterCenter = new KLineEdit( hbFooterFormat );
00805   leFooterRight = new KLineEdit( hbFooterFormat );
00806   lFooterFormat->setBuddy( leFooterLeft );
00807 
00808   grid->addWidget(new QLabel( i18n("Colors:"), gbFooter ), 1, 0);
00809 
00810   KHBox *hbFooterColors = new KHBox( gbFooter );
00811   grid->addWidget(hbFooterColors, 1, 1);
00812 
00813   hbFooterColors->setSpacing( -1 );
00814   QLabel *lFooterBgCol = new QLabel( i18n("Foreground:"), hbFooterColors );
00815   kcbtnFooterFg = new KColorButton( hbFooterColors );
00816   lFooterBgCol->setBuddy( kcbtnFooterFg );
00817   cbFooterEnableBgColor = new QCheckBox( i18n("&Background"), hbFooterColors );
00818   kcbtnFooterBg = new KColorButton( hbFooterColors );
00819 
00820   lo->addStretch( 1 );
00821 
00822   // user friendly
00823   connect( cbEnableHeader, SIGNAL(toggled(bool)), gbHeader, SLOT(setEnabled(bool)) );
00824   connect( cbEnableFooter, SIGNAL(toggled(bool)), gbFooter, SLOT(setEnabled(bool)) );
00825   connect( cbHeaderEnableBgColor, SIGNAL(toggled(bool)), kcbtnHeaderBg, SLOT(setEnabled(bool)) );
00826   connect( cbFooterEnableBgColor, SIGNAL(toggled(bool)), kcbtnFooterBg, SLOT(setEnabled(bool)) );
00827 
00828   // set defaults
00829   cbEnableHeader->setChecked( true );
00830   leHeaderLeft->setText( "%y" );
00831   leHeaderCenter->setText( "%f" );
00832   leHeaderRight->setText( "%p" );
00833   kcbtnHeaderFg->setColor( QColor("black") );
00834   cbHeaderEnableBgColor->setChecked( false );
00835   kcbtnHeaderBg->setColor( QColor("lightgrey") );
00836 
00837   cbEnableFooter->setChecked( true );
00838   leFooterRight->setText( "%U" );
00839   kcbtnFooterFg->setColor( QColor("black") );
00840   cbFooterEnableBgColor->setChecked( false );
00841   kcbtnFooterBg->setColor( QColor("lightgrey") );
00842 
00843   // whatsthis
00844   QString  s = i18n("<p>Format of the page header. The following tags are supported:</p>");
00845   QString s1 = i18n(
00846       "<ul><li><tt>%u</tt>: current user name</li>"
00847       "<li><tt>%d</tt>: complete date/time in short format</li>"
00848       "<li><tt>%D</tt>: complete date/time in long format</li>"
00849       "<li><tt>%h</tt>: current time</li>"
00850       "<li><tt>%y</tt>: current date in short format</li>"
00851       "<li><tt>%Y</tt>: current date in long format</li>"
00852       "<li><tt>%f</tt>: file name</li>"
00853       "<li><tt>%U</tt>: full URL of the document</li>"
00854       "<li><tt>%p</tt>: page number</li>"
00855       "</ul><br />");
00856   leHeaderRight->setWhatsThis(s + s1 );
00857   leHeaderCenter->setWhatsThis(s + s1 );
00858   leHeaderLeft->setWhatsThis(s + s1 );
00859   s = i18n("<p>Format of the page footer. The following tags are supported:</p>");
00860   leFooterRight->setWhatsThis(s + s1 );
00861   leFooterCenter->setWhatsThis(s + s1 );
00862   leFooterLeft->setWhatsThis(s + s1 );
00863 
00864   readSettings();
00865 }
00866 
00867 KatePrintHeaderFooter::~KatePrintHeaderFooter()
00868 {
00869   writeSettings();
00870 }
00871 
00872 QFont KatePrintHeaderFooter::font()
00873 {
00874     return lFontPreview->font();
00875 }
00876 
00877 bool KatePrintHeaderFooter::useHeader()
00878 {
00879   return cbEnableHeader->isChecked();
00880 }
00881 
00882 QStringList KatePrintHeaderFooter::headerFormat()
00883 {
00884   QStringList l;
00885   l << leHeaderLeft->text() << leHeaderCenter->text() << leHeaderRight->text();
00886   return l;
00887 }
00888 
00889 QColor KatePrintHeaderFooter::headerForeground()
00890 {
00891   return kcbtnHeaderFg->color();
00892 }
00893 
00894 QColor KatePrintHeaderFooter::headerBackground()
00895 {
00896   return kcbtnHeaderBg->color();
00897 }
00898 
00899 bool KatePrintHeaderFooter::useHeaderBackground()
00900 {
00901   return cbHeaderEnableBgColor->isChecked();
00902 }
00903 
00904 bool KatePrintHeaderFooter::useFooter()
00905 {
00906   return cbEnableFooter->isChecked();
00907 }
00908 
00909 QStringList KatePrintHeaderFooter::footerFormat()
00910 {
00911   QStringList l;
00912   l<< leFooterLeft->text() << leFooterCenter->text() << leFooterRight->text();
00913   return l;
00914 }
00915 
00916 QColor KatePrintHeaderFooter::footerForeground()
00917 {
00918   return kcbtnFooterFg->color();
00919 }
00920 
00921 QColor KatePrintHeaderFooter::footerBackground()
00922 {
00923   return kcbtnFooterBg->color();
00924 }
00925 
00926 bool KatePrintHeaderFooter::useFooterBackground()
00927 {
00928   return cbFooterEnableBgColor->isChecked();
00929 }
00930 
00931 void KatePrintHeaderFooter::setHFFont()
00932 {
00933   QFont fnt( lFontPreview->font() );
00934   // display a font dialog
00935   if ( KFontDialog::getFont( fnt, false, this ) == KFontDialog::Accepted )
00936   {
00937     // set preview
00938     lFontPreview->setFont( fnt );
00939     lFontPreview->setText( (fnt.family() + ", %1pt").arg( fnt.pointSize() ) );
00940   }
00941 }
00942 
00943 void KatePrintHeaderFooter::readSettings()
00944 {
00945   KSharedConfigPtr config = KGlobal::config();
00946   KConfigGroup printGroup( config, "Kate Print Settings" );
00947   
00948   // Header
00949   KConfigGroup headerFooterGroup( &printGroup, "HeaderFooter" );
00950   bool isHeaderEnabledChecked = headerFooterGroup.readEntry( "HeaderEnabled", true );
00951   cbEnableHeader->setChecked( isHeaderEnabledChecked );
00952 
00953   QString headerFormatLeft = headerFooterGroup.readEntry( "HeaderFormatLeft", "%y" );
00954   leHeaderLeft->setText( headerFormatLeft );
00955 
00956   QString headerFormatCenter = headerFooterGroup.readEntry( "HeaderFormatCenter", "%f" );
00957   leHeaderCenter->setText( headerFormatCenter );
00958 
00959   QString headerFormatRight = headerFooterGroup.readEntry( "HeaderFormatRight", "%p" );
00960   leHeaderRight->setText( headerFormatRight );
00961 
00962   QColor headerForeground = headerFooterGroup.readEntry( "HeaderForeground", QColor("black") );
00963   kcbtnHeaderFg->setColor( headerForeground );
00964 
00965   bool isHeaderBackgroundChecked = headerFooterGroup.readEntry( "HeaderBackgroundEnabled", false );
00966   cbHeaderEnableBgColor->setChecked( isHeaderBackgroundChecked );
00967 
00968   QColor headerBackground = headerFooterGroup.readEntry( "HeaderBackground", QColor("lightgrey") );
00969   kcbtnHeaderBg->setColor( headerBackground );
00970   
00971   // Footer
00972   bool isFooterEnabledChecked = headerFooterGroup.readEntry( "FooterEnabled", true );
00973   cbEnableFooter->setChecked( isFooterEnabledChecked );
00974 
00975   QString footerFormatLeft = headerFooterGroup.readEntry( "FooterFormatLeft", QString() );
00976   leFooterLeft->setText( footerFormatLeft );
00977 
00978   QString footerFormatCenter = headerFooterGroup.readEntry( "FooterFormatCenter", QString() );
00979   leFooterCenter->setText( footerFormatCenter );
00980 
00981   QString footerFormatRight = headerFooterGroup.readEntry( "FooterFormatRight", "%U" );
00982   leFooterRight->setText( footerFormatRight );
00983 
00984   QColor footerForeground = headerFooterGroup.readEntry( "FooterForeground", QColor("black") );
00985   kcbtnFooterFg->setColor( footerForeground );
00986 
00987   bool isFooterBackgroundChecked = headerFooterGroup.readEntry( "FooterBackgroundEnabled", false );
00988   cbFooterEnableBgColor->setChecked( isFooterBackgroundChecked );
00989 
00990   QColor footerBackground = headerFooterGroup.readEntry( "FooterBackground", QColor("lightgrey") );
00991   kcbtnFooterBg->setColor( footerBackground );
00992 
00993   // Font
00994   QFont headerFooterFont = headerFooterGroup.readEntry( "HeaderFooterFont", QFont() );
00995   lFontPreview->setFont( headerFooterFont );
00996   lFontPreview->setText( QString(headerFooterFont.family() + ", %1pt").arg( headerFooterFont.pointSize() ) );
00997 }
00998 
00999 void KatePrintHeaderFooter::writeSettings()
01000 {
01001   KSharedConfigPtr config = KGlobal::config();
01002   KConfigGroup printGroup( config, "Kate Print Settings" );
01003   
01004   // Header
01005   KConfigGroup headerFooterGroup( &printGroup, "HeaderFooter" );
01006   headerFooterGroup.writeEntry( "HeaderEnabled", useHeader() );
01007 
01008   QStringList format = headerFormat();
01009   headerFooterGroup.writeEntry( "HeaderFormatLeft", format[0] );
01010   headerFooterGroup.writeEntry( "HeaderFormatCenter", format[1] );
01011   headerFooterGroup.writeEntry( "HeaderFormatRight", format[2] );
01012   headerFooterGroup.writeEntry( "HeaderForeground", headerForeground() );
01013   headerFooterGroup.writeEntry( "HeaderBackgroundEnabled", useHeaderBackground() );
01014   headerFooterGroup.writeEntry( "HeaderBackground", headerBackground() );
01015   
01016   // Footer
01017   headerFooterGroup.writeEntry( "FooterEnabled", useFooter() );
01018 
01019   format = footerFormat();
01020   headerFooterGroup.writeEntry( "FooterFormatLeft", format[0] );
01021   headerFooterGroup.writeEntry( "FooterFormatCenter", format[1] );
01022   headerFooterGroup.writeEntry( "FooterFormatRight", format[2] );
01023   headerFooterGroup.writeEntry( "FooterForeground", footerForeground() );
01024   headerFooterGroup.writeEntry( "FooterBackgroundEnabled", useFooterBackground() );
01025   headerFooterGroup.writeEntry( "FooterBackground", footerBackground() );
01026 
01027   // Font
01028   headerFooterGroup.writeEntry( "HeaderFooterFont", font() );
01029 
01030   config->sync();
01031 }
01032 
01033 //END KatePrintHeaderFooter
01034 
01035 //BEGIN KatePrintLayout
01036 
01037 KatePrintLayout::KatePrintLayout( QWidget *parent)
01038   : QWidget( parent )
01039 {
01040   setWindowTitle( i18n("L&ayout") );
01041 
01042   QVBoxLayout *lo = new QVBoxLayout ( this );
01043 
01044   KHBox *hb = new KHBox( this );
01045   lo->addWidget( hb );
01046   QLabel *lSchema = new QLabel( i18n("&Schema:"), hb );
01047   cmbSchema = new KComboBox( hb );
01048   cmbSchema->setEditable( false );
01049   lSchema->setBuddy( cmbSchema );
01050 
01051   cbDrawBackground = new QCheckBox( i18n("Draw bac&kground color"), this );
01052   lo->addWidget( cbDrawBackground );
01053 
01054   cbEnableBox = new QCheckBox( i18n("Draw &boxes"), this );
01055   lo->addWidget( cbEnableBox );
01056 
01057   gbBoxProps = new QGroupBox( this );
01058   gbBoxProps->setTitle(i18n("Box Properties"));
01059   QGridLayout* grid = new QGridLayout(gbBoxProps);
01060   lo->addWidget( gbBoxProps );
01061 
01062   QLabel *lBoxWidth = new QLabel( i18n("W&idth:"), gbBoxProps );
01063   grid->addWidget(lBoxWidth, 0, 0);
01064   sbBoxWidth = new QSpinBox( gbBoxProps );
01065   sbBoxWidth->setRange( 1, 100 );
01066   sbBoxWidth->setSingleStep( 1 );
01067   grid->addWidget(sbBoxWidth, 0, 1);
01068   lBoxWidth->setBuddy( sbBoxWidth );
01069 
01070   QLabel *lBoxMargin = new QLabel( i18n("&Margin:"), gbBoxProps );
01071   grid->addWidget(lBoxMargin, 1, 0);
01072   sbBoxMargin = new QSpinBox( gbBoxProps );
01073   sbBoxMargin->setRange( 0, 100 );
01074   sbBoxMargin->setSingleStep( 1 );
01075   grid->addWidget(sbBoxMargin, 1, 1);
01076   lBoxMargin->setBuddy( sbBoxMargin );
01077 
01078   QLabel *lBoxColor = new QLabel( i18n("Co&lor:"), gbBoxProps );
01079   grid->addWidget(lBoxColor, 2, 0);
01080   kcbtnBoxColor = new KColorButton( gbBoxProps );
01081   grid->addWidget(kcbtnBoxColor, 2, 1);
01082   lBoxColor->setBuddy( kcbtnBoxColor );
01083 
01084   connect( cbEnableBox, SIGNAL(toggled(bool)), gbBoxProps, SLOT(setEnabled(bool)) );
01085 
01086   lo->addStretch( 1 );
01087   // set defaults:
01088   sbBoxMargin->setValue( 6 );
01089   gbBoxProps->setEnabled( false );
01090   cmbSchema->addItems (KateGlobal::self()->schemaManager()->list ());
01091   cmbSchema->setCurrentIndex( 1 );
01092 
01093   // whatsthis
01094   cmbSchema->setWhatsThis(i18n(
01095         "Select the color scheme to use for the print." ) );
01096   cbDrawBackground->setWhatsThis(i18n(
01097         "<p>If enabled, the background color of the editor will be used.</p>"
01098         "<p>This may be useful if your color scheme is designed for a dark background.</p>") );
01099   cbEnableBox->setWhatsThis(i18n(
01100         "<p>If enabled, a box as defined in the properties below will be drawn "
01101         "around the contents of each page. The Header and Footer will be separated "
01102         "from the contents with a line as well.</p>") );
01103   sbBoxWidth->setWhatsThis(i18n(
01104         "The width of the box outline" ) );
01105   sbBoxMargin->setWhatsThis(i18n(
01106         "The margin inside boxes, in pixels") );
01107   kcbtnBoxColor->setWhatsThis(i18n(
01108         "The line color to use for boxes") );
01109 
01110   readSettings();
01111 }
01112 
01113 KatePrintLayout::~KatePrintLayout()
01114 {
01115   writeSettings();
01116 }
01117 
01118 QString KatePrintLayout::colorScheme()
01119 {
01120   return cmbSchema->currentText();
01121 }
01122 
01123 bool KatePrintLayout::useBackground()
01124 {
01125   return cbDrawBackground->isChecked();
01126 }
01127 
01128 bool KatePrintLayout::useBox()
01129 {
01130   return cbEnableBox->isChecked();
01131 }
01132 
01133 int KatePrintLayout::boxWidth()
01134 {
01135   return sbBoxWidth->value();
01136 }
01137 
01138 int KatePrintLayout::boxMargin()
01139 {
01140   return sbBoxMargin->value();
01141 }
01142 
01143 QColor KatePrintLayout::boxColor()
01144 {
01145   return kcbtnBoxColor->color();
01146 }
01147 
01148 void KatePrintLayout::readSettings()
01149 {
01150   KSharedConfigPtr config = KGlobal::config();
01151   KConfigGroup printGroup(config, "Kate Print Settings");
01152   
01153   KConfigGroup layoutGroup(&printGroup, "Layout");
01154 
01155   QString colorScheme = layoutGroup.readEntry( "ColorScheme", KateGlobal::self()->schemaManager()->name(1) );
01156   cmbSchema->setCurrentItem( colorScheme );
01157 
01158   bool isBackgroundChecked = layoutGroup.readEntry( "BackgroundColorEnabled", false );
01159   cbDrawBackground->setChecked( isBackgroundChecked );
01160 
01161   bool isBoxChecked = layoutGroup.readEntry( "BoxEnabled", false );
01162   cbEnableBox->setChecked( isBoxChecked );
01163 
01164   int boxWidth = layoutGroup.readEntry( "BoxWidth", 1 );
01165   sbBoxWidth->setValue( boxWidth );
01166 
01167   int boxMargin = layoutGroup.readEntry( "BoxMargin", 6 );
01168   sbBoxMargin->setValue( boxMargin );
01169 
01170   QColor boxColor = layoutGroup.readEntry( "BoxColor", QColor() );
01171   kcbtnBoxColor->setColor( boxColor );
01172 }
01173     
01174 void KatePrintLayout::writeSettings()
01175 {
01176   KSharedConfigPtr config = KGlobal::config();
01177   KConfigGroup printGroup(config, "Kate Print Settings");
01178   
01179   KConfigGroup layoutGroup(&printGroup, "Layout");
01180   layoutGroup.writeEntry( "ColorScheme", colorScheme() );
01181   layoutGroup.writeEntry( "BackgroundColorEnabled", useBackground() );
01182   layoutGroup.writeEntry( "BoxEnabled", useBox() );
01183   layoutGroup.writeEntry( "BoxWidth", boxWidth() );
01184   layoutGroup.writeEntry( "BoxMargin", boxMargin() );
01185   layoutGroup.writeEntry( "BoxColor", boxColor() );
01186   
01187   config->sync();
01188 }
01189 
01190 //END KatePrintLayout
01191 
01192 #include "kateprinter.moc"
01193 
01194 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal