23 #include <QFocusEvent> 26 : QsciScintilla( parent )
27 , mWidgetTitle( title )
31 if ( !parent && mWidgetTitle.isEmpty() )
33 setWindowTitle( QStringLiteral(
"Text Editor" ) );
37 setWindowTitle( mWidgetTitle );
40 setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
46 #if QSCINTILLA_VERSION >= 0x020800 && QSCINTILLA_VERSION < 0x020900 47 if ( event->reason() != Qt::ActiveWindowFocusReason )
61 QFocusEvent newFocusEvent( QEvent::FocusOut, Qt::ActiveWindowFocusReason );
62 QsciScintilla::focusOutEvent( &newFocusEvent );
67 QsciScintilla::focusOutEvent( event );
76 if ( event->key() == Qt::Key_Escape && !isListActive() )
79 QWidget::keyPressEvent( event );
83 QsciScintilla::keyPressEvent( event );
87 void QgsCodeEditor::setSciWidget()
90 setCaretLineVisible(
true );
91 setCaretLineBackgroundColor( QColor( 252, 243, 237 ) );
93 setBraceMatching( QsciScintilla::SloppyBraceMatch );
94 setMatchedBraceBackgroundColor( QColor( 183, 249, 7 ) );
100 setAutoIndent(
true );
101 setIndentationWidth( 4 );
102 setTabIndents(
true );
103 setBackspaceUnindents(
true );
106 setAutoCompletionThreshold( 2 );
107 setAutoCompletionSource( QsciScintilla::AcsAPIs );
112 setWindowTitle( title );
120 QFont marginFont( QStringLiteral(
"Courier" ), 10 );
121 setMarginLineNumbers( 1,
true );
122 setMarginsFont( marginFont );
123 setMarginWidth( 1, QStringLiteral(
"00000" ) );
124 setMarginsForegroundColor( QColor( 62, 62, 227 ) );
125 setMarginsBackgroundColor( QColor( 249, 249, 249 ) );
129 setMarginWidth( 0, 0 );
130 setMarginWidth( 1, 0 );
131 setMarginWidth( 2, 0 );
140 setFolding( QsciScintilla::PlainFoldStyle );
141 setFoldMarginColors( QColor( 244, 244, 244 ), QColor( 244, 244, 244 ) );
145 setFolding( QsciScintilla::NoFoldStyle );
152 if ( hasSelectedText() )
154 replaceSelectedText( text );
159 getCursorPosition( &line, &index );
160 insertAt( text, line, index );
161 setCursorPosition( line, index + text.length() );
168 return font.fixedPitch();
174 QString loadFont = settings.
value( QStringLiteral(
"pythonConsole/fontfamilytextEditor" ),
"Monospace" ).toString();
175 int fontSize = settings.
value( QStringLiteral(
"pythonConsole/fontsizeEditor" ), 10 ).toInt();
177 QFont font( loadFont );
178 font.setFixedPitch(
true );
179 font.setPointSize( fontSize );
180 font.setStyleHint( QFont::TypeWriter );
181 font.setStretch( QFont::SemiCondensed );
182 font.setLetterSpacing( QFont::PercentageSpacing, 87.0 );
183 font.setBold(
false );
This class is a composition of two QSettings instances:
void setFoldingVisible(bool folding)
Set folding visible state.
void keyPressEvent(QKeyEvent *event) override
void insertText(const QString &text)
Insert text at cursor position, or replace any selected text if user has made a selection.
QgsCodeEditor(QWidget *parent=nullptr, const QString &title=QString(), bool folding=false, bool margin=false)
Construct a new code editor.
void setMarginVisible(bool margin)
Set margin visible state.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
void setTitle(const QString &title)
Set the widget title.
bool isFixedPitch(const QFont &font)
void focusOutEvent(QFocusEvent *event) override