SpellCheckTokenizer::SpellCheckTokenizer(const QString *text) { this->text = text; boundaryFinder = QTextBoundaryFinder(QTextBoundaryFinder::Word, *text); position = 0; startWord = -1; if(boundaryFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem) startWord = 0; }
TextBreakIterator* sentenceBreakIterator(const UChar* string, int length) { if (!string) return 0; if (!iterator) iterator = new QTextBoundaryFinder; *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Sentence, (const QChar *)string, length, buffer, sizeof(buffer)); return static_cast<TextBreakIterator*>(iterator); }
void Filter::replace( const Word& w, const QString& newWord) { int oldLen = w.word.length(); //start spell checkin from the just correct word m_buffer = m_buffer.replace( w.start, oldLen, newWord ); m_finder = QTextBoundaryFinder(QTextBoundaryFinder::Word, m_buffer); m_finder.setPosition(w.start); }
void Speller::populateContextMenu(QMenu* menu, const QWebHitTestResult &hitTest) { m_element = hitTest.element(); if (!m_enabled || m_element.isNull() || m_element.attribute(QLatin1String("type")) == QLatin1String("password")) { return; } const QString text = m_element.evaluateJavaScript("this.value").toString(); const int pos = m_element.evaluateJavaScript("this.selectionStart").toInt() + 1; QTextBoundaryFinder finder = QTextBoundaryFinder(QTextBoundaryFinder::Word, text); finder.setPosition(pos); m_startPos = finder.toPreviousBoundary(); m_endPos = finder.toNextBoundary(); const QString &word = text.mid(m_startPos, m_endPos - m_startPos).trimmed(); if (!isValidWord(word) || !isMisspelled(word)) { return; } const int limit = 6; QStringList suggests = suggest(word); int count = suggests.count() > limit ? limit : suggests.count(); QFont boldFont = menu->font(); boldFont.setBold(true); for (int i = 0; i < count; ++i) { QAction* act = menu->addAction(suggests.at(i), this, SLOT(replaceWord())); act->setData(suggests.at(i)); act->setFont(boldFont); } if (count == 0) { menu->addAction(tr("No suggestions"))->setEnabled(false); } menu->addAction(tr("Add to dictionary"), this, SLOT(addToDictionary()))->setData(word); menu->addSeparator(); }
void Filter::setBuffer( const QString& buffer ) { m_buffer = buffer; m_finder = QTextBoundaryFinder(QTextBoundaryFinder::Word, m_buffer); }