From aa9e04aeb08e65a5f213f4207f48557b69ba0690 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Oct 2013 08:29:53 +0530 Subject: [PATCH] Highlight cursor line --- src/calibre/gui2/tweak_book/editor/text.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 0a40b9da92..67ff2cdd1c 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -9,7 +9,8 @@ __copyright__ = '2013, Kovid Goyal ' import textwrap from PyQt4.Qt import ( - QPlainTextEdit, QApplication, QFontDatabase, QToolTip, QPalette, QFont) + QPlainTextEdit, QApplication, QFontDatabase, QToolTip, QPalette, QFont, + QTextEdit, QTextFormat) from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book.editor.themes import THEMES, DEFAULT_THEME, theme_color @@ -36,6 +37,7 @@ class TextEdit(QPlainTextEdit): self.highlighter = SyntaxHighlighter(self) self.apply_theme() self.setMouseTracking(True) + self.cursorPositionChanged.connect(self.highlight_cursor_line) def apply_theme(self): theme = THEMES.get(tprefs['editor_theme'], None) @@ -44,6 +46,7 @@ class TextEdit(QPlainTextEdit): self.theme = theme pal = self.palette() pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg')) + pal.setColor(pal.AlternateBase, theme_color(theme, 'CursorLine', 'bg')) pal.setColor(pal.Text, theme_color(theme, 'Normal', 'fg')) pal.setColor(pal.Highlight, theme_color(theme, 'Visual', 'bg')) pal.setColor(pal.HighlightedText, theme_color(theme, 'Visual', 'fg')) @@ -68,6 +71,14 @@ class TextEdit(QPlainTextEdit): self.highlighter.setDocument(self.document()) self.setPlainText(text) + def highlight_cursor_line(self): + sel = QTextEdit.ExtraSelection() + sel.format.setBackground(self.palette().alternateBase()) + sel.format.setProperty(QTextFormat.FullWidthSelection, True) + sel.cursor = self.textCursor() + sel.cursor.clearSelection() + self.setExtraSelections([sel]) + def event(self, ev): if ev.type() == ev.ToolTip: self.show_tooltip(ev)