SqlTextEdit: Highlight current line

This commit is contained in:
Martin Kleusberg
2013-05-04 21:10:50 +02:00
parent a95d33e5ee
commit 0de7ff8564
4 changed files with 33 additions and 2 deletions

View File

@@ -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();
}
}

View File

@@ -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>

View File

@@ -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 == '_';

View File

@@ -37,6 +37,7 @@ private:
private slots:
void insertCompletion(const QString& completion);
void highlightCurrentLine();
private:
QCompleter* m_Completer;