Esempio n. 1
0
static QsciLexer* createLexerByExtension(QString ext)
{
	ext = ext.toLower();

	QsciLexer* lexer = 0;

    QSettings settings;
    QString themePath = settings.value("editorTheme").toString();

	if (ext == "lua")
	{
		QsciLexerLua* lexerlua = new QsciLexerLua;
		lexer = lexerlua;

		QsciAPIs* api = new QsciAPIs(lexer);
//		api->add(QString("addEventListener(type, listener, [data]) Registers a listener function and an optional data value"));
		api->load("Resources/gideros_annot.api");
		api->prepare();
		lexer->setAPIs(api);

        if (themePath != "")
        {
        QSettings editorTheme(themePath, QSettings::IniFormat);
        lexer->readSettings(editorTheme);
        }
        else
        {
            lexer->setColor(Qt::blue, QsciLexerLua::Keyword);
            lexer->setColor(QColor(0xff, 0x80, 0x00), QsciLexerLua::Number);
        }
    }
    else if (ext == "xml")
    {
        lexer = new QsciLexerXML;
    }
    else if ((ext == "hlsl") || (ext == "glsl") )
    {
        lexer = new QsciLexerCPP;

        if (themePath != "")
        {
        QSettings editorTheme(themePath, QSettings::IniFormat);
        lexer->readSettings(editorTheme);
        }
    }

    if (lexer && themePath == "")
	{ 
#ifdef Q_OS_MAC
		lexer->setFont(QFont("Monaco", 12));
#else
		lexer->setFont(QFont("Courier New", 10));
#endif
		lexer->setPaper(QColor(255, 255, 255));
	}

	return lexer;
}