Skip to content

Commit 0de7ff8

Browse files
committed
SqlTextEdit: Highlight current line
1 parent a95d33e commit 0de7ff8

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/PreferencesDialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
177177
return QColor(Qt::darkMagenta).name();
178178
else if(name == "string_colour")
179179
return QColor(Qt::red).name();
180+
else if(name == "currentline_colour")
181+
return QColor(236, 236, 245).name();
180182
}
181183
}
182184

src/PreferencesDialog.ui

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@
267267
<string/>
268268
</property>
269269
</item>
270+
<item>
271+
<property name="text">
272+
<string>currentline</string>
273+
</property>
274+
<property name="text">
275+
<string>Current line</string>
276+
</property>
277+
</item>
270278
</widget>
271279
</item>
272280
</layout>

src/sqltextedit.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "sqltextedit.h"
2+
#include "PreferencesDialog.h"
23

34
#include <QKeyEvent>
45
#include <QAbstractItemView>
@@ -16,8 +17,10 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) :
1617
m_Completer->setWrapAround(false);
1718
m_Completer->setWidget(this);
1819

19-
QObject::connect(m_Completer, SIGNAL(activated(QString)),
20-
this, SLOT(insertCompletion(QString)));
20+
connect(m_Completer, SIGNAL(activated(QString)), this, SLOT(insertCompletion(QString)));
21+
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
22+
23+
highlightCurrentLine();
2124
}
2225

2326
SqlTextEdit::~SqlTextEdit()
@@ -91,6 +94,23 @@ void SqlTextEdit::insertCompletion(const QString& completion)
9194
setTextCursor(tc);
9295
}
9396

97+
void SqlTextEdit::highlightCurrentLine()
98+
{
99+
QList<QTextEdit::ExtraSelection> extra_selections;
100+
101+
QTextEdit::ExtraSelection selection;
102+
selection.format.setBackground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_colour").toString()));
103+
selection.format.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_bold").toBool() ? QFont::Bold : QFont::Normal);
104+
selection.format.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_italic").toBool());
105+
selection.format.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_underline").toBool());
106+
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
107+
selection.cursor = textCursor();
108+
selection.cursor.clearSelection();
109+
extra_selections.append(selection);
110+
111+
setExtraSelections(extra_selections);
112+
}
113+
94114
namespace {
95115
bool isSqliteIdentifierChar(QChar c) {
96116
return c.isLetterOrNumber() || c == '.' || c == '_';

src/sqltextedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SqlTextEdit : public QTextEdit
3737

3838
private slots:
3939
void insertCompletion(const QString& completion);
40+
void highlightCurrentLine();
4041

4142
private:
4243
QCompleter* m_Completer;

0 commit comments

Comments
 (0)