1/*
2 SPDX-FileCopyrightText: 2007, 2008 Matthew Woehlke <mw_triad@users.sourceforge.net>
3 SPDX-FileCopyrightText: 2003 Christoph Cullmann <cullmann@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "kateconfig.h"
9
10#include "katedocument.h"
11#include "kateglobal.h"
12#include "katepartdebug.h"
13#include "katerenderer.h"
14#include "katesyntaxmanager.h"
15#include "kateview.h"
16
17#include <KConfigGroup>
18
19#include <KEncodingProber>
20#include <QGuiApplication>
21#include <QSettings>
22#include <QStringDecoder>
23#include <QStringEncoder>
24#include <QStringListModel>
25
26#include <Sonnet/GuessLanguage>
27#include <Sonnet/Speller>
28
29// BEGIN KateConfig
30KateConfig::KateConfig(const KateConfig *parent)
31 : m_parent(parent)
32 , m_configKeys(m_parent ? nullptr : new QStringList())
33 , m_configKeyToEntry(m_parent ? nullptr : new QHash<QString, const ConfigEntry *>())
34{
35}
36
37KateConfig::~KateConfig() = default;
38
39void KateConfig::addConfigEntry(ConfigEntry &&entry)
40{
41 // shall only be called for toplevel config
42 Q_ASSERT(isGlobal());
43
44 // There shall be no gaps in the entries; i.e. in KateViewConfig constructor
45 // addConfigEntry() is called on each value from the ConfigEntryTypes enum in
46 // the same order as the enumrators.
47 // we might later want to use a vector
48 // qDebug() << m_configEntries.size() << entry.enumKey;
49 Q_ASSERT(m_configEntries.size() == static_cast<size_t>(entry.enumKey));
50
51 // add new element
52 m_configEntries.emplace(args: entry.enumKey, args&: entry);
53}
54
55void KateConfig::finalizeConfigEntries()
56{
57 // shall only be called for toplevel config
58 Q_ASSERT(isGlobal());
59
60 // compute list of all config keys + register map from key => config entry
61 //
62 // we skip entries without a command name, these config entries are not exposed ATM
63 for (const auto &entry : m_configEntries) {
64 if (!entry.second.commandName.isEmpty()) {
65 Q_ASSERT_X(!m_configKeys->contains(entry.second.commandName),
66 "finalizeConfigEntries",
67 (QLatin1String("KEY NOT UNIQUE: ") + entry.second.commandName).toLocal8Bit().constData());
68 m_configKeys->append(t: entry.second.commandName);
69 m_configKeyToEntry->insert(key: entry.second.commandName, value: &entry.second);
70 }
71 }
72}
73
74void KateConfig::readConfigEntries(const KConfigGroup &config)
75{
76 configStart();
77
78 // read all config entries, even the ones ATM not set in this config object but known in the toplevel one
79 for (const auto &entry : fullConfigEntries()) {
80 setValue(key: entry.second.enumKey, value: config.readEntry(key: entry.second.configKey, aDefault: entry.second.defaultValue));
81 }
82
83 configEnd();
84}
85
86void KateConfig::writeConfigEntries(KConfigGroup &config) const
87{
88 // write all config entries, even the ones ATM not set in this config object but known in the toplevel one
89 for (const auto &entry : fullConfigEntries()) {
90 config.writeEntry(key: entry.second.configKey, value: value(key: entry.second.enumKey));
91 }
92}
93
94void KateConfig::configStart()
95{
96 configSessionNumber++;
97
98 if (configSessionNumber > 1) {
99 return;
100 }
101}
102
103void KateConfig::configEnd()
104{
105 if (configSessionNumber == 0) {
106 return;
107 }
108
109 configSessionNumber--;
110
111 if (configSessionNumber > 0) {
112 return;
113 }
114
115 updateConfig();
116}
117
118QVariant KateConfig::value(const int key) const
119{
120 // first: local lookup
121 const auto it = m_configEntries.find(x: key);
122 if (it != m_configEntries.end()) {
123 return it->second.value;
124 }
125
126 // else: fallback to parent config, if any
127 if (m_parent) {
128 return m_parent->value(key);
129 }
130
131 // if we arrive here, the key was invalid! => programming error
132 // for release builds, we just return invalid variant
133 Q_ASSERT(false);
134 return QVariant();
135}
136
137bool KateConfig::setValue(const int key, const QVariant &value)
138{
139 // check: is this key known at all?
140 const auto &knownEntries = fullConfigEntries();
141 const auto knownIt = knownEntries.find(x: key);
142 if (knownIt == knownEntries.end()) {
143 // if we arrive here, the key was invalid! => programming error
144 // for release builds, we just fail to set the value
145 Q_ASSERT(false);
146 return false;
147 }
148
149 // validator set? use it, if not accepting, abort setting
150 if (knownIt->second.validator && !knownIt->second.validator(value)) {
151 return false;
152 }
153
154 // check if value already there for this config
155 auto valueIt = m_configEntries.find(x: key);
156 if (valueIt != m_configEntries.end()) {
157 // skip any work if value is equal
158 if (valueIt->second.value == value) {
159 return true;
160 }
161
162 // else: alter value and be done
163 configStart();
164 valueIt->second.value = value;
165 configEnd();
166 return true;
167 }
168
169 // if not in this hash, we must copy the known entry and adjust the value
170 configStart();
171 auto res = m_configEntries.emplace(args: key, args: knownIt->second);
172 res.first->second.value = value;
173 configEnd();
174 return true;
175}
176
177QVariant KateConfig::value(const QString &key) const
178{
179 // check if we know this key, if not, return invalid variant
180 const auto &knownEntries = fullConfigKeyToEntry();
181 const auto it = knownEntries.find(key);
182 if (it == knownEntries.end()) {
183 return QVariant();
184 }
185
186 // key known, dispatch to normal value() function with enum
187 return value(key: it.value()->enumKey);
188}
189
190bool KateConfig::setValue(const QString &key, const QVariant &value)
191{
192 // check if we know this key, if not, ignore the set
193 const auto &knownEntries = fullConfigKeyToEntry();
194 const auto it = knownEntries.find(key);
195 if (it == knownEntries.end()) {
196 return false;
197 }
198
199 // key known, dispatch to normal setValue() function with enum
200 return setValue(key: it.value()->enumKey, value);
201}
202
203// END
204
205// BEGIN HelperFunctions
206KateGlobalConfig *KateGlobalConfig::s_global = nullptr;
207KateDocumentConfig *KateDocumentConfig::s_global = nullptr;
208KateViewConfig *KateViewConfig::s_global = nullptr;
209KateRendererConfig *KateRendererConfig::s_global = nullptr;
210
211/**
212 * validate if an encoding is ok
213 * @param name encoding name
214 * @return encoding ok?
215 */
216static bool isEncodingOk(const QString &name)
217{
218 return QStringDecoder(name.toUtf8().constData()).isValid() && QStringEncoder(name.toUtf8().constData()).isValid();
219}
220
221static bool inBounds(const int min, const QVariant &value, const int max)
222{
223 const int val = value.toInt();
224 return (val >= min) && (val <= max);
225}
226
227static bool isPositive(const QVariant &value)
228{
229 bool ok;
230 value.toUInt(ok: &ok);
231 return ok;
232}
233// END
234
235// BEGIN KateGlobalConfig
236KateGlobalConfig::KateGlobalConfig()
237{
238 // register this as our global instance
239 Q_ASSERT(isGlobal());
240 s_global = this;
241
242 // avoid updateConfig effects like config write in constructor, see bug 377067
243 Q_ASSERT(configSessionNumber == 0);
244 ++configSessionNumber;
245
246 // init all known config entries
247 addConfigEntry(entry: ConfigEntry(EncodingProberType, "Encoding Prober Type", QString(), KEncodingProber::Universal));
248 addConfigEntry(entry: ConfigEntry(FallbackEncoding,
249 "Fallback Encoding",
250 QString(),
251 QString::fromUtf8(utf8: QStringConverter::nameForEncoding(e: QStringConverter::Latin1)),
252 [](const QVariant &value) {
253 return isEncodingOk(name: value.toString());
254 }));
255
256 // finalize the entries, e.g. hashs them
257 finalizeConfigEntries();
258
259 // init with defaults from config or really hardcoded ones
260 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Editor"));
261 readConfig(config: cg);
262
263 // avoid updateConfig effects like config write in constructor, see bug 377067
264 Q_ASSERT(configSessionNumber == 1);
265 --configSessionNumber;
266}
267
268void KateGlobalConfig::readConfig(const KConfigGroup &config)
269{
270 // start config update group
271 configStart();
272
273 // read generic entries
274 readConfigEntries(config);
275
276 // end config update group, might trigger updateConfig()
277 configEnd();
278}
279
280void KateGlobalConfig::writeConfig(KConfigGroup &config)
281{
282 // write generic entries
283 writeConfigEntries(config);
284}
285
286void KateGlobalConfig::updateConfig()
287{
288 // write config
289 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Editor"));
290 writeConfig(config&: cg);
291 KTextEditor::EditorPrivate::config()->sync();
292
293 // trigger emission of KTextEditor::Editor::configChanged
294 KTextEditor::EditorPrivate::self()->triggerConfigChanged();
295}
296// END
297
298// BEGIN KateDocumentConfig
299KateDocumentConfig::KateDocumentConfig()
300{
301 // register this as our global instance
302 Q_ASSERT(isGlobal());
303 s_global = this;
304
305 // avoid updateConfig effects like config write in constructor, see bug 377067
306 Q_ASSERT(configSessionNumber == 0);
307 ++configSessionNumber;
308
309 // init all known config entries
310 addConfigEntry(entry: ConfigEntry(TabWidth, "Tab Width", QStringLiteral("tab-width"), 4, [](const QVariant &value) {
311 return value.toInt() >= 1;
312 }));
313 addConfigEntry(entry: ConfigEntry(IndentationWidth, "Indentation Width", QStringLiteral("indent-width"), 4, [](const QVariant &value) {
314 return value.toInt() >= 1;
315 }));
316 addConfigEntry(entry: ConfigEntry(OnTheFlySpellCheck, "On-The-Fly Spellcheck", QStringLiteral("on-the-fly-spellcheck"), false));
317 addConfigEntry(entry: ConfigEntry(IndentOnTextPaste, "Indent On Text Paste", QStringLiteral("indent-pasted-text"), true));
318 addConfigEntry(entry: ConfigEntry(ReplaceTabsWithSpaces, "ReplaceTabsDyn", QStringLiteral("replace-tabs"), true));
319 addConfigEntry(entry: ConfigEntry(BackupOnSaveLocal, "Backup Local", QStringLiteral("backup-on-save-local"), false));
320 addConfigEntry(entry: ConfigEntry(BackupOnSaveRemote, "Backup Remote", QStringLiteral("backup-on-save-remote"), false));
321 addConfigEntry(entry: ConfigEntry(BackupOnSavePrefix, "Backup Prefix", QStringLiteral("backup-on-save-prefix"), QString()));
322 addConfigEntry(entry: ConfigEntry(BackupOnSaveSuffix, "Backup Suffix", QStringLiteral("backup-on-save-suffix"), QStringLiteral("~")));
323 addConfigEntry(entry: ConfigEntry(IndentationMode, "Indentation Mode", QString(), QStringLiteral("normal")));
324 addConfigEntry(entry: ConfigEntry(TabHandlingMode, "Tab Handling", QString(), KateDocumentConfig::tabSmart));
325 addConfigEntry(entry: ConfigEntry(StaticWordWrap, "Word Wrap", QString(), false));
326 addConfigEntry(entry: ConfigEntry(StaticWordWrapColumn, "Word Wrap Column", QString(), 80, [](const QVariant &value) {
327 return value.toInt() >= 1;
328 }));
329 addConfigEntry(entry: ConfigEntry(PageUpDownMovesCursor, "PageUp/PageDown Moves Cursor", QString(), false));
330 addConfigEntry(entry: ConfigEntry(SmartHome, "Smart Home", QString(), true));
331 addConfigEntry(entry: ConfigEntry(ShowTabs, "Show Tabs", QString(), true));
332 addConfigEntry(entry: ConfigEntry(IndentOnTab, "Indent On Tab", QString(), true));
333 addConfigEntry(entry: ConfigEntry(KeepExtraSpaces, "Keep Extra Spaces", QString(), false));
334 addConfigEntry(entry: ConfigEntry(BackspaceIndents, "Indent On Backspace", QString(), true));
335 addConfigEntry(entry: ConfigEntry(ShowSpacesMode, "Show Spaces", QString(), KateDocumentConfig::None));
336 addConfigEntry(entry: ConfigEntry(TrailingMarkerSize, "Trailing Marker Size", QString(), 1));
337 addConfigEntry(entry: ConfigEntry(RemoveSpacesMode, "Remove Spaces", QString(), 1 /* on modified lines per default */, [](const QVariant &value) {
338 return inBounds(min: 0, value, max: 2);
339 }));
340 addConfigEntry(entry: ConfigEntry(NewlineAtEOF, "Newline at End of File", QString(), true));
341 addConfigEntry(entry: ConfigEntry(OverwriteMode, "Overwrite Mode", QString(), false));
342 addConfigEntry(
343 entry: ConfigEntry(Encoding, "Encoding", QString(), QString::fromUtf8(utf8: QStringConverter::nameForEncoding(e: QStringConverter::Utf8)), [](const QVariant &value) {
344 return isEncodingOk(name: value.toString());
345 }));
346 addConfigEntry(entry: ConfigEntry(EndOfLine, "End of Line", QString(), 0));
347 addConfigEntry(entry: ConfigEntry(AllowEndOfLineDetection, "Allow End of Line Detection", QString(), true));
348 addConfigEntry(entry: ConfigEntry(ByteOrderMark, "BOM", QString(), false));
349 addConfigEntry(entry: ConfigEntry(SwapFile, "Swap File Mode", QString(), KateDocumentConfig::EnableSwapFile));
350 addConfigEntry(entry: ConfigEntry(SwapFileDirectory, "Swap Directory", QString(), QString()));
351 addConfigEntry(entry: ConfigEntry(SwapFileSyncInterval, "Swap Sync Interval", QString(), 15));
352 addConfigEntry(entry: ConfigEntry(LineLengthLimit, "Line Length Limit", QString(), 10000));
353 addConfigEntry(entry: ConfigEntry(CamelCursor, "Camel Cursor", QString(), true));
354 addConfigEntry(entry: ConfigEntry(AutoDetectIndent, "Auto Detect Indent", QString(), true));
355
356 // Auto save and co.
357 addConfigEntry(entry: ConfigEntry(AutoSave, "Auto Save", QString(), false));
358 addConfigEntry(entry: ConfigEntry(AutoSaveOnFocusOut, "Auto Save On Focus Out", QString(), false));
359 addConfigEntry(entry: ConfigEntry(AutoSaveInteral, "Auto Save Interval", QString(), 0));
360
361 // Shall we do auto reloading for stuff e.g. in Git?
362 addConfigEntry(entry: ConfigEntry(AutoReloadIfStateIsInVersionControl, "Auto Reload If State Is In Version Control", QString(), true));
363
364 // finalize the entries, e.g. hashs them
365 finalizeConfigEntries();
366
367 // init with defaults from config or really hardcoded ones
368 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Document"));
369 readConfig(config: cg);
370
371 // avoid updateConfig effects like config write in constructor, see bug 377067
372 Q_ASSERT(configSessionNumber == 1);
373 --configSessionNumber;
374}
375
376KateDocumentConfig::KateDocumentConfig(KTextEditor::DocumentPrivate *doc)
377 : KateConfig(s_global)
378 , m_doc(doc)
379{
380 // per document config doesn't read stuff per default
381}
382
383void KateDocumentConfig::readConfig(const KConfigGroup &config)
384{
385 // start config update group
386 configStart();
387
388 // read generic entries
389 readConfigEntries(config);
390
391 // fixup sonnet config, see KateSpellCheckConfigTab::apply(), too
392 // WARNING: this is slightly hackish, but it's currently the only way to
393 // do it, see also the KTextEdit class
394 if (isGlobal()) {
395 const QSettings settings(QStringLiteral("KDE"), QStringLiteral("Sonnet"));
396 const bool onTheFlyChecking = settings.value(QStringLiteral("checkerEnabledByDefault"), defaultValue: false).toBool();
397 setOnTheFlySpellCheck(onTheFlyChecking);
398
399 // ensure we load the default dictionary speller + trigrams early
400 // this avoids hangs for auto-spellchecking on first edits
401 // do this if we have on the fly spellchecking on only
402 if (onTheFlyChecking) {
403 Sonnet::Speller speller;
404 speller.setLanguage(Sonnet::Speller().defaultLanguage());
405 Sonnet::GuessLanguage languageGuesser;
406 languageGuesser.identify(QStringLiteral("dummy to trigger identify"));
407 }
408 }
409
410 // backwards compatibility mappings
411 // convert stuff, old entries deleted in writeConfig
412 if (const int backupFlags = config.readEntry(key: "Backup Flags", defaultValue: 0)) {
413 setBackupOnSaveLocal(backupFlags & 0x1);
414 setBackupOnSaveRemote(backupFlags & 0x2);
415 }
416
417 // end config update group, might trigger updateConfig()
418 configEnd();
419}
420
421void KateDocumentConfig::writeConfig(KConfigGroup &config)
422{
423 // write generic entries
424 writeConfigEntries(config);
425
426 // backwards compatibility mappings
427 // here we remove old entries we converted on readConfig
428 config.deleteEntry(key: "Backup Flags");
429}
430
431void KateDocumentConfig::updateConfig()
432{
433 if (m_doc) {
434 m_doc->updateConfig();
435 return;
436 }
437
438 if (isGlobal()) {
439 const auto docs = KTextEditor::EditorPrivate::self()->documents();
440 for (auto doc : docs) {
441 static_cast<KTextEditor::DocumentPrivate *>(doc)->updateConfig();
442 }
443
444 // write config
445 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Document"));
446 writeConfig(config&: cg);
447 KTextEditor::EditorPrivate::config()->sync();
448
449 // trigger emission of KTextEditor::Editor::configChanged
450 KTextEditor::EditorPrivate::self()->triggerConfigChanged();
451 }
452}
453
454QString KateDocumentConfig::eolString() const
455{
456 switch (eol()) {
457 case KateDocumentConfig::eolDos:
458 return QStringLiteral("\r\n");
459
460 case KateDocumentConfig::eolMac:
461 return QStringLiteral("\r");
462
463 default:
464 return QStringLiteral("\n");
465 }
466}
467// END
468
469// BEGIN KateViewConfig
470KateViewConfig::KateViewConfig()
471{
472 // register this as our global instance
473 Q_ASSERT(isGlobal());
474 s_global = this;
475
476 // avoid updateConfig effects like config write in constructor, see bug 377067
477 Q_ASSERT(configSessionNumber == 0);
478 ++configSessionNumber;
479
480 // Init all known config entries
481 // NOTE: Ensure to keep the same order as listed in enum ConfigEntryTypes or it will later assert!
482 // addConfigEntry(ConfigEntry(<EnumKey>, <ConfigKey>, <CommandName>, <DefaultValue>, [<ValidatorFunction>]))
483 addConfigEntry(entry: ConfigEntry(AllowMarkMenu, "Allow Mark Menu", QStringLiteral("allow-mark-menu"), true));
484 addConfigEntry(entry: ConfigEntry(AutoBrackets, "Auto Brackets", QStringLiteral("auto-brackets"), true));
485 addConfigEntry(entry: ConfigEntry(AutoCenterLines, "Auto Center Lines", QStringLiteral("auto-center-lines"), 0));
486 addConfigEntry(entry: ConfigEntry(AutomaticCompletionInvocation, "Auto Completion", QString(), true));
487 addConfigEntry(entry: ConfigEntry(AutomaticCompletionPreselectFirst, "Auto Completion Preselect First Entry", QString(), true));
488 addConfigEntry(entry: ConfigEntry(BackspaceRemoveComposedCharacters, "Backspace Remove Composed Characters", QString(), false));
489 addConfigEntry(entry: ConfigEntry(BookmarkSorting, "Bookmark Menu Sorting", QString(), 0));
490 addConfigEntry(entry: ConfigEntry(CharsToEncloseSelection, "Chars To Enclose Selection", QStringLiteral("enclose-selection"), QStringLiteral("<>(){}[]'\"")));
491 addConfigEntry(entry: ConfigEntry(ClipboardHistoryEntries, "Max Clipboard History Entries", QString(), 20, [](const QVariant &value) {
492 return inBounds(min: 1, value, max: 999);
493 }));
494 addConfigEntry(
495 entry: ConfigEntry(DefaultMarkType, "Default Mark Type", QStringLiteral("default-mark-type"), KTextEditor::Document::markType01, [](const QVariant &value) {
496 return isPositive(value);
497 }));
498 addConfigEntry(entry: ConfigEntry(DynWordWrapAlignIndent, "Dynamic Word Wrap Align Indent", QString(), 80, [](const QVariant &value) {
499 return inBounds(min: 0, value, max: 100);
500 }));
501 addConfigEntry(entry: ConfigEntry(DynWordWrapIndicators, "Dynamic Word Wrap Indicators", QString(), 1, [](const QVariant &value) {
502 return inBounds(min: 0, value, max: 2);
503 }));
504 addConfigEntry(entry: ConfigEntry(DynWrapAnywhere, "Dynamic Wrap not at word boundaries", QStringLiteral("dynamic-word-wrap-anywhere"), false));
505 addConfigEntry(entry: ConfigEntry(DynWrapAtStaticMarker, "Dynamic Word Wrap At Static Marker", QString(), false));
506 addConfigEntry(entry: ConfigEntry(DynamicWordWrap, "Dynamic Word Wrap", QStringLiteral("dynamic-word-wrap"), true));
507 addConfigEntry(entry: ConfigEntry(EnterToInsertCompletion, "Enter To Insert Completion", QStringLiteral("enter-to-insert-completion"), true));
508 addConfigEntry(entry: ConfigEntry(FoldFirstLine, "Fold First Line", QString(), false));
509 addConfigEntry(entry: ConfigEntry(InputMode, "Input Mode", QString(), 0, [](const QVariant &value) {
510 return isPositive(value);
511 }));
512 addConfigEntry(entry: ConfigEntry(KeywordCompletion, "Keyword Completion", QStringLiteral("keyword-completion"), true));
513 addConfigEntry(entry: ConfigEntry(MaxHistorySize, "Maximum Search History Size", QString(), 100, [](const QVariant &value) {
514 return inBounds(min: 0, value, max: 999);
515 }));
516 addConfigEntry(entry: ConfigEntry(MousePasteAtCursorPosition, "Mouse Paste At Cursor Position", QString(), false));
517 addConfigEntry(entry: ConfigEntry(PersistentSelection, "Persistent Selection", QStringLiteral("persistent-selectionq"), false));
518 addConfigEntry(entry: ConfigEntry(ScrollBarMiniMapWidth, "Scroll Bar Mini Map Width", QString(), 60, [](const QVariant &value) {
519 return inBounds(min: 0, value, max: 999);
520 }));
521 addConfigEntry(entry: ConfigEntry(ScrollPastEnd, "Scroll Past End", QString(), false));
522 addConfigEntry(entry: ConfigEntry(SearchFlags, "Search/Replace Flags", QString(), IncFromCursor | PowerMatchCase | PowerModePlainText));
523 addConfigEntry(entry: ConfigEntry(TabCompletion, "Enable Tab completion", QString(), false));
524 addConfigEntry(entry: ConfigEntry(ShowBracketMatchPreview, "Bracket Match Preview", QStringLiteral("bracket-match-preview"), false));
525 addConfigEntry(entry: ConfigEntry(ShowFoldingBar, "Folding Bar", QStringLiteral("folding-bar"), true));
526 addConfigEntry(entry: ConfigEntry(ShowFoldingPreview, "Folding Preview", QStringLiteral("folding-preview"), true));
527 addConfigEntry(entry: ConfigEntry(ShowIconBar, "Icon Bar", QStringLiteral("icon-bar"), false));
528 addConfigEntry(entry: ConfigEntry(ShowLineCount, "Show Line Count", QString(), false));
529 addConfigEntry(entry: ConfigEntry(ShowLineModification, "Line Modification", QStringLiteral("modification-markers"), true));
530 addConfigEntry(entry: ConfigEntry(ShowLineNumbers, "Line Numbers", QStringLiteral("line-numbers"), true));
531 addConfigEntry(entry: ConfigEntry(ShowScrollBarMarks, "Scroll Bar Marks", QString(), false));
532 addConfigEntry(entry: ConfigEntry(ShowScrollBarMiniMap, "Scroll Bar MiniMap", QStringLiteral("scrollbar-minimap"), true));
533 addConfigEntry(entry: ConfigEntry(ShowScrollBarMiniMapAll, "Scroll Bar Mini Map All", QString(), true));
534 addConfigEntry(entry: ConfigEntry(ShowScrollBarPreview, "Scroll Bar Preview", QStringLiteral("scrollbar-preview"), true));
535 addConfigEntry(entry: ConfigEntry(ShowScrollbars, "Show Scrollbars", QString(), AlwaysOn, [](const QVariant &value) {
536 return inBounds(min: 0, value, max: 2);
537 }));
538 addConfigEntry(entry: ConfigEntry(ShowWordCount, "Show Word Count", QString(), false));
539 addConfigEntry(entry: ConfigEntry(TextDragAndDrop, "Text Drag And Drop", QString(), true));
540 addConfigEntry(entry: ConfigEntry(SmartCopyCut, "Smart Copy Cut", QString(), true));
541 addConfigEntry(entry: ConfigEntry(UserSetsOfCharsToEncloseSelection, "User Sets Of Chars To Enclose Selection", QString(), QStringList()));
542 addConfigEntry(entry: ConfigEntry(ViInputModeStealKeys, "Vi Input Mode Steal Keys", QString(), false));
543 addConfigEntry(entry: ConfigEntry(ViRelativeLineNumbers, "Vi Relative Line Numbers", QString(), false));
544 addConfigEntry(entry: ConfigEntry(WordCompletion, "Word Completion", QString(), true));
545 addConfigEntry(entry: ConfigEntry(WordCompletionMinimalWordLength,
546 "Word Completion Minimal Word Length",
547 QStringLiteral("word-completion-minimal-word-length"),
548 3,
549 [](const QVariant &value) {
550 return inBounds(min: 0, value, max: 99);
551 }));
552 addConfigEntry(entry: ConfigEntry(WordCompletionRemoveTail, "Word Completion Remove Tail", QString(), true));
553 addConfigEntry(entry: ConfigEntry(ShowDocWithCompletion, "Show Documentation With Completion", QString(), true));
554 addConfigEntry(entry: ConfigEntry(MultiCursorModifier, "Multiple Cursor Modifier", QString(), (int)Qt::AltModifier));
555 addConfigEntry(entry: ConfigEntry(ShowFoldingOnHoverOnly, "Show Folding Icons On Hover Only", QString(), true));
556
557 // Statusbar stuff
558 addConfigEntry(entry: ConfigEntry(ShowStatusbarLineColumn, "Show Statusbar Line Column", QString(), true));
559 addConfigEntry(entry: ConfigEntry(ShowStatusbarDictionary, "Show Statusbar Dictionary", QString(), true));
560 addConfigEntry(entry: ConfigEntry(ShowStatusbarInputMode, "Show Statusbar Input Mode", QString(), true));
561 addConfigEntry(entry: ConfigEntry(ShowStatusbarHighlightingMode, "Show Statusbar Highlighting Mode", QString(), true));
562 addConfigEntry(entry: ConfigEntry(ShowStatusbarTabSettings, "Show Statusbar Tab Settings", QString(), true));
563 addConfigEntry(entry: ConfigEntry(ShowStatusbarFileEncoding, "Show File Encoding", QString(), true));
564 addConfigEntry(entry: ConfigEntry(StatusbarLineColumnCompact, "Statusbar Line Column Compact Mode", QString(), true));
565 addConfigEntry(entry: ConfigEntry(ShowStatusbarEOL, "Shoe Line Ending Type in Statusbar", QString(), false));
566 addConfigEntry(entry: ConfigEntry(EnableAccessibility, "Enable Accessibility", QString(), true));
567
568 // Never forget to finalize or the <CommandName> becomes not available
569 finalizeConfigEntries();
570
571 // init with defaults from config or really hardcoded ones
572 KConfigGroup config(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor View"));
573 readConfig(config);
574
575 // avoid updateConfig effects like config write in constructor, see bug 377067
576 Q_ASSERT(configSessionNumber == 1);
577 --configSessionNumber;
578}
579
580KateViewConfig::KateViewConfig(KTextEditor::ViewPrivate *view)
581 : KateConfig(s_global)
582 , m_view(view)
583{
584}
585
586KateViewConfig::~KateViewConfig() = default;
587
588void KateViewConfig::readConfig(const KConfigGroup &config)
589{
590 configStart();
591
592 // read generic entries
593 readConfigEntries(config);
594
595 configEnd();
596}
597
598void KateViewConfig::writeConfig(KConfigGroup &config)
599{
600 // write generic entries
601 writeConfigEntries(config);
602}
603
604void KateViewConfig::updateConfig()
605{
606 if (m_view) {
607 m_view->updateConfig();
608 return;
609 }
610
611 if (isGlobal()) {
612 for (KTextEditor::ViewPrivate *view : KTextEditor::EditorPrivate::self()->views()) {
613 view->updateConfig();
614 }
615
616 // write config
617 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor View"));
618 writeConfig(config&: cg);
619 KTextEditor::EditorPrivate::config()->sync();
620
621 // trigger emission of KTextEditor::Editor::configChanged
622 KTextEditor::EditorPrivate::self()->triggerConfigChanged();
623 }
624}
625// END
626
627// BEGIN KateRendererConfig
628KateRendererConfig::KateRendererConfig()
629 : m_lineMarkerColor(KTextEditor::Document::reservedMarkersCount())
630 , m_schemaSet(false)
631 , m_fontSet(false)
632 , m_wordWrapMarkerSet(false)
633 , m_showIndentationLinesSet(false)
634 , m_showWholeBracketExpressionSet(false)
635 , m_backgroundColorSet(false)
636 , m_selectionColorSet(false)
637 , m_highlightedLineColorSet(false)
638 , m_highlightedBracketColorSet(false)
639 , m_wordWrapMarkerColorSet(false)
640 , m_tabMarkerColorSet(false)
641 , m_indentationLineColorSet(false)
642 , m_iconBarColorSet(false)
643 , m_foldingColorSet(false)
644 , m_lineNumberColorSet(false)
645 , m_currentLineNumberColorSet(false)
646 , m_separatorColorSet(false)
647 , m_spellingMistakeLineColorSet(false)
648 , m_templateColorsSet(false)
649 , m_modifiedLineColorSet(false)
650 , m_savedLineColorSet(false)
651 , m_searchHighlightColorSet(false)
652 , m_replaceHighlightColorSet(false)
653 , m_lineMarkerColorSet(m_lineMarkerColor.size())
654
655{
656 // init bitarray
657 m_lineMarkerColorSet.fill(aval: true);
658
659 // register this as our global instance
660 Q_ASSERT(isGlobal());
661 s_global = this;
662
663 // avoid updateConfig effects like config write in constructor, see bug 377067
664 Q_ASSERT(configSessionNumber == 0);
665 ++configSessionNumber;
666
667 // Init all known config entries
668 addConfigEntry(entry: ConfigEntry(AutoColorThemeSelection, "Auto Color Theme Selection", QString(), true));
669
670 // Never forget to finalize or the <CommandName> becomes not available
671 finalizeConfigEntries();
672
673 // init with defaults from config or really hardcoded ones
674 KConfigGroup config(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Renderer"));
675 readConfig(config);
676
677 // avoid updateConfig effects like config write in constructor, see bug 377067
678 Q_ASSERT(configSessionNumber == 1);
679 --configSessionNumber;
680}
681
682KateRendererConfig::KateRendererConfig(KateRenderer *renderer)
683 : KateConfig(s_global)
684 , m_lineMarkerColor(KTextEditor::Document::reservedMarkersCount())
685 , m_schemaSet(false)
686 , m_fontSet(false)
687 , m_wordWrapMarkerSet(false)
688 , m_showIndentationLinesSet(false)
689 , m_showWholeBracketExpressionSet(false)
690 , m_backgroundColorSet(false)
691 , m_selectionColorSet(false)
692 , m_highlightedLineColorSet(false)
693 , m_highlightedBracketColorSet(false)
694 , m_wordWrapMarkerColorSet(false)
695 , m_tabMarkerColorSet(false)
696 , m_indentationLineColorSet(false)
697 , m_iconBarColorSet(false)
698 , m_foldingColorSet(false)
699 , m_lineNumberColorSet(false)
700 , m_currentLineNumberColorSet(false)
701 , m_separatorColorSet(false)
702 , m_spellingMistakeLineColorSet(false)
703 , m_templateColorsSet(false)
704 , m_modifiedLineColorSet(false)
705 , m_savedLineColorSet(false)
706 , m_searchHighlightColorSet(false)
707 , m_replaceHighlightColorSet(false)
708 , m_lineMarkerColorSet(m_lineMarkerColor.size())
709 , m_renderer(renderer)
710{
711 // init bitarray
712 m_lineMarkerColorSet.fill(aval: false);
713}
714
715KateRendererConfig::~KateRendererConfig() = default;
716
717namespace
718{
719const char KEY_FONT[] = "Text Font";
720const char KEY_COLOR_THEME[] = "Color Theme";
721const char KEY_WORD_WRAP_MARKER[] = "Word Wrap Marker";
722const char KEY_SHOW_INDENTATION_LINES[] = "Show Indentation Lines";
723const char KEY_SHOW_WHOLE_BRACKET_EXPRESSION[] = "Show Whole Bracket Expression";
724const char KEY_ANIMATE_BRACKET_MATCHING[] = "Animate Bracket Matching";
725const char KEY_LINE_HEIGHT_MULTIPLIER[] = "Line Height Multiplier";
726}
727
728void KateRendererConfig::readConfig(const KConfigGroup &config)
729{
730 configStart();
731
732 // read generic entries
733 readConfigEntries(config);
734
735 // read font
736 setFont(config.readEntry(key: KEY_FONT, defaultValue: QFontDatabase::systemFont(type: QFontDatabase::FixedFont)));
737
738 // setSchema will default to right theme
739 setSchema(config.readEntry(key: KEY_COLOR_THEME, aDefault: QString()));
740
741 setWordWrapMarker(config.readEntry(key: KEY_WORD_WRAP_MARKER, defaultValue: false));
742
743 setShowIndentationLines(config.readEntry(key: KEY_SHOW_INDENTATION_LINES, defaultValue: false));
744
745 setShowWholeBracketExpression(config.readEntry(key: KEY_SHOW_WHOLE_BRACKET_EXPRESSION, defaultValue: false));
746
747 setAnimateBracketMatching(config.readEntry(key: KEY_ANIMATE_BRACKET_MATCHING, defaultValue: false));
748
749 setLineHeightMultiplier(config.readEntry<qreal>(key: KEY_LINE_HEIGHT_MULTIPLIER, defaultValue: 1.0));
750
751 configEnd();
752}
753
754void KateRendererConfig::writeConfig(KConfigGroup &config)
755{
756 // write generic entries
757 writeConfigEntries(config);
758
759 config.writeEntry(key: KEY_FONT, value: baseFont());
760
761 config.writeEntry(key: KEY_COLOR_THEME, value: schema());
762
763 config.writeEntry(key: KEY_WORD_WRAP_MARKER, value: wordWrapMarker());
764
765 config.writeEntry(key: KEY_SHOW_INDENTATION_LINES, value: showIndentationLines());
766
767 config.writeEntry(key: KEY_SHOW_WHOLE_BRACKET_EXPRESSION, value: showWholeBracketExpression());
768
769 config.writeEntry(key: KEY_ANIMATE_BRACKET_MATCHING, value: animateBracketMatching());
770
771 config.writeEntry<qreal>(key: KEY_LINE_HEIGHT_MULTIPLIER, value: lineHeightMultiplier());
772}
773
774void KateRendererConfig::updateConfig()
775{
776 if (m_renderer) {
777 m_renderer->updateConfig();
778 return;
779 }
780
781 if (isGlobal()) {
782 for (auto view : KTextEditor::EditorPrivate::self()->views()) {
783 view->renderer()->updateConfig();
784 }
785
786 // write config
787 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Renderer"));
788 writeConfig(config&: cg);
789 KTextEditor::EditorPrivate::config()->sync();
790
791 // trigger emission of KTextEditor::Editor::configChanged
792 KTextEditor::EditorPrivate::self()->triggerConfigChanged();
793 }
794}
795
796const QString &KateRendererConfig::schema() const
797{
798 if (m_schemaSet || isGlobal()) {
799 return m_schema;
800 }
801
802 return s_global->schema();
803}
804
805void KateRendererConfig::setSchema(QString schema)
806{
807 // check if we have some matching theme, else fallback to best theme for current palette
808 // same behavior as for the "Automatic Color Theme Selection"
809 if (!KateHlManager::self()->repository().theme(themeName: schema).isValid()) {
810 schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
811 }
812
813 if (m_schemaSet && m_schema == schema) {
814 return;
815 }
816
817 configStart();
818 m_schemaSet = true;
819 m_schema = schema;
820 setSchemaInternal(m_schema);
821 configEnd();
822}
823
824void KateRendererConfig::reloadSchema()
825{
826 if (isGlobal()) {
827 setSchemaInternal(m_schema);
828 for (KTextEditor::ViewPrivate *view : KTextEditor::EditorPrivate::self()->views()) {
829 view->rendererConfig()->reloadSchema();
830 }
831 }
832
833 else if (m_renderer && m_schemaSet) {
834 setSchemaInternal(m_schema);
835 }
836
837 // trigger renderer/view update
838 if (m_renderer) {
839 m_renderer->updateConfig();
840 }
841}
842
843void KateRendererConfig::setSchemaInternal(const QString &schema)
844{
845 // we always set the theme if we arrive here!
846 m_schemaSet = true;
847
848 // for the global config, we honor the auto selection based on the palette
849 // do the same if the set theme really doesn't exist, we need a valid theme or the rendering will be broken in bad ways!
850 if ((isGlobal() && value(key: AutoColorThemeSelection).toBool()) || !KateHlManager::self()->repository().theme(themeName: schema).isValid()) {
851 // always choose some theme matching the current application palette
852 // we will arrive here after palette changed signals, too!
853 m_schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
854 } else {
855 // take user given theme 1:1
856 m_schema = schema;
857 }
858
859 const auto theme = KateHlManager::self()->repository().theme(themeName: m_schema);
860
861 m_backgroundColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::BackgroundColor));
862 m_backgroundColorSet = true;
863
864 m_selectionColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::TextSelection));
865 m_selectionColorSet = true;
866
867 m_highlightedLineColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::CurrentLine));
868 m_highlightedLineColorSet = true;
869
870 m_highlightedBracketColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::BracketMatching));
871 m_highlightedBracketColorSet = true;
872
873 m_wordWrapMarkerColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::WordWrapMarker));
874 m_wordWrapMarkerColorSet = true;
875
876 m_tabMarkerColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::TabMarker));
877 m_tabMarkerColorSet = true;
878
879 m_indentationLineColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::IndentationLine));
880 m_indentationLineColorSet = true;
881
882 m_iconBarColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::IconBorder));
883 m_iconBarColorSet = true;
884
885 m_foldingColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::CodeFolding));
886 m_foldingColorSet = true;
887
888 m_lineNumberColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::LineNumbers));
889 m_lineNumberColorSet = true;
890
891 m_currentLineNumberColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::CurrentLineNumber));
892 m_currentLineNumberColorSet = true;
893
894 m_separatorColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::Separator));
895 m_separatorColorSet = true;
896
897 m_spellingMistakeLineColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::SpellChecking));
898 m_spellingMistakeLineColorSet = true;
899
900 m_modifiedLineColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::ModifiedLines));
901 m_modifiedLineColorSet = true;
902
903 m_savedLineColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::SavedLines));
904 m_savedLineColorSet = true;
905
906 m_searchHighlightColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::SearchHighlight));
907 m_searchHighlightColorSet = true;
908
909 m_replaceHighlightColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::ReplaceHighlight));
910 m_replaceHighlightColorSet = true;
911
912 for (int i = 0; i <= KSyntaxHighlighting::Theme::MarkError - KSyntaxHighlighting::Theme::MarkBookmark; i++) {
913 QColor col =
914 QColor::fromRgba(rgba: theme.editorColor(role: static_cast<KSyntaxHighlighting::Theme::EditorColorRole>(i + KSyntaxHighlighting::Theme::MarkBookmark)));
915 m_lineMarkerColorSet[i] = true;
916 m_lineMarkerColor[i] = col;
917 }
918
919 m_templateBackgroundColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::TemplateBackground));
920
921 m_templateFocusedEditablePlaceholderColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::TemplateFocusedPlaceholder));
922
923 m_templateEditablePlaceholderColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::TemplatePlaceholder));
924
925 m_templateNotEditablePlaceholderColor = QColor::fromRgba(rgba: theme.editorColor(role: KSyntaxHighlighting::Theme::TemplateReadOnlyPlaceholder));
926
927 m_templateColorsSet = true;
928}
929
930const QFont &KateRendererConfig::baseFont() const
931{
932 if (m_fontSet || isGlobal()) {
933 return m_font;
934 }
935
936 return s_global->baseFont();
937}
938
939void KateRendererConfig::setFont(const QFont &font)
940{
941 if (m_fontSet && m_font == font) {
942 return;
943 }
944
945 configStart();
946 m_font = font;
947 m_fontSet = true;
948
949 // Set full hinting instead to ensure the letters are aligned properly, bug 482659
950 // https://codereview.qt-project.org/c/qt/qtbase/+/546168
951 m_font.setHintingPreference(QFont::PreferFullHinting);
952
953 configEnd();
954}
955
956bool KateRendererConfig::wordWrapMarker() const
957{
958 if (m_wordWrapMarkerSet || isGlobal()) {
959 return m_wordWrapMarker;
960 }
961
962 return s_global->wordWrapMarker();
963}
964
965void KateRendererConfig::setWordWrapMarker(bool on)
966{
967 if (m_wordWrapMarkerSet && m_wordWrapMarker == on) {
968 return;
969 }
970
971 configStart();
972
973 m_wordWrapMarkerSet = true;
974 m_wordWrapMarker = on;
975
976 configEnd();
977}
978
979const QColor &KateRendererConfig::backgroundColor() const
980{
981 if (m_backgroundColorSet || isGlobal()) {
982 return m_backgroundColor;
983 }
984
985 return s_global->backgroundColor();
986}
987
988void KateRendererConfig::setBackgroundColor(const QColor &col)
989{
990 if (m_backgroundColorSet && m_backgroundColor == col) {
991 return;
992 }
993
994 configStart();
995
996 m_backgroundColorSet = true;
997 m_backgroundColor = col;
998
999 configEnd();
1000}
1001
1002const QColor &KateRendererConfig::selectionColor() const
1003{
1004 if (m_selectionColorSet || isGlobal()) {
1005 return m_selectionColor;
1006 }
1007
1008 return s_global->selectionColor();
1009}
1010
1011void KateRendererConfig::setSelectionColor(const QColor &col)
1012{
1013 if (m_selectionColorSet && m_selectionColor == col) {
1014 return;
1015 }
1016
1017 configStart();
1018
1019 m_selectionColorSet = true;
1020 m_selectionColor = col;
1021
1022 configEnd();
1023}
1024
1025const QColor &KateRendererConfig::highlightedLineColor() const
1026{
1027 if (m_highlightedLineColorSet || isGlobal()) {
1028 return m_highlightedLineColor;
1029 }
1030
1031 return s_global->highlightedLineColor();
1032}
1033
1034void KateRendererConfig::setHighlightedLineColor(const QColor &col)
1035{
1036 if (m_highlightedLineColorSet && m_highlightedLineColor == col) {
1037 return;
1038 }
1039
1040 configStart();
1041
1042 m_highlightedLineColorSet = true;
1043 m_highlightedLineColor = col;
1044
1045 configEnd();
1046}
1047
1048const QColor &KateRendererConfig::lineMarkerColor(KTextEditor::Document::MarkTypes type) const
1049{
1050 int index = 0;
1051 if (type > 0) {
1052 while ((type >> index++) ^ 1) { }
1053 }
1054 index -= 1;
1055
1056 if (index < 0 || index >= KTextEditor::Document::reservedMarkersCount()) {
1057 static QColor dummy;
1058 return dummy;
1059 }
1060
1061 if (m_lineMarkerColorSet[index] || isGlobal()) {
1062 return m_lineMarkerColor[index];
1063 }
1064
1065 return s_global->lineMarkerColor(type);
1066}
1067
1068const QColor &KateRendererConfig::highlightedBracketColor() const
1069{
1070 if (m_highlightedBracketColorSet || isGlobal()) {
1071 return m_highlightedBracketColor;
1072 }
1073
1074 return s_global->highlightedBracketColor();
1075}
1076
1077void KateRendererConfig::setHighlightedBracketColor(const QColor &col)
1078{
1079 if (m_highlightedBracketColorSet && m_highlightedBracketColor == col) {
1080 return;
1081 }
1082
1083 configStart();
1084
1085 m_highlightedBracketColorSet = true;
1086 m_highlightedBracketColor = col;
1087
1088 configEnd();
1089}
1090
1091const QColor &KateRendererConfig::wordWrapMarkerColor() const
1092{
1093 if (m_wordWrapMarkerColorSet || isGlobal()) {
1094 return m_wordWrapMarkerColor;
1095 }
1096
1097 return s_global->wordWrapMarkerColor();
1098}
1099
1100void KateRendererConfig::setWordWrapMarkerColor(const QColor &col)
1101{
1102 if (m_wordWrapMarkerColorSet && m_wordWrapMarkerColor == col) {
1103 return;
1104 }
1105
1106 configStart();
1107
1108 m_wordWrapMarkerColorSet = true;
1109 m_wordWrapMarkerColor = col;
1110
1111 configEnd();
1112}
1113
1114const QColor &KateRendererConfig::tabMarkerColor() const
1115{
1116 if (m_tabMarkerColorSet || isGlobal()) {
1117 return m_tabMarkerColor;
1118 }
1119
1120 return s_global->tabMarkerColor();
1121}
1122
1123void KateRendererConfig::setTabMarkerColor(const QColor &col)
1124{
1125 if (m_tabMarkerColorSet && m_tabMarkerColor == col) {
1126 return;
1127 }
1128
1129 configStart();
1130
1131 m_tabMarkerColorSet = true;
1132 m_tabMarkerColor = col;
1133
1134 configEnd();
1135}
1136
1137const QColor &KateRendererConfig::indentationLineColor() const
1138{
1139 if (m_indentationLineColorSet || isGlobal()) {
1140 return m_indentationLineColor;
1141 }
1142
1143 return s_global->indentationLineColor();
1144}
1145
1146void KateRendererConfig::setIndentationLineColor(const QColor &col)
1147{
1148 if (m_indentationLineColorSet && m_indentationLineColor == col) {
1149 return;
1150 }
1151
1152 configStart();
1153
1154 m_indentationLineColorSet = true;
1155 m_indentationLineColor = col;
1156
1157 configEnd();
1158}
1159
1160const QColor &KateRendererConfig::iconBarColor() const
1161{
1162 if (m_iconBarColorSet || isGlobal()) {
1163 return m_iconBarColor;
1164 }
1165
1166 return s_global->iconBarColor();
1167}
1168
1169void KateRendererConfig::setIconBarColor(const QColor &col)
1170{
1171 if (m_iconBarColorSet && m_iconBarColor == col) {
1172 return;
1173 }
1174
1175 configStart();
1176
1177 m_iconBarColorSet = true;
1178 m_iconBarColor = col;
1179
1180 configEnd();
1181}
1182
1183const QColor &KateRendererConfig::foldingColor() const
1184{
1185 if (m_foldingColorSet || isGlobal()) {
1186 return m_foldingColor;
1187 }
1188
1189 return s_global->foldingColor();
1190}
1191
1192void KateRendererConfig::setFoldingColor(const QColor &col)
1193{
1194 if (m_foldingColorSet && m_foldingColor == col) {
1195 return;
1196 }
1197
1198 configStart();
1199
1200 m_foldingColorSet = true;
1201 m_foldingColor = col;
1202
1203 configEnd();
1204}
1205
1206const QColor &KateRendererConfig::templateBackgroundColor() const
1207{
1208 if (m_templateColorsSet || isGlobal()) {
1209 return m_templateBackgroundColor;
1210 }
1211
1212 return s_global->templateBackgroundColor();
1213}
1214
1215const QColor &KateRendererConfig::templateEditablePlaceholderColor() const
1216{
1217 if (m_templateColorsSet || isGlobal()) {
1218 return m_templateEditablePlaceholderColor;
1219 }
1220
1221 return s_global->templateEditablePlaceholderColor();
1222}
1223
1224const QColor &KateRendererConfig::templateFocusedEditablePlaceholderColor() const
1225{
1226 if (m_templateColorsSet || isGlobal()) {
1227 return m_templateFocusedEditablePlaceholderColor;
1228 }
1229
1230 return s_global->templateFocusedEditablePlaceholderColor();
1231}
1232
1233const QColor &KateRendererConfig::templateNotEditablePlaceholderColor() const
1234{
1235 if (m_templateColorsSet || isGlobal()) {
1236 return m_templateNotEditablePlaceholderColor;
1237 }
1238
1239 return s_global->templateNotEditablePlaceholderColor();
1240}
1241
1242const QColor &KateRendererConfig::lineNumberColor() const
1243{
1244 if (m_lineNumberColorSet || isGlobal()) {
1245 return m_lineNumberColor;
1246 }
1247
1248 return s_global->lineNumberColor();
1249}
1250
1251void KateRendererConfig::setLineNumberColor(const QColor &col)
1252{
1253 if (m_lineNumberColorSet && m_lineNumberColor == col) {
1254 return;
1255 }
1256
1257 configStart();
1258
1259 m_lineNumberColorSet = true;
1260 m_lineNumberColor = col;
1261
1262 configEnd();
1263}
1264
1265const QColor &KateRendererConfig::currentLineNumberColor() const
1266{
1267 if (m_currentLineNumberColorSet || isGlobal()) {
1268 return m_currentLineNumberColor;
1269 }
1270
1271 return s_global->currentLineNumberColor();
1272}
1273
1274void KateRendererConfig::setCurrentLineNumberColor(const QColor &col)
1275{
1276 if (m_currentLineNumberColorSet && m_currentLineNumberColor == col) {
1277 return;
1278 }
1279
1280 configStart();
1281
1282 m_currentLineNumberColorSet = true;
1283 m_currentLineNumberColor = col;
1284
1285 configEnd();
1286}
1287
1288const QColor &KateRendererConfig::separatorColor() const
1289{
1290 if (m_separatorColorSet || isGlobal()) {
1291 return m_separatorColor;
1292 }
1293
1294 return s_global->separatorColor();
1295}
1296
1297void KateRendererConfig::setSeparatorColor(const QColor &col)
1298{
1299 if (m_separatorColorSet && m_separatorColor == col) {
1300 return;
1301 }
1302
1303 configStart();
1304
1305 m_separatorColorSet = true;
1306 m_separatorColor = col;
1307
1308 configEnd();
1309}
1310
1311const QColor &KateRendererConfig::spellingMistakeLineColor() const
1312{
1313 if (m_spellingMistakeLineColorSet || isGlobal()) {
1314 return m_spellingMistakeLineColor;
1315 }
1316
1317 return s_global->spellingMistakeLineColor();
1318}
1319
1320void KateRendererConfig::setSpellingMistakeLineColor(const QColor &col)
1321{
1322 if (m_spellingMistakeLineColorSet && m_spellingMistakeLineColor == col) {
1323 return;
1324 }
1325
1326 configStart();
1327
1328 m_spellingMistakeLineColorSet = true;
1329 m_spellingMistakeLineColor = col;
1330
1331 configEnd();
1332}
1333
1334const QColor &KateRendererConfig::modifiedLineColor() const
1335{
1336 if (m_modifiedLineColorSet || isGlobal()) {
1337 return m_modifiedLineColor;
1338 }
1339
1340 return s_global->modifiedLineColor();
1341}
1342
1343void KateRendererConfig::setModifiedLineColor(const QColor &col)
1344{
1345 if (m_modifiedLineColorSet && m_modifiedLineColor == col) {
1346 return;
1347 }
1348
1349 configStart();
1350
1351 m_modifiedLineColorSet = true;
1352 m_modifiedLineColor = col;
1353
1354 configEnd();
1355}
1356
1357const QColor &KateRendererConfig::savedLineColor() const
1358{
1359 if (m_savedLineColorSet || isGlobal()) {
1360 return m_savedLineColor;
1361 }
1362
1363 return s_global->savedLineColor();
1364}
1365
1366void KateRendererConfig::setSavedLineColor(const QColor &col)
1367{
1368 if (m_savedLineColorSet && m_savedLineColor == col) {
1369 return;
1370 }
1371
1372 configStart();
1373
1374 m_savedLineColorSet = true;
1375 m_savedLineColor = col;
1376
1377 configEnd();
1378}
1379
1380const QColor &KateRendererConfig::searchHighlightColor() const
1381{
1382 if (m_searchHighlightColorSet || isGlobal()) {
1383 return m_searchHighlightColor;
1384 }
1385
1386 return s_global->searchHighlightColor();
1387}
1388
1389void KateRendererConfig::setSearchHighlightColor(const QColor &col)
1390{
1391 if (m_searchHighlightColorSet && m_searchHighlightColor == col) {
1392 return;
1393 }
1394
1395 configStart();
1396
1397 m_searchHighlightColorSet = true;
1398 m_searchHighlightColor = col;
1399
1400 configEnd();
1401}
1402
1403const QColor &KateRendererConfig::replaceHighlightColor() const
1404{
1405 if (m_replaceHighlightColorSet || isGlobal()) {
1406 return m_replaceHighlightColor;
1407 }
1408
1409 return s_global->replaceHighlightColor();
1410}
1411
1412void KateRendererConfig::setReplaceHighlightColor(const QColor &col)
1413{
1414 if (m_replaceHighlightColorSet && m_replaceHighlightColor == col) {
1415 return;
1416 }
1417
1418 configStart();
1419
1420 m_replaceHighlightColorSet = true;
1421 m_replaceHighlightColor = col;
1422
1423 configEnd();
1424}
1425
1426void KateRendererConfig::setLineHeightMultiplier(qreal value)
1427{
1428 configStart();
1429 m_lineHeightMultiplier = value;
1430 configEnd();
1431}
1432
1433bool KateRendererConfig::showIndentationLines() const
1434{
1435 if (m_showIndentationLinesSet || isGlobal()) {
1436 return m_showIndentationLines;
1437 }
1438
1439 return s_global->showIndentationLines();
1440}
1441
1442void KateRendererConfig::setShowIndentationLines(bool on)
1443{
1444 if (m_showIndentationLinesSet && m_showIndentationLines == on) {
1445 return;
1446 }
1447
1448 configStart();
1449
1450 m_showIndentationLinesSet = true;
1451 m_showIndentationLines = on;
1452
1453 configEnd();
1454}
1455
1456bool KateRendererConfig::showWholeBracketExpression() const
1457{
1458 if (m_showWholeBracketExpressionSet || isGlobal()) {
1459 return m_showWholeBracketExpression;
1460 }
1461
1462 return s_global->showWholeBracketExpression();
1463}
1464
1465void KateRendererConfig::setShowWholeBracketExpression(bool on)
1466{
1467 if (m_showWholeBracketExpressionSet && m_showWholeBracketExpression == on) {
1468 return;
1469 }
1470
1471 configStart();
1472
1473 m_showWholeBracketExpressionSet = true;
1474 m_showWholeBracketExpression = on;
1475
1476 configEnd();
1477}
1478
1479bool KateRendererConfig::animateBracketMatching()
1480{
1481 return s_global->m_animateBracketMatching;
1482}
1483
1484void KateRendererConfig::setAnimateBracketMatching(bool on)
1485{
1486 if (!isGlobal()) {
1487 s_global->setAnimateBracketMatching(on);
1488 } else if (on != m_animateBracketMatching) {
1489 configStart();
1490 m_animateBracketMatching = on;
1491 configEnd();
1492 }
1493}
1494
1495// END
1496

source code of ktexteditor/src/utils/kateconfig.cpp