Changeset View
Changeset View
Standalone View
Standalone View
src/syntax/katehighlight.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 58 | { | |||
---|---|---|---|---|---|
63 | if (textStyle == KSyntaxHighlighting::Theme::Others) { | 63 | if (textStyle == KSyntaxHighlighting::Theme::Others) { | ||
64 | return KTextEditor::dsOthers; | 64 | return KTextEditor::dsOthers; | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | // else: simple cast | 67 | // else: simple cast | ||
68 | return static_cast<KTextEditor::DefaultStyle>(textStyle); | 68 | return static_cast<KTextEditor::DefaultStyle>(textStyle); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | /** | ||||
72 | * convert theme/schema name from KTextEditor => KSyntaxHighlighting. | ||||
73 | * NOTE: "KDE" and "Vim (dark)" themes don't exist in KSyntaxHighlighting. | ||||
74 | */ | ||||
75 | inline QString convertThemeName(const QString &themeName) | ||||
76 | { | ||||
77 | if (themeName == QLatin1String("Normal")) { | ||||
78 | return QLatin1String("Default"); | ||||
mwolff: return QStringLiteral, otherwise you allocate on every function call (also below) | |||||
79 | } else if (themeName == QLatin1String("Solarized (light)")) { | ||||
80 | return QLatin1String("Solarized Light"); | ||||
81 | } else if (themeName == QLatin1String("Solarized (dark)")) { | ||||
82 | return QLatin1String("Solarized Dark"); | ||||
83 | } | ||||
84 | return themeName; | ||||
85 | } | ||||
86 | | ||||
71 | } | 87 | } | ||
72 | //END | 88 | //END | ||
73 | 89 | | |||
74 | //BEGIN KateHighlighting | 90 | //BEGIN KateHighlighting | ||
75 | KateHighlighting::KateHighlighting(const KSyntaxHighlighting::Definition &def) | 91 | KateHighlighting::KateHighlighting(const KSyntaxHighlighting::Definition &def) | ||
76 | { | 92 | { | ||
77 | /** | 93 | /** | ||
78 | * get name and section, always works | 94 | * get name and section, always works | ||
▲ Show 20 Lines • Show All 423 Lines • ▼ Show 20 Line(s) | |||||
502 | void KateHighlighting::clearAttributeArrays() | 518 | void KateHighlighting::clearAttributeArrays() | ||
503 | { | 519 | { | ||
504 | // just clear the hashed attributes, we create them lazy again | 520 | // just clear the hashed attributes, we create them lazy again | ||
505 | m_attributeArrays.clear(); | 521 | m_attributeArrays.clear(); | ||
506 | } | 522 | } | ||
507 | 523 | | |||
508 | QVector<KTextEditor::Attribute::Ptr> KateHighlighting::attributesForDefinition() | 524 | QVector<KTextEditor::Attribute::Ptr> KateHighlighting::attributesForDefinition() | ||
509 | { | 525 | { | ||
526 | KSyntaxHighlighting::Theme currentTheme = KateHlManager::self()->repository().theme(convertThemeName(KateRendererConfig::global()->schema())); | ||||
527 | | ||||
510 | /** | 528 | /** | ||
511 | * create list of all known things | 529 | * create list of all known things | ||
512 | */ | 530 | */ | ||
513 | QVector<KTextEditor::Attribute::Ptr> array; | 531 | QVector<KTextEditor::Attribute::Ptr> array; | ||
514 | for (const auto &format : m_formats) { | 532 | for (const auto &format : m_formats) { | ||
515 | /** | 533 | /** | ||
516 | * FIXME: atm we just set some theme here for later color generation | 534 | * atm we just set the current chosen theme here for later color generation | ||
517 | */ | 535 | */ | ||
536 | if (currentTheme.isValid()) { | ||||
537 | setTheme(currentTheme); | ||||
538 | } else { | ||||
518 | setTheme(KateHlManager::self()->repository().defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); | 539 | setTheme(KateHlManager::self()->repository().defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); | ||
540 | } | ||||
519 | 541 | | |||
520 | /** | 542 | /** | ||
521 | * create a KTextEditor attribute matching the given format | 543 | * create a KTextEditor attribute matching the given format | ||
522 | */ | 544 | */ | ||
523 | KTextEditor::Attribute::Ptr newAttribute(new KTextEditor::Attribute(nameForAttrib(array.size()), textStyleToDefaultStyle(format.textStyle()))); | 545 | KTextEditor::Attribute::Ptr newAttribute(new KTextEditor::Attribute(nameForAttrib(array.size()), textStyleToDefaultStyle(format.textStyle()))); | ||
524 | 546 | | |||
547 | if (currentTheme.isValid()) { | ||||
525 | if (format.hasTextColor(theme())) { | 548 | if (format.hasTextColor(theme())) { | ||
526 | newAttribute->setForeground(format.textColor(theme())); | 549 | newAttribute->setForeground(format.textColor(theme())); | ||
527 | newAttribute->setSelectedForeground(format.selectedTextColor(theme())); | 550 | newAttribute->setSelectedForeground(format.selectedTextColor(theme())); | ||
528 | } | 551 | } | ||
529 | 552 | | |||
530 | if (format.hasBackgroundColor(theme())) { | 553 | if (format.hasBackgroundColor(theme())) { | ||
531 | newAttribute->setBackground(format.backgroundColor(theme())); | 554 | newAttribute->setBackground(format.backgroundColor(theme())); | ||
532 | newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); | 555 | newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); | ||
Show All 9 Lines | |||||
542 | 565 | | |||
543 | if (format.isUnderline(theme())) { | 566 | if (format.isUnderline(theme())) { | ||
544 | newAttribute->setFontUnderline(true); | 567 | newAttribute->setFontUnderline(true); | ||
545 | } | 568 | } | ||
546 | 569 | | |||
547 | if (format.isStrikeThrough(theme())) { | 570 | if (format.isStrikeThrough(theme())) { | ||
548 | newAttribute->setFontStrikeOut(true); | 571 | newAttribute->setFontStrikeOut(true); | ||
549 | } | 572 | } | ||
573 | } | ||||
550 | 574 | | |||
551 | newAttribute->setSkipSpellChecking(format.spellCheck()); | 575 | newAttribute->setSkipSpellChecking(format.spellCheck()); | ||
552 | 576 | | |||
553 | array.append(newAttribute); | 577 | array.append(newAttribute); | ||
554 | } | 578 | } | ||
555 | return array; | 579 | return array; | ||
556 | } | 580 | } | ||
557 | 581 | | |||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |
return QStringLiteral, otherwise you allocate on every function call (also below)