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; }
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(); }
void SciDoc::loadAutocompletionAPI(const QString& lexName, QsciLexer* lexer) { if ( NULL == lexer ) return; QDir dir(AppInfo::configDirPath() + "/apis"); QString fileName = lexName.toLower() + ".api"; fileName.replace(QString("+"), "plus").replace(QString("#"), "sharp"); if ( dir.entryList(QDir::Files).contains(fileName) ) { QsciAPIs* apis = new QsciAPIs(lexer); if ( apis->load(dir.absoluteFilePath(fileName)) ) { // HACK: hardcoded dependencies if (lexName == "Qorus") { apis->load(dir.absoluteFilePath("qore.api")); } apis->prepare(); lexer->setAPIs(apis); } else { delete apis; } } }
static QsciLexer* createLexerByExtension(QString ext) { ext = ext.toLower(); QsciLexer* lexer = 0; 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); lexerlua->setFoldCompact(false); // this function does not exists in QsciLexer lexerlua->setColor(Qt::blue, QsciLexerLua::Keyword); lexerlua->setColor(QColor(0xff, 0x80, 0x00), QsciLexerLua::Number); // to be filled } else if (ext == "xml") { lexer = new QsciLexerXML; } else if ((ext == "hlsl") || (ext == "glsl") ) { lexer = new QsciLexerCPP; } if (lexer) { #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; }
ScriptingArea::ScriptingArea(MapEditor *parent) : QDockWidget(parent) { setWindowTitle("Zone de scripting"); // partie zone de texte QsciLexerLua *lexerLua = new QsciLexerLua(); m_textZone.setLexer(lexerLua); m_textZone.setUtf8(true); m_textZone.setMarginLineNumbers(1, true); // numérotation des lignes m_textZone.setMarginWidth(1, 30); // agrandissement de la marge //this->setAutoCompletionSource(AcsAPIs); //this->setAutoCompletionThreshold(1); QsciLexerLua *lexLua= new QsciLexerLua(); QsciAPIs *api = new QsciAPIs(lexLua); if ( ! api->load(":/ressources/autocompetion.api") ) { Log::e("ScriptingArea") << "Erreur chargement autocompletion.api"; } api->prepare(); m_textZone.setAutoCompletionSource(QsciScintilla::AcsAPIs); m_textZone.setLexer(lexLua); m_textZone.setAutoCompletionThreshold(1); clear(); // partie arbre des fonctions possibles QTreeWidget *treeDoc = new QTreeWidget(); treeDoc->setHeaderHidden(true); QDomDocument doc; QFile f(EDITOR_DATA_DIR + "/scriptingFunctions.xml"); if ( ! f.open(QIODevice::ReadOnly) ) { Log::e("Editor") << "erreur ouverture " << f.fileName() << " : " << f.errorString(); } doc.setContent(&f); f.close(); QDomElement root = doc.documentElement(); QDomNode n = root.firstChild(); while( ! n.isNull() ) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, n.toElement().tagName()); treeDoc->insertTopLevelItem(0, item); QDomNode instance = n.firstChild(); while ( ! instance.isNull() ) { QTreeWidgetItem *item2 = new QTreeWidgetItem(); item2->setText(0, instance.toElement().attribute("signature")); item->addChild(item2); instance = instance.nextSibling(); } n = n.nextSibling(); } // ajout dans le layout QSplitter *splitter = new QSplitter(Qt::Horizontal); splitter->addWidget(&m_textZone); splitter->addWidget(treeDoc); // on agrandit le premier widget, la zone de texte splitter->setStretchFactor(0, 0.75 * width()); QHBoxLayout *scriptingDockLayout = new QHBoxLayout(); scriptingDockLayout->addWidget(splitter); QWidget *scriptingDockContent = new QWidget(); setWidget(scriptingDockContent); scriptingDockContent->setLayout(scriptingDockLayout); }
void QgsCodeEditorPython::setSciLexerPython() { // current line setCaretWidth( 2 ); setEdgeMode( QsciScintilla::EdgeLine ); setEdgeColumn( 80 ); setEdgeColor( QColor( "#FF0000" ) ); setWhitespaceVisibility( QsciScintilla::WsVisibleAfterIndent ); QFont font = getMonospaceFont(); QsciLexerPython* pyLexer = new QsciLexerPython(); pyLexer->setDefaultFont( font ); pyLexer->setFont( font, 1 ); // comment pyLexer->setFont( font, 3 ); // singlequotes pyLexer->setFont( font, 4 ); // doublequotes pyLexer->setFont( font, 6 ); // triplequotes pyLexer->setColor( Qt::red, 1 ); // comment color pyLexer->setColor( Qt::darkGreen, 5 ); // keyword color pyLexer->setColor( Qt::darkBlue, 15 ); // decorator color QsciAPIs* apis = new QsciAPIs( pyLexer ); // check if the file is a prepared apis file. //QString mPapFileName = QFileInfo( mAPISFilesList[0] ).fileName(); //QString isPapFile = mPapFileName.right( 3 ); //QgsDebugMsg( QString( "file extension: %1" ).arg( isPapFile ) ); if ( mAPISFilesList.isEmpty() ) { mPapFile = QgsApplication::pkgDataPath() + "/python/qsci_apis/pyqgis.pap"; apis->loadPrepared( mPapFile ); } else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == "pap" ) { if ( !QFileInfo( mAPISFilesList[0] ).exists() ) { QgsDebugMsg( QString( "The apis file %1 not found" ).arg( mAPISFilesList[0] ) ); return; } mPapFile = mAPISFilesList[0]; apis->loadPrepared( mPapFile ); } else { for ( int i = 0; i < mAPISFilesList.size(); i++ ) { if ( !QFileInfo( mAPISFilesList[i] ).exists() ) { QgsDebugMsg( QString( "The apis file %1 was not found" ).arg( mAPISFilesList[i] ) ); return; } else { apis->load( mAPISFilesList[i] ); } } apis->prepare(); pyLexer->setAPIs( apis ); } setLexer( pyLexer ); setMarginVisible( true ); setFoldingVisible( true ); }