blob: 6c389159e0dd461edbfac0bdde67b4cc91eaa8bc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "sqlview.h"
#include "sqlitesyntaxhighlighter.h"
#include "uiconfig.h"
SqlView::SqlView(QWidget *parent) :
QTextEdit(parent)
{
highlighter = new SqliteSyntaxHighlighter(this->document());
setFont(CFG_UI.Fonts.SqlEditor.get());
connect(CFG_UI.Fonts.SqlEditor, SIGNAL(changed(QVariant)), this, SLOT(changeFont(QVariant)));
setReadOnly(true);
}
void SqlView::setTextBackgroundColor(int from, int to, const QColor& color)
{
bool wasRo = false;
if (isReadOnly())
{
wasRo = true;
setReadOnly(false);
}
QTextCharFormat format;
format.setBackground(color);
QTextCursor cur(document());
cur.setPosition(from);
cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, to - from + 1);
cur.mergeCharFormat(format);
if (wasRo)
setReadOnly(true);
}
void SqlView::changeFont(const QVariant &font)
{
setFont(font.value<QFont>());
}
|