diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index e87e533a639007b860d66f0a032983560285b275..a5192acdf917ba6aa58a3e2fb693eb2088177ab5 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -1889,6 +1889,10 @@ void CPPEditor::setFontSettings(const TextEditor::FontSettings &fs) m_occurrencesFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES)); m_occurrencesUnusedFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_UNUSED)); + m_occurrencesUnusedFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); + m_occurrencesUnusedFormat.setUnderlineColor(m_occurrencesUnusedFormat.foreground().color()); + m_occurrencesUnusedFormat.clearForeground(); + m_occurrencesUnusedFormat.setToolTip(tr("Unused variable")); m_occurrenceRenameFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_RENAME)); // only set the background, we do not want to modify foreground properties set by the syntax highlighter or the link diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp index 6c93ca8ffa5ea5c2e67cdeedc0437312e1d7cea9..46315187a07474b8f00e0a6441235cb41d90805a 100644 --- a/src/plugins/cppeditor/cpphoverhandler.cpp +++ b/src/plugins/cppeditor/cpphoverhandler.cpp @@ -272,8 +272,10 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in if (!doc) return; // nothing to do + QString formatTooltip = edit->extraSelectionTooltip(pos); QTextCursor tc(edit->document()); tc.setPosition(pos); + const unsigned lineNumber = tc.block().blockNumber() + 1; // Find the last symbol up to the cursor position @@ -392,6 +394,11 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in m_helpEngineNeedsSetup = false; } + + if (!formatTooltip.isEmpty()) { + m_toolTip = formatTooltip; + } + if (!m_toolTip.isEmpty()) m_toolTip = Qt::escape(m_toolTip); diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 625bb8bee562e45b57fc5d80ade256e9da3154c3..501ef46377d3e99c52bafeda3017944f716e4a83 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -4239,6 +4239,21 @@ QList<QTextEdit::ExtraSelection> BaseTextEditor::extraSelections(ExtraSelectionK return d->m_extraSelections[kind]; } +QString BaseTextEditor::extraSelectionTooltip(int pos) const +{ + QList<QTextEdit::ExtraSelection> all; + for (int i = 0; i < NExtraSelectionKinds; ++i) { + const QList<QTextEdit::ExtraSelection> &sel = d->m_extraSelections[i]; + for (int j = 0; j < sel.size(); ++j) { + const QTextEdit::ExtraSelection &s = sel.at(j); + if (s.cursor.selectionStart() <= pos + && s.cursor.selectionEnd() >= pos + && !s.format.toolTip().isEmpty()) + return s.format.toolTip(); + } + } + return QString(); +} // the blocks list must be sorted void BaseTextEditor::setIfdefedOutBlocks(const QList<BaseTextEditor::BlockRange> &blocks) diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 9a04cf6076f14cfcaa2597f746b0dfddb03a845e..0dc8eb005cdbc352ad13597ee2d845c51c927d07 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -478,6 +478,7 @@ public: }; void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections); QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const; + QString extraSelectionTooltip(int pos) const; struct BlockRange { diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp index 18880da65f615a5bc786ae5ecf7540e9ead4e7e2..0fb51ebd17fa89fa567ea608cf0dfb21792c46b8 100644 --- a/src/plugins/texteditor/fontsettingspage.cpp +++ b/src/plugins/texteditor/fontsettingspage.cpp @@ -258,7 +258,7 @@ QColor FormatDescription::foreground() const return m_format.foreground(); } } else if (m_name == QLatin1String(Constants::C_OCCURRENCES_UNUSED)) { - return Qt::lightGray; + return Qt::darkYellow; } else if (m_name == QLatin1String(Constants::C_PARENTHESES)) { return QColor(Qt::red); } diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp index 5c9d621a836b6ee6bd53fe382605d6485d9e4c20..9b76385efc9a51c6a4602ba9ad7b932dad89a1b5 100644 --- a/src/plugins/texteditor/texteditoroverlay.cpp +++ b/src/plugins/texteditor/texteditoroverlay.cpp @@ -159,6 +159,7 @@ void TextEditorOverlay::paintSelection(QPainter *painter, const QTextCursor &beg QVector<QPointF> points; const int margin = m_borderWidth/2; + const int extra = 0; points += (selection.at(0).topLeft() + selection.at(0).topRight()) / 2 + QPointF(0, -margin); points += selection.at(0).topRight() + QPointF(margin+1, -margin); @@ -178,8 +179,8 @@ void TextEditorOverlay::paintSelection(QPainter *painter, const QTextCursor &beg } points += selection.at(selection.count()-1).topRight() + QPointF(margin+1, 0); - points += selection.at(selection.count()-1).bottomRight() + QPointF(margin+1, margin+1); - points += selection.at(selection.count()-1).bottomLeft() + QPointF(-margin, margin+1); + points += selection.at(selection.count()-1).bottomRight() + QPointF(margin+1, margin+extra); + points += selection.at(selection.count()-1).bottomLeft() + QPointF(-margin, margin+extra); points += selection.at(selection.count()-1).topLeft() + QPointF(-margin, 0); for(int i = selection.count()-2; i > 0; --i) { @@ -188,11 +189,11 @@ void TextEditorOverlay::paintSelection(QPainter *painter, const QTextCursor &beg selection.at(i).left(), selection.at(i+1).left()) - margin; - points += QPointF(x, selection.at(i).bottom()+1); + points += QPointF(x, selection.at(i).bottom()+extra); points += QPointF(x, selection.at(i).top()); } - points += selection.at(0).bottomLeft() + QPointF(-margin, 1); + points += selection.at(0).bottomLeft() + QPointF(-margin, extra); points += selection.at(0).topLeft() + QPointF(-margin, -margin); @@ -225,15 +226,28 @@ void TextEditorOverlay::paintSelection(QPainter *painter, const QTextCursor &beg path.closeSubpath(); painter->save(); - QPen pen(color, m_borderWidth); + QColor penColor = color; + penColor.setAlpha(220); + QPen pen(penColor, m_borderWidth); painter->translate(-.5, -.5); - QColor brush = color; - brush.setAlpha(30); + + path.translate(offset); + QRectF pathRect = path.controlPointRect(); + + QLinearGradient linearGrad(pathRect.topLeft(), pathRect.bottomLeft()); + QColor col1 = color.lighter(150); + col1.setAlpha(20); + QColor col2 = color; + col2.setAlpha(80); + linearGrad.setColorAt(0, col1); + linearGrad.setColorAt(1, col2); + QBrush brush(linearGrad); + + painter->setRenderHint(QPainter::Antialiasing); pen.setJoinStyle(Qt::RoundJoin); painter->setPen(pen); painter->setBrush(brush); - path.translate(offset); painter->drawPath(path); painter->restore(); }