Exemple #1
0
SqlEditorWidget::SqlEditorWidget(QWidget * parent)
    : QsciScintilla(parent),
      m_searchText(""),
      m_searchIndicator(9) // see QsciScintilla docs
{
    m_prefs = Preferences::instance();

    setMarginLineNumbers(0, true);
    setBraceMatching(SloppyBraceMatch);
    setAutoIndent(true);

    QsciLexerSQL * lexer = new QsciLexerSQL(this);

    QsciAPIs * api = new QsciAPIs(lexer);
    if (!api->load(":/api/sqlite.api"))
        qDebug("api is not loaded");
    else
    {
        api->prepare();
        lexer->setAPIs(api);
    }
    setAutoCompletionSource(QsciScintilla::AcsAll);
    setAutoCompletionCaseSensitivity(false);
    setAutoCompletionReplaceWord(true);

    setCaretLineVisible(m_prefs->activeHighlighting());
    setCaretLineBackgroundColor(m_prefs->activeHighlightColor());
    setUtf8(true);

    setFolding(QsciScintilla::BoxedFoldStyle);
    lexer->setFoldComments(true);
    lexer->setFoldCompact(false);

    setLexer(lexer);

    // search all occurrences
    // allow indicator painting *under* the text (but it makes editor slower a bit...)
    // It paints a colored box under the text for all occurrences of m_searchText.
    SendScintilla(QsciScintilla::SCI_SETTWOPHASEDRAW, 1);
    SendScintilla(QsciScintilla::SCI_INDICSETSTYLE, m_searchIndicator, QsciScintilla::INDIC_ROUNDBOX);
    // TODO/FIXME: make it configurable
    SendScintilla(QsciScintilla::SCI_INDICSETFORE, m_searchIndicator, QColor(255, 230, 90, 100));
    SendScintilla(QsciScintilla::SCI_INDICSETUNDER, m_searchIndicator, 1);
    // end of search all occurrences

    connect(this, SIGNAL(linesChanged()),
            this, SLOT(linesChanged()));
    connect(this, SIGNAL(cursorPositionChanged(int, int)),
            this, SLOT(cursorPositionChanged(int, int)));

    setCursorPosition(0, 0);
    linesChanged();
    prefsChanged();
}
QsciLexer * toSyntaxAnalyzerNL::createLexer(QObject *parent)
{
    QsciLexerSQL *retval = new QsciLexerSQL(parent);
    retval->setFoldComments(true);
    retval->setFoldCompact(false);

    toStylesMap sMap = toConfigurationNewSingle::Instance().option(ToConfiguration::Editor::EditStyleMap).value<toStylesMap>();
    sMap.updateLexer(retval);

    return retval;
}