mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-04-27 07:29:13 -05: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();
|
return QColor(Qt::darkMagenta).name();
|
||||||
else if(name == "string_colour")
|
else if(name == "string_colour")
|
||||||
return QColor(Qt::red).name();
|
return QColor(Qt::red).name();
|
||||||
|
else if(name == "currentline_colour")
|
||||||
|
return QColor(236, 236, 245).name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -267,6 +267,14 @@
|
|||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>currentline</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Current line</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
+22
-2
@@ -1,4 +1,5 @@
|
|||||||
#include "sqltextedit.h"
|
#include "sqltextedit.h"
|
||||||
|
#include "PreferencesDialog.h"
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
@@ -16,8 +17,10 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) :
|
|||||||
m_Completer->setWrapAround(false);
|
m_Completer->setWrapAround(false);
|
||||||
m_Completer->setWidget(this);
|
m_Completer->setWidget(this);
|
||||||
|
|
||||||
QObject::connect(m_Completer, SIGNAL(activated(QString)),
|
connect(m_Completer, SIGNAL(activated(QString)), this, SLOT(insertCompletion(QString)));
|
||||||
this, SLOT(insertCompletion(QString)));
|
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
|
||||||
|
|
||||||
|
highlightCurrentLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
SqlTextEdit::~SqlTextEdit()
|
SqlTextEdit::~SqlTextEdit()
|
||||||
@@ -91,6 +94,23 @@ void SqlTextEdit::insertCompletion(const QString& completion)
|
|||||||
setTextCursor(tc);
|
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 {
|
namespace {
|
||||||
bool isSqliteIdentifierChar(QChar c) {
|
bool isSqliteIdentifierChar(QChar c) {
|
||||||
return c.isLetterOrNumber() || c == '.' || c == '_';
|
return c.isLetterOrNumber() || c == '.' || c == '_';
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void insertCompletion(const QString& completion);
|
void insertCompletion(const QString& completion);
|
||||||
|
void highlightCurrentLine();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QCompleter* m_Completer;
|
QCompleter* m_Completer;
|
||||||
|
|||||||
Reference in New Issue
Block a user