Exemplo n.º 1
0
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 );
};
Exemplo n.º 2
0
void Editor::setEditorStyle (void)
{
	//QFont font ("Consolas", 14, QFont::Normal, false);
	QFont font (config.editorFontName, config.editorFontSize, QFont::Normal, false);

	lblCursorPosition->setFont(font);
	QFontMetrics fontMetrics(font);

    //QColor backColor = QColor(22, 30, 32);
	TextStyle style;
	config.GetThemeStyle(config.themeName, "DEFAULT", style);
	QColor backColor = style.backColor;//QColor(config.editorColorName);

    setColor(backColor);
	
	QString css = "color:" + style.foreColor.name() + ";";
	css += "background-color:" + style.backColor.name() + ";";
	css += "border: 1px solid " + style.foreColor.name() + ";";
	lblCursorPosition->setStyleSheet(css);
	
	// margin
	setMarginLineNumbers(100, true);
	setMarginsFont(font);
	config.GetThemeStyle(config.themeName, "MARGIN", style);
	setMarginsBackgroundColor(style.backColor);//QColor(24,32,34));//QColor(20,28,30));
	setMarginsForegroundColor(style.foreColor); //QColor(42,50,52));
	setMarginWidth(0, fontMetrics.width("00000") + 6);	
	
	// General editor things
	setTabWidth(4);	
	ensureCursorVisible();
	setIndicatorForegroundColor (Qt::red, 1);	

	// compile error/warning mark
	markerDefine(QsciScintilla::RightArrow, 1); 
	setMarkerBackgroundColor(Qt::red, 1);	
	markerDefine(QsciScintilla::Circle, 0);
	setMarkerBackgroundColor(Qt::red, 0);
	setMarkerForegroundColor(Qt::white, 0);

	// caret
	setCaretLineVisible(true);
	setCaretWidth(2);
	config.GetThemeStyle(config.themeName, "CARET", style);
	setCaretForegroundColor(style.foreColor);//QColor(220, 200, 200));
	caretLineBackColor = style.backColor;
	setCaretLineBackgroundColor(caretLineBackColor);//QColor(24, 32, 34));
	//setCaretLineBackgroundColor(QColor(255, 0, 0, 100));
	//SendScintilla (SC_TECHNOLOGY_DIRECTWRITE, 1);
	//SendScintilla (SCI_SETBUFFEREDDRAW, 1);
	//SendScintilla (SCI_SETTWOPHASEDRAW, 1);
	//SendScintilla (SCI_SETFONTQUALITY,  SC_EFF_QUALITY_NON_ANTIALIASED);//SC_EFF_QUALITY_DEFAULT);	

	// matched and unmatched braces coloring
	if (config.highlightBraces) {
		setBraceMatching(QsciScintilla::SloppyBraceMatch);
	} else {
		setBraceMatching(QsciScintilla::NoBraceMatch);
	}
	setMatchedBraceBackgroundColor(backColor);
	setMatchedBraceForegroundColor(QColor(220, 220, 50));
	setUnmatchedBraceBackgroundColor(QColor(0,0,0));
	setUnmatchedBraceForegroundColor(QColor(255, 0, 0));

	// selection
	config.GetThemeStyle(config.themeName, "SELECTION", style);
	setSelectionForegroundColor(style.foreColor);//QColor(150, 150, 150));
	setSelectionBackgroundColor(style.backColor);//QColor(52, 60, 62));
	
	// maim cpp styles
	setLexerStyle(-1, "DEFAULT");//QColor (120, 120, 120),backColor);	
	//setLexerStyle(-1, Qt::red, Qt::blue);	
	//setLexerStyle(QsciLexerCPP::Default, Qt::blue, Qt::yellow);
	setLexerStyle(QsciLexerCPP::Default, "DEFAULT");
	//setLexerStyle(QsciLexerCPP::callSTYLE_CALLTIP, QColor (255,0,0), QColor(255,255,255));
	
	setLexerStyle(QsciLexerCPP::Comment, "COMMENT");
	setLexerStyle(QsciLexerCPP::CommentDoc, "COMMENT DOC");		
	setLexerStyle(QsciLexerCPP::CommentLine, "COMMENT LIN E DOC");
	setLexerStyle(QsciLexerCPP::Number, "NUMBER");
	setLexerStyle(QsciLexerCPP::Keyword, "KEYWORD");
	setLexerStyle(QsciLexerCPP::DoubleQuotedString, "DOUBLE QUOTED STRING");
	setLexerStyle(QsciLexerCPP::SingleQuotedString, "SINGLE QUOTED STRING");
	setLexerStyle(QsciLexerCPP::PreProcessor, "PREPROCESSOR");
	setLexerStyle(QsciLexerCPP::Operator, "OPERATOR");
	setLexerStyle(QsciLexerCPP::Identifier, "IDENTIFIER");
	setLexerStyle(QsciLexerCPP::UnclosedString, "UNCLOSED STRING");
	
	// secondary styles
	setLexerStyle(QsciLexerCPP::UUID, "UUID");	
	setLexerStyle(QsciLexerCPP::VerbatimString, "VERBATIM STRING");
	setLexerStyle(QsciLexerCPP::Regex, "REGEX");
	setLexerStyle(QsciLexerCPP::CommentLineDoc, "COMMENT LINE DOC");
	setLexerStyle(QsciLexerCPP::KeywordSet2, "KEYWORD SET 2");
	setLexerStyle(QsciLexerCPP::CommentDocKeyword, "COMMENT DOC KEYWORD");
	setLexerStyle(QsciLexerCPP::CommentDocKeywordError, "COMMENT DOC KEYWORD ERROR");
	setLexerStyle(QsciLexerCPP::GlobalClass, "GLOBAL CLASS");
	setLexerStyle(QsciLexerCPP::RawString, "DOUBLE QUOTED STRING");
	setLexerStyle(QsciLexerCPP::TripleQuotedVerbatimString, "VERBATIM STRING");
	setLexerStyle(QsciLexerCPP::HashQuotedString, "VERBATIM STRING");
	setLexerStyle(QsciLexerCPP::PreProcessorComment, "PREPROCESSOR");
	setLexerStyle(QsciLexerCPP::PreProcessorCommentLineDoc, "PREPROCESSOR"); 		
}