25 #include <QFontDatabase>
27 #include <QFocusEvent>
30 : QsciScintilla( parent )
31 , mWidgetTitle( title )
35 if ( !parent && mWidgetTitle.isEmpty() )
37 setWindowTitle( QStringLiteral(
"Text Editor" ) );
41 setWindowTitle( mWidgetTitle );
44 setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
46 SendScintilla( SCI_SETADDITIONALSELECTIONTYPING, 1 );
47 SendScintilla( SCI_SETMULTIPASTE, 1 );
48 SendScintilla( SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION );
54 #if QSCINTILLA_VERSION >= 0x020800 && QSCINTILLA_VERSION < 0x020900
55 if ( event->reason() != Qt::ActiveWindowFocusReason )
69 QFocusEvent newFocusEvent( QEvent::FocusOut, Qt::ActiveWindowFocusReason );
70 QsciScintilla::focusOutEvent( &newFocusEvent );
75 QsciScintilla::focusOutEvent( event );
84 if ( event->key() == Qt::Key_Escape && !isListActive() )
87 QWidget::keyPressEvent( event );
91 QsciScintilla::keyPressEvent( event );
95 void QgsCodeEditor::setSciWidget()
97 QHash< QString, QColor > colors;
101 for (
const auto &key : ini.allKeys() )
106 QPalette
pal = qApp->palette();
112 setCaretLineVisible(
true );
113 setCaretLineBackgroundColor( colors.value( QStringLiteral(
"caretLineColor" ), QColor( 252, 243, 237 ) ) );
114 setCaretForegroundColor( colors.value( QStringLiteral(
"cursorColor" ), QColor( 51, 51, 51 ) ) );
115 setSelectionForegroundColor( colors.value( QStringLiteral(
"selectionForegroundColor" ),
pal.color( QPalette::HighlightedText ) ) );
116 setSelectionBackgroundColor( colors.value( QStringLiteral(
"selectionBackgroundColor" ),
pal.color( QPalette::Highlight ) ) );
118 setBraceMatching( QsciScintilla::SloppyBraceMatch );
119 setMatchedBraceBackgroundColor( colors.value( QStringLiteral(
"matchedBraceColor" ), QColor( 183, 249, 7 ) ) );
122 setMarginsForegroundColor( colors.value( QStringLiteral(
"marginForegroundColor" ), QColor( 62, 62, 227 ) ) );
123 setMarginsBackgroundColor( colors.value( QStringLiteral(
"marginBackgroundColor" ), QColor( 249, 249, 249 ) ) );
124 setIndentationGuidesForegroundColor( colors.value( QStringLiteral(
"marginForegroundColor" ), QColor( 62, 62, 227 ) ) );
125 setIndentationGuidesBackgroundColor( colors.value( QStringLiteral(
"marginBackgroundColor" ), QColor( 249, 249, 249 ) ) );
128 QColor foldColor = colors.value( QStringLiteral(
"foldColor" ), QColor( 244, 244, 244 ) );
129 setFoldMarginColors( foldColor, foldColor );
131 setAutoIndent(
true );
132 setIndentationWidth( 4 );
133 setTabIndents(
true );
134 setBackspaceUnindents(
true );
137 setAutoCompletionThreshold( 2 );
138 setAutoCompletionSource( QsciScintilla::AcsAPIs );
143 setWindowTitle( title );
151 QFont marginFont( QStringLiteral(
"Courier" ), 10 );
152 setMarginLineNumbers( 1,
true );
153 setMarginsFont( marginFont );
154 setMarginWidth( 1, QStringLiteral(
"00000" ) );
158 setMarginWidth( 0, 0 );
159 setMarginWidth( 1, 0 );
160 setMarginWidth( 2, 0 );
169 setFolding( QsciScintilla::PlainFoldStyle );
173 setFolding( QsciScintilla::NoFoldStyle );
180 if ( hasSelectedText() )
182 replaceSelectedText( text );
187 getCursorPosition( &line, &index );
188 insertAt( text, line, index );
189 setCursorPosition( line, index + text.length() );
196 return font.fixedPitch();
201 QFont font = QFontDatabase::systemFont( QFontDatabase::FixedFont );
204 font.setPointSize( QLabel().font().pointSize() );
207 int fontSize = settings.
value( QStringLiteral(
"qgis/stylesheet/fontPointSize" ), 10 ).toInt();
208 font.setPointSize( fontSize );
210 font.setBold(
false );