Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/duchain/navigation/useswidget.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 66 | { | |||
---|---|---|---|---|---|
101 | range += KTextEditor::Range(0, -leftCut, 0, -leftCut); | 101 | range += KTextEditor::Range(0, -leftCut, 0, -leftCut); | ||
102 | 102 | | |||
103 | Q_ASSERT(range.start().column() >= 0 && range.end().column() <= line.length()); | 103 | Q_ASSERT(range.start().column() >= 0 && range.end().column() <= line.length()); | ||
104 | 104 | | |||
105 | //TODO: share code with context browser | 105 | //TODO: share code with context browser | ||
106 | // mixing (255, 255, 0, 100) with white yields this: | 106 | // mixing (255, 255, 0, 100) with white yields this: | ||
107 | const QColor foreground(0, 0, 0); | 107 | const QColor foreground(0, 0, 0); | ||
108 | 108 | | |||
109 | return "<code>" + line.left(range.start().column()).toHtmlEscaped() | 109 | return QLatin1String("<code>") + line.left(range.start().column()).toHtmlEscaped() | ||
110 | + "<span style=\"background-color:" + backgroundColor(false) + ";color:" + foreground.name() + ";\">" | 110 | + QLatin1String("<span style=\"background-color:") + backgroundColor(false) + QLatin1String(";color:") + foreground.name() + QLatin1String(";\">") | ||
111 | + line.mid(range.start().column(), range.end().column() - range.start().column()).toHtmlEscaped() | 111 | + line.mid(range.start().column(), range.end().column() - range.start().column()).toHtmlEscaped() | ||
112 | + "</span>" + line.mid(range.end().column(), line.length() - range.end().column()).toHtmlEscaped() + "</code>"; | 112 | + QLatin1String("</span>") + line.mid(range.end().column(), line.length() - range.end().column()).toHtmlEscaped() + QLatin1String("</code>"); | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | /** | 115 | /** | ||
116 | * Note: the links in the HTML here are only used for styling | 116 | * Note: the links in the HTML here are only used for styling | ||
117 | * the navigation is implemented in the mouse press event handler | 117 | * the navigation is implemented in the mouse press event handler | ||
118 | */ | 118 | */ | ||
119 | OneUseWidget::OneUseWidget(IndexedDeclaration declaration, const IndexedString& document, KTextEditor::Range range, const CodeRepresentation& code) : m_range(new PersistentMovingRange(range, document)), m_declaration(declaration), m_document(document) { | 119 | OneUseWidget::OneUseWidget(IndexedDeclaration declaration, const IndexedString& document, KTextEditor::Range range, const CodeRepresentation& code) : m_range(new PersistentMovingRange(range, document)), m_declaration(declaration), m_document(document) { | ||
120 | 120 | | |||
121 | //Make the sizing of this widget independent of the content, because we will adapt the content to the size | 121 | //Make the sizing of this widget independent of the content, because we will adapt the content to the size | ||
122 | setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); | 122 | setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); | ||
123 | 123 | | |||
124 | m_sourceLine = code.line(m_range->range().start().line()); | 124 | m_sourceLine = code.line(m_range->range().start().line()); | ||
125 | 125 | | |||
126 | m_layout = new QHBoxLayout(this); | 126 | m_layout = new QHBoxLayout(this); | ||
127 | m_layout->setContentsMargins(0, 0, 0, 0); | 127 | m_layout->setContentsMargins(0, 0, 0, 0); | ||
128 | setLayout(m_layout); | 128 | setLayout(m_layout); | ||
129 | 129 | | |||
130 | setCursor(Qt::PointingHandCursor); | 130 | setCursor(Qt::PointingHandCursor); | ||
131 | 131 | | |||
132 | m_label = new QLabel(this); | 132 | m_label = new QLabel(this); | ||
133 | m_icon = new QLabel(this); | 133 | m_icon = new QLabel(this); | ||
134 | m_icon->setPixmap(QIcon::fromTheme(QStringLiteral("code-function")).pixmap(16)); | 134 | m_icon->setPixmap(QIcon::fromTheme(QStringLiteral("code-function")).pixmap(16)); | ||
135 | 135 | | |||
136 | DUChainReadLocker lock(DUChain::lock()); | 136 | DUChainReadLocker lock(DUChain::lock()); | ||
137 | QString text = "<a>" + i18nc("refers to a line in source code", "Line <b>%1</b>:", range.start().line()) + QStringLiteral("</a>"); | 137 | QString text = QLatin1String("<a>") + i18nc("refers to a line in source code", "Line <b>%1</b>:", range.start().line()) + QStringLiteral("</a>"); | ||
138 | if(!m_sourceLine.isEmpty() && m_sourceLine.length() > m_range->range().end().column()) { | 138 | if(!m_sourceLine.isEmpty() && m_sourceLine.length() > m_range->range().end().column()) { | ||
139 | 139 | | |||
140 | text += " " + highlightAndEscapeUseText(m_sourceLine, 0, m_range->range()); | 140 | text += QLatin1String(" ") + highlightAndEscapeUseText(m_sourceLine, 0, m_range->range()); | ||
141 | 141 | | |||
142 | //Useful tooltip: | 142 | //Useful tooltip: | ||
143 | int start = m_range->range().start().line() - tooltipContextSize; | 143 | int start = m_range->range().start().line() - tooltipContextSize; | ||
144 | int end = m_range->range().end().line() + tooltipContextSize + 1; | 144 | int end = m_range->range().end().line() + tooltipContextSize + 1; | ||
145 | 145 | | |||
146 | QString toolTipText; | 146 | QString toolTipText; | ||
147 | for(int a = start; a < end; ++a) { | 147 | for(int a = start; a < end; ++a) { | ||
148 | QString lineText = code.line(a).toHtmlEscaped(); | 148 | QString lineText = code.line(a).toHtmlEscaped(); | ||
149 | if (m_range->range().start().line() <= a && m_range->range().end().line() >= a) { | 149 | if (m_range->range().start().line() <= a && m_range->range().end().line() >= a) { | ||
150 | lineText = QStringLiteral("<b>") + lineText + QStringLiteral("</b>"); | 150 | lineText = QStringLiteral("<b>") + lineText + QStringLiteral("</b>"); | ||
151 | } | 151 | } | ||
152 | if(!lineText.trimmed().isEmpty()) { | 152 | if(!lineText.trimmed().isEmpty()) { | ||
153 | toolTipText += lineText + "<br>"; | 153 | toolTipText += lineText + QLatin1String("<br>"); | ||
154 | } | 154 | } | ||
155 | } | 155 | } | ||
156 | if ( toolTipText.endsWith(QLatin1String("<br>")) ) { | 156 | if ( toolTipText.endsWith(QLatin1String("<br>")) ) { | ||
157 | toolTipText.remove(toolTipText.length() - 4, 4); | 157 | toolTipText.remove(toolTipText.length() - 4, 4); | ||
158 | } | 158 | } | ||
159 | setToolTip(QStringLiteral("<html><body><pre>") + toolTipText + QStringLiteral("</pre></body></html>")); | 159 | setToolTip(QStringLiteral("<html><body><pre>") + toolTipText + QStringLiteral("</pre></body></html>")); | ||
160 | } | 160 | } | ||
161 | m_label->setText(text); | 161 | m_label->setText(text); | ||
162 | 162 | | |||
163 | m_layout->addWidget(m_icon); | 163 | m_layout->addWidget(m_icon); | ||
164 | m_layout->addWidget(m_label); | 164 | m_layout->addWidget(m_label); | ||
165 | m_layout->setAlignment(Qt::AlignLeft); | 165 | m_layout->setAlignment(Qt::AlignLeft); | ||
166 | } | 166 | } | ||
167 | 167 | | |||
168 | void OneUseWidget::setHighlighted(bool highlight) | 168 | void OneUseWidget::setHighlighted(bool highlight) | ||
169 | { | 169 | { | ||
170 | if (highlight == m_isHighlighted) { | 170 | if (highlight == m_isHighlighted) { | ||
171 | return; | 171 | return; | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | if (highlight) { | 174 | if (highlight) { | ||
175 | m_label->setText(m_label->text().replace("background-color:" + backgroundColor(false), "background-color:" + backgroundColor(true))); | 175 | m_label->setText(m_label->text().replace(QLatin1String("background-color:") + backgroundColor(false), | ||
176 | QLatin1String("background-color:") + backgroundColor(true))); | ||||
176 | m_isHighlighted = true; | 177 | m_isHighlighted = true; | ||
177 | } else { | 178 | } else { | ||
178 | m_label->setText(m_label->text().replace("background-color:" + backgroundColor(true), "background-color:" + backgroundColor(false))); | 179 | m_label->setText(m_label->text().replace(QLatin1String("background-color:") + backgroundColor(true), | ||
180 | QLatin1String("background-color:") + backgroundColor(false))); | ||||
179 | m_isHighlighted = false; | 181 | m_isHighlighted = false; | ||
180 | } | 182 | } | ||
181 | } | 183 | } | ||
182 | 184 | | |||
183 | bool KDevelop::OneUseWidget::isHighlighted() const | 185 | bool KDevelop::OneUseWidget::isHighlighted() const | ||
184 | { | 186 | { | ||
185 | return m_isHighlighted; | 187 | return m_isHighlighted; | ||
186 | } | 188 | } | ||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Line(s) | 398 | foreach(const IndexedDeclaration usedDeclaration, usedDeclarations) { | |||
402 | 404 | | |||
403 | if(usedDeclarationIndex != std::numeric_limits<int>::max()) { | 405 | if(usedDeclarationIndex != std::numeric_limits<int>::max()) { | ||
404 | foreach(OneUseWidget* widget, createUseWidgets(code, usedDeclarationIndex, usedDeclaration, ctx)) | 406 | foreach(OneUseWidget* widget, createUseWidgets(code, usedDeclarationIndex, usedDeclaration, ctx)) | ||
405 | addItem(widget); | 407 | addItem(widget); | ||
406 | } | 408 | } | ||
407 | } | 409 | } | ||
408 | } | 410 | } | ||
409 | 411 | | |||
410 | QLabel* headerLabel = new QLabel(i18nc("%1: source file", "In %1", "<a href='navigateToFunction'>" | 412 | QLabel* headerLabel = new QLabel(i18nc("%1: source file", "In %1", QLatin1String("<a href='navigateToFunction'>") | ||
411 | + headerText.toHtmlEscaped() + "</a>: ")); | 413 | + headerText.toHtmlEscaped() + QLatin1String("</a>: "))); | ||
412 | addHeaderItem(headerLabel); | 414 | addHeaderItem(headerLabel); | ||
413 | setUpdatesEnabled(true); | 415 | setUpdatesEnabled(true); | ||
414 | connect(headerLabel, &QLabel::linkActivated, this, &ContextUsesWidget::linkWasActivated); | 416 | connect(headerLabel, &QLabel::linkActivated, this, &ContextUsesWidget::linkWasActivated); | ||
415 | } | 417 | } | ||
416 | 418 | | |||
417 | void ContextUsesWidget::linkWasActivated(const QString& link) { | 419 | void ContextUsesWidget::linkWasActivated(const QString& link) { | ||
418 | if ( link == QLatin1String("navigateToFunction") ) { | 420 | if ( link == QLatin1String("navigateToFunction") ) { | ||
419 | DUChainReadLocker lock(DUChain::lock()); | 421 | DUChainReadLocker lock(DUChain::lock()); | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 454 | { | |||
471 | 473 | | |||
472 | if(topContext.isLoaded()) | 474 | if(topContext.isLoaded()) | ||
473 | m_usesCount = DUChainUtils::contextCountUses(topContext.data(), declaration.data()); | 475 | m_usesCount = DUChainUtils::contextCountUses(topContext.data(), declaration.data()); | ||
474 | 476 | | |||
475 | QString labelText = i18ncp("%1: number of uses, %2: filename with uses", "%2: 1 use", "%2: %1 uses", | 477 | QString labelText = i18ncp("%1: number of uses, %2: filename with uses", "%2: 1 use", "%2: %1 uses", | ||
476 | m_usesCount, ICore::self()->projectController()->prettyFileName(topContext.url().toUrl())); | 478 | m_usesCount, ICore::self()->projectController()->prettyFileName(topContext.url().toUrl())); | ||
477 | label->setText(labelText); | 479 | label->setText(labelText); | ||
478 | 480 | | |||
479 | m_toggleButton->setText(" <a href='toggleCollapsed'>[" + i18nc("Refers to closing a UI element", "Collapse") + "]</a>"); | 481 | m_toggleButton->setText(QLatin1String(" <a href='toggleCollapsed'>[") + i18nc("Refers to closing a UI element", "Collapse") + QLatin1String("]</a>")); | ||
480 | 482 | | |||
481 | connect(m_toggleButton, &QLabel::linkActivated, this, &TopContextUsesWidget::labelClicked); | 483 | connect(m_toggleButton, &QLabel::linkActivated, this, &TopContextUsesWidget::labelClicked); | ||
482 | addHeaderItem(headerWidget); | 484 | addHeaderItem(headerWidget); | ||
483 | setUpdatesEnabled(true); | 485 | setUpdatesEnabled(true); | ||
484 | } | 486 | } | ||
485 | 487 | | |||
486 | int TopContextUsesWidget::usesCount() const | 488 | int TopContextUsesWidget::usesCount() const | ||
487 | { | 489 | { | ||
Show All 14 Lines | 493 | QList<ContextUsesWidget*> buildContextUses(const CodeRepresentation& code, const QList<IndexedDeclaration>& declarations, DUContext* context) { | |||
502 | foreach(DUContext* child, context->childContexts()) | 504 | foreach(DUContext* child, context->childContexts()) | ||
503 | ret += buildContextUses(code, declarations, child); | 505 | ret += buildContextUses(code, declarations, child); | ||
504 | 506 | | |||
505 | return ret; | 507 | return ret; | ||
506 | } | 508 | } | ||
507 | 509 | | |||
508 | void TopContextUsesWidget::setExpanded(bool expanded) { | 510 | void TopContextUsesWidget::setExpanded(bool expanded) { | ||
509 | if(!expanded) { | 511 | if(!expanded) { | ||
510 | m_toggleButton->setText(" <a href='toggleCollapsed'>[" + i18nc("Refers to opening a UI element", "Expand") + "]</a>"); | 512 | m_toggleButton->setText(QLatin1String(" <a href='toggleCollapsed'>[") + i18nc("Refers to opening a UI element", "Expand") + QLatin1String("]</a>")); | ||
511 | deleteItems(); | 513 | deleteItems(); | ||
512 | }else{ | 514 | }else{ | ||
513 | m_toggleButton->setText(" <a href='toggleCollapsed'>[" + i18nc("Refers to closing a UI element", "Collapse") + "]</a>"); | 515 | m_toggleButton->setText(QLatin1String(" <a href='toggleCollapsed'>[") + i18nc("Refers to closing a UI element", "Collapse") + QLatin1String("]</a>")); | ||
514 | if(hasItems()) | 516 | if(hasItems()) | ||
515 | return; | 517 | return; | ||
516 | DUChainReadLocker lock(DUChain::lock()); | 518 | DUChainReadLocker lock(DUChain::lock()); | ||
517 | TopDUContext* topContext = m_topContext.data(); | 519 | TopDUContext* topContext = m_topContext.data(); | ||
518 | 520 | | |||
519 | if(topContext && m_declaration.data()) { | 521 | if(topContext && m_declaration.data()) { | ||
520 | 522 | | |||
521 | CodeRepresentation::Ptr code = createCodeRepresentation(topContext->url()); | 523 | CodeRepresentation::Ptr code = createCodeRepresentation(topContext->url()); | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | |||||
583 | 585 | | |||
584 | void UsesWidget::redrawHeaderLine() | 586 | void UsesWidget::redrawHeaderLine() | ||
585 | { | 587 | { | ||
586 | m_headerLine->setText(headerLineText()); | 588 | m_headerLine->setText(headerLineText()); | ||
587 | } | 589 | } | ||
588 | 590 | | |||
589 | const QString UsesWidget::headerLineText() const | 591 | const QString UsesWidget::headerLineText() const | ||
590 | { | 592 | { | ||
591 | return i18np("1 use found", "%1 uses found", countAllUses()) + " • " | 593 | return i18np("1 use found", "%1 uses found", countAllUses()) + QLatin1String(" • " | ||
592 | "<a href='expandAll'>[" + i18n("Expand all") + "]</a> • " | 594 | "<a href='expandAll'>[") + i18n("Expand all") + QLatin1String("]</a> • " | ||
593 | "<a href='collapseAll'>[" + i18n("Collapse all") + "]</a>"; | 595 | "<a href='collapseAll'>[") + i18n("Collapse all") + QLatin1String("]</a>"); | ||
594 | } | 596 | } | ||
595 | 597 | | |||
596 | unsigned int UsesWidget::countAllUses() const | 598 | unsigned int UsesWidget::countAllUses() const | ||
597 | { | 599 | { | ||
598 | unsigned int totalUses = 0; | 600 | unsigned int totalUses = 0; | ||
599 | foreach ( QWidget* w, items() ) { | 601 | foreach ( QWidget* w, items() ) { | ||
600 | if ( TopContextUsesWidget* useWidget = dynamic_cast<TopContextUsesWidget*>(w) ) { | 602 | if ( TopContextUsesWidget* useWidget = dynamic_cast<TopContextUsesWidget*>(w) ) { | ||
601 | totalUses += useWidget->usesCount(); | 603 | totalUses += useWidget->usesCount(); | ||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |