ScintillaEditor::ScintillaEditor(QWidget* parent) : QsciScintilla(parent) { /* -setup editor and configurations */ //set and display line numbers; margin '1' is the default line number maring setMarginWidth(1, 55); setMarginLineNumbers(1, true); //create the lexer manager lexerManager = new SyntaxHighlightManager(this); //set editor properties/settings setAutoIndent(true); setTabWidth(4); setMarginsBackgroundColor( LeptonConfig::mainSettings->getValueAsColor("editor_theme", "margins_background") ); setMarginsForegroundColor( LeptonConfig::mainSettings->getValueAsColor("editor_theme", "margins_foreground") ); setWhitespaceVisibility( LeptonConfig::mainSettings->getWhiteSpaceVisibility() ); setWhitespaceForegroundColor( LeptonConfig::mainSettings->getValueAsColor("editor_theme", "whitespace_color") ); setCaretForegroundColor( LeptonConfig::mainSettings->getValueAsColor("editor_theme", "caret_color") ); setCallTipsHighlightColor( LeptonConfig::mainSettings->getValueAsColor("editor_theme", "highlight_color") ); setSelectionBackgroundColor( LeptonConfig::mainSettings->getValueAsColor("editor_theme", "selection_background") ); setSelectionForegroundColor( LeptonConfig::mainSettings->getValueAsColor("editor_theme", "selection_foreground") ); setIndentationsUseTabs(false); //use spaces instead of tabs for indentation //*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ //$ Stub code used to test Scintilla features $$ //$ $$ //$ $$ //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ }
void chanEditorWidget::init(){ m_action = new QAction(this); m_action->setCheckable(true); connect(m_action, SIGNAL(triggered()), this, SLOT(show())); connect(m_action, SIGNAL(triggered()), this, SLOT(setFocus())); connect(this, SIGNAL(textChanged()), this, SLOT(documentWasModified())); QsciLexerCPP* lexer = new QsciLexerCPP(this); setLexer(lexer); //设置边框行号 setMarginLineNumbers(1, true); //精确的括号匹配 setBraceMatching(QsciScintilla::BraceMatch::StrictBraceMatch); //设置折叠 setFolding(QsciScintilla::FoldStyle::CircledTreeFoldStyle); //设置自动填充有效 setAutoCompletionFillupsEnabled(true); //所有可能的来源 setAutoCompletionSource(QsciScintilla::AcsAll); //补字符号 setCaretLineVisible(true); setAutoIndent(true); setUtf8(true); setWhitespaceVisibility(QsciScintilla::WsVisible); setAttribute(Qt::WA_DeleteOnClose); }
QsciEditor::QsciEditor( QWidget *parent ) : QsciScintilla( parent ) { setFocus(); /* Set tab width, and fonts */ setTabWidth( 4 ); setFont( QFont( "Envy Code R", 9 ) ); setTabIndents( true ); setIndentationsUseTabs( true ); /* Set folding style */ setFolding( QsciScintilla::BoxedTreeFoldStyle ); /* Remove Horizontal Scrollbar, put a Vertical one */ setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); /* Whitespace, indentation markings, and eol */ setIndentationGuides( false ); setWhitespaceVisibility( WsInvisible ); setEolMode( EolUnix ); /* Create Margins */ setMarginWidth( 0, QString( " %1 " ).arg( lines() ) ); setMarginWidth( 1, " " ); setMarginWidth( 2, 10 ); setMarginsFont( QFont( "Envy Code R", 9 ) ); setWrapMode( QsciScintilla::WrapWord ); /* Current Line Visibility */ ensureCursorVisible(); setCaretLineVisible( true ); setCaretLineBackgroundColor( QColor( "#555555" ) ); setCaretForegroundColor( QColor( "#FAFFAF" ) ); setCaretWidth( 2 ); /* Selection Color */ // setSelectionBackgroundColor( "#333964" ); // setSelectionForegroundColor( "*" ); /* Margin and folding margins background colors */ setMarginsBackgroundColor( QColor( "#A0A0A0" ) ); setFoldMarginColors( QColor( "#666666" ), Qt::black ); /* Set the width of the line */ setLineWidth( 144 ); ensureLineVisible( true ); /* Set the paper and pen color - Editor BG and FG color */ setPaper( Qt::black ); setColor( Qt::white ); /* Brace coloring */ setBraceMatching( QsciScintilla::SloppyBraceMatch ); setUnmatchedBraceForegroundColor( Qt::red ); setUnmatchedBraceBackgroundColor( Qt::black ); setMatchedBraceForegroundColor( Qt::darkGreen ); setMatchedBraceBackgroundColor( Qt::black ); /* Multi-selection and typing */ SendScintilla( SCI_SETADDITIONALSELECTIONTYPING, true ); SendScintilla( SCI_SETMULTIPLESELECTION, true ); SendScintilla( SCI_SETMULTIPASTE, true ); /* Scroll beyond the last line */ SendScintilla( SCI_SETENDATLASTLINE, false ); /* Set the editor state as not modified */ setModified( false ); /* Auto Save Timer: 60 sec */ autoSaveTimer = new QBasicTimer(); /* Enable and Show Custom context Menu */ setContextMenuPolicy( Qt::CustomContextMenu ); /* Connections */ setupActions(); /* Default Lexer */ setLexer( new QLexerDefault() ); QsciScintilla::FoldStyle state = static_cast<QsciScintilla::FoldStyle>( ( !folding() ) * 5 ); if ( !state ) foldAll( false ); setFolding( state ); };
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 ); }