25 #include <QFocusEvent> 28 : QsciScintilla( parent )
29 , mWidgetTitle( title )
33 if ( !parent && mWidgetTitle.isEmpty() )
35 setWindowTitle( QStringLiteral(
"Text Editor" ) );
39 setWindowTitle( mWidgetTitle );
42 setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
44 SendScintilla( SCI_SETADDITIONALSELECTIONTYPING, 1 );
45 SendScintilla( SCI_SETMULTIPASTE, 1 );
46 SendScintilla( SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION );
52 #if QSCINTILLA_VERSION >= 0x020800 && QSCINTILLA_VERSION < 0x020900 53 if ( event->reason() != Qt::ActiveWindowFocusReason )
67 QFocusEvent newFocusEvent( QEvent::FocusOut, Qt::ActiveWindowFocusReason );
68 QsciScintilla::focusOutEvent( &newFocusEvent );
73 QsciScintilla::focusOutEvent( event );
82 if ( event->key() == Qt::Key_Escape && !isListActive() )
85 QWidget::keyPressEvent( event );
89 QsciScintilla::keyPressEvent( event );
93 void QgsCodeEditor::setSciWidget()
95 QHash< QString, QColor > colors;
99 for (
const auto &key : ini.allKeys() )
104 QPalette
pal = qApp->palette();
107 setCaretLineVisible(
true );
108 setCaretLineBackgroundColor( colors.value( QStringLiteral(
"caretLineColor" ), QColor( 252, 243, 237 ) ) );
109 setCaretForegroundColor( colors.value( QStringLiteral(
"cursorColor" ), QColor( 51, 51, 51 ) ) );
110 setSelectionForegroundColor( colors.value( QStringLiteral(
"selectionForegroundColor" ), pal.color( QPalette::HighlightedText ) ) );
111 setSelectionBackgroundColor( colors.value( QStringLiteral(
"selectionBackgroundColor" ), pal.color( QPalette::Highlight ) ) );
113 setBraceMatching( QsciScintilla::SloppyBraceMatch );
114 setMatchedBraceBackgroundColor( colors.value( QStringLiteral(
"matchedBraceColor" ), QColor( 183, 249, 7 ) ) );
117 setMarginsForegroundColor( colors.value( QStringLiteral(
"marginForegroundColor" ), QColor( 62, 62, 227 ) ) );
118 setMarginsBackgroundColor( colors.value( QStringLiteral(
"marginBackgroundColor" ), QColor( 249, 249, 249 ) ) );
119 setIndentationGuidesForegroundColor( colors.value( QStringLiteral(
"marginForegroundColor" ), QColor( 62, 62, 227 ) ) );
120 setIndentationGuidesBackgroundColor( colors.value( QStringLiteral(
"marginBackgroundColor" ), QColor( 249, 249, 249 ) ) );
123 QColor foldColor = colors.value( QStringLiteral(
"foldColor" ), QColor( 244, 244, 244 ) );
124 setFoldMarginColors( foldColor, foldColor );
126 setAutoIndent(
true );
127 setIndentationWidth( 4 );
128 setTabIndents(
true );
129 setBackspaceUnindents(
true );
132 setAutoCompletionThreshold( 2 );
133 setAutoCompletionSource( QsciScintilla::AcsAPIs );
138 setWindowTitle( title );
146 QFont marginFont( QStringLiteral(
"Courier" ), 10 );
147 setMarginLineNumbers( 1,
true );
148 setMarginsFont( marginFont );
149 setMarginWidth( 1, QStringLiteral(
"00000" ) );
153 setMarginWidth( 0, 0 );
154 setMarginWidth( 1, 0 );
155 setMarginWidth( 2, 0 );
164 setFolding( QsciScintilla::PlainFoldStyle );
168 setFolding( QsciScintilla::NoFoldStyle );
175 if ( hasSelectedText() )
177 replaceSelectedText( text );
182 getCursorPosition( &line, &index );
183 insertAt( text, line, index );
184 setCursorPosition( line, index + text.length() );
191 return font.fixedPitch();
197 QString loadFont = settings.
value( QStringLiteral(
"pythonConsole/fontfamilytextEditor" ),
"Monospace" ).toString();
198 int fontSize = settings.
value( QStringLiteral(
"pythonConsole/fontsizeEditor" ), 10 ).toInt();
200 QFont font( loadFont );
201 font.setFixedPitch(
true );
202 font.setPointSize( fontSize );
203 font.setStyleHint( QFont::TypeWriter );
204 font.setBold(
false );
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.
void setTitle(const QString &title)
Set the widget title.
bool isFixedPitch(const QFont &font)
void focusOutEvent(QFocusEvent *event) override
static QColor decodeColor(const QString &str)