forked from qt-creator/qt-creator
some tuning of the overlay search result selection
This commit is contained in:
@@ -1871,6 +1871,9 @@ void BaseTextEditorPrivate::highlightSearchResults(const QTextBlock &block,
|
|||||||
if (m_searchExpr.isEmpty())
|
if (m_searchExpr.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int blockPosition = block.position();
|
||||||
|
|
||||||
|
QTextCursor cursor = q->textCursor();
|
||||||
QString text = block.text();
|
QString text = block.text();
|
||||||
text.replace(QChar::Nbsp, QLatin1Char(' '));
|
text.replace(QChar::Nbsp, QLatin1Char(' '));
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
@@ -1885,8 +1888,8 @@ void BaseTextEditorPrivate::highlightSearchResults(const QTextBlock &block,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (m_findScope.isNull()
|
if (m_findScope.isNull()
|
||||||
|| (block.position() + idx >= m_findScope.selectionStart()
|
|| (blockPosition + idx >= m_findScope.selectionStart()
|
||||||
&& block.position() + idx + l <= m_findScope.selectionEnd())) {
|
&& blockPosition + idx + l <= m_findScope.selectionEnd())) {
|
||||||
if (selections) {
|
if (selections) {
|
||||||
QTextLayout::FormatRange selection;
|
QTextLayout::FormatRange selection;
|
||||||
selection.start = idx;
|
selection.start = idx;
|
||||||
@@ -1895,10 +1898,12 @@ void BaseTextEditorPrivate::highlightSearchResults(const QTextBlock &block,
|
|||||||
selections->append(selection);
|
selections->append(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
overlay->addOverlaySelection(block.position() + idx,
|
overlay->addOverlaySelection(blockPosition + idx,
|
||||||
block.position() + idx + l,
|
blockPosition + idx + l,
|
||||||
m_searchResultFormat.background().color().darker(120),
|
m_searchResultFormat.background().color().darker(120),
|
||||||
QColor());
|
QColor(), false,
|
||||||
|
(idx == cursor.selectionStart() - blockPosition
|
||||||
|
&& idx + l == cursor.selectionEnd() - blockPosition));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2935,7 +2940,7 @@ void BaseTextEditor::slotCursorPositionChanged()
|
|||||||
saveCurrentCursorPositionForNavigation();
|
saveCurrentCursorPositionForNavigation();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->m_parenthesesMatchingEnabled) {
|
if (d->m_parenthesesMatchingEnabled && hasFocus()) {
|
||||||
// Delay update when no matching is displayed yet, to avoid flicker
|
// Delay update when no matching is displayed yet, to avoid flicker
|
||||||
if (extraSelections(ParenthesesMatchingSelection).isEmpty()
|
if (extraSelections(ParenthesesMatchingSelection).isEmpty()
|
||||||
&& d->m_animator == 0) {
|
&& d->m_animator == 0) {
|
||||||
@@ -4268,6 +4273,12 @@ void BaseTextEditor::changeEvent(QEvent *e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::focusInEvent(QFocusEvent *e)
|
||||||
|
{
|
||||||
|
QPlainTextEdit::focusInEvent(e);
|
||||||
|
slotCursorPositionChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditor::focusOutEvent(QFocusEvent *e)
|
void BaseTextEditor::focusOutEvent(QFocusEvent *e)
|
||||||
{
|
{
|
||||||
QPlainTextEdit::focusOutEvent(e);
|
QPlainTextEdit::focusOutEvent(e);
|
||||||
|
@@ -418,6 +418,7 @@ protected:
|
|||||||
void keyPressEvent(QKeyEvent *e);
|
void keyPressEvent(QKeyEvent *e);
|
||||||
void wheelEvent(QWheelEvent *e);
|
void wheelEvent(QWheelEvent *e);
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
|
void focusInEvent(QFocusEvent *e);
|
||||||
void focusOutEvent(QFocusEvent *e);
|
void focusOutEvent(QFocusEvent *e);
|
||||||
|
|
||||||
void showEvent(QShowEvent *);
|
void showEvent(QShowEvent *);
|
||||||
|
@@ -37,7 +37,9 @@ void TextEditorOverlay::clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorOverlay::addOverlaySelection(int begin, int end,
|
void TextEditorOverlay::addOverlaySelection(int begin, int end,
|
||||||
const QColor &fg, const QColor &bg, bool lockSize)
|
const QColor &fg, const QColor &bg,
|
||||||
|
bool lockSize,
|
||||||
|
bool dropShadow)
|
||||||
{
|
{
|
||||||
if (end < begin)
|
if (end < begin)
|
||||||
return;
|
return;
|
||||||
@@ -57,6 +59,8 @@ void TextEditorOverlay::addOverlaySelection(int begin, int end,
|
|||||||
if (lockSize)
|
if (lockSize)
|
||||||
selection.m_fixedLength = (end - begin);
|
selection.m_fixedLength = (end - begin);
|
||||||
|
|
||||||
|
selection.m_dropShadow = dropShadow;
|
||||||
|
|
||||||
m_selections += selection;
|
m_selections += selection;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@@ -232,9 +236,16 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorOverlay::paintSelection(QPainter *painter, const QTextCursor &begin, const QTextCursor &end,
|
void TextEditorOverlay::paintSelection(QPainter *painter,
|
||||||
const QColor &fg, const QColor &bg)
|
const OverlaySelection &selection)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const QTextCursor &begin = selection.m_cursor_begin;
|
||||||
|
const QTextCursor &end= selection.m_cursor_end;
|
||||||
|
const QColor &fg = selection.m_fg;
|
||||||
|
const QColor &bg = selection.m_bg;
|
||||||
|
|
||||||
|
|
||||||
if (begin.isNull() || end.isNull() || begin.position() > end.position())
|
if (begin.isNull() || end.isNull() || begin.position() > end.position())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -268,9 +279,12 @@ void TextEditorOverlay::paintSelection(QPainter *painter, const QTextCursor &beg
|
|||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorOverlay::fillSelection(QPainter *painter, const QTextCursor &begin, const QTextCursor &end,
|
void TextEditorOverlay::fillSelection(QPainter *painter,
|
||||||
|
const OverlaySelection &selection,
|
||||||
const QColor &color)
|
const QColor &color)
|
||||||
{
|
{
|
||||||
|
const QTextCursor &begin = selection.m_cursor_begin;
|
||||||
|
const QTextCursor &end= selection.m_cursor_end;
|
||||||
if (begin.isNull() || end.isNull() || begin.position() > end.position())
|
if (begin.isNull() || end.isNull() || begin.position() > end.position())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -279,6 +293,11 @@ void TextEditorOverlay::fillSelection(QPainter *painter, const QTextCursor &begi
|
|||||||
painter->save();
|
painter->save();
|
||||||
painter->translate(-.5, -.5);
|
painter->translate(-.5, -.5);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
if (selection.m_dropShadow) {
|
||||||
|
painter->translate(2, 2);
|
||||||
|
painter->fillPath(path, QColor(0, 0, 0, 100));
|
||||||
|
painter->translate(-2, -2);
|
||||||
|
}
|
||||||
painter->fillPath(path, color);
|
painter->fillPath(path, color);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
@@ -293,12 +312,7 @@ void TextEditorOverlay::paint(QPainter *painter, const QRect &clip)
|
|||||||
!= selection.m_fixedLength)
|
!= selection.m_fixedLength)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
paintSelection(painter,
|
paintSelection(painter, selection);
|
||||||
selection.m_cursor_begin,
|
|
||||||
selection.m_cursor_end,
|
|
||||||
selection.m_fg,
|
|
||||||
selection.m_bg
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,11 +326,7 @@ void TextEditorOverlay::fill(QPainter *painter, const QColor &color, const QRect
|
|||||||
!= selection.m_fixedLength)
|
!= selection.m_fixedLength)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fillSelection(painter,
|
fillSelection(painter, selection, color);
|
||||||
selection.m_cursor_begin,
|
|
||||||
selection.m_cursor_end,
|
|
||||||
color
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,12 +8,13 @@ namespace TextEditor {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
struct TEXTEDITOR_EXPORT OverlaySelection {
|
struct TEXTEDITOR_EXPORT OverlaySelection {
|
||||||
OverlaySelection():m_fixedLength(-1){}
|
OverlaySelection():m_fixedLength(-1), m_dropShadow(false){}
|
||||||
QTextCursor m_cursor_begin;
|
QTextCursor m_cursor_begin;
|
||||||
QTextCursor m_cursor_end;
|
QTextCursor m_cursor_end;
|
||||||
QColor m_fg;
|
QColor m_fg;
|
||||||
QColor m_bg;
|
QColor m_bg;
|
||||||
int m_fixedLength;
|
int m_fixedLength;
|
||||||
|
bool m_dropShadow;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT TextEditorOverlay : public QObject
|
class TEXTEDITOR_EXPORT TextEditorOverlay : public QObject
|
||||||
@@ -47,16 +48,14 @@ public:
|
|||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void addOverlaySelection(const QTextCursor &cursor, const QColor &fg, const QColor &bg, bool lockSize = false);
|
void addOverlaySelection(const QTextCursor &cursor, const QColor &fg, const QColor &bg, bool lockSize = false);
|
||||||
void addOverlaySelection(int begin, int end, const QColor &fg, const QColor &bg, bool lockSize = false);
|
void addOverlaySelection(int begin, int end, const QColor &fg, const QColor &bg, bool lockSize = false, bool dropShadow = false);
|
||||||
|
|
||||||
inline bool isEmpty() const { return m_selections.isEmpty(); }
|
inline bool isEmpty() const { return m_selections.isEmpty(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPainterPath createSelectionPath(const QTextCursor &begin, const QTextCursor &end, const QRect& clip);
|
QPainterPath createSelectionPath(const QTextCursor &begin, const QTextCursor &end, const QRect& clip);
|
||||||
void paintSelection(QPainter *painter, const QTextCursor &begin, const QTextCursor &end,
|
void paintSelection(QPainter *painter, const OverlaySelection &selection);
|
||||||
const QColor &fg, const QColor &bg);
|
void fillSelection(QPainter *painter, const OverlaySelection &selection, const QColor &color);
|
||||||
void fillSelection(QPainter *painter, const QTextCursor &begin, const QTextCursor &end,
|
|
||||||
const QColor &color);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user