* Note: the links in the HTML here are only used for styling * the navigation is implemented in the mouse press event handler */
| 107 | * the navigation is implemented in the mouse press event handler |
| 108 | */ |
| 109 | OneUseWidget::OneUseWidget(IndexedDeclaration declaration, const IndexedString& document, KTextEditor::Range range, |
| 110 | const CodeRepresentation& code) : m_range(new PersistentMovingRange(range, document)) |
| 111 | , m_declaration(declaration) |
| 112 | , m_document(document) |
| 113 | { |
| 114 | //Make the sizing of this widget independent of the content, because we will adapt the content to the size |
| 115 | setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); |
| 116 | |
| 117 | m_sourceLine = code.line(m_range->range().start().line()); |
| 118 | |
| 119 | m_layout = new QHBoxLayout(this); |
| 120 | m_layout->setContentsMargins(0, 0, 0, 0); |
| 121 | setLayout(m_layout); |
| 122 | |
| 123 | setCursor(Qt::PointingHandCursor); |
| 124 | |
| 125 | m_label = new QLabel(this); |
| 126 | m_icon = new QLabel(this); |
| 127 | m_icon->setPixmap(QIcon::fromTheme(QStringLiteral("code-function")).pixmap(16)); |
| 128 | |
| 129 | DUChainReadLocker lock(DUChain::lock()); |
| 130 | QString text = QLatin1String("<a>") + i18nc("refers to a line in source code", "Line <b>%1</b>:", |
| 131 | range.start().line()) + QLatin1String("</a>"); |
| 132 | if (!m_sourceLine.isEmpty() && m_sourceLine.length() > m_range->range().end().column()) { |
| 133 | text += QLatin1String(" ") + highlightAndEscapeUseText(m_sourceLine, 0, m_range->range()); |
| 134 | |
| 135 | //Useful tooltip: |
| 136 | int start = m_range->range().start().line() - tooltipContextSize; |
| 137 | int end = m_range->range().end().line() + tooltipContextSize + 1; |
| 138 | |
| 139 | QStringList toolTipLines; |
| 140 | for (int a = start; a < end; ++a) { |
| 141 | QString lineText = code.line(a).toHtmlEscaped(); |
| 142 | if (m_range->range().start().line() <= a && m_range->range().end().line() >= a) { |
| 143 | lineText = QLatin1String("<b>") + lineText + QLatin1String("</b>"); |
| 144 | } |
| 145 | if (!lineText.trimmed().isEmpty()) { |
| 146 | toolTipLines.append(lineText); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | setToolTip(QLatin1String("<html><body><pre>") + toolTipLines.join(QLatin1String("<br>")) + |
| 151 | QLatin1String("</pre></body></html>")); |
| 152 | } |
| 153 | m_label->setText(text); |
| 154 | |
| 155 | m_layout->addWidget(m_icon); |
| 156 | m_layout->addWidget(m_label); |
| 157 | m_layout->setAlignment(Qt::AlignLeft); |
| 158 | } |
| 159 | |
| 160 | void OneUseWidget::setHighlighted(bool highlight) |
| 161 | { |
nothing calls this directly
no test coverage detected