10#include "printconfigwidgets.h"
12#include "kateglobal.h"
13#include "katesyntaxmanager.h"
15#include <KColorButton>
16#include <KConfigGroup>
17#include <KFontRequester>
18#include <KLocalizedString>
19#include <KSharedConfig>
30using namespace KatePrinter;
33KatePrintTextSettings::KatePrintTextSettings(
QWidget *parent)
36 setWindowTitle(
i18n(
"Te&xt Settings"));
40 cbLineNumbers =
new QCheckBox(
i18n(
"Print line &numbers"),
this);
46 cbFolding =
new QCheckBox(
i18n(
"Don't print folded code"),
this);
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>"));
62KatePrintTextSettings::~KatePrintTextSettings()
67bool KatePrintTextSettings::printLineNumbers()
72bool KatePrintTextSettings::printGuide()
77bool KatePrintTextSettings::dontPrintFoldedCode()
const
82void KatePrintTextSettings::readSettings()
85 KConfigGroup printGroup(config, QStringLiteral(
"Printing"));
87 KConfigGroup textGroup(&printGroup, QStringLiteral(
"Text"));
88 bool isLineNumbersChecked = textGroup.readEntry(
"LineNumbers",
false);
89 cbLineNumbers->
setChecked(isLineNumbersChecked);
91 bool isLegendChecked = textGroup.readEntry(
"Legend",
false);
94 cbFolding->
setChecked(textGroup.readEntry(
"DontPrintFoldedCode",
true));
97void KatePrintTextSettings::writeSettings()
100 KConfigGroup printGroup(config, QStringLiteral(
"Printing"));
102 KConfigGroup textGroup(&printGroup, QStringLiteral(
"Text"));
103 textGroup.writeEntry(
"LineNumbers", printLineNumbers());
104 textGroup.writeEntry(
"Legend", printGuide());
105 textGroup.writeEntry(
"DontPrintFoldedCode", dontPrintFoldedCode());
113KatePrintHeaderFooter::KatePrintHeaderFooter(
QWidget *parent)
116 setWindowTitle(
i18n(
"Hea&der && Footer"));
137 gbHeader->setTitle(
i18n(
"Header Properties"));
148 leHeaderLeft =
new QLineEdit(hbHeaderFormat);
150 leHeaderCenter =
new QLineEdit(hbHeaderFormat);
152 leHeaderRight =
new QLineEdit(hbHeaderFormat);
153 lHeaderFormat->
setBuddy(leHeaderLeft);
174 lHeaderFgCol->
setBuddy(kcbtnHeaderFg);
175 cbHeaderEnableBgColor =
new QCheckBox(
i18n(
"Bac&kground"), hbHeaderColors);
176 layoutColors->
addWidget(cbHeaderEnableBgColor);
181 gbFooter->setTitle(
i18n(
"Footer Properties"));
194 leFooterLeft =
new QLineEdit(hbFooterFormat);
196 leFooterCenter =
new QLineEdit(hbFooterFormat);
198 leFooterRight =
new QLineEdit(hbFooterFormat);
200 lFooterFormat->
setBuddy(leFooterLeft);
220 lFooterBgCol->
setBuddy(kcbtnFooterFg);
221 cbFooterEnableBgColor =
new QCheckBox(
i18n(
"&Background"), hbFooterColors);
222 layoutColors->
addWidget(cbFooterEnableBgColor);
235 cbEnableHeader->setChecked(
true);
236 leHeaderLeft->setText(QStringLiteral(
"%y"));
237 leHeaderCenter->setText(QStringLiteral(
"%f"));
238 leHeaderRight->setText(QStringLiteral(
"%p"));
240 cbHeaderEnableBgColor->setChecked(
false);
243 cbEnableFooter->setChecked(
true);
244 leFooterRight->setText(QStringLiteral(
"%U"));
246 cbFooterEnableBgColor->setChecked(
false);
250 QString s =
i18n(
"<p>Format of the page header. The following tags are supported:</p>");
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>"
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);
274KatePrintHeaderFooter::~KatePrintHeaderFooter()
279QFont KatePrintHeaderFooter::font()
281 return lFontPreview->
font();
284bool KatePrintHeaderFooter::useHeader()
292 l << leHeaderLeft->
text() << leHeaderCenter->
text() << leHeaderRight->
text();
296QColor KatePrintHeaderFooter::headerForeground()
298 return kcbtnHeaderFg->
color();
301QColor KatePrintHeaderFooter::headerBackground()
303 return kcbtnHeaderBg->
color();
306bool KatePrintHeaderFooter::useHeaderBackground()
308 return cbHeaderEnableBgColor->
isChecked();
311bool KatePrintHeaderFooter::useFooter()
319 l << leFooterLeft->
text() << leFooterCenter->
text() << leFooterRight->
text();
323QColor KatePrintHeaderFooter::footerForeground()
325 return kcbtnFooterFg->
color();
328QColor KatePrintHeaderFooter::footerBackground()
330 return kcbtnFooterBg->
color();
333bool KatePrintHeaderFooter::useFooterBackground()
335 return cbFooterEnableBgColor->
isChecked();
338void KatePrintHeaderFooter::showContextMenu(
const QPoint &pos)
346 if (contextMenu ==
nullptr) {
379 lineEdit->
insert(placeHolder);
384void KatePrintHeaderFooter::readSettings()
387 KConfigGroup printGroup(config, QStringLiteral(
"Printing"));
390 KConfigGroup headerFooterGroup(&printGroup, QStringLiteral(
"HeaderFooter"));
391 bool isHeaderEnabledChecked = headerFooterGroup.readEntry(
"HeaderEnabled",
true);
392 cbEnableHeader->
setChecked(isHeaderEnabledChecked);
394 QString headerFormatLeft = headerFooterGroup.readEntry(
"HeaderFormatLeft",
"%y");
395 leHeaderLeft->
setText(headerFormatLeft);
397 QString headerFormatCenter = headerFooterGroup.readEntry(
"HeaderFormatCenter",
"%f");
398 leHeaderCenter->
setText(headerFormatCenter);
400 QString headerFormatRight = headerFooterGroup.readEntry(
"HeaderFormatRight",
"%p");
401 leHeaderRight->
setText(headerFormatRight);
403 QColor headerForeground = headerFooterGroup.readEntry(
"HeaderForeground",
QColor(
"black"));
404 kcbtnHeaderFg->
setColor(headerForeground);
406 bool isHeaderBackgroundChecked = headerFooterGroup.readEntry(
"HeaderBackgroundEnabled",
false);
407 cbHeaderEnableBgColor->
setChecked(isHeaderBackgroundChecked);
409 QColor headerBackground = headerFooterGroup.readEntry(
"HeaderBackground",
QColor(
"lightgrey"));
410 kcbtnHeaderBg->
setColor(headerBackground);
413 bool isFooterEnabledChecked = headerFooterGroup.readEntry(
"FooterEnabled",
true);
414 cbEnableFooter->
setChecked(isFooterEnabledChecked);
416 QString footerFormatLeft = headerFooterGroup.readEntry(
"FooterFormatLeft",
QString());
417 leFooterLeft->
setText(footerFormatLeft);
419 QString footerFormatCenter = headerFooterGroup.readEntry(
"FooterFormatCenter",
QString());
420 leFooterCenter->
setText(footerFormatCenter);
422 QString footerFormatRight = headerFooterGroup.readEntry(
"FooterFormatRight",
"%U");
423 leFooterRight->
setText(footerFormatRight);
425 QColor footerForeground = headerFooterGroup.readEntry(
"FooterForeground",
QColor(
"black"));
426 kcbtnFooterFg->
setColor(footerForeground);
428 bool isFooterBackgroundChecked = headerFooterGroup.readEntry(
"FooterBackgroundEnabled",
false);
429 cbFooterEnableBgColor->
setChecked(isFooterBackgroundChecked);
431 QColor footerBackground = headerFooterGroup.readEntry(
"FooterBackground",
QColor(
"lightgrey"));
432 kcbtnFooterBg->
setColor(footerBackground);
437void KatePrintHeaderFooter::writeSettings()
440 KConfigGroup printGroup(config, QStringLiteral(
"Printing"));
443 KConfigGroup headerFooterGroup(&printGroup, QStringLiteral(
"HeaderFooter"));
444 headerFooterGroup.writeEntry(
"HeaderEnabled", useHeader());
447 headerFooterGroup.writeEntry(
"HeaderFormatLeft", format[0]);
448 headerFooterGroup.writeEntry(
"HeaderFormatCenter", format[1]);
449 headerFooterGroup.writeEntry(
"HeaderFormatRight", format[2]);
450 headerFooterGroup.writeEntry(
"HeaderForeground", headerForeground());
451 headerFooterGroup.writeEntry(
"HeaderBackgroundEnabled", useHeaderBackground());
452 headerFooterGroup.writeEntry(
"HeaderBackground", headerBackground());
455 headerFooterGroup.writeEntry(
"FooterEnabled", useFooter());
457 format = footerFormat();
458 headerFooterGroup.writeEntry(
"FooterFormatLeft", format[0]);
459 headerFooterGroup.writeEntry(
"FooterFormatCenter", format[1]);
460 headerFooterGroup.writeEntry(
"FooterFormatRight", format[2]);
461 headerFooterGroup.writeEntry(
"FooterForeground", footerForeground());
462 headerFooterGroup.writeEntry(
"FooterBackgroundEnabled", useFooterBackground());
463 headerFooterGroup.writeEntry(
"FooterBackground", footerBackground());
466 headerFooterGroup.writeEntry(
"HeaderFooterFont", font());
475KatePrintLayout::KatePrintLayout(
QWidget *parent)
478 setWindowTitle(
i18n(
"L&ayout"));
488 cmbSchema->setEditable(
false);
498 cbDrawBackground =
new QCheckBox(
i18n(
"Draw bac&kground color"),
this);
505 gbBoxProps->setTitle(
i18n(
"Box Properties"));
511 sbBoxWidth =
new QSpinBox(gbBoxProps);
512 sbBoxWidth->setRange(1, 100);
513 sbBoxWidth->setSingleStep(1);
519 sbBoxMargin =
new QSpinBox(gbBoxProps);
520 sbBoxMargin->setRange(0, 100);
521 sbBoxMargin->setSingleStep(1);
535 sbBoxMargin->setValue(6);
536 gbBoxProps->setEnabled(
false);
538 const auto themes = KateHlManager::self()->sortedThemes();
539 for (
const auto &theme : themes) {
540 cmbSchema->addItem(theme.translatedName(),
QVariant(theme.name()));
544 cmbSchema->setCurrentIndex(cmbSchema->findData(
QVariant(QStringLiteral(
"Printing"))));
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"));
562KatePrintLayout::~KatePrintLayout()
567QFont KatePrintLayout::textFont()
569 return lFontPreview->
font();
572QString KatePrintLayout::colorScheme()
577bool KatePrintLayout::useBackground()
582bool KatePrintLayout::useBox()
587int KatePrintLayout::boxWidth()
589 return sbBoxWidth->
value();
592int KatePrintLayout::boxMargin()
594 return sbBoxMargin->
value();
597QColor KatePrintLayout::boxColor()
599 return kcbtnBoxColor->
color();
602void KatePrintLayout::readSettings()
605 KConfigGroup printGroup(config, QStringLiteral(
"Printing"));
607 KConfigGroup layoutGroup(&printGroup, QStringLiteral(
"Layout"));
610 QString colorScheme = layoutGroup.readEntry(
"ColorScheme",
"Printing");
619 bool isBackgroundChecked = layoutGroup.readEntry(
"BackgroundColorEnabled",
false);
620 cbDrawBackground->
setChecked(isBackgroundChecked);
622 bool isBoxChecked = layoutGroup.readEntry(
"BoxEnabled",
false);
625 int boxWidth = layoutGroup.readEntry(
"BoxWidth", 1);
628 int boxMargin = layoutGroup.readEntry(
"BoxMargin", 6);
631 QColor boxColor = layoutGroup.readEntry(
"BoxColor",
QColor());
635void KatePrintLayout::writeSettings()
638 KConfigGroup printGroup(config, QStringLiteral(
"Printing"));
640 KConfigGroup layoutGroup(&printGroup, QStringLiteral(
"Layout"));
641 layoutGroup.writeEntry(
"ColorScheme", colorScheme());
642 layoutGroup.writeEntry(
"Font", textFont());
643 layoutGroup.writeEntry(
"BackgroundColorEnabled", useBackground());
644 layoutGroup.writeEntry(
"BoxEnabled", useBox());
645 layoutGroup.writeEntry(
"BoxWidth", boxWidth());
646 layoutGroup.writeEntry(
"BoxMargin", boxMargin());
647 layoutGroup.writeEntry(
"BoxColor", boxColor());
virtual void setFont(const QFont &font, bool onlyFixed=false)
static KSharedConfigPtr config()
The global configuration of katepart, e.g.
static Editor * instance()
Accessor to get the Editor instance.
QFont font() const
Get the current global editor font.
QString i18n(const char *text, const TYPE &arg...)
QVariant data() const const
void setData(const QVariant &data)
void addLayout(QLayout *layout, int stretch)
void addStretch(int stretch)
virtual void setSpacing(int spacing) override
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
QVariant itemData(int index, int role) const const
QIcon fromTheme(const QString &name)
void setBuddy(QWidget *buddy)
QMenu * createStandardContextMenu()
void insert(const QString &newText)
T qobject_cast(QObject *object)
QObject * sender() const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const