Changeset View
Changeset View
Standalone View
Standalone View
src/printing/kateprinter.cpp
Show All 18 Lines | |||||
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
20 | * Boston, MA 02110-1301, USA. | 20 | * Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "kateprinter.h" | 23 | #include "kateprinter.h" | ||
24 | 24 | | |||
25 | #include "kateconfig.h" | 25 | #include "kateconfig.h" | ||
26 | #include "katedocument.h" | 26 | #include "katedocument.h" | ||
27 | #include "kateglobal.h" | ||||
27 | #include "kateview.h" | 28 | #include "kateview.h" | ||
28 | 29 | | |||
29 | #include <KConfigGroup> | 30 | #include <KConfigGroup> | ||
30 | #include <KSharedConfig> | 31 | #include <KSharedConfig> | ||
31 | 32 | | |||
32 | #include <QApplication> | 33 | #include <QApplication> | ||
33 | #include <QPrinter> | 34 | #include <QPrinter> | ||
34 | #include <QPrintDialog> | 35 | #include <QPrintDialog> | ||
Show All 17 Lines | |||||
52 | 53 | | |||
53 | public Q_SLOTS: | 54 | public Q_SLOTS: | ||
54 | void paint(QPrinter *printer); | 55 | void paint(QPrinter *printer); | ||
55 | 56 | | |||
56 | private: | 57 | private: | ||
57 | KTextEditor::ViewPrivate *m_view; | 58 | KTextEditor::ViewPrivate *m_view; | ||
58 | KTextEditor::DocumentPrivate *m_doc; | 59 | KTextEditor::DocumentPrivate *m_doc; | ||
59 | PrintPainter *m_painter; | 60 | PrintPainter *m_painter; | ||
61 | static void readSettings(QPrinter *printer); | ||||
62 | static void writeSettings(QPrinter *printer); | ||||
60 | }; | 63 | }; | ||
61 | 64 | | |||
62 | KatePrinterPrivate::KatePrinterPrivate(KTextEditor::DocumentPrivate *doc, KTextEditor::ViewPrivate *view) | 65 | KatePrinterPrivate::KatePrinterPrivate(KTextEditor::DocumentPrivate *doc, KTextEditor::ViewPrivate *view) | ||
63 | : QObject() | 66 | : QObject() | ||
64 | , m_view(view) | 67 | , m_view(view) | ||
65 | , m_doc(doc) | 68 | , m_doc(doc) | ||
66 | , m_painter(new PrintPainter(m_doc, m_view)) | 69 | , m_painter(new PrintPainter(m_doc, m_view)) | ||
67 | { | 70 | { | ||
Show All 19 Lines | 79 | { | |||
87 | tabs << kpl; | 90 | tabs << kpl; | ||
88 | 91 | | |||
89 | QWidget *parentWidget = m_doc->widget(); | 92 | QWidget *parentWidget = m_doc->widget(); | ||
90 | 93 | | |||
91 | if (!parentWidget) { | 94 | if (!parentWidget) { | ||
92 | parentWidget = QApplication::activeWindow(); | 95 | parentWidget = QApplication::activeWindow(); | ||
93 | } | 96 | } | ||
94 | 97 | | |||
98 | readSettings(printer); | ||||
99 | | ||||
95 | QPointer<QPrintDialog> printDialog(new QPrintDialog(printer, parentWidget)); | 100 | QPointer<QPrintDialog> printDialog(new QPrintDialog(printer, parentWidget)); | ||
96 | printDialog->setOptionTabs(tabs); | 101 | printDialog->setOptionTabs(tabs); | ||
97 | 102 | | |||
98 | if (m_view && m_view->selection()) { | 103 | if (m_view && m_view->selection()) { | ||
99 | printer->setPrintRange(QPrinter::Selection); | 104 | printer->setPrintRange(QPrinter::Selection); | ||
100 | printDialog->setOption(QAbstractPrintDialog::PrintSelection, true); | 105 | printDialog->setOption(QAbstractPrintDialog::PrintSelection, true); | ||
101 | } | 106 | } | ||
102 | 107 | | |||
103 | printDialog->setOption(QAbstractPrintDialog::PrintPageRange, true); | 108 | printDialog->setOption(QAbstractPrintDialog::PrintPageRange, true); | ||
104 | 109 | | |||
105 | const int dlgCode = printDialog->exec(); | 110 | const int dlgCode = printDialog->exec(); | ||
106 | if (dlgCode != QDialog::Accepted || !printDialog) { | 111 | if (dlgCode != QDialog::Accepted || !printDialog) { | ||
107 | delete printDialog; | 112 | delete printDialog; | ||
108 | return false; | 113 | return false; | ||
109 | } | 114 | } | ||
110 | 115 | | |||
116 | writeSettings(printer); | ||||
117 | | ||||
111 | // configure the painter | 118 | // configure the painter | ||
112 | m_painter->setPrintGuide(kpts->printGuide()); | 119 | m_painter->setPrintGuide(kpts->printGuide()); | ||
113 | m_painter->setPrintLineNumbers(kpts->printLineNumbers()); | 120 | m_painter->setPrintLineNumbers(kpts->printLineNumbers()); | ||
114 | 121 | | |||
115 | m_painter->setColorScheme(kpl->colorScheme()); | 122 | m_painter->setColorScheme(kpl->colorScheme()); | ||
116 | m_painter->setUseBackground(kpl->useBackground()); | 123 | m_painter->setUseBackground(kpl->useBackground()); | ||
117 | m_painter->setUseBox(kpl->useBox()); | 124 | m_painter->setUseBox(kpl->useBox()); | ||
118 | m_painter->setBoxMargin(kpl->boxMargin()); | 125 | m_painter->setBoxMargin(kpl->boxMargin()); | ||
Show All 26 Lines | 151 | { | |||
145 | m_painter->paint(printer); | 152 | m_painter->paint(printer); | ||
146 | } | 153 | } | ||
147 | 154 | | |||
148 | void KatePrinterPrivate::setColorScheme(const QString &scheme) | 155 | void KatePrinterPrivate::setColorScheme(const QString &scheme) | ||
149 | { | 156 | { | ||
150 | m_painter->setColorScheme(scheme); | 157 | m_painter->setColorScheme(scheme); | ||
151 | } | 158 | } | ||
152 | 159 | | |||
160 | void KatePrinterPrivate::writeSettings(QPrinter *printer) | ||||
161 | { | ||||
162 | KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); | ||||
163 | KConfigGroup group(config, QStringLiteral("Kate Print Settings")); | ||||
164 | KConfigGroup margins(&group, QStringLiteral("Margins")); | ||||
165 | | ||||
166 | qreal left, right, top, bottom; | ||||
167 | printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter); | ||||
168 | | ||||
169 | margins.writeEntry( "left", left); | ||||
170 | margins.writeEntry( "top", top); | ||||
171 | margins.writeEntry( "right", right); | ||||
172 | margins.writeEntry( "bottom", bottom); | ||||
173 | } | ||||
174 | | ||||
175 | void KatePrinterPrivate::readSettings(QPrinter *printer) | ||||
176 | { | ||||
177 | KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); | ||||
178 | KConfigGroup group(config, QStringLiteral("Kate Print Settings")); | ||||
179 | KConfigGroup margins(&group, QStringLiteral("Margins")); | ||||
180 | | ||||
181 | qreal left, right, top, bottom; | ||||
182 | printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter); | ||||
183 | | ||||
184 | left = margins.readEntry("left", left); | ||||
185 | top = margins.readEntry("top", top); | ||||
186 | right = margins.readEntry("right", right); | ||||
187 | bottom = margins.readEntry("bottom", bottom); | ||||
188 | | ||||
189 | printer->setPageMargins(left, top, right, bottom, QPrinter::Millimeter); | ||||
190 | } | ||||
191 | | ||||
153 | //END KatePrinterPrivate | 192 | //END KatePrinterPrivate | ||
154 | 193 | | |||
155 | //BEGIN KatePrinter | 194 | //BEGIN KatePrinter | ||
156 | 195 | | |||
157 | bool KatePrinter::print(KTextEditor::ViewPrivate *view) | 196 | bool KatePrinter::print(KTextEditor::ViewPrivate *view) | ||
158 | { | 197 | { | ||
159 | QPrinter printer; | 198 | QPrinter printer; | ||
160 | KatePrinterPrivate p(view->doc(), view); | 199 | KatePrinterPrivate p(view->doc(), view); | ||
Show All 33 Lines |