void MultiLineEdit::setSpellCheckEnabled(bool enabled) { highlighter()->setActive(enabled); if (enabled) { highlighter()->slotRehighlight(); } }
void SimpleRichTextEdit::addToIgnoreList() { highlighter()->ignoreWord(m_selectedWordCursor.selectedText()); highlighter()->rehighlight(); m_selectedWordCursor.clearSelection(); }
void SimpleRichTextEdit::addToDictionary() { highlighter()->addWordToDictionary(m_selectedWordCursor.selectedText()); highlighter()->rehighlight(); m_selectedWordCursor.clearSelection(); }
void KreTextEdit::createHighlighter() { KTextEdit::createHighlighter(); Sonnet::Highlighter * current_highlighter = highlighter(); if (current_highlighter) current_highlighter->setAutomatic( false ); }
MultiLineEdit::MultiLineEdit(QWidget* parent) : MultiLineEditParent(parent) { document()->setDocumentMargin(0); setAcceptRichText(false); #ifdef HAVE_KDE enableFindReplace(false); #endif #if defined HAVE_SONNET && !defined HAVE_KDE _spellCheckDecorator = new Sonnet::SpellCheckDecorator(this); highlighter()->setActive(highlighter()->checkerEnabledByDefault()); #endif setMode(SingleLine); setLineWrapEnabled(false); reset(); // Prevent QTextHtmlImporter::appendNodeText from eating whitespace document()->setDefaultStyleSheet("span { white-space: pre-wrap; }"); connect(this, &QTextEdit::textChanged, this, &MultiLineEdit::on_textChanged); _mircColorMap["00"] = "#ffffff"; _mircColorMap["01"] = "#000000"; _mircColorMap["02"] = "#000080"; _mircColorMap["03"] = "#008000"; _mircColorMap["04"] = "#ff0000"; _mircColorMap["05"] = "#800000"; _mircColorMap["06"] = "#800080"; _mircColorMap["07"] = "#ffa500"; _mircColorMap["08"] = "#ffff00"; _mircColorMap["09"] = "#00ff00"; _mircColorMap["10"] = "#008080"; _mircColorMap["11"] = "#00ffff"; _mircColorMap["12"] = "#4169e1"; _mircColorMap["13"] = "#ff00ff"; _mircColorMap["14"] = "#808080"; _mircColorMap["15"] = "#c0c0c0"; }
void MultiLineEdit::contextMenuEvent(QContextMenuEvent* event) { QMenu* menu = createStandardContextMenu(); menu->addSeparator(); auto action = menu->addAction(tr("Auto Spell Check")); action->setCheckable(true); action->setChecked(highlighter()->isActive()); connect(action, &QAction::toggled, this, &MultiLineEdit::setSpellCheckEnabled); menu->exec(event->globalPos()); delete menu; }
QMenu * SimpleRichTextEdit::createContextMenu(const QPoint &mouseGlobalPos) { Qt::TextInteractionFlags interactionFlags = this->textInteractionFlags(); QTextDocument *document = this->document(); QTextCursor cursor = textCursor(); const bool showTextSelectionActions = (Qt::TextEditable | Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse) & interactionFlags; QMenu *menu = new QMenu(this); if(interactionFlags & Qt::TextEditable) { m_actions[Undo]->setEnabled(document->isUndoAvailable()); menu->addAction(m_actions[Undo]); m_actions[Redo]->setEnabled(document->isRedoAvailable()); menu->addAction(m_actions[Redo]); menu->addSeparator(); m_actions[Cut]->setEnabled(cursor.hasSelection()); menu->addAction(m_actions[Cut]); } if(showTextSelectionActions) { m_actions[Copy]->setEnabled(cursor.hasSelection()); menu->addAction(m_actions[Copy]); } if(interactionFlags & Qt::TextEditable) { #if !defined(QT_NO_CLIPBOARD) m_actions[Paste]->setEnabled(canPaste()); menu->addAction(m_actions[Paste]); #endif m_actions[Delete]->setEnabled(cursor.hasSelection()); menu->addAction(m_actions[Delete]); m_actions[Clear]->setEnabled(!document->isEmpty()); menu->addAction(m_actions[Clear]); if(m_insertUnicodeControlCharMenu && interactionFlags & Qt::TextEditable) { menu->addSeparator(); menu->addMenu(m_insertUnicodeControlCharMenu); } } if(showTextSelectionActions) { menu->addSeparator(); m_actions[SelectAll]->setEnabled(!document->isEmpty()); menu->addAction(m_actions[SelectAll]); } if(interactionFlags & Qt::TextEditable) { menu->addSeparator(); m_actions[ToggleBold]->setCheckable(true); m_actions[ToggleBold]->setChecked(fontBold()); menu->addAction(m_actions[ToggleBold]); m_actions[ToggleItalic]->setCheckable(true); m_actions[ToggleItalic]->setChecked(fontItalic()); menu->addAction(m_actions[ToggleItalic]); m_actions[ToggleUnderline]->setCheckable(true); m_actions[ToggleUnderline]->setChecked(fontUnderline()); menu->addAction(m_actions[ToggleUnderline]); m_actions[ToggleStrikeOut]->setCheckable(true); m_actions[ToggleStrikeOut]->setChecked(fontStrikeOut()); menu->addAction(m_actions[ToggleStrikeOut]); menu->addAction(m_actions[ChangeTextColor]); menu->addSeparator(); m_actions[CheckSpelling]->setEnabled(!document->isEmpty()); menu->addAction(m_actions[CheckSpelling]); m_actions[ToggleAutoSpellChecking]->setChecked(checkSpellingEnabled()); menu->addAction(m_actions[ToggleAutoSpellChecking]); if(checkSpellingEnabled()) { setupWordUnderPositionCursor(mouseGlobalPos); QString selectedWord = m_selectedWordCursor.selectedText(); if(!selectedWord.isEmpty() && highlighter() && highlighter()->isWordMisspelled(selectedWord)) { QMenu *suggestionsMenu = menu->addMenu(i18n("Suggestions")); suggestionsMenu->addAction(i18n("Ignore"), this, SLOT(addToIgnoreList())); suggestionsMenu->addAction(i18n("Add to Dictionary"), this, SLOT(addToDictionary())); suggestionsMenu->addSeparator(); QStringList suggestions = highlighter()->suggestionsForWord(m_selectedWordCursor.selectedText()); if(suggestions.empty()) suggestionsMenu->addAction(i18n("No suggestions"))->setEnabled(false); else { for(QStringList::ConstIterator it = suggestions.begin(), end = suggestions.end(); it != end; ++it) suggestionsMenu->addAction(*it, this, SLOT(replaceWithSuggestion())); } } } menu->addSeparator(); m_actions[AllowTabulations]->setCheckable(true); m_actions[AllowTabulations]->setChecked(!tabChangesFocus()); menu->addAction(m_actions[AllowTabulations]); } return menu; }
void Checker::process_file() { srchilite::RegexRuleFactory rule_factory; srchilite::LangDefManager lang_def_manager(&rule_factory); srchilite::SourceHighlighter highlighter( lang_def_manager.getHighlightState(LANG_PATH, file_language.second)); srchilite::FormatterManager manager( PseudoFormatterPtr(new PseudoFormatter(token_types, tokens, env.current_line_index))); manager.addFormatter("cbracket_open", new_formatter("cbracket_open")); manager.addFormatter("cbracket_close", new_formatter("cbracket_close")); manager.addFormatter("pasbracket_open", new_formatter("pasbracket_open")); manager.addFormatter("pasbracket_close", new_formatter("pasbracket_close")); manager.addFormatter("keyword", new_formatter("keyword")); manager.addFormatter("number", new_formatter("number")); manager.addFormatter("label", new_formatter("label")); manager.addFormatter("preproc", new_formatter("preproc")); manager.addFormatter("comment", new_formatter("comment")); manager.addFormatter("string", new_formatter("string")); manager.addFormatter("specialchar", new_formatter("string")); manager.addFormatter("symbol", new_formatter("symbol")); manager.addFormatter("type", new_formatter("type")); manager.addFormatter("usertype", new_formatter("classname")); manager.addFormatter("classname", new_formatter("classname")); manager.addFormatter("function", new_formatter("function")); manager.addFormatter("identifier", new_formatter("identifier")); manager.addFormatter("case", new_formatter("case")); manager.addFormatter("of", new_formatter("of")); manager.addFormatter("typeblock", new_formatter("typeblock")); manager.addFormatter("varblock", new_formatter("varblock")); manager.addFormatter("keyword_declaring_varblock", new_formatter("keyword_declaring_varblock")); manager.addFormatter("keyword_declaring_func", new_formatter("keyword_declaring_func")); manager.addFormatter( "keyword_with_following_operation", new_formatter("keyword_with_following_operation")); manager.addFormatter( "keyword_with_following_operation_after_braces", new_formatter("keyword_with_following_operation_after_braces")); manager.addFormatter("switch_labels", new_formatter("switch_labels")); manager.addFormatter("semicolon", new_formatter("semicolon")); manager.addFormatter("brace", new_formatter("brace")); manager.addFormatter("bracket", new_formatter("bracket")); highlighter.setFormatterManager(&manager); srchilite::FormatterParams params; highlighter.setFormatterParams(¶ms); for(env.current_line_index = 0; file_to_process.good(); ++env.current_line_index) { getline(file_to_process, env.current_line); check_line_length(); check_if_empty(); lines.push_back(LineInfo(env.current_line, env.current_line.size(), 0, 0, 0)); if(env.current_line.size() != 0) { params.start = 0; highlighter.highlightParagraph(env.current_line); }; } check_newline_at_eof(); calculate_expected_depth(); if(settings.indentation_policy != IP_IGNORE) check_indentation(); process_tokens(); }
void MultiLineEdit::createHighlighter() { KTextEdit::createHighlighter(); if (highlighter()) highlighter()->setAutomatic(false); }
int main() { // we highlight C++ code for simplicity srchilite::SourceHighlighter highlighter (srchilite::Instances::getLangDefManager().getHighlightState( DATADIR, "cpp.lang"));
/** Main routine */ int main(int argc,char **argv) { // process inputs that were passed to us via QUERY_STRING std::cout << "Content-Type:application/javascript;charset=utf-8\r\n\n"; std::string callback; try { // get input parameters const char *queryEnv = getenv("QUERY_STRING"); std::string queryString; if (queryEnv) { queryString = queryEnv; } else if (argc>=2) { queryString = argv[1]; } else { std::cout << "No input!\n"; exit(1); } // parse query string std::vector<std::string> parts = split(queryString,'&'); std::string searchFor,callback; int num=1,page=0; for (std::vector<std::string>::const_iterator it=parts.begin();it!=parts.end();++it) { std::vector<std::string> kv = split(*it,'='); if (kv.size()==2) { std::string val = uriDecode(kv[1]); if (kv[0]=="q") searchFor = val; else if (kv[0]=="n") num = fromString<int>(val); else if (kv[0]=="p") page = fromString<int>(val); else if (kv[0]=="cb") callback = val; } } std::string indexDir = "doxysearch.db"; if (queryString=="test") // user test { bool dbOk = dirExists(indexDir); if (dbOk) { std::cout << "Test successful."; } else { std::cout << "Test failed: cannot find search index " << indexDir; } exit(0); } // create query Xapian::Database db(indexDir); Xapian::Enquire enquire(db); Xapian::Query query; std::vector<std::string> words = split(searchFor,' '); for (std::vector<std::string>::const_iterator it=words.begin();it!=words.end();++it) { query = Xapian::Query(Xapian::Query::OP_OR,query,Xapian::Query(*it)); } enquire.set_query(query); // get results Xapian::MSet matches = enquire.get_mset(page*num,num); unsigned int hits = matches.get_matches_estimated(); unsigned int offset = page*num; unsigned int pages = num>0 ? (hits+num-1)/num : 0; if (offset>hits) offset=hits; if (offset+num>hits) num=hits-offset; // write results as JSONP std::cout << callback.c_str() << "("; std::cout << "{" << std::endl << " \"hits\":" << hits << "," << std::endl << " \"first\":" << offset << "," << std::endl << " \"count\":" << num << "," << std::endl << " \"page\":" << page << "," << std::endl << " \"pages\":" << pages << "," << std::endl << " \"query\": \"" << escapeString(searchFor) << "\"," << std::endl << " \"items\":[" << std::endl; // foreach search result unsigned int o = offset; for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i,++o) { std::vector<Fragment> hl; Xapian::Document doc = i.get_document(); highlighter(doc.get_value(FIELD_DOC),words,hl); std::cout << " {\"type\": \"" << doc.get_value(FIELD_TYPE) << "\"," << std::endl << " \"name\": \"" << doc.get_value(FIELD_NAME) << doc.get_value(FIELD_ARGS) << "\"," << std::endl << " \"tag\": \"" << doc.get_value(FIELD_TAG) << "\"," << std::endl << " \"url\": \"" << doc.get_value(FIELD_URL) << "\"," << std::endl; std::cout << " \"fragments\":[" << std::endl; int c=0; bool first=true; for (std::vector<Fragment>::const_iterator it = hl.begin();it!=hl.end() && c<3;++it,++c) { if (!first) std::cout << "," << std::endl; std::cout << " \"" << escapeString((*it).text) << "\""; first=false; } if (!first) std::cout << std::endl; std::cout << " ]" << std::endl; std::cout << " }"; if (o<offset+num-1) std::cout << ","; std::cout << std::endl; } std::cout << " ]" << std::endl << "})" << std::endl; } catch (const Xapian::Error &e) // Xapian exception { showError(callback,e.get_description()); } catch (...) // Any other exception { showError(callback,"Unknown Exception!"); exit(1); } return 0; }