void LuaEditor::initLexer() { lexer = new QsciLexerLua; lexer->setFoldCompact(false); lexer->setColor(QColor(128, 128, 255), 5); lexer->setColor(QColor(0, 220, 0), 1); lexer->setColor(QColor(0, 220, 0), 2); lexer->setColor(QColor(Qt::red), 6); lexer->setColor(QColor(Qt::red), 8); lexer->setColor(QColor(255, 128, 0), 13); lexer->setColor(QColor(51, 102, 255), 15); lexer->setColor(QColor(72, 61, 139), 10); lexer->setFont(QFont("Courier New", 11, QFont::Bold)); QSettings settings(ORGNAME, APPNAME); settings.beginGroup("QtLuaPad"); bool autoComp = settings.value("autocompletion").toBool(); QString funcFile = settings.value("funcfile").toString().toLatin1(); settings.endGroup(); if(autoComp) { setAutoCompletionSource(QsciScintilla::AcsAll); setAutoCompletionCaseSensitivity(false); setAutoCompletionFillupsEnabled(true); setAutoCompletionThreshold(2); setAutoCompletionShowSingle(true); QsciAPIs *apis = new QsciAPIs(lexer); xmlDocPtr doc = xmlParseFile(funcFile.toLatin1()); if(!doc) { QMessageBox::critical(NULL, "Unable to load keywords!", tr("Could not load keywords file. No such file or directory."), QMessageBox::Ok, QMessageBox::NoButton); return; } xmlNodePtr root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"functions")) { QMessageBox::critical(NULL, "Error", tr("Malformed functions file.")); return; } for (xmlNodePtr p = root->children; p; p = p->next) { if(p->type != XML_ELEMENT_NODE) continue; if(xmlStrcmp(p->name, (const xmlChar*)"function")) continue; QString func = QString((const char*)p->children->content); apis->add(func); } apis->prepare(); lexer->setAPIs(apis); } }
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(); }
// The worker thread entry point. void QsciAPIsWorker::run() { // Sanity check. if (!prepared) return; // Tell the main thread we have started. QApplication::postEvent(proxy, new QEvent(WorkerStarted)); // Sort the full list. prepared->raw_apis.sort(); QStringList wseps = proxy->lexer()->autoCompletionWordSeparators(); bool cs = proxy->lexer()->caseSensitive(); // Split each entry into separate words but ignoring any arguments. for (int a = 0; a < prepared->raw_apis.count(); ++a) { // Check to see if we should stop. if (abort) break; QStringList words = prepared->apiWords(a, wseps, true); for (int w = 0; w < words.count(); ++w) { const QString &word = words[w]; // Add the word's position to any existing list for this word. QsciAPIs::WordIndexList wil = prepared->wdict[word]; // If the language is case insensitive and we haven't seen this // word before then save it in the case dictionary. if (!cs && wil.count() == 0) prepared->cdict[word.upper()] = word; wil.append(QsciAPIs::WordIndex(a, w)); prepared->wdict[word] = wil; } } if (cs) prepared->words = prepared->wdict.keys(); else prepared->words = prepared->cdict.keys(); // Tell the main thread we have finished. QApplication::postEvent(proxy, new QEvent(abort ? WorkerAborted : WorkerFinished)); }
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; }
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; } } }
/** * Initializes the autocompletion. * @param additionalElements * Additional elements for the autocompletion api. */ void SingleDocument::initAutoCompletion(QStringList additionalElements) { if(lexer() && lexer()->apis()) { QsciAPIs* apis = static_cast<QsciAPIs*>(lexer()->apis()); apis->clear(); QMap<QString, QStringList>::iterator i; for (i = g_apiFiles.begin(); i != g_apiFiles.end(); ++i) { for(auto el : i.value()) { apis->add(el); } } for(auto el : additionalElements) { apis->add(el); } apis->prepare(); } }
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); }
QsciLexerQSS::QsciLexerQSS(QObject *parent) : QsciLexerCSS(parent) { QsciAPIs *api = new QsciAPIs(this); const QString stringKeywords = QString(keywords(1)) + keywords(2); QStringList listKeywords = stringKeywords.split(QRegExp("\\s+"), QString::SkipEmptyParts); // Qt classes listKeywords << "QAbstractScrollArea" << "QCheckBox" << "QColumnView" << "QComboBox" << "QDateEdit" << "QDateTimeEdit" << "QDialog" << "QDialogButtonBox" << "QDockWidget" << "QDoubleSpinBox" << "QFrame" << "QGroupBox" << "QHeaderView" << "QLabel" << "QLineEdit" << "QListView" << "QListWidget" << "QMainWindow" << "QMenu" << "QMenuBar" << "QMessageBox" << "QProgressBar" << "QPushButton" << "QRadioButton" << "QScrollBar" << "QSizeGrip" << "QSlider" << "QSpinBox" << "QSplitter" << "QStatusBar" << "QTabBar" << "QTabWidget" << "QTableView" << "QTableWidget" << "QTextEdit" << "QTimeEdit" << "QToolBar" << "QToolButton" << "QToolBox" << "QToolTip" << "QTreeView" << "QTreeWidget" << "QWidget" // alignment << "top" << "bottom" << "left" << "right" << "center" // attachment << "scroll" << "fixed" // border image << "none" << "stretch" << "repeat" // border style << "dashed" << "dot-dash" << "dot-dot-dash" << "dotted" << "double" << "inset" << "outset" << "ridge" << "solid" << "none" // font << "normal" << "italic" << "oblique" << "bold" // gradients << "qlineargradient" << "qradialgradient" << "qconicalgradient" // origin << "margin" << "border" << "padding" << "content" // palette role << "alternate-base" << "base" << "bright-text" << "button" << "button-text" << "dark" << "highlight" << "highlighted-text" << "light" << "link" << "link-visited" << "mid" << "midlight" << "shadow" << "text" << "window" << "window-text" // repeat << "repeat" << "repeat-x" << "repeat-y" << "no-repeat" ; listKeywords.removeDuplicates(); foreach(const QString &word, listKeywords) { api->add(word); }
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 ); }