mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
SqlTextEdit: Highlight current line
This commit is contained in:
@@ -177,6 +177,8 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
|
||||
return QColor(Qt::darkMagenta).name();
|
||||
else if(name == "string_colour")
|
||||
return QColor(Qt::red).name();
|
||||
else if(name == "currentline_colour")
|
||||
return QColor(236, 236, 245).name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -267,6 +267,14 @@
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>currentline</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Current line</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "sqltextedit.h"
|
||||
#include "PreferencesDialog.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QAbstractItemView>
|
||||
@@ -16,8 +17,10 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) :
|
||||
m_Completer->setWrapAround(false);
|
||||
m_Completer->setWidget(this);
|
||||
|
||||
QObject::connect(m_Completer, SIGNAL(activated(QString)),
|
||||
this, SLOT(insertCompletion(QString)));
|
||||
connect(m_Completer, SIGNAL(activated(QString)), this, SLOT(insertCompletion(QString)));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
|
||||
|
||||
highlightCurrentLine();
|
||||
}
|
||||
|
||||
SqlTextEdit::~SqlTextEdit()
|
||||
@@ -91,6 +94,23 @@ void SqlTextEdit::insertCompletion(const QString& completion)
|
||||
setTextCursor(tc);
|
||||
}
|
||||
|
||||
void SqlTextEdit::highlightCurrentLine()
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> extra_selections;
|
||||
|
||||
QTextEdit::ExtraSelection selection;
|
||||
selection.format.setBackground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_colour").toString()));
|
||||
selection.format.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_bold").toBool() ? QFont::Bold : QFont::Normal);
|
||||
selection.format.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_italic").toBool());
|
||||
selection.format.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_underline").toBool());
|
||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
selection.cursor = textCursor();
|
||||
selection.cursor.clearSelection();
|
||||
extra_selections.append(selection);
|
||||
|
||||
setExtraSelections(extra_selections);
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool isSqliteIdentifierChar(QChar c) {
|
||||
return c.isLetterOrNumber() || c == '.' || c == '_';
|
||||
|
||||
@@ -37,6 +37,7 @@ private:
|
||||
|
||||
private slots:
|
||||
void insertCompletion(const QString& completion);
|
||||
void highlightCurrentLine();
|
||||
|
||||
private:
|
||||
QCompleter* m_Completer;
|
||||
|
||||
Reference in New Issue
Block a user