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; }
void toSqlText::setFont (const QFont & font) { // Only sets font lexer - one for all styles // this may (or may not) need to be changed in a future QsciLexer *lexer = super::lexer(); if (lexer) { lexer->setDefaultFont(font); lexer->setFont(font); /* this is workaround against qscintilla 1.6 setFont(font) bug */ if ( qobject_cast<QsciLexerSQL*>(lexer)) { lexer->setFont(font, QsciLexerSQL::Default); lexer->setFont(font, QsciLexerSQL::Comment); lexer->setFont(font, QsciLexerSQL::CommentLine); lexer->setFont(font, QsciLexerSQL::PlusComment); lexer->setFont(font, QsciLexerSQL::CommentLineHash); lexer->setFont(font, QsciLexerSQL::CommentDocKeyword); lexer->setFont(font, QsciLexerSQL::CommentDocKeywordError); lexer->setFont(font, QsciLexerSQL::DoubleQuotedString); lexer->setFont(font, QsciLexerSQL::SingleQuotedString); lexer->setFont(font, QsciLexerSQL::PlusPrompt); } update(); } super::setFont(font); }
/** * Recursively updates lexer style properties, using the data stored in the * model. * @param node The style node holding the lexer to update */ void LexerStyleModel::updateLexerStyle(const Node* node) const { StyleData* data = static_cast<StyleData*>(node->data()); QsciLexer* lexer = data->lexer_; int style = data->style_; // Update lexer properties. QFont font = propertyDataFromNode(node, Font)->value_.value<QFont>(); lexer->setFont(font, style); QColor foreground = propertyDataFromNode(node, Foreground)->value_.value<QColor>(); lexer->setColor(foreground, style); QColor background = propertyDataFromNode(node, Background)->value_.value<QColor>(); lexer->setPaper(background, style); // This is really nasty, but Scintilla leaves us no choice... // The EOL Fill flag needs to be set in order for whitespace past the end // of line to be drawn in the desired background colour. We apply this flag // to the default style, as well as any styles that have the same background // colour as the default. if ((style == lexer->defaultStyle()) || (lexer->paper(style) == lexer->paper(lexer->defaultStyle()))) { lexer->setEolFill(true, style); } // Recursive call. for (int i = 0; i < node->childCount(); i++) updateLexerStyle(node->child(i)); }
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 EditorPage::handleMonoFontChanged () { QsciLexer *lexer = Ui_.TextEditor_->lexer (); if (!lexer) return; QFont font = XmlSettingsManager::Instance ()-> property ("MonoFont").value<QFont> (); lexer->setFont (font); }
/** * Updates the editor widget to use a new set of configuration parameters. * @param config The configuration parameters */ void Editor::applyConfig(const Config& config) { QsciLexer* lex = lexer(); if (lex) lex->setFont(config.font_); else setFont(config.font_); setIndentationsUseTabs(config.indentTabs_); setTabWidth(config.tabWidth_); setCaretLineVisible(config.hlCurLine_); }
CodeWindow::CodeWindow( QSettings* appSettings, const ConnectorPath& conPath, QWidget* parent) : QDialog( parent), _ui( new Ui::CodeWindow) { _ui->setupUi( this); this->setWindowTitle( QString("CodeEdit ") + conPath.normPath()); _appSettings = appSettings; readSettings(); _font = QFont("MonoSpace", 10); _font.setStyleHint( QFont::TypeWriter); MTextEdit* textEdit = _ui->textEdit; #ifdef QSCINTILLA QsciLexer* lexer = 0; if (path.endsWith(".js")) lexer = new QsciLexerJavaScript; if (path.endsWith(".html") || path.endsWith(".xhtml")) lexer = new QsciLexerHTML; if (lexer) { lexer->setFont( _font); textEdit->editor()->setLexer( lexer); } else { textEdit->setFont( _font); } textEdit->editor()->setTabWidth(4); textEdit->editor()->setMarginWidth(0, 35); textEdit->editor()->setMarginLineNumbers(0, true); textEdit->editor()->setUtf8(true); textEdit->editor()->setAutoIndent(true); textEdit->editor()->setBraceMatching( QsciScintilla::StrictBraceMatch); textEdit->editor()->setMatchedBraceForegroundColor( Qt::red); #else QFontMetrics fm( _font); int tabWidthInPixels = fm.width(" "); textEdit->editor()->setTabStopWidth( tabWidthInPixels); textEdit->editor()->setCurrentFont( _font); #endif QString path = conPath.localPath(); _isHtml = path.endsWith(".html") || path.endsWith(".xhtml"); _isSetPlainText = true; // Default _arnItem.open( path); setText( _arnItem.toString()); }