summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/sqlview.cpp
blob: e65a60f86d2736964b3b8ebea81a6391dde4a959 (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
39
40
41
42
43
#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::setSqliteVersion(int version)
{
    highlighter->setSqliteVersion(version);
}

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