File indexing completed on 2024-03-24 04:00:20
0001 /* 0002 SPDX-FileCopyrightText: 2002-2010 Anders Lund <anders@alweb.dk> 0003 0004 Rewritten based on code of: 0005 SPDX-FileCopyrightText: 2002 Michael Goffioul <kdeprint@swing.be> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "printconfigwidgets.h" 0011 0012 #include "kateglobal.h" 0013 #include "katesyntaxmanager.h" 0014 0015 #include <KColorButton> 0016 #include <KConfigGroup> 0017 #include <KFontRequester> 0018 #include <KLocalizedString> 0019 #include <KSharedConfig> 0020 #include <QComboBox> 0021 0022 #include <QBoxLayout> 0023 #include <QCheckBox> 0024 #include <QGroupBox> 0025 #include <QLabel> 0026 #include <QLineEdit> 0027 #include <QMenu> 0028 #include <QSpinBox> 0029 0030 using namespace KatePrinter; 0031 0032 // BEGIN KatePrintTextSettings 0033 KatePrintTextSettings::KatePrintTextSettings(QWidget *parent) 0034 : QWidget(parent) 0035 { 0036 setWindowTitle(i18n("Te&xt Settings")); 0037 0038 QVBoxLayout *lo = new QVBoxLayout(this); 0039 0040 cbLineNumbers = new QCheckBox(i18n("Print line &numbers"), this); 0041 lo->addWidget(cbLineNumbers); 0042 0043 cbGuide = new QCheckBox(i18n("Print &legend"), this); 0044 lo->addWidget(cbGuide); 0045 0046 cbFolding = new QCheckBox(i18n("Don't print folded code"), this); 0047 lo->addWidget(cbFolding); 0048 0049 lo->addStretch(1); 0050 0051 // set defaults - nothing to do :-) 0052 0053 // whatsthis 0054 cbLineNumbers->setWhatsThis(i18n("<p>If enabled, line numbers will be printed on the left side of the page(s).</p>")); 0055 cbGuide->setWhatsThis( 0056 i18n("<p>Print a box displaying typographical conventions for the document type, as " 0057 "defined by the syntax highlighting being used.</p>")); 0058 0059 readSettings(); 0060 } 0061 0062 KatePrintTextSettings::~KatePrintTextSettings() 0063 { 0064 writeSettings(); 0065 } 0066 0067 bool KatePrintTextSettings::printLineNumbers() 0068 { 0069 return cbLineNumbers->isChecked(); 0070 } 0071 0072 bool KatePrintTextSettings::printGuide() 0073 { 0074 return cbGuide->isChecked(); 0075 } 0076 0077 bool KatePrintTextSettings::dontPrintFoldedCode() const 0078 { 0079 return cbFolding->isChecked(); 0080 } 0081 0082 void KatePrintTextSettings::readSettings() 0083 { 0084 KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); 0085 KConfigGroup printGroup(config, QStringLiteral("Printing")); 0086 0087 KConfigGroup textGroup(&printGroup, QStringLiteral("Text")); 0088 bool isLineNumbersChecked = textGroup.readEntry("LineNumbers", false); 0089 cbLineNumbers->setChecked(isLineNumbersChecked); 0090 0091 bool isLegendChecked = textGroup.readEntry("Legend", false); 0092 cbGuide->setChecked(isLegendChecked); 0093 0094 cbFolding->setChecked(textGroup.readEntry("DontPrintFoldedCode", true)); 0095 } 0096 0097 void KatePrintTextSettings::writeSettings() 0098 { 0099 KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); 0100 KConfigGroup printGroup(config, QStringLiteral("Printing")); 0101 0102 KConfigGroup textGroup(&printGroup, QStringLiteral("Text")); 0103 textGroup.writeEntry("LineNumbers", printLineNumbers()); 0104 textGroup.writeEntry("Legend", printGuide()); 0105 textGroup.writeEntry("DontPrintFoldedCode", dontPrintFoldedCode()); 0106 0107 config->sync(); 0108 } 0109 0110 // END KatePrintTextSettings 0111 0112 // BEGIN KatePrintHeaderFooter 0113 KatePrintHeaderFooter::KatePrintHeaderFooter(QWidget *parent) 0114 : QWidget(parent) 0115 { 0116 setWindowTitle(i18n("Hea&der && Footer")); 0117 0118 QVBoxLayout *lo = new QVBoxLayout(this); 0119 0120 // enable 0121 QHBoxLayout *lo1 = new QHBoxLayout(); 0122 lo->addLayout(lo1); 0123 cbEnableHeader = new QCheckBox(i18n("Pr&int header"), this); 0124 lo1->addWidget(cbEnableHeader); 0125 cbEnableFooter = new QCheckBox(i18n("Pri&nt footer"), this); 0126 lo1->addWidget(cbEnableFooter); 0127 0128 // font 0129 QHBoxLayout *lo2 = new QHBoxLayout(); 0130 lo->addLayout(lo2); 0131 lo2->addWidget(new QLabel(i18n("Header/footer font:"), this)); 0132 lFontPreview = new KFontRequester(this); 0133 lo2->addWidget(lFontPreview); 0134 0135 // header 0136 gbHeader = new QGroupBox(this); 0137 gbHeader->setTitle(i18n("Header Properties")); 0138 QGridLayout *grid = new QGridLayout(gbHeader); 0139 lo->addWidget(gbHeader); 0140 0141 QLabel *lHeaderFormat = new QLabel(i18n("&Format:"), gbHeader); 0142 grid->addWidget(lHeaderFormat, 0, 0); 0143 0144 QFrame *hbHeaderFormat = new QFrame(gbHeader); 0145 QHBoxLayout *layoutFormat = new QHBoxLayout(hbHeaderFormat); 0146 grid->addWidget(hbHeaderFormat, 0, 1); 0147 0148 leHeaderLeft = new QLineEdit(hbHeaderFormat); 0149 layoutFormat->addWidget(leHeaderLeft); 0150 leHeaderCenter = new QLineEdit(hbHeaderFormat); 0151 layoutFormat->addWidget(leHeaderCenter); 0152 leHeaderRight = new QLineEdit(hbHeaderFormat); 0153 lHeaderFormat->setBuddy(leHeaderLeft); 0154 layoutFormat->addWidget(leHeaderRight); 0155 0156 leHeaderLeft->setContextMenuPolicy(Qt::CustomContextMenu); 0157 leHeaderCenter->setContextMenuPolicy(Qt::CustomContextMenu); 0158 leHeaderRight->setContextMenuPolicy(Qt::CustomContextMenu); 0159 connect(leHeaderLeft, &QLineEdit::customContextMenuRequested, this, &KatePrintHeaderFooter::showContextMenu); 0160 connect(leHeaderCenter, &QLineEdit::customContextMenuRequested, this, &KatePrintHeaderFooter::showContextMenu); 0161 connect(leHeaderRight, &QLineEdit::customContextMenuRequested, this, &KatePrintHeaderFooter::showContextMenu); 0162 0163 grid->addWidget(new QLabel(i18n("Colors:"), gbHeader), 1, 0); 0164 0165 QFrame *hbHeaderColors = new QFrame(gbHeader); 0166 QHBoxLayout *layoutColors = new QHBoxLayout(hbHeaderColors); 0167 layoutColors->setSpacing(-1); 0168 grid->addWidget(hbHeaderColors, 1, 1); 0169 0170 QLabel *lHeaderFgCol = new QLabel(i18n("Foreground:"), hbHeaderColors); 0171 layoutColors->addWidget(lHeaderFgCol); 0172 kcbtnHeaderFg = new KColorButton(hbHeaderColors); 0173 layoutColors->addWidget(kcbtnHeaderFg); 0174 lHeaderFgCol->setBuddy(kcbtnHeaderFg); 0175 cbHeaderEnableBgColor = new QCheckBox(i18n("Bac&kground"), hbHeaderColors); 0176 layoutColors->addWidget(cbHeaderEnableBgColor); 0177 kcbtnHeaderBg = new KColorButton(hbHeaderColors); 0178 layoutColors->addWidget(kcbtnHeaderBg); 0179 0180 gbFooter = new QGroupBox(this); 0181 gbFooter->setTitle(i18n("Footer Properties")); 0182 grid = new QGridLayout(gbFooter); 0183 lo->addWidget(gbFooter); 0184 0185 // footer 0186 QLabel *lFooterFormat = new QLabel(i18n("For&mat:"), gbFooter); 0187 grid->addWidget(lFooterFormat, 0, 0); 0188 0189 QFrame *hbFooterFormat = new QFrame(gbFooter); 0190 layoutFormat = new QHBoxLayout(hbFooterFormat); 0191 layoutFormat->setSpacing(-1); 0192 grid->addWidget(hbFooterFormat, 0, 1); 0193 0194 leFooterLeft = new QLineEdit(hbFooterFormat); 0195 layoutFormat->addWidget(leFooterLeft); 0196 leFooterCenter = new QLineEdit(hbFooterFormat); 0197 layoutFormat->addWidget(leFooterCenter); 0198 leFooterRight = new QLineEdit(hbFooterFormat); 0199 layoutFormat->addWidget(leFooterRight); 0200 lFooterFormat->setBuddy(leFooterLeft); 0201 0202 leFooterLeft->setContextMenuPolicy(Qt::CustomContextMenu); 0203 leFooterCenter->setContextMenuPolicy(Qt::CustomContextMenu); 0204 leFooterRight->setContextMenuPolicy(Qt::CustomContextMenu); 0205 connect(leFooterLeft, &QLineEdit::customContextMenuRequested, this, &KatePrintHeaderFooter::showContextMenu); 0206 connect(leFooterCenter, &QLineEdit::customContextMenuRequested, this, &KatePrintHeaderFooter::showContextMenu); 0207 connect(leFooterRight, &QLineEdit::customContextMenuRequested, this, &KatePrintHeaderFooter::showContextMenu); 0208 0209 grid->addWidget(new QLabel(i18n("Colors:"), gbFooter), 1, 0); 0210 0211 QFrame *hbFooterColors = new QFrame(gbFooter); 0212 layoutColors = new QHBoxLayout(hbFooterColors); 0213 layoutColors->setSpacing(-1); 0214 grid->addWidget(hbFooterColors, 1, 1); 0215 0216 QLabel *lFooterBgCol = new QLabel(i18n("Foreground:"), hbFooterColors); 0217 layoutColors->addWidget(lFooterBgCol); 0218 kcbtnFooterFg = new KColorButton(hbFooterColors); 0219 layoutColors->addWidget(kcbtnFooterFg); 0220 lFooterBgCol->setBuddy(kcbtnFooterFg); 0221 cbFooterEnableBgColor = new QCheckBox(i18n("&Background"), hbFooterColors); 0222 layoutColors->addWidget(cbFooterEnableBgColor); 0223 kcbtnFooterBg = new KColorButton(hbFooterColors); 0224 layoutColors->addWidget(kcbtnFooterBg); 0225 0226 lo->addStretch(1); 0227 0228 // user friendly 0229 connect(cbEnableHeader, &QCheckBox::toggled, gbHeader, &QGroupBox::setEnabled); 0230 connect(cbEnableFooter, &QCheckBox::toggled, gbFooter, &QGroupBox::setEnabled); 0231 connect(cbHeaderEnableBgColor, &QCheckBox::toggled, kcbtnHeaderBg, &KColorButton::setEnabled); 0232 connect(cbFooterEnableBgColor, &QCheckBox::toggled, kcbtnFooterBg, &KColorButton::setEnabled); 0233 0234 // set defaults 0235 cbEnableHeader->setChecked(true); 0236 leHeaderLeft->setText(QStringLiteral("%y")); 0237 leHeaderCenter->setText(QStringLiteral("%f")); 0238 leHeaderRight->setText(QStringLiteral("%p")); 0239 kcbtnHeaderFg->setColor(Qt::black); 0240 cbHeaderEnableBgColor->setChecked(false); 0241 kcbtnHeaderBg->setColor(Qt::lightGray); 0242 0243 cbEnableFooter->setChecked(true); 0244 leFooterRight->setText(QStringLiteral("%U")); 0245 kcbtnFooterFg->setColor(Qt::black); 0246 cbFooterEnableBgColor->setChecked(false); 0247 kcbtnFooterBg->setColor(Qt::lightGray); 0248 0249 // whatsthis 0250 QString s = i18n("<p>Format of the page header. The following tags are supported:</p>"); 0251 QString s1 = i18n( 0252 "<ul><li><tt>%u</tt>: current user name</li>" 0253 "<li><tt>%d</tt>: complete date/time in short format</li>" 0254 "<li><tt>%D</tt>: complete date/time in long format</li>" 0255 "<li><tt>%h</tt>: current time</li>" 0256 "<li><tt>%y</tt>: current date in short format</li>" 0257 "<li><tt>%Y</tt>: current date in long format</li>" 0258 "<li><tt>%f</tt>: file name</li>" 0259 "<li><tt>%U</tt>: full URL of the document</li>" 0260 "<li><tt>%p</tt>: page number</li>" 0261 "<li><tt>%P</tt>: total amount of pages</li>" 0262 "</ul><br />"); 0263 leHeaderRight->setWhatsThis(s + s1); 0264 leHeaderCenter->setWhatsThis(s + s1); 0265 leHeaderLeft->setWhatsThis(s + s1); 0266 s = i18n("<p>Format of the page footer. The following tags are supported:</p>"); 0267 leFooterRight->setWhatsThis(s + s1); 0268 leFooterCenter->setWhatsThis(s + s1); 0269 leFooterLeft->setWhatsThis(s + s1); 0270 0271 readSettings(); 0272 } 0273 0274 KatePrintHeaderFooter::~KatePrintHeaderFooter() 0275 { 0276 writeSettings(); 0277 } 0278 0279 QFont KatePrintHeaderFooter::font() 0280 { 0281 return lFontPreview->font(); 0282 } 0283 0284 bool KatePrintHeaderFooter::useHeader() 0285 { 0286 return cbEnableHeader->isChecked(); 0287 } 0288 0289 QStringList KatePrintHeaderFooter::headerFormat() 0290 { 0291 QStringList l; 0292 l << leHeaderLeft->text() << leHeaderCenter->text() << leHeaderRight->text(); 0293 return l; 0294 } 0295 0296 QColor KatePrintHeaderFooter::headerForeground() 0297 { 0298 return kcbtnHeaderFg->color(); 0299 } 0300 0301 QColor KatePrintHeaderFooter::headerBackground() 0302 { 0303 return kcbtnHeaderBg->color(); 0304 } 0305 0306 bool KatePrintHeaderFooter::useHeaderBackground() 0307 { 0308 return cbHeaderEnableBgColor->isChecked(); 0309 } 0310 0311 bool KatePrintHeaderFooter::useFooter() 0312 { 0313 return cbEnableFooter->isChecked(); 0314 } 0315 0316 QStringList KatePrintHeaderFooter::footerFormat() 0317 { 0318 QStringList l; 0319 l << leFooterLeft->text() << leFooterCenter->text() << leFooterRight->text(); 0320 return l; 0321 } 0322 0323 QColor KatePrintHeaderFooter::footerForeground() 0324 { 0325 return kcbtnFooterFg->color(); 0326 } 0327 0328 QColor KatePrintHeaderFooter::footerBackground() 0329 { 0330 return kcbtnFooterBg->color(); 0331 } 0332 0333 bool KatePrintHeaderFooter::useFooterBackground() 0334 { 0335 return cbFooterEnableBgColor->isChecked(); 0336 } 0337 0338 void KatePrintHeaderFooter::showContextMenu(const QPoint &pos) 0339 { 0340 QLineEdit *lineEdit = qobject_cast<QLineEdit *>(sender()); 0341 if (!lineEdit) { 0342 return; 0343 } 0344 0345 QMenu *const contextMenu = lineEdit->createStandardContextMenu(); 0346 if (contextMenu == nullptr) { 0347 return; 0348 } 0349 contextMenu->addSeparator(); 0350 0351 // create original context menu 0352 QMenu *menu = contextMenu->addMenu(i18n("Add Placeholder...")); 0353 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); 0354 QAction *a = menu->addAction(i18n("Current User Name") + QLatin1String("\t%u")); 0355 a->setData(QLatin1String("%u")); 0356 a = menu->addAction(i18n("Complete Date/Time (short format)") + QLatin1String("\t%d")); 0357 a->setData(QLatin1String("%d")); 0358 a = menu->addAction(i18n("Complete Date/Time (long format)") + QLatin1String("\t%D")); 0359 a->setData(QLatin1String("%D")); 0360 a = menu->addAction(i18n("Current Time") + QLatin1String("\t%h")); 0361 a->setData(QLatin1String("%h")); 0362 a = menu->addAction(i18n("Current Date (short format)") + QLatin1String("\t%y")); 0363 a->setData(QLatin1String("%y")); 0364 a = menu->addAction(i18n("Current Date (long format)") + QLatin1String("\t%Y")); 0365 a->setData(QLatin1String("%Y")); 0366 a = menu->addAction(i18n("File Name") + QLatin1String("\t%f")); 0367 a->setData(QLatin1String("%f")); 0368 a = menu->addAction(i18n("Full document URL") + QLatin1String("\t%U")); 0369 a->setData(QLatin1String("%U")); 0370 a = menu->addAction(i18n("Page Number") + QLatin1String("\t%p")); 0371 a->setData(QLatin1String("%p")); 0372 a = menu->addAction(i18n("Total Amount of Pages") + QLatin1String("\t%P")); 0373 a->setData(QLatin1String("%P")); 0374 0375 QAction *const result = contextMenu->exec(lineEdit->mapToGlobal(pos)); 0376 if (result) { 0377 QString placeHolder = result->data().toString(); 0378 if (!placeHolder.isEmpty()) { 0379 lineEdit->insert(placeHolder); 0380 } 0381 } 0382 } 0383 0384 void KatePrintHeaderFooter::readSettings() 0385 { 0386 KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); 0387 KConfigGroup printGroup(config, QStringLiteral("Printing")); 0388 0389 // Header 0390 KConfigGroup headerFooterGroup(&printGroup, QStringLiteral("HeaderFooter")); 0391 bool isHeaderEnabledChecked = headerFooterGroup.readEntry("HeaderEnabled", true); 0392 cbEnableHeader->setChecked(isHeaderEnabledChecked); 0393 0394 QString headerFormatLeft = headerFooterGroup.readEntry("HeaderFormatLeft", "%y"); 0395 leHeaderLeft->setText(headerFormatLeft); 0396 0397 QString headerFormatCenter = headerFooterGroup.readEntry("HeaderFormatCenter", "%f"); 0398 leHeaderCenter->setText(headerFormatCenter); 0399 0400 QString headerFormatRight = headerFooterGroup.readEntry("HeaderFormatRight", "%p"); 0401 leHeaderRight->setText(headerFormatRight); 0402 0403 QColor headerForeground = headerFooterGroup.readEntry("HeaderForeground", QColor("black")); 0404 kcbtnHeaderFg->setColor(headerForeground); 0405 0406 bool isHeaderBackgroundChecked = headerFooterGroup.readEntry("HeaderBackgroundEnabled", false); 0407 cbHeaderEnableBgColor->setChecked(isHeaderBackgroundChecked); 0408 0409 QColor headerBackground = headerFooterGroup.readEntry("HeaderBackground", QColor("lightgrey")); 0410 kcbtnHeaderBg->setColor(headerBackground); 0411 0412 // Footer 0413 bool isFooterEnabledChecked = headerFooterGroup.readEntry("FooterEnabled", true); 0414 cbEnableFooter->setChecked(isFooterEnabledChecked); 0415 0416 QString footerFormatLeft = headerFooterGroup.readEntry("FooterFormatLeft", QString()); 0417 leFooterLeft->setText(footerFormatLeft); 0418 0419 QString footerFormatCenter = headerFooterGroup.readEntry("FooterFormatCenter", QString()); 0420 leFooterCenter->setText(footerFormatCenter); 0421 0422 QString footerFormatRight = headerFooterGroup.readEntry("FooterFormatRight", "%U"); 0423 leFooterRight->setText(footerFormatRight); 0424 0425 QColor footerForeground = headerFooterGroup.readEntry("FooterForeground", QColor("black")); 0426 kcbtnFooterFg->setColor(footerForeground); 0427 0428 bool isFooterBackgroundChecked = headerFooterGroup.readEntry("FooterBackgroundEnabled", false); 0429 cbFooterEnableBgColor->setChecked(isFooterBackgroundChecked); 0430 0431 QColor footerBackground = headerFooterGroup.readEntry("FooterBackground", QColor("lightgrey")); 0432 kcbtnFooterBg->setColor(footerBackground); 0433 0434 lFontPreview->setFont(headerFooterGroup.readEntry("HeaderFooterFont", KTextEditor::Editor::instance()->font())); 0435 } 0436 0437 void KatePrintHeaderFooter::writeSettings() 0438 { 0439 KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); 0440 KConfigGroup printGroup(config, QStringLiteral("Printing")); 0441 0442 // Header 0443 KConfigGroup headerFooterGroup(&printGroup, QStringLiteral("HeaderFooter")); 0444 headerFooterGroup.writeEntry("HeaderEnabled", useHeader()); 0445 0446 QStringList format = headerFormat(); 0447 headerFooterGroup.writeEntry("HeaderFormatLeft", format[0]); 0448 headerFooterGroup.writeEntry("HeaderFormatCenter", format[1]); 0449 headerFooterGroup.writeEntry("HeaderFormatRight", format[2]); 0450 headerFooterGroup.writeEntry("HeaderForeground", headerForeground()); 0451 headerFooterGroup.writeEntry("HeaderBackgroundEnabled", useHeaderBackground()); 0452 headerFooterGroup.writeEntry("HeaderBackground", headerBackground()); 0453 0454 // Footer 0455 headerFooterGroup.writeEntry("FooterEnabled", useFooter()); 0456 0457 format = footerFormat(); 0458 headerFooterGroup.writeEntry("FooterFormatLeft", format[0]); 0459 headerFooterGroup.writeEntry("FooterFormatCenter", format[1]); 0460 headerFooterGroup.writeEntry("FooterFormatRight", format[2]); 0461 headerFooterGroup.writeEntry("FooterForeground", footerForeground()); 0462 headerFooterGroup.writeEntry("FooterBackgroundEnabled", useFooterBackground()); 0463 headerFooterGroup.writeEntry("FooterBackground", footerBackground()); 0464 0465 // Font 0466 headerFooterGroup.writeEntry("HeaderFooterFont", font()); 0467 0468 config->sync(); 0469 } 0470 0471 // END KatePrintHeaderFooter 0472 0473 // BEGIN KatePrintLayout 0474 0475 KatePrintLayout::KatePrintLayout(QWidget *parent) 0476 : QWidget(parent) 0477 { 0478 setWindowTitle(i18n("L&ayout")); 0479 0480 QVBoxLayout *lo = new QVBoxLayout(this); 0481 0482 QHBoxLayout *hb = new QHBoxLayout(); 0483 lo->addLayout(hb); 0484 QLabel *lSchema = new QLabel(i18n("&Color theme:"), this); 0485 hb->addWidget(lSchema); 0486 cmbSchema = new QComboBox(this); 0487 hb->addWidget(cmbSchema); 0488 cmbSchema->setEditable(false); 0489 lSchema->setBuddy(cmbSchema); 0490 0491 // font 0492 QHBoxLayout *lo2 = new QHBoxLayout(); 0493 lo->addLayout(lo2); 0494 lo2->addWidget(new QLabel(i18n("Font:"), this)); 0495 lFontPreview = new KFontRequester(this); 0496 lo2->addWidget(lFontPreview); 0497 0498 cbDrawBackground = new QCheckBox(i18n("Draw bac&kground color"), this); 0499 lo->addWidget(cbDrawBackground); 0500 0501 cbEnableBox = new QCheckBox(i18n("Draw &boxes"), this); 0502 lo->addWidget(cbEnableBox); 0503 0504 gbBoxProps = new QGroupBox(this); 0505 gbBoxProps->setTitle(i18n("Box Properties")); 0506 QGridLayout *grid = new QGridLayout(gbBoxProps); 0507 lo->addWidget(gbBoxProps); 0508 0509 QLabel *lBoxWidth = new QLabel(i18n("W&idth:"), gbBoxProps); 0510 grid->addWidget(lBoxWidth, 0, 0); 0511 sbBoxWidth = new QSpinBox(gbBoxProps); 0512 sbBoxWidth->setRange(1, 100); 0513 sbBoxWidth->setSingleStep(1); 0514 grid->addWidget(sbBoxWidth, 0, 1); 0515 lBoxWidth->setBuddy(sbBoxWidth); 0516 0517 QLabel *lBoxMargin = new QLabel(i18n("&Margin:"), gbBoxProps); 0518 grid->addWidget(lBoxMargin, 1, 0); 0519 sbBoxMargin = new QSpinBox(gbBoxProps); 0520 sbBoxMargin->setRange(0, 100); 0521 sbBoxMargin->setSingleStep(1); 0522 grid->addWidget(sbBoxMargin, 1, 1); 0523 lBoxMargin->setBuddy(sbBoxMargin); 0524 0525 QLabel *lBoxColor = new QLabel(i18n("Co&lor:"), gbBoxProps); 0526 grid->addWidget(lBoxColor, 2, 0); 0527 kcbtnBoxColor = new KColorButton(gbBoxProps); 0528 grid->addWidget(kcbtnBoxColor, 2, 1); 0529 lBoxColor->setBuddy(kcbtnBoxColor); 0530 0531 connect(cbEnableBox, &QCheckBox::toggled, gbBoxProps, &QGroupBox::setEnabled); 0532 0533 lo->addStretch(1); 0534 // set defaults: 0535 sbBoxMargin->setValue(6); 0536 gbBoxProps->setEnabled(false); 0537 0538 const auto themes = KateHlManager::self()->sortedThemes(); 0539 for (const auto &theme : themes) { 0540 cmbSchema->addItem(theme.translatedName(), QVariant(theme.name())); 0541 } 0542 0543 // default is printing, MUST BE THERE 0544 cmbSchema->setCurrentIndex(cmbSchema->findData(QVariant(QStringLiteral("Printing")))); 0545 0546 // whatsthis 0547 cmbSchema->setWhatsThis(i18n("Select the color theme to use for the print.")); 0548 cbDrawBackground->setWhatsThis( 0549 i18n("<p>If enabled, the background color of the editor will be used.</p>" 0550 "<p>This may be useful if your color theme is designed for a dark background.</p>")); 0551 cbEnableBox->setWhatsThis( 0552 i18n("<p>If enabled, a box as defined in the properties below will be drawn " 0553 "around the contents of each page. The Header and Footer will be separated " 0554 "from the contents with a line as well.</p>")); 0555 sbBoxWidth->setWhatsThis(i18n("The width of the box outline")); 0556 sbBoxMargin->setWhatsThis(i18n("The margin inside boxes, in pixels")); 0557 kcbtnBoxColor->setWhatsThis(i18n("The line color to use for boxes")); 0558 0559 readSettings(); 0560 } 0561 0562 KatePrintLayout::~KatePrintLayout() 0563 { 0564 writeSettings(); 0565 } 0566 0567 QFont KatePrintLayout::textFont() 0568 { 0569 return lFontPreview->font(); 0570 } 0571 0572 QString KatePrintLayout::colorScheme() 0573 { 0574 return cmbSchema->itemData(cmbSchema->currentIndex()).toString(); 0575 } 0576 0577 bool KatePrintLayout::useBackground() 0578 { 0579 return cbDrawBackground->isChecked(); 0580 } 0581 0582 bool KatePrintLayout::useBox() 0583 { 0584 return cbEnableBox->isChecked(); 0585 } 0586 0587 int KatePrintLayout::boxWidth() 0588 { 0589 return sbBoxWidth->value(); 0590 } 0591 0592 int KatePrintLayout::boxMargin() 0593 { 0594 return sbBoxMargin->value(); 0595 } 0596 0597 QColor KatePrintLayout::boxColor() 0598 { 0599 return kcbtnBoxColor->color(); 0600 } 0601 0602 void KatePrintLayout::readSettings() 0603 { 0604 KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); 0605 KConfigGroup printGroup(config, QStringLiteral("Printing")); 0606 0607 KConfigGroup layoutGroup(&printGroup, QStringLiteral("Layout")); 0608 0609 // get color schema back 0610 QString colorScheme = layoutGroup.readEntry("ColorScheme", "Printing"); 0611 int index = cmbSchema->findData(QVariant(colorScheme)); 0612 if (index != -1) { 0613 cmbSchema->setCurrentIndex(index); 0614 } 0615 0616 // Font 0617 lFontPreview->setFont(layoutGroup.readEntry("Font", KTextEditor::Editor::instance()->font())); 0618 0619 bool isBackgroundChecked = layoutGroup.readEntry("BackgroundColorEnabled", false); 0620 cbDrawBackground->setChecked(isBackgroundChecked); 0621 0622 bool isBoxChecked = layoutGroup.readEntry("BoxEnabled", false); 0623 cbEnableBox->setChecked(isBoxChecked); 0624 0625 int boxWidth = layoutGroup.readEntry("BoxWidth", 1); 0626 sbBoxWidth->setValue(boxWidth); 0627 0628 int boxMargin = layoutGroup.readEntry("BoxMargin", 6); 0629 sbBoxMargin->setValue(boxMargin); 0630 0631 QColor boxColor = layoutGroup.readEntry("BoxColor", QColor()); 0632 kcbtnBoxColor->setColor(boxColor); 0633 } 0634 0635 void KatePrintLayout::writeSettings() 0636 { 0637 KSharedConfigPtr config = KTextEditor::EditorPrivate::config(); 0638 KConfigGroup printGroup(config, QStringLiteral("Printing")); 0639 0640 KConfigGroup layoutGroup(&printGroup, QStringLiteral("Layout")); 0641 layoutGroup.writeEntry("ColorScheme", colorScheme()); 0642 layoutGroup.writeEntry("Font", textFont()); 0643 layoutGroup.writeEntry("BackgroundColorEnabled", useBackground()); 0644 layoutGroup.writeEntry("BoxEnabled", useBox()); 0645 layoutGroup.writeEntry("BoxWidth", boxWidth()); 0646 layoutGroup.writeEntry("BoxMargin", boxMargin()); 0647 layoutGroup.writeEntry("BoxColor", boxColor()); 0648 0649 config->sync(); 0650 } 0651 0652 // END KatePrintLayout