Commit 32d0bc1f authored by mae's avatar mae
Browse files

some tuning of the layer extra selections

Remove overlap. Add extra selection tooltips for the cpp hover handler.
parent 16fcb82d
......@@ -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
......
......@@ -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);
......
......@@ -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)
......
......@@ -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
{
......
......@@ -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);
}
......
......@@ -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();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment