1/*
2 SPDX-FileCopyrightText: 2002-2010 Anders Lund <anders@alweb.dk>
3
4 Rewritten based on code of:
5 SPDX-FileCopyrightText: 2002 Michael Goffioul <kdeprint@swing.be>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "printconfigwidgets.h"
11
12#include "kateglobal.h"
13#include "katesyntaxmanager.h"
14
15#include <KColorButton>
16#include <KConfigGroup>
17#include <KFontRequester>
18#include <KLocalizedString>
19#include <KSharedConfig>
20#include <QComboBox>
21
22#include <QBoxLayout>
23#include <QCheckBox>
24#include <QGroupBox>
25#include <QLabel>
26#include <QLineEdit>
27#include <QMenu>
28#include <QSpinBox>
29
30using namespace KatePrinter;
31
32// BEGIN KatePrintTextSettings
33KatePrintTextSettings::KatePrintTextSettings(QWidget *parent)
34 : QWidget(parent)
35{
36 setWindowTitle(i18n("Te&xt Settings"));
37
38 QVBoxLayout *lo = new QVBoxLayout(this);
39
40 cbLineNumbers = new QCheckBox(i18n("Print line &numbers"), this);
41 lo->addWidget(cbLineNumbers);
42
43 cbGuide = new QCheckBox(i18n("Print &legend"), this);
44 lo->addWidget(cbGuide);
45
46 cbFolding = new QCheckBox(i18n("Don't print folded code"), this);
47 lo->addWidget(cbFolding);
48
49 lo->addStretch(stretch: 1);
50
51 // set defaults - nothing to do :-)
52
53 // whatsthis
54 cbLineNumbers->setWhatsThis(i18n("<p>If enabled, line numbers will be printed on the left side of the page(s).</p>"));
55 cbGuide->setWhatsThis(
56 i18n("<p>Print a box displaying typographical conventions for the document type, as "
57 "defined by the syntax highlighting being used.</p>"));
58
59 readSettings();
60}
61
62KatePrintTextSettings::~KatePrintTextSettings()
63{
64 writeSettings();
65}
66
67bool KatePrintTextSettings::printLineNumbers()
68{
69 return cbLineNumbers->isChecked();
70}
71
72bool KatePrintTextSettings::printGuide()
73{
74 return cbGuide->isChecked();
75}
76
77bool KatePrintTextSettings::dontPrintFoldedCode() const
78{
79 return cbFolding->isChecked();
80}
81
82void KatePrintTextSettings::readSettings()
83{
84 KSharedConfigPtr config = KTextEditor::EditorPrivate::config();
85 KConfigGroup printGroup(config, QStringLiteral("Printing"));
86
87 KConfigGroup textGroup(&printGroup, QStringLiteral("Text"));
88 bool isLineNumbersChecked = textGroup.readEntry(key: "LineNumbers", defaultValue: false);
89 cbLineNumbers->setChecked(isLineNumbersChecked);
90
91 bool isLegendChecked = textGroup.readEntry(key: "Legend", defaultValue: false);
92 cbGuide->setChecked(isLegendChecked);
93
94 cbFolding->setChecked(textGroup.readEntry(key: "DontPrintFoldedCode", defaultValue: true));
95}
96
97void KatePrintTextSettings::writeSettings()
98{
99 KSharedConfigPtr config = KTextEditor::EditorPrivate::config();
100 KConfigGroup printGroup(config, QStringLiteral("Printing"));
101
102 KConfigGroup textGroup(&printGroup, QStringLiteral("Text"));
103 textGroup.writeEntry(key: "LineNumbers", value: printLineNumbers());
104 textGroup.writeEntry(key: "Legend", value: printGuide());
105 textGroup.writeEntry(key: "DontPrintFoldedCode", value: dontPrintFoldedCode());
106
107 config->sync();
108}
109
110// END KatePrintTextSettings
111
112// BEGIN KatePrintHeaderFooter
113KatePrintHeaderFooter::KatePrintHeaderFooter(QWidget *parent)
114 : QWidget(parent)
115{
116 setWindowTitle(i18n("Hea&der && Footer"));
117
118 QVBoxLayout *lo = new QVBoxLayout(this);
119
120 // enable
121 QHBoxLayout *lo1 = new QHBoxLayout();
122 lo->addLayout(layout: lo1);
123 cbEnableHeader = new QCheckBox(i18n("Pr&int header"), this);
124 lo1->addWidget(cbEnableHeader);
125 cbEnableFooter = new QCheckBox(i18n("Pri&nt footer"), this);
126 lo1->addWidget(cbEnableFooter);
127
128 // font
129 QHBoxLayout *lo2 = new QHBoxLayout();
130 lo->addLayout(layout: lo2);
131 lo2->addWidget(new QLabel(i18n("Header/footer font:"), this));
132 lFontPreview = new KFontRequester(this);
133 lo2->addWidget(lFontPreview);
134
135 // header
136 gbHeader = new QGroupBox(this);
137 gbHeader->setTitle(i18n("Header Properties"));
138 QGridLayout *grid = new QGridLayout(gbHeader);
139 lo->addWidget(gbHeader);
140
141 QLabel *lHeaderFormat = new QLabel(i18n("&Format:"), gbHeader);
142 grid->addWidget(lHeaderFormat, row: 0, column: 0);
143
144 QFrame *hbHeaderFormat = new QFrame(gbHeader);
145 QHBoxLayout *layoutFormat = new QHBoxLayout(hbHeaderFormat);
146 grid->addWidget(hbHeaderFormat, row: 0, column: 1);
147
148 leHeaderLeft = new QLineEdit(hbHeaderFormat);
149 layoutFormat->addWidget(leHeaderLeft);
150 leHeaderCenter = new QLineEdit(hbHeaderFormat);
151 layoutFormat->addWidget(leHeaderCenter);
152 leHeaderRight = new QLineEdit(hbHeaderFormat);
153 lHeaderFormat->setBuddy(leHeaderLeft);
154 layoutFormat->addWidget(leHeaderRight);
155
156 leHeaderLeft->setContextMenuPolicy(Qt::CustomContextMenu);
157 leHeaderCenter->setContextMenuPolicy(Qt::CustomContextMenu);
158 leHeaderRight->setContextMenuPolicy(Qt::CustomContextMenu);
159 connect(sender: leHeaderLeft, signal: &QLineEdit::customContextMenuRequested, context: this, slot: &KatePrintHeaderFooter::showContextMenu);
160 connect(sender: leHeaderCenter, signal: &QLineEdit::customContextMenuRequested, context: this, slot: &KatePrintHeaderFooter::showContextMenu);
161 connect(sender: leHeaderRight, signal: &QLineEdit::customContextMenuRequested, context: this, slot: &KatePrintHeaderFooter::showContextMenu);
162
163 grid->addWidget(new QLabel(i18n("Colors:"), gbHeader), row: 1, column: 0);
164
165 QFrame *hbHeaderColors = new QFrame(gbHeader);
166 QHBoxLayout *layoutColors = new QHBoxLayout(hbHeaderColors);
167 layoutColors->setSpacing(-1);
168 grid->addWidget(hbHeaderColors, row: 1, column: 1);
169
170 QLabel *lHeaderFgCol = new QLabel(i18n("Foreground:"), hbHeaderColors);
171 layoutColors->addWidget(lHeaderFgCol);
172 kcbtnHeaderFg = new KColorButton(hbHeaderColors);
173 layoutColors->addWidget(kcbtnHeaderFg);
174 lHeaderFgCol->setBuddy(kcbtnHeaderFg);
175 cbHeaderEnableBgColor = new QCheckBox(i18n("Bac&kground"), hbHeaderColors);
176 layoutColors->addWidget(cbHeaderEnableBgColor);
177 kcbtnHeaderBg = new KColorButton(hbHeaderColors);
178 layoutColors->addWidget(kcbtnHeaderBg);
179
180 gbFooter = new QGroupBox(this);
181 gbFooter->setTitle(i18n("Footer Properties"));
182 grid = new QGridLayout(gbFooter);
183 lo->addWidget(gbFooter);
184
185 // footer
186 QLabel *lFooterFormat = new QLabel(i18n("For&mat:"), gbFooter);
187 grid->addWidget(lFooterFormat, row: 0, column: 0);
188
189 QFrame *hbFooterFormat = new QFrame(gbFooter);
190 layoutFormat = new QHBoxLayout(hbFooterFormat);
191 layoutFormat->setSpacing(-1);
192 grid->addWidget(hbFooterFormat, row: 0, column: 1);
193
194 leFooterLeft = new QLineEdit(hbFooterFormat);
195 layoutFormat->addWidget(leFooterLeft);
196 leFooterCenter = new QLineEdit(hbFooterFormat);
197 layoutFormat->addWidget(leFooterCenter);
198 leFooterRight = new QLineEdit(hbFooterFormat);
199 layoutFormat->addWidget(leFooterRight);
200 lFooterFormat->setBuddy(leFooterLeft);
201
202 leFooterLeft->setContextMenuPolicy(Qt::CustomContextMenu);
203 leFooterCenter->setContextMenuPolicy(Qt::CustomContextMenu);
204 leFooterRight->setContextMenuPolicy(Qt::CustomContextMenu);
205 connect(sender: leFooterLeft, signal: &QLineEdit::customContextMenuRequested, context: this, slot: &KatePrintHeaderFooter::showContextMenu);
206 connect(sender: leFooterCenter, signal: &QLineEdit::customContextMenuRequested, context: this, slot: &KatePrintHeaderFooter::showContextMenu);
207 connect(sender: leFooterRight, signal: &QLineEdit::customContextMenuRequested, context: this, slot: &KatePrintHeaderFooter::showContextMenu);
208
209 grid->addWidget(new QLabel(i18n("Colors:"), gbFooter), row: 1, column: 0);
210
211 QFrame *hbFooterColors = new QFrame(gbFooter);
212 layoutColors = new QHBoxLayout(hbFooterColors);
213 layoutColors->setSpacing(-1);
214 grid->addWidget(hbFooterColors, row: 1, column: 1);
215
216 QLabel *lFooterBgCol = new QLabel(i18n("Foreground:"), hbFooterColors);
217 layoutColors->addWidget(lFooterBgCol);
218 kcbtnFooterFg = new KColorButton(hbFooterColors);
219 layoutColors->addWidget(kcbtnFooterFg);
220 lFooterBgCol->setBuddy(kcbtnFooterFg);
221 cbFooterEnableBgColor = new QCheckBox(i18n("&Background"), hbFooterColors);
222 layoutColors->addWidget(cbFooterEnableBgColor);
223 kcbtnFooterBg = new KColorButton(hbFooterColors);
224 layoutColors->addWidget(kcbtnFooterBg);
225
226 lo->addStretch(stretch: 1);
227
228 // user friendly
229 connect(sender: cbEnableHeader, signal: &QCheckBox::toggled, context: gbHeader, slot: &QGroupBox::setEnabled);
230 connect(sender: cbEnableFooter, signal: &QCheckBox::toggled, context: gbFooter, slot: &QGroupBox::setEnabled);
231 connect(sender: cbHeaderEnableBgColor, signal: &QCheckBox::toggled, context: kcbtnHeaderBg, slot: &KColorButton::setEnabled);
232 connect(sender: cbFooterEnableBgColor, signal: &QCheckBox::toggled, context: kcbtnFooterBg, slot: &KColorButton::setEnabled);
233
234 // set defaults
235 cbEnableHeader->setChecked(true);
236 leHeaderLeft->setText(QStringLiteral("%y"));
237 leHeaderCenter->setText(QStringLiteral("%f"));
238 leHeaderRight->setText(QStringLiteral("%p"));
239 kcbtnHeaderFg->setColor(Qt::black);
240 cbHeaderEnableBgColor->setChecked(false);
241 kcbtnHeaderBg->setColor(Qt::lightGray);
242
243 cbEnableFooter->setChecked(true);
244 leFooterRight->setText(QStringLiteral("%U"));
245 kcbtnFooterFg->setColor(Qt::black);
246 cbFooterEnableBgColor->setChecked(false);
247 kcbtnFooterBg->setColor(Qt::lightGray);
248
249 // whatsthis
250 QString s = i18n("<p>Format of the page header. The following tags are supported:</p>");
251 QString s1 = i18n(
252 "<ul><li><tt>%u</tt>: current user name</li>"
253 "<li><tt>%d</tt>: complete date/time in short format</li>"
254 "<li><tt>%D</tt>: complete date/time in long format</li>"
255 "<li><tt>%h</tt>: current time</li>"
256 "<li><tt>%y</tt>: current date in short format</li>"
257 "<li><tt>%Y</tt>: current date in long format</li>"
258 "<li><tt>%f</tt>: file name</li>"
259 "<li><tt>%U</tt>: full URL of the document</li>"
260 "<li><tt>%p</tt>: page number</li>"
261 "<li><tt>%P</tt>: total amount of pages</li>"
262 "</ul><br />");
263 leHeaderRight->setWhatsThis(s + s1);
264 leHeaderCenter->setWhatsThis(s + s1);
265 leHeaderLeft->setWhatsThis(s + s1);
266 s = i18n("<p>Format of the page footer. The following tags are supported:</p>");
267 leFooterRight->setWhatsThis(s + s1);
268 leFooterCenter->setWhatsThis(s + s1);
269 leFooterLeft->setWhatsThis(s + s1);
270
271 readSettings();
272}
273
274KatePrintHeaderFooter::~KatePrintHeaderFooter()
275{
276 writeSettings();
277}
278
279QFont KatePrintHeaderFooter::font()
280{
281 return lFontPreview->font();
282}
283
284bool KatePrintHeaderFooter::useHeader()
285{
286 return cbEnableHeader->isChecked();
287}
288
289QStringList KatePrintHeaderFooter::headerFormat()
290{
291 QStringList l;
292 l << leHeaderLeft->text() << leHeaderCenter->text() << leHeaderRight->text();
293 return l;
294}
295
296QColor KatePrintHeaderFooter::headerForeground()
297{
298 return kcbtnHeaderFg->color();
299}
300
301QColor KatePrintHeaderFooter::headerBackground()
302{
303 return kcbtnHeaderBg->color();
304}
305
306bool KatePrintHeaderFooter::useHeaderBackground()
307{
308 return cbHeaderEnableBgColor->isChecked();
309}
310
311bool KatePrintHeaderFooter::useFooter()
312{
313 return cbEnableFooter->isChecked();
314}
315
316QStringList KatePrintHeaderFooter::footerFormat()
317{
318 QStringList l;
319 l << leFooterLeft->text() << leFooterCenter->text() << leFooterRight->text();
320 return l;
321}
322
323QColor KatePrintHeaderFooter::footerForeground()
324{
325 return kcbtnFooterFg->color();
326}
327
328QColor KatePrintHeaderFooter::footerBackground()
329{
330 return kcbtnFooterBg->color();
331}
332
333bool KatePrintHeaderFooter::useFooterBackground()
334{
335 return cbFooterEnableBgColor->isChecked();
336}
337
338void KatePrintHeaderFooter::showContextMenu(const QPoint &pos)
339{
340 QLineEdit *lineEdit = qobject_cast<QLineEdit *>(object: sender());
341 if (!lineEdit) {
342 return;
343 }
344
345 QMenu *const contextMenu = lineEdit->createStandardContextMenu();
346 if (contextMenu == nullptr) {
347 return;
348 }
349 contextMenu->addSeparator();
350
351 // create original context menu
352 QMenu *menu = contextMenu->addMenu(i18n("Add Placeholder..."));
353 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
354 QAction *a = menu->addAction(i18n("Current User Name") + QLatin1String("\t%u"));
355 a->setData(QLatin1String("%u"));
356 a = menu->addAction(i18n("Complete Date/Time (short format)") + QLatin1String("\t%d"));
357 a->setData(QLatin1String("%d"));
358 a = menu->addAction(i18n("Complete Date/Time (long format)") + QLatin1String("\t%D"));
359 a->setData(QLatin1String("%D"));
360 a = menu->addAction(i18n("Current Time") + QLatin1String("\t%h"));
361 a->setData(QLatin1String("%h"));
362 a = menu->addAction(i18n("Current Date (short format)") + QLatin1String("\t%y"));
363 a->setData(QLatin1String("%y"));
364 a = menu->addAction(i18n("Current Date (long format)") + QLatin1String("\t%Y"));
365 a->setData(QLatin1String("%Y"));
366 a = menu->addAction(i18n("File Name") + QLatin1String("\t%f"));
367 a->setData(QLatin1String("%f"));
368 a = menu->addAction(i18n("Full document URL") + QLatin1String("\t%U"));
369 a->setData(QLatin1String("%U"));
370 a = menu->addAction(i18n("Page Number") + QLatin1String("\t%p"));
371 a->setData(QLatin1String("%p"));
372 a = menu->addAction(i18n("Total Amount of Pages") + QLatin1String("\t%P"));
373 a->setData(QLatin1String("%P"));
374
375 QAction *const result = contextMenu->exec(pos: lineEdit->mapToGlobal(pos));
376 if (result) {
377 QString placeHolder = result->data().toString();
378 if (!placeHolder.isEmpty()) {
379 lineEdit->insert(placeHolder);
380 }
381 }
382}
383
384void KatePrintHeaderFooter::readSettings()
385{
386 KSharedConfigPtr config = KTextEditor::EditorPrivate::config();
387 KConfigGroup printGroup(config, QStringLiteral("Printing"));
388
389 // Header
390 KConfigGroup headerFooterGroup(&printGroup, QStringLiteral("HeaderFooter"));
391 bool isHeaderEnabledChecked = headerFooterGroup.readEntry(key: "HeaderEnabled", defaultValue: true);
392 cbEnableHeader->setChecked(isHeaderEnabledChecked);
393
394 QString headerFormatLeft = headerFooterGroup.readEntry(key: "HeaderFormatLeft", aDefault: "%y");
395 leHeaderLeft->setText(headerFormatLeft);
396
397 QString headerFormatCenter = headerFooterGroup.readEntry(key: "HeaderFormatCenter", aDefault: "%f");
398 leHeaderCenter->setText(headerFormatCenter);
399
400 QString headerFormatRight = headerFooterGroup.readEntry(key: "HeaderFormatRight", aDefault: "%p");
401 leHeaderRight->setText(headerFormatRight);
402
403 QColor headerForeground = headerFooterGroup.readEntry(key: "HeaderForeground", defaultValue: QColor("black"));
404 kcbtnHeaderFg->setColor(headerForeground);
405
406 bool isHeaderBackgroundChecked = headerFooterGroup.readEntry(key: "HeaderBackgroundEnabled", defaultValue: false);
407 cbHeaderEnableBgColor->setChecked(isHeaderBackgroundChecked);
408
409 QColor headerBackground = headerFooterGroup.readEntry(key: "HeaderBackground", defaultValue: QColor("lightgrey"));
410 kcbtnHeaderBg->setColor(headerBackground);
411
412 // Footer
413 bool isFooterEnabledChecked = headerFooterGroup.readEntry(key: "FooterEnabled", defaultValue: true);
414 cbEnableFooter->setChecked(isFooterEnabledChecked);
415
416 QString footerFormatLeft = headerFooterGroup.readEntry(key: "FooterFormatLeft", aDefault: QString());
417 leFooterLeft->setText(footerFormatLeft);
418
419 QString footerFormatCenter = headerFooterGroup.readEntry(key: "FooterFormatCenter", aDefault: QString());
420 leFooterCenter->setText(footerFormatCenter);
421
422 QString footerFormatRight = headerFooterGroup.readEntry(key: "FooterFormatRight", aDefault: "%U");
423 leFooterRight->setText(footerFormatRight);
424
425 QColor footerForeground = headerFooterGroup.readEntry(key: "FooterForeground", defaultValue: QColor("black"));
426 kcbtnFooterFg->setColor(footerForeground);
427
428 bool isFooterBackgroundChecked = headerFooterGroup.readEntry(key: "FooterBackgroundEnabled", defaultValue: false);
429 cbFooterEnableBgColor->setChecked(isFooterBackgroundChecked);
430
431 QColor footerBackground = headerFooterGroup.readEntry(key: "FooterBackground", defaultValue: QColor("lightgrey"));
432 kcbtnFooterBg->setColor(footerBackground);
433
434 lFontPreview->setFont(font: headerFooterGroup.readEntry(key: "HeaderFooterFont", defaultValue: KTextEditor::Editor::instance()->font()));
435}
436
437void KatePrintHeaderFooter::writeSettings()
438{
439 KSharedConfigPtr config = KTextEditor::EditorPrivate::config();
440 KConfigGroup printGroup(config, QStringLiteral("Printing"));
441
442 // Header
443 KConfigGroup headerFooterGroup(&printGroup, QStringLiteral("HeaderFooter"));
444 headerFooterGroup.writeEntry(key: "HeaderEnabled", value: useHeader());
445
446 QStringList format = headerFormat();
447 headerFooterGroup.writeEntry(key: "HeaderFormatLeft", value: format[0]);
448 headerFooterGroup.writeEntry(key: "HeaderFormatCenter", value: format[1]);
449 headerFooterGroup.writeEntry(key: "HeaderFormatRight", value: format[2]);
450 headerFooterGroup.writeEntry(key: "HeaderForeground", value: headerForeground());
451 headerFooterGroup.writeEntry(key: "HeaderBackgroundEnabled", value: useHeaderBackground());
452 headerFooterGroup.writeEntry(key: "HeaderBackground", value: headerBackground());
453
454 // Footer
455 headerFooterGroup.writeEntry(key: "FooterEnabled", value: useFooter());
456
457 format = footerFormat();
458 headerFooterGroup.writeEntry(key: "FooterFormatLeft", value: format[0]);
459 headerFooterGroup.writeEntry(key: "FooterFormatCenter", value: format[1]);
460 headerFooterGroup.writeEntry(key: "FooterFormatRight", value: format[2]);
461 headerFooterGroup.writeEntry(key: "FooterForeground", value: footerForeground());
462 headerFooterGroup.writeEntry(key: "FooterBackgroundEnabled", value: useFooterBackground());
463 headerFooterGroup.writeEntry(key: "FooterBackground", value: footerBackground());
464
465 // Font
466 headerFooterGroup.writeEntry(key: "HeaderFooterFont", value: font());
467
468 config->sync();
469}
470
471// END KatePrintHeaderFooter
472
473// BEGIN KatePrintLayout
474
475KatePrintLayout::KatePrintLayout(QWidget *parent)
476 : QWidget(parent)
477{
478 setWindowTitle(i18n("L&ayout"));
479
480 QVBoxLayout *lo = new QVBoxLayout(this);
481
482 QHBoxLayout *hb = new QHBoxLayout();
483 lo->addLayout(layout: hb);
484 QLabel *lSchema = new QLabel(i18n("&Color theme:"), this);
485 hb->addWidget(lSchema);
486 cmbSchema = new QComboBox(this);
487 hb->addWidget(cmbSchema);
488 cmbSchema->setEditable(false);
489 lSchema->setBuddy(cmbSchema);
490
491 // font
492 QHBoxLayout *lo2 = new QHBoxLayout();
493 lo->addLayout(layout: lo2);
494 lo2->addWidget(new QLabel(i18n("Font:"), this));
495 lFontPreview = new KFontRequester(this);
496 lo2->addWidget(lFontPreview);
497
498 cbDrawBackground = new QCheckBox(i18n("Draw bac&kground color"), this);
499 lo->addWidget(cbDrawBackground);
500
501 cbEnableBox = new QCheckBox(i18n("Draw &boxes"), this);
502 lo->addWidget(cbEnableBox);
503
504 gbBoxProps = new QGroupBox(this);
505 gbBoxProps->setTitle(i18n("Box Properties"));
506 QGridLayout *grid = new QGridLayout(gbBoxProps);
507 lo->addWidget(gbBoxProps);
508
509 QLabel *lBoxWidth = new QLabel(i18n("W&idth:"), gbBoxProps);
510 grid->addWidget(lBoxWidth, row: 0, column: 0);
511 sbBoxWidth = new QSpinBox(gbBoxProps);
512 sbBoxWidth->setRange(min: 1, max: 100);
513 sbBoxWidth->setSingleStep(1);
514 grid->addWidget(sbBoxWidth, row: 0, column: 1);
515 lBoxWidth->setBuddy(sbBoxWidth);
516
517 QLabel *lBoxMargin = new QLabel(i18n("&Margin:"), gbBoxProps);
518 grid->addWidget(lBoxMargin, row: 1, column: 0);
519 sbBoxMargin = new QSpinBox(gbBoxProps);
520 sbBoxMargin->setRange(min: 0, max: 100);
521 sbBoxMargin->setSingleStep(1);
522 grid->addWidget(sbBoxMargin, row: 1, column: 1);
523 lBoxMargin->setBuddy(sbBoxMargin);
524
525 QLabel *lBoxColor = new QLabel(i18n("Co&lor:"), gbBoxProps);
526 grid->addWidget(lBoxColor, row: 2, column: 0);
527 kcbtnBoxColor = new KColorButton(gbBoxProps);
528 grid->addWidget(kcbtnBoxColor, row: 2, column: 1);
529 lBoxColor->setBuddy(kcbtnBoxColor);
530
531 connect(sender: cbEnableBox, signal: &QCheckBox::toggled, context: gbBoxProps, slot: &QGroupBox::setEnabled);
532
533 lo->addStretch(stretch: 1);
534 // set defaults:
535 sbBoxMargin->setValue(6);
536 gbBoxProps->setEnabled(false);
537
538 const auto themes = KateHlManager::self()->sortedThemes();
539 for (const auto &theme : themes) {
540 cmbSchema->addItem(atext: theme.translatedName(), auserData: QVariant(theme.name()));
541 }
542
543 // default is printing, MUST BE THERE
544 cmbSchema->setCurrentIndex(cmbSchema->findData(data: QVariant(QStringLiteral("Printing"))));
545
546 // whatsthis
547 cmbSchema->setWhatsThis(i18n("Select the color theme to use for the print."));
548 cbDrawBackground->setWhatsThis(
549 i18n("<p>If enabled, the background color of the editor will be used.</p>"
550 "<p>This may be useful if your color theme is designed for a dark background.</p>"));
551 cbEnableBox->setWhatsThis(
552 i18n("<p>If enabled, a box as defined in the properties below will be drawn "
553 "around the contents of each page. The Header and Footer will be separated "
554 "from the contents with a line as well.</p>"));
555 sbBoxWidth->setWhatsThis(i18n("The width of the box outline"));
556 sbBoxMargin->setWhatsThis(i18n("The margin inside boxes, in pixels"));
557 kcbtnBoxColor->setWhatsThis(i18n("The line color to use for boxes"));
558
559 readSettings();
560}
561
562KatePrintLayout::~KatePrintLayout()
563{
564 writeSettings();
565}
566
567QFont KatePrintLayout::textFont()
568{
569 return lFontPreview->font();
570}
571
572QString KatePrintLayout::colorScheme()
573{
574 return cmbSchema->itemData(index: cmbSchema->currentIndex()).toString();
575}
576
577bool KatePrintLayout::useBackground()
578{
579 return cbDrawBackground->isChecked();
580}
581
582bool KatePrintLayout::useBox()
583{
584 return cbEnableBox->isChecked();
585}
586
587int KatePrintLayout::boxWidth()
588{
589 return sbBoxWidth->value();
590}
591
592int KatePrintLayout::boxMargin()
593{
594 return sbBoxMargin->value();
595}
596
597QColor KatePrintLayout::boxColor()
598{
599 return kcbtnBoxColor->color();
600}
601
602void KatePrintLayout::readSettings()
603{
604 KSharedConfigPtr config = KTextEditor::EditorPrivate::config();
605 KConfigGroup printGroup(config, QStringLiteral("Printing"));
606
607 KConfigGroup layoutGroup(&printGroup, QStringLiteral("Layout"));
608
609 // get color schema back
610 QString colorScheme = layoutGroup.readEntry(key: "ColorScheme", aDefault: "Printing");
611 int index = cmbSchema->findData(data: QVariant(colorScheme));
612 if (index != -1) {
613 cmbSchema->setCurrentIndex(index);
614 }
615
616 // Font
617 lFontPreview->setFont(font: layoutGroup.readEntry(key: "Font", defaultValue: KTextEditor::Editor::instance()->font()));
618
619 bool isBackgroundChecked = layoutGroup.readEntry(key: "BackgroundColorEnabled", defaultValue: false);
620 cbDrawBackground->setChecked(isBackgroundChecked);
621
622 bool isBoxChecked = layoutGroup.readEntry(key: "BoxEnabled", defaultValue: false);
623 cbEnableBox->setChecked(isBoxChecked);
624
625 int boxWidth = layoutGroup.readEntry(key: "BoxWidth", defaultValue: 1);
626 sbBoxWidth->setValue(boxWidth);
627
628 int boxMargin = layoutGroup.readEntry(key: "BoxMargin", defaultValue: 6);
629 sbBoxMargin->setValue(boxMargin);
630
631 QColor boxColor = layoutGroup.readEntry(key: "BoxColor", defaultValue: QColor());
632 kcbtnBoxColor->setColor(boxColor);
633}
634
635void KatePrintLayout::writeSettings()
636{
637 KSharedConfigPtr config = KTextEditor::EditorPrivate::config();
638 KConfigGroup printGroup(config, QStringLiteral("Printing"));
639
640 KConfigGroup layoutGroup(&printGroup, QStringLiteral("Layout"));
641 layoutGroup.writeEntry(key: "ColorScheme", value: colorScheme());
642 layoutGroup.writeEntry(key: "Font", value: textFont());
643 layoutGroup.writeEntry(key: "BackgroundColorEnabled", value: useBackground());
644 layoutGroup.writeEntry(key: "BoxEnabled", value: useBox());
645 layoutGroup.writeEntry(key: "BoxWidth", value: boxWidth());
646 layoutGroup.writeEntry(key: "BoxMargin", value: boxMargin());
647 layoutGroup.writeEntry(key: "BoxColor", value: boxColor());
648
649 config->sync();
650}
651
652// END KatePrintLayout
653

source code of ktexteditor/src/printing/printconfigwidgets.cpp