MCPcopy Create free account
hub / github.com/KDE/kdevelop / OneUseWidget

Method OneUseWidget

kdevplatform/language/duchain/navigation/useswidget.cpp:109–158  ·  view source on GitHub ↗

* Note: the links in the HTML here are only used for styling * the navigation is implemented in the mouse press event handler */

Source from the content-addressed store, hash-verified

107 * the navigation is implemented in the mouse press event handler
108 */
109OneUseWidget::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("&nbsp;&nbsp;") + 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
160void OneUseWidget::setHighlighted(bool highlight)
161{

Callers

nothing calls this directly

Calls 14

pixmapMethod · 0.80
toHtmlEscapedMethod · 0.80
joinMethod · 0.80
lineMethod · 0.45
startMethod · 0.45
rangeMethod · 0.45
isEmptyMethod · 0.45
lengthMethod · 0.45
columnMethod · 0.45
endMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected