Differential D22158 Diff 60904 kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp
Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp
Show All 30 Lines | |||||
31 | #include "../namespacealiasdeclaration.h" | 31 | #include "../namespacealiasdeclaration.h" | ||
32 | #include "../types/functiontype.h" | 32 | #include "../types/functiontype.h" | ||
33 | #include "../types/structuretype.h" | 33 | #include "../types/structuretype.h" | ||
34 | #include <debug.h> | 34 | #include <debug.h> | ||
35 | #include <interfaces/icontextbrowser.h> | 35 | #include <interfaces/icontextbrowser.h> | ||
36 | #include <interfaces/idocumentationcontroller.h> | 36 | #include <interfaces/idocumentationcontroller.h> | ||
37 | #include <interfaces/iplugincontroller.h> | 37 | #include <interfaces/iplugincontroller.h> | ||
38 | 38 | | |||
39 | #include <KColorScheme> | ||||
40 | | ||||
39 | namespace KDevelop { | 41 | namespace KDevelop { | ||
40 | class AbstractNavigationContextPrivate | 42 | class AbstractNavigationContextPrivate | ||
41 | { | 43 | { | ||
42 | public: | 44 | public: | ||
43 | QVector<NavigationContextPointer> m_children; //Used to keep alive all children until this is deleted | 45 | QVector<NavigationContextPointer> m_children; //Used to keep alive all children until this is deleted | ||
44 | 46 | | |||
45 | int m_selectedLink = 0; //The link currently selected | 47 | int m_selectedLink = 0; //The link currently selected | ||
46 | NavigationAction m_selectedLinkAction; //Target of the currently selected link | 48 | NavigationAction m_selectedLinkAction; //Target of the currently selected link | ||
47 | 49 | | |||
48 | bool m_shorten = false; | 50 | bool m_shorten = false; | ||
49 | 51 | | |||
50 | //A counter used while building the html-code to count the used links. | 52 | //A counter used while building the html-code to count the used links. | ||
51 | int m_linkCount = -1; | 53 | int m_linkCount = -1; | ||
52 | //Something else than -1 if the current position is represented by a line-number, not a link. | 54 | //Something else than -1 if the current position is represented by a line-number, not a link. | ||
53 | int m_currentLine = 0; | 55 | int m_currentLine = 0; | ||
54 | int m_currentPositionLine = 0; | 56 | int m_currentPositionLine = 0; | ||
55 | QMap<QString, NavigationAction> m_links; | 57 | QMap<QString, NavigationAction> m_links; | ||
56 | QMap<int, int> m_linkLines; //Holds the line for each link | 58 | QMap<int, int> m_linkLines; //Holds the line for each link | ||
57 | QMap<int, NavigationAction> m_intLinks; | 59 | QMap<int, NavigationAction> m_intLinks; | ||
58 | AbstractNavigationContext* m_previousContext; | 60 | AbstractNavigationContext* m_previousContext; | ||
59 | TopDUContextPointer m_topContext; | 61 | TopDUContextPointer m_topContext; | ||
60 | 62 | | |||
61 | QString m_currentText; //Here the text is built | 63 | QString m_currentText; //Here the text is built | ||
64 | | ||||
65 | ColorizerTheme m_theme; | ||||
62 | }; | 66 | }; | ||
63 | 67 | | |||
64 | void AbstractNavigationContext::setTopContext(const TopDUContextPointer& context) | 68 | void AbstractNavigationContext::setTopContext(const TopDUContextPointer& context) | ||
65 | { | 69 | { | ||
66 | Q_D(AbstractNavigationContext); | 70 | Q_D(AbstractNavigationContext); | ||
67 | 71 | | |||
68 | d->m_topContext = context; | 72 | d->m_topContext = context; | ||
69 | } | 73 | } | ||
70 | 74 | | |||
71 | TopDUContextPointer AbstractNavigationContext::topContext() const | 75 | TopDUContextPointer AbstractNavigationContext::topContext() const | ||
72 | { | 76 | { | ||
73 | Q_D(const AbstractNavigationContext); | 77 | Q_D(const AbstractNavigationContext); | ||
74 | 78 | | |||
75 | return d->m_topContext; | 79 | return d->m_topContext; | ||
76 | } | 80 | } | ||
77 | 81 | | |||
78 | AbstractNavigationContext::AbstractNavigationContext(const TopDUContextPointer& topContext, | 82 | AbstractNavigationContext::AbstractNavigationContext(const TopDUContextPointer& topContext, | ||
79 | AbstractNavigationContext* previousContext) | 83 | AbstractNavigationContext* previousContext) | ||
80 | : d_ptr(new AbstractNavigationContextPrivate) | 84 | : d_ptr(new AbstractNavigationContextPrivate) | ||
81 | { | 85 | { | ||
82 | Q_D(AbstractNavigationContext); | 86 | Q_D(AbstractNavigationContext); | ||
83 | 87 | | |||
84 | d->m_previousContext = previousContext; | 88 | d->m_previousContext = previousContext; | ||
85 | d->m_topContext = topContext; | 89 | d->m_topContext = topContext; | ||
90 | const KColorScheme scheme(QPalette::Normal, KColorScheme::View); | ||||
91 | d->m_theme = ColorizerTheme(scheme); | ||||
86 | 92 | | |||
87 | qRegisterMetaType<KTextEditor::Cursor>("KTextEditor::Cursor"); | 93 | qRegisterMetaType<KTextEditor::Cursor>("KTextEditor::Cursor"); | ||
88 | qRegisterMetaType<IDocumentation::Ptr>("IDocumentation::Ptr"); | 94 | qRegisterMetaType<IDocumentation::Ptr>("IDocumentation::Ptr"); | ||
89 | } | 95 | } | ||
90 | 96 | | |||
91 | AbstractNavigationContext::~AbstractNavigationContext() | 97 | AbstractNavigationContext::~AbstractNavigationContext() | ||
92 | { | 98 | { | ||
93 | } | 99 | } | ||
94 | 100 | | |||
95 | void AbstractNavigationContext::makeLink(const QString& name, const DeclarationPointer& declaration, | 101 | void AbstractNavigationContext::makeLink(const QString& name, const DeclarationPointer& declaration, | ||
96 | NavigationAction::Type actionType) | 102 | NavigationAction::Type actionType) | ||
97 | { | 103 | { | ||
98 | NavigationAction action(declaration, actionType); | 104 | NavigationAction action(declaration, actionType); | ||
99 | makeLink(name, QString(), action); | 105 | makeLink(name, QString(), action); | ||
100 | } | 106 | } | ||
101 | 107 | | |||
102 | QString AbstractNavigationContext::createLink(const QString& name, const QString&, const NavigationAction& action) | 108 | QString AbstractNavigationContext::createLink(const QString& name, const QString&, const NavigationAction& action) | ||
103 | { | 109 | { | ||
104 | Q_D(AbstractNavigationContext); | 110 | Q_D(AbstractNavigationContext); | ||
105 | 111 | | |||
106 | if (d->m_shorten) { | 112 | if (d->m_shorten) { | ||
107 | //Do not create links in shortened mode, it's only for viewing | 113 | //Do not create links in shortened mode, it's only for viewing | ||
108 | return typeHighlight(name.toHtmlEscaped()); | 114 | return theme().typeHighlight(name.toHtmlEscaped()); | ||
109 | } | 115 | } | ||
110 | 116 | | |||
111 | // NOTE: Since the by definition in the HTML standard some uri components | 117 | // NOTE: Since the by definition in the HTML standard some uri components | ||
112 | // are case-insensitive, we define a new lowercase link-id for each | 118 | // are case-insensitive, we define a new lowercase link-id for each | ||
113 | // link. Otherwise Qt 5 seems to mess up the casing and the link | 119 | // link. Otherwise Qt 5 seems to mess up the casing and the link | ||
114 | // cannot be matched when it's executed. | 120 | // cannot be matched when it's executed. | ||
115 | QString hrefId = QStringLiteral("link_%1").arg(d->m_links.count()); | 121 | QString hrefId = QStringLiteral("link_%1").arg(d->m_links.count()); | ||
116 | 122 | | |||
117 | d->m_links[hrefId] = action; | 123 | d->m_links[hrefId] = action; | ||
118 | d->m_intLinks[d->m_linkCount] = action; | 124 | d->m_intLinks[d->m_linkCount] = action; | ||
119 | d->m_linkLines[d->m_linkCount] = d->m_currentLine; | 125 | d->m_linkLines[d->m_linkCount] = d->m_currentLine; | ||
120 | if (d->m_currentPositionLine == d->m_currentLine) { | 126 | if (d->m_currentPositionLine == d->m_currentLine) { | ||
121 | d->m_currentPositionLine = -1; | 127 | d->m_currentPositionLine = -1; | ||
122 | d->m_selectedLink = d->m_linkCount; | 128 | d->m_selectedLink = d->m_linkCount; | ||
123 | } | 129 | } | ||
124 | 130 | | |||
125 | QString str = name.toHtmlEscaped(); | 131 | QString str = name.toHtmlEscaped(); | ||
126 | if (d->m_linkCount == d->m_selectedLink) | 132 | if (d->m_linkCount == d->m_selectedLink) | ||
127 | str = QLatin1String("<font style=\"background-color:#f1f1f1;\" color=\"#880088\">") + str + QLatin1String( | 133 | str = theme().positionHighlight(str); | ||
128 | "</font>"); | | |||
129 | 134 | | |||
130 | QString ret = QLatin1String("<a href=\"") + hrefId + QLatin1Char('\"') + | 135 | QString ret = QLatin1String("<a href=\"") + hrefId + QLatin1Char('\"') + | ||
131 | ((d->m_linkCount == d->m_selectedLink && | 136 | ((d->m_linkCount == d->m_selectedLink && | ||
132 | d->m_currentPositionLine == | 137 | d->m_currentPositionLine == | ||
133 | -1) ? QStringLiteral(" name = \"currentPosition\"") : QString()) + QLatin1Char('>') + str + | 138 | -1) ? QStringLiteral(" name = \"currentPosition\"") : QString()) + QLatin1Char('>') + str + | ||
134 | QLatin1String("</a>"); | 139 | QLatin1String("</a>"); | ||
135 | 140 | | |||
136 | if (d->m_selectedLink == d->m_linkCount) | 141 | if (d->m_selectedLink == d->m_linkCount) | ||
▲ Show 20 Lines • Show All 437 Lines • ▼ Show 20 Line(s) | 577 | { | |||
574 | 579 | | |||
575 | QRegExp newLineRegExp(QStringLiteral("<br>|<br */>|</p>")); | 580 | QRegExp newLineRegExp(QStringLiteral("<br>|<br */>|</p>")); | ||
576 | const auto lines = splitAndKeep(html, newLineRegExp); | 581 | const auto lines = splitAndKeep(html, newLineRegExp); | ||
577 | for (const QString& line : lines) { | 582 | for (const QString& line : lines) { | ||
578 | d->m_currentText += line; | 583 | d->m_currentText += line; | ||
579 | if (line.indexOf(newLineRegExp) != -1) { | 584 | if (line.indexOf(newLineRegExp) != -1) { | ||
580 | ++d->m_currentLine; | 585 | ++d->m_currentLine; | ||
581 | if (d->m_currentLine == d->m_currentPositionLine) { | 586 | if (d->m_currentLine == d->m_currentPositionLine) { | ||
582 | d->m_currentText += QStringLiteral( | 587 | d->m_currentText += theme().positionHighlight( | ||
583 | "<font color=\"#880088\"> <a name = \"currentPosition\" ><-></a> </font>"); // ><-> is <-> | 588 | QStringLiteral("<a name = \"currentPosition\" ><-></a>")); // ><-> is <-> | ||
584 | } | 589 | } | ||
585 | } | 590 | } | ||
586 | } | 591 | } | ||
587 | } | 592 | } | ||
588 | 593 | | |||
589 | QString AbstractNavigationContext::currentHtml() const | 594 | QString AbstractNavigationContext::currentHtml() const | ||
590 | { | 595 | { | ||
591 | Q_D(const AbstractNavigationContext); | 596 | Q_D(const AbstractNavigationContext); | ||
592 | 597 | | |||
593 | return d->m_currentText; | 598 | return d->m_currentText; | ||
594 | } | 599 | } | ||
595 | 600 | | |||
601 | const ColorizerTheme& AbstractNavigationContext::theme() const | ||||
602 | { | ||||
603 | Q_D(const AbstractNavigationContext); | ||||
604 | | ||||
605 | return d->m_theme; | ||||
606 | } | ||||
607 | | ||||
596 | QString Colorizer::operator()(const QString& str) const | 608 | QString Colorizer::operator()(const QString& str) const | ||
597 | { | 609 | { | ||
598 | QString ret = QLatin1String("<font color=\"#") + m_color + QLatin1String("\">") + str + QLatin1String("</font>"); | 610 | QString ret = QLatin1String("<font color=\"") + m_color + QLatin1String("\">") + str + QLatin1String("</font>"); | ||
599 | 611 | | |||
600 | if (m_formatting & Fixed) | 612 | if (m_formatting & Fixed) | ||
601 | ret = QLatin1String("<tt>") + ret + QLatin1String("</tt>"); | 613 | ret = QLatin1String("<tt>") + ret + QLatin1String("</tt>"); | ||
602 | if (m_formatting & Bold) | 614 | if (m_formatting & Bold) | ||
603 | ret = QLatin1String("<b>") + ret + QLatin1String("</b>"); | 615 | ret = QLatin1String("<b>") + ret + QLatin1String("</b>"); | ||
604 | if (m_formatting & Italic) | 616 | if (m_formatting & Italic) | ||
605 | ret = QLatin1String("<i>") + ret + QLatin1String("</i>"); | 617 | ret = QLatin1String("<i>") + ret + QLatin1String("</i>"); | ||
606 | 618 | | |||
607 | return ret; | 619 | return ret; | ||
608 | } | 620 | } | ||
609 | 621 | | |||
610 | const Colorizer AbstractNavigationContext::typeHighlight(QStringLiteral("006000")); | 622 | QString ColorizerTheme::foreground(const KColorScheme& scheme, KColorScheme::ForegroundRole role) | ||
611 | const Colorizer AbstractNavigationContext::errorHighlight(QStringLiteral("990000")); | 623 | { | ||
612 | const Colorizer AbstractNavigationContext::labelHighlight(QStringLiteral("000000")); | 624 | return scheme.foreground(role).color().name(); | ||
613 | const Colorizer AbstractNavigationContext::codeHighlight(QStringLiteral("005000")); | 625 | } | ||
614 | const Colorizer AbstractNavigationContext::propertyHighlight(QStringLiteral("009900")); | 626 | | ||
615 | const Colorizer AbstractNavigationContext::navigationHighlight(QStringLiteral("000099")); | 627 | ColorizerTheme::ColorizerTheme(const KColorScheme& scheme) | ||
616 | const Colorizer AbstractNavigationContext::importantHighlight(QStringLiteral( | 628 | : typeHighlight(foreground(scheme, KColorScheme::LinkText)) | ||
617 | "000000"), Colorizer::Bold | Colorizer::Italic); | 629 | , positionHighlight(foreground(scheme, KColorScheme::LinkText)) | ||
618 | const Colorizer AbstractNavigationContext::commentHighlight(QStringLiteral("303030")); | 630 | , errorHighlight(foreground(scheme, KColorScheme::NegativeText)) | ||
619 | const Colorizer AbstractNavigationContext::nameHighlight(QStringLiteral("000000"), Colorizer::Bold); | 631 | , labelHighlight(foreground(scheme, KColorScheme::NormalText)) | ||
632 | , codeHighlight(foreground(scheme, KColorScheme::PositiveText)) | ||||
633 | , propertyHighlight(foreground(scheme, KColorScheme::NeutralText)) | ||||
634 | , navigationHighlight(foreground(scheme, KColorScheme::NormalText)) | ||||
635 | , importantHighlight(foreground(scheme, KColorScheme::ActiveText), Colorizer::Bold | Colorizer::Italic) | ||||
636 | , commentHighlight(foreground(scheme, KColorScheme::InactiveText)) | ||||
637 | , nameHighlight(foreground(scheme, KColorScheme::ActiveText), Colorizer::Bold) | ||||
638 | { | ||||
639 | } | ||||
640 | | ||||
620 | } | 641 | } |