23 #include <QFocusEvent> 26 : QsciScintilla( parent )
27 , mWidgetTitle( title )
31 if ( !parent && mWidgetTitle.
isEmpty() )
33 setWindowTitle(
"Text Editor" );
34 setMinimumSize( 800, 300 );
38 setWindowTitle( mWidgetTitle );
41 setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
51 #if QSCINTILLA_VERSION >= 0x020800 && QSCINTILLA_VERSION < 0x020900 52 if ( event->
reason() != Qt::ActiveWindowFocusReason )
66 QFocusEvent newFocusEvent( QEvent::FocusOut, Qt::ActiveWindowFocusReason );
67 QsciScintilla::focusOutEvent( &newFocusEvent );
72 QsciScintilla::focusOutEvent( event );
81 if ( event->
key() == Qt::Key_Escape && !isListActive() )
88 QsciScintilla::keyPressEvent( event );
92 void QgsCodeEditor::setSciWidget()
95 setCaretLineVisible(
true );
96 setCaretLineBackgroundColor(
QColor(
"#fcf3ed" ) );
98 setBraceMatching( QsciScintilla::SloppyBraceMatch );
99 setMatchedBraceBackgroundColor(
QColor(
"#b7f907" ) );
105 setAutoIndent(
true );
106 setIndentationWidth( 4 );
107 setTabIndents(
true );
108 setBackspaceUnindents(
true );
111 setAutoCompletionThreshold( 2 );
112 setAutoCompletionSource( QsciScintilla::AcsAPIs );
117 setWindowTitle( title );
125 QFont marginFont(
"Courier", 10 );
126 setMarginLineNumbers( 1,
true );
127 setMarginsFont( marginFont );
128 setMarginWidth( 1,
"00000" );
129 setMarginsForegroundColor(
QColor(
"#3E3EE3" ) );
130 setMarginsBackgroundColor(
QColor(
"#f9f9f9" ) );
134 setMarginWidth( 0, 0 );
135 setMarginWidth( 1, 0 );
136 setMarginWidth( 2, 0 );
145 setFolding( QsciScintilla::PlainFoldStyle );
146 setFoldMarginColors(
QColor(
"#f4f4f4" ),
QColor(
"#f4f4f4" ) );
150 setFolding( QsciScintilla::NoFoldStyle );
157 if ( hasSelectedText() )
159 replaceSelectedText( theText );
164 getCursorPosition( &line, &index );
165 insertAt( theText, line, index );
166 setCursorPosition( line, index + theText.
length() );
179 QString loadFont = settings.
value(
"pythonConsole/fontfamilytextEditor",
"Monospace" ).
toString();
180 int fontSize = settings.
value(
"pythonConsole/fontsizeEditor", 10 ).
toInt();
182 QFont font( loadFont );
void setPointSize(int pointSize)
void setFoldingVisible(bool folding)
Set folding visible state.
void keyPressEvent(QKeyEvent *event) override
void setBold(bool enable)
Qt::FocusReason reason() const
QgsCodeEditor(QWidget *parent=nullptr, const QString &title="", bool folding=false, bool margin=false)
Construct a new code editor.
int toInt(bool *ok) const
void setStyleHint(StyleHint hint, StyleStrategy strategy)
void setMarginVisible(bool margin)
Set margin visible state.
QVariant value(const QString &key, const QVariant &defaultValue) const
void setTitle(const QString &title)
Set the widget title.
bool isFixedPitch(const QFont &font)
void setLetterSpacing(SpacingType type, qreal spacing)
void focusOutEvent(QFocusEvent *event) override
void setFixedPitch(bool enable)
void insertText(const QString &theText)
Insert text at cursor position, or replace any selected text if user has made a selection.
void setStretch(int factor)