void FastoScintilla::setShowAutoCompletion(bool showA) { showAutoCompletion_ = showA; if (showAutoCompletion_) { setAutoCompletionSource(QsciScintilla::AcsAPIs); } else { setAutoCompletionSource(QsciScintilla::AcsNone); } }
/** * Disable the auto complete * */ void ScriptEditor::disableAutoCompletion() { setAutoCompletionSource(QsciScintilla::AcsNone); setCallTipsVisible(QsciScintilla::CallTipsNone); setAutoCompletionThreshold(-1); setCallTipsVisible(-1); }
/** * Enable the auto complete */ void ScriptEditor::enableAutoCompletion() { setAutoCompletionSource(QsciScintilla::AcsAPIs); setCallTipsVisible(QsciScintilla::CallTipsNoAutoCompletionContext); setAutoCompletionThreshold(2); setCallTipsVisible(0); // This actually makes all of them visible }
void LuaEditor::initLexer() { lexer = new QsciLexerLua; lexer->setFoldCompact(false); lexer->setColor(QColor(128, 128, 255), 5); lexer->setColor(QColor(0, 220, 0), 1); lexer->setColor(QColor(0, 220, 0), 2); lexer->setColor(QColor(Qt::red), 6); lexer->setColor(QColor(Qt::red), 8); lexer->setColor(QColor(255, 128, 0), 13); lexer->setColor(QColor(51, 102, 255), 15); lexer->setColor(QColor(72, 61, 139), 10); lexer->setFont(QFont("Courier New", 11, QFont::Bold)); QSettings settings(ORGNAME, APPNAME); settings.beginGroup("QtLuaPad"); bool autoComp = settings.value("autocompletion").toBool(); QString funcFile = settings.value("funcfile").toString().toLatin1(); settings.endGroup(); if(autoComp) { setAutoCompletionSource(QsciScintilla::AcsAll); setAutoCompletionCaseSensitivity(false); setAutoCompletionFillupsEnabled(true); setAutoCompletionThreshold(2); setAutoCompletionShowSingle(true); QsciAPIs *apis = new QsciAPIs(lexer); xmlDocPtr doc = xmlParseFile(funcFile.toLatin1()); if(!doc) { QMessageBox::critical(NULL, "Unable to load keywords!", tr("Could not load keywords file. No such file or directory."), QMessageBox::Ok, QMessageBox::NoButton); return; } xmlNodePtr root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"functions")) { QMessageBox::critical(NULL, "Error", tr("Malformed functions file.")); return; } for (xmlNodePtr p = root->children; p; p = p->next) { if(p->type != XML_ELEMENT_NODE) continue; if(xmlStrcmp(p->name, (const xmlChar*)"function")) continue; QString func = QString((const char*)p->children->content); apis->add(func); } apis->prepare(); lexer->setAPIs(apis); } }
SqlEditorWidget::SqlEditorWidget(QWidget * parent) : QsciScintilla(parent), m_searchText(""), m_searchIndicator(9) // see QsciScintilla docs { m_prefs = Preferences::instance(); setMarginLineNumbers(0, true); setBraceMatching(SloppyBraceMatch); setAutoIndent(true); QsciLexerSQL * lexer = new QsciLexerSQL(this); QsciAPIs * api = new QsciAPIs(lexer); if (!api->load(":/api/sqlite.api")) qDebug("api is not loaded"); else { api->prepare(); lexer->setAPIs(api); } setAutoCompletionSource(QsciScintilla::AcsAll); setAutoCompletionCaseSensitivity(false); setAutoCompletionReplaceWord(true); setCaretLineVisible(m_prefs->activeHighlighting()); setCaretLineBackgroundColor(m_prefs->activeHighlightColor()); setUtf8(true); setFolding(QsciScintilla::BoxedFoldStyle); lexer->setFoldComments(true); lexer->setFoldCompact(false); setLexer(lexer); // search all occurrences // allow indicator painting *under* the text (but it makes editor slower a bit...) // It paints a colored box under the text for all occurrences of m_searchText. SendScintilla(QsciScintilla::SCI_SETTWOPHASEDRAW, 1); SendScintilla(QsciScintilla::SCI_INDICSETSTYLE, m_searchIndicator, QsciScintilla::INDIC_ROUNDBOX); // TODO/FIXME: make it configurable SendScintilla(QsciScintilla::SCI_INDICSETFORE, m_searchIndicator, QColor(255, 230, 90, 100)); SendScintilla(QsciScintilla::SCI_INDICSETUNDER, m_searchIndicator, 1); // end of search all occurrences connect(this, SIGNAL(linesChanged()), this, SLOT(linesChanged())); connect(this, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(cursorPositionChanged(int, int))); setCursorPosition(0, 0); linesChanged(); prefsChanged(); }
MdiChild::MdiChild() { setAttribute(Qt::WA_DeleteOnClose); isUntitled = true; forceClose = false; saveAndClose = false; lexer = 0; setAutoIndent(true); setMarginLineNumbers(1,true); setFolding(QsciScintilla::BoxedFoldStyle); setMarginType(1, QsciScintilla::NumberMargin); setMarginWidth(1,"00000"); setAutoCompletionSource(QsciScintilla::AcsDocument); setAutoCompletionThreshold(2); }
void chanEditorWidget::init(){ m_action = new QAction(this); m_action->setCheckable(true); connect(m_action, SIGNAL(triggered()), this, SLOT(show())); connect(m_action, SIGNAL(triggered()), this, SLOT(setFocus())); connect(this, SIGNAL(textChanged()), this, SLOT(documentWasModified())); QsciLexerCPP* lexer = new QsciLexerCPP(this); setLexer(lexer); //设置边框行号 setMarginLineNumbers(1, true); //精确的括号匹配 setBraceMatching(QsciScintilla::BraceMatch::StrictBraceMatch); //设置折叠 setFolding(QsciScintilla::FoldStyle::CircledTreeFoldStyle); //设置自动填充有效 setAutoCompletionFillupsEnabled(true); //所有可能的来源 setAutoCompletionSource(QsciScintilla::AcsAll); //补字符号 setCaretLineVisible(true); setAutoIndent(true); setUtf8(true); setWhitespaceVisibility(QsciScintilla::WsVisible); setAttribute(Qt::WA_DeleteOnClose); }
void QgsCodeEditor::setSciWidget() { setUtf8( true ); setCaretLineVisible( true ); setCaretLineBackgroundColor( QColor( "#fcf3ed" ) ); setBraceMatching( QsciScintilla::SloppyBraceMatch ); setMatchedBraceBackgroundColor( QColor( "#b7f907" ) ); // whether margin will be shown setMarginVisible( mMargin ); // whether margin will be shown setFoldingVisible( mFolding ); // indentation setAutoIndent( true ); setIndentationWidth( 4 ); setTabIndents( true ); setBackspaceUnindents( true ); setTabWidth( 4 ); // autocomplete setAutoCompletionThreshold( 2 ); setAutoCompletionSource( QsciScintilla::AcsAPIs ); }
FastoScintilla::FastoScintilla(QWidget* parent) : QsciScintilla(parent), lineNumberMarginWidth_(0), showAutoCompletion_(false) { setAutoIndent(true); setIndentationsUseTabs(false); setIndentationWidth(indentationWidth); setUtf8(true); setMarginWidth(1, 0); setCaretForegroundColor(caretForegroundColor); setMatchedBraceForegroundColor(matchedBraceForegroundColor); setMatchedBraceBackgroundColor(matchedBraceBackgroundColor); setSelectionBackgroundColor(selectionBackgroundColor); setSelectionForegroundColor(selectionForegroundColor); setContentsMargins(0, 0, 0, 0); setViewportMargins(3, 3, 3, 3); setMarginLineNumbers(0, true); // Margins colors // line numbers margin setMarginsBackgroundColor(marginsBackgroundColor); setMarginsForegroundColor(marginsForegroundColor); SendScintilla(QsciScintilla::SCI_SETHSCROLLBAR, 0); setWrapMode(QsciScintilla::WrapNone); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); VERIFY(connect(this, &FastoScintilla::linesChanged, this, &FastoScintilla::updateLineNumbersMarginWidth)); setAutoCompletionThreshold(1); setAutoCompletionCaseSensitivity(false); setAutoCompletionSource(QsciScintilla::AcsNone); }
/** * Initializes the lexer. * @param script * The script file. */ void SingleDocument::initLexer(QString script) { (void)script; if(lexer() == 0) { setLexer(new QsciLexerJavaScript(this)); QsciAPIs* apis = new QsciAPIs(lexer()); (void)apis; setAutoCompletionSource(QsciScintilla::AcsAPIs); setAutoCompletionCaseSensitivity(true); setAutoCompletionThreshold(3); setAutoIndent(true); setIndentationWidth(4); setTabWidth(4); setMarginLineNumbers(0,true); setMarginType(0, QsciScintilla::NumberMargin); setMarginsForegroundColor(QColor(128, 128, 128)); } }
SonicPiScintilla::SonicPiScintilla(SonicPiLexer *lexer, SonicPiTheme *theme) : QsciScintilla() { this->theme = theme; standardCommands()->clearKeys(); standardCommands()->clearAlternateKeys(); QString skey; QSettings settings("sonic-pi.net", "Key bindings"); #if defined(Q_OS_MAC) int SPi_CTRL = Qt::META; int SPi_META = Qt::CTRL; #else int SPi_CTRL = Qt::CTRL; int SPi_META = Qt::ALT; #endif // basic navigation addKeyBinding(settings, QsciCommand::PageDown, Qt::Key_PageDown); addKeyBinding(settings, QsciCommand::PageUp, Qt::Key_PageUp); addKeyBinding(settings, QsciCommand::LineDown, Qt::Key_N | SPi_CTRL); addOtherKeyBinding(settings, QsciCommand::LineDown, Qt::Key_Down); addKeyBinding(settings, QsciCommand::LineDownExtend, Qt::Key_Down | Qt::SHIFT); addKeyBinding(settings, QsciCommand::LineUp, Qt::Key_P | SPi_CTRL); addOtherKeyBinding(settings, QsciCommand::LineUp, Qt::Key_Up); addKeyBinding(settings, QsciCommand::LineUpExtend, Qt::Key_Up | Qt::SHIFT); addKeyBinding(settings, QsciCommand::CharRight, Qt::Key_F | SPi_CTRL); addOtherKeyBinding(settings, QsciCommand::CharRight, Qt::Key_Right); addKeyBinding(settings, QsciCommand::CharRightExtend, Qt::Key_Right | Qt::SHIFT); addKeyBinding(settings, QsciCommand::WordRight, Qt::Key_F | SPi_META); addOtherKeyBinding(settings, QsciCommand::WordRight, Qt::Key_Right | SPi_CTRL); addKeyBinding(settings, QsciCommand::WordRightExtend, Qt::Key_Right | SPi_CTRL | Qt::SHIFT); addKeyBinding(settings, QsciCommand::CharLeft, Qt::Key_B | SPi_CTRL); addOtherKeyBinding(settings, QsciCommand::CharLeft, Qt::Key_Left); addKeyBinding(settings, QsciCommand::CharLeftExtend, Qt::Key_Left | Qt::SHIFT); addKeyBinding(settings, QsciCommand::WordLeft, Qt::Key_B | SPi_META); addOtherKeyBinding(settings, QsciCommand::WordLeft, Qt::Key_Left | SPi_CTRL); addKeyBinding(settings, QsciCommand::WordLeftExtend, Qt::Key_Left | SPi_CTRL | Qt::SHIFT); addKeyBinding(settings, QsciCommand::Delete, Qt::Key_D | SPi_CTRL); addOtherKeyBinding(settings, QsciCommand::Delete, Qt::Key_Delete); addKeyBinding(settings, QsciCommand::DeleteBack, Qt::Key_H | SPi_CTRL); addOtherKeyBinding(settings, QsciCommand::DeleteBack, Qt::Key_Backspace); addKeyBinding(settings, QsciCommand::Home, Qt::Key_A | SPi_CTRL); addKeyBinding(settings, QsciCommand::VCHome, Qt::Key_Home); addKeyBinding(settings, QsciCommand::VCHomeExtend, Qt::Key_Home | Qt::SHIFT); addKeyBinding(settings, QsciCommand::DocumentStart, Qt::Key_Home | SPi_CTRL); addKeyBinding(settings, QsciCommand::DocumentStartExtend, Qt::Key_Home | SPi_CTRL | Qt::SHIFT); addKeyBinding(settings, QsciCommand::LineEnd, Qt::Key_E | SPi_CTRL); addOtherKeyBinding(settings, QsciCommand::LineEnd, Qt::Key_End); addKeyBinding(settings, QsciCommand::LineEndExtend, Qt::Key_End | Qt::SHIFT); addKeyBinding(settings, QsciCommand::DocumentEnd, Qt::Key_End | SPi_CTRL); addKeyBinding(settings, QsciCommand::DocumentEndExtend, Qt::Key_End | SPi_CTRL | Qt::SHIFT); addKeyBinding(settings, QsciCommand::Delete, Qt::Key_D | SPi_CTRL); addKeyBinding(settings, QsciCommand::VerticalCentreCaret, Qt::Key_L | SPi_CTRL); // tab return addKeyBinding(settings, QsciCommand::Newline, Qt::Key_Return); addKeyBinding(settings, QsciCommand::Backtab, Qt::Key_Tab | Qt::SHIFT); // copy paste addKeyBinding(settings, QsciCommand::SelectionCopy, Qt::Key_C | SPi_META); addOtherKeyBinding(settings, QsciCommand::SelectionCopy, Qt::Key_C | SPi_CTRL); addKeyBinding(settings, QsciCommand::SelectionCut, Qt::Key_X | SPi_META); addOtherKeyBinding(settings, QsciCommand::SelectionCut, Qt::Key_X | SPi_CTRL); addKeyBinding(settings, QsciCommand::Paste, Qt::Key_V | SPi_META); addOtherKeyBinding(settings, QsciCommand::Paste, Qt::Key_Y | SPi_CTRL); addKeyBinding(settings, QsciCommand::Undo, Qt::Key_Z | SPi_META); addOtherKeyBinding(settings, QsciCommand::Undo, Qt::Key_Z | SPi_CTRL); addKeyBinding(settings, QsciCommand::Redo, Qt::Key_Z | Qt::SHIFT | SPi_META); addOtherKeyBinding(settings, QsciCommand::Redo, Qt::Key_Z | Qt::SHIFT | SPi_CTRL); addKeyBinding(settings, QsciCommand::SelectAll, Qt::Key_A | SPi_META); // delete word left and right addKeyBinding(settings, QsciCommand::DeleteWordLeft, Qt::Key_Backslash | SPi_META); addKeyBinding(settings, QsciCommand::DeleteWordLeft, Qt::Key_Backspace | SPi_META); addKeyBinding(settings, QsciCommand::DeleteWordRight, Qt::Key_D | SPi_META); standardCommands()->readSettings(settings); this->setMatchedBraceBackgroundColor(theme->color("MatchedBraceBackground")); this->setMatchedBraceForegroundColor(theme->color("MatchedBraceForeground")); setIndentationWidth(2); setIndentationGuides(true); setIndentationGuidesForegroundColor(theme->color("IndentationGuidesForeground")); setBraceMatching( SonicPiScintilla::SloppyBraceMatch); //TODO: add preference toggle for this: //this->setFolding(SonicPiScintilla::CircledTreeFoldStyle, 2); setCaretLineVisible(true); setCaretLineBackgroundColor(theme->color("CaretLineBackground")); setFoldMarginColors(theme->color("FoldMarginForeground"),theme->color("FoldMarginForeground")); setMarginLineNumbers(0, true); setMarginsBackgroundColor(theme->color("MarginBackground")); setMarginsForegroundColor(theme->color("MarginForeground")); setMarginsFont(QFont("Menlo", 15, -1, true)); setUtf8(true); setText("#loading..."); setLexer((QsciLexer *)lexer); markerDefine(RightArrow, 8); setMarkerBackgroundColor("deeppink", 8); setAutoCompletionThreshold(1); setAutoCompletionSource(SonicPiScintilla::AcsAPIs); setAutoCompletionCaseSensitivity(false); setSelectionBackgroundColor(theme->color("SelectionBackground")); setSelectionForegroundColor(theme->color("SelectionForeground")); setCaretWidth(5); setCaretForegroundColor(theme->color("CaretForeground")); setEolMode(EolUnix); SendScintilla(SCI_SETWORDCHARS, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:_?!"); }
Editor::Editor(QWidget *parent) : QsciScintilla(parent) { // identify this widget as a code editor // WindoweIconText is used only for windows widgets. // So, it's free for us to use it here setWindowIconText("editor"); //setEolMode(QsciScintilla::EolUnix); lexer = new QsciLexerCPP; this->setLexer(lexer); this->setUtf8(true); //setAutoCompletionThreshold(0); api = new QsciAPIs(lexer); api->prepare(); LoadStyleSheet(this, "style_code_editor.css"); setAutoCompletionThreshold(3); setAutoCompletionSource(QsciScintilla::AcsAll); context= new QMenu(this); LoadStyleSheet(context, "style_menu.css"); actionHelpWithThis = context->addAction("Help with this code"); connect(actionHelpWithThis, SIGNAL(triggered()), this, SLOT(HelpWithThis())); context->addSeparator(); QAction * action = context->addAction("Undo"); action->setShortcut(tr("Ctrl+Z")); connect(action, SIGNAL(triggered()), this, SLOT(MenuUndo())); action = context->addAction("Redo"); action->setShortcut(tr("Ctrl+Y")); connect(action, SIGNAL(triggered()), this, SLOT(MenuRedo())); context->addSeparator(); action = context->addAction("Cut"); action->setShortcut(tr("Ctrl+X")); connect(action, SIGNAL(triggered()), this, SLOT(MenuCut())); action = context->addAction("Copy"); action->setShortcut(tr("Ctrl+C")); connect(action, SIGNAL(triggered()), this, SLOT(MenuCopy())); action = context->addAction("Paste"); action->setShortcut(tr("Ctrl+V")); connect(action, SIGNAL(triggered()), this, SLOT(MenuPaste())); /*action = context->addAction("Delete"); connect(action, SIGNAL(triggered()), this, SLOT(MenuDelete())); */ context->addSeparator(); action = context->addAction("Select all"); action->setShortcut(tr("Ctrl+A")); connect(action, SIGNAL(triggered()), this, SLOT(MenuSelectAll())); setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this,SLOT(ShowEditorMenu(const QPoint ))); connect(this, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(onCursorPositionChanged(int, int))); lblCursorPosition = new QLabel(this); LoadStyleSheet(lblCursorPosition, "style_cursorpos.css"); lblCursorPosition->setVisible(true); QVBoxLayout * vl = new QVBoxLayout(this); //QVBoxLayout * vl2 = new QVBoxLayout(this); int scrollbarw = qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent); QHBoxLayout * hl = new QHBoxLayout(this); hl->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Expanding, QSizePolicy::Fixed)); hl->addWidget(lblCursorPosition); hl->addSpacerItem(new QSpacerItem (scrollbarw,0, QSizePolicy::Fixed, QSizePolicy::Fixed)); vl->addLayout(hl); vl->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Fixed,QSizePolicy::Expanding )); lastModifiedTime = QDateTime::currentDateTime(); setAutoIndent(true); setEditorStyle(); }