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 SciDoc::print() { QsciPrinter prn; QPrintDialog dlg(&prn, this); if (dlg.exec() == QDialog::Accepted) { prn.setWrapMode(EditorSettings::get(EditorSettings::WrapWords) || PrintSettings::get(PrintSettings::AlwaysWrap) ? QsciScintilla::WrapWord : QsciScintilla::WrapNone); int line1(-1), line2(-1), col1(-1), col2(-1); JuffScintilla* edit = int_->curEdit_; if ( edit ) { QsciLexer* lexer = edit->lexer(); if ( !PrintSettings::get(PrintSettings::KeepBgColor) ) { lexer->setDefaultPaper(Qt::white); lexer->setPaper(Qt::white); lexer->setDefaultColor(Qt::black); } if ( !PrintSettings::get(PrintSettings::KeepColors) ) { lexer->setColor(Qt::black); } edit->getSelection(&line1, &col1, &line2, &col2); if (line1 >=0 && line2 >= 0 && col1 >= 0 && col2 >= 0) { // We have selection. Print it. --line2; prn.printRange(edit, line1, line2); } else { // We don't have selection. Print the whole text. prn.printRange(edit, 0); } QFont font = EditorSettings::font(); LexerStorage::instance()->updateLexers(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)); }