10#include "kateprinter.h"
12#include "kateconfig.h"
13#include "katedocument.h"
14#include "kateglobal.h"
17#include <KConfigGroup>
18#include <KSharedConfig>
20#include <QApplication>
23#include <QPrintDialog>
24#include <QPrintPreviewDialog>
27#include "printconfigwidgets.h"
28#include "printpainter.h"
30using namespace KatePrinter;
33class KatePrinterPrivate :
public QObject
39 void setColorScheme(
const QString &scheme);
45 KTextEditor::ViewPrivate *m_view;
47 PrintPainter m_painter;
48 static void readSettings(
QPrinter *printer);
49 static void writeSettings(
QPrinter *printer);
56 , m_painter(m_doc, m_view)
60bool KatePrinterPrivate::print(
QPrinter *printer)
65 KatePrintTextSettings *kpts =
new KatePrintTextSettings;
66 KatePrintHeaderFooter *kphf =
new KatePrintHeaderFooter;
67 KatePrintLayout *kpl =
new KatePrintLayout;
80 readSettings(printer);
83 printDialog->setOptionTabs(tabs);
85 if (m_view && m_view->selection()) {
92 const int dlgCode = printDialog->exec();
98 writeSettings(printer);
101 m_painter.setPrintGuide(kpts->printGuide());
102 m_painter.setPrintLineNumbers(kpts->printLineNumbers());
103 m_painter.setDontPrintFoldedCode(kpts->dontPrintFoldedCode());
105 m_painter.setColorScheme(kpl->colorScheme());
106 m_painter.setTextFont(kpl->textFont());
107 m_painter.setUseBackground(kpl->useBackground());
108 m_painter.setUseBox(kpl->useBox());
109 m_painter.setBoxMargin(kpl->boxMargin());
110 m_painter.setBoxWidth(kpl->boxWidth());
111 m_painter.setBoxColor(kpl->boxColor());
113 m_painter.setHeadersFont(kphf->font());
115 m_painter.setUseHeader(kphf->useHeader());
116 m_painter.setHeaderBackground(kphf->headerBackground());
117 m_painter.setHeaderForeground(kphf->headerForeground());
118 m_painter.setUseHeaderBackground(kphf->useHeaderBackground());
119 m_painter.setHeaderFormat(kphf->headerFormat());
121 m_painter.setUseFooter(kphf->useFooter());
122 m_painter.setFooterBackground(kphf->footerBackground());
123 m_painter.setFooterForeground(kphf->footerForeground());
124 m_painter.setUseFooterBackground(kphf->useFooterBackground());
125 m_painter.setFooterFormat(kphf->footerFormat());
128 m_painter.paint(printer);
133void KatePrinterPrivate::paint(
QPrinter *printer)
135 m_painter.paint(printer);
138void KatePrinterPrivate::setColorScheme(
const QString &scheme)
140 m_painter.setColorScheme(scheme);
143void KatePrinterPrivate::writeSettings(
QPrinter *printer)
146 KConfigGroup group(config, QStringLiteral(
"Kate Print Settings"));
147 KConfigGroup margins(&group, QStringLiteral(
"Margins"));
150 margins.writeEntry(
"left", m.
left());
151 margins.writeEntry(
"top", m.
top());
152 margins.writeEntry(
"right", m.
right());
153 margins.writeEntry(
"bottom", m.
bottom());
156void KatePrinterPrivate::readSettings(
QPrinter *printer)
159 KConfigGroup group(config, QStringLiteral(
"Kate Print Settings"));
160 KConfigGroup margins(&group, QStringLiteral(
"Margins"));
166 left = margins.readEntry(
"left", left);
167 top = margins.readEntry(
"top", top);
168 right = margins.readEntry(
"right", right);
169 bottom = margins.readEntry(
"bottom", bottom);
178bool KatePrinter::print(KTextEditor::ViewPrivate *view)
181 KatePrinterPrivate p(view->doc(), view);
182 return p.print(&printer);
185bool KatePrinter::printPreview(KTextEditor::ViewPrivate *view)
188 KatePrinterPrivate p(view->doc(), view);
189 p.setColorScheme(QStringLiteral(
"Printing"));
192 return preview.exec();
198 KatePrinterPrivate p(doc);
199 return p.print(&printer);
205 KatePrinterPrivate p(doc);
206 p.setColorScheme(QStringLiteral(
"Printing"));
209 return preview.exec();
Backend of KTextEditor::Document related public KTextEditor interfaces.
QString documentName() const override
Get this document's name.
QWidget * widget() override
static KSharedConfigPtr config()
The global configuration of katepart, e.g.
qreal bottom() const const
qreal right() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QPageLayout pageLayout() const const
virtual bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)
QMarginsF margins() const const
void setDocName(const QString &name)
void setPrintRange(PrintRange range)
void paintRequested(QPrinter *printer)
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)