示例#1
0
void HunspellDialog::changeWord()
{
	//If we have ignored a word or its already changed, skip to the next.
	if(m_wfList->at(m_wfListIndex).ignore || m_wfList->at(m_wfListIndex).changed)
		goToNextWord();
	replaceWord(m_wfListIndex);
	goToNextWord();
}
示例#2
0
void HunspellDialog::changeAllWords()
{
	if(m_wfList->at(m_wfListIndex).ignore && !m_wfList->at(m_wfListIndex).changed)
		return;
	QString wordToChange=m_wfList->at(m_wfListIndex).w;
	//Do we start from 0 or from the instance of the word where we are... 0 for now
	for(int i=0;i<m_wfList->count();++i)
		if(m_wfList->at(i).w==wordToChange)
			replaceWord(i);
	goToNextWord();
}
示例#3
0
void MainForm::contextMenuRequested(const QPoint &point)
{
    QAction *action;
    QMenu * menu = new QMenu(textEdit);
    QStringList sl = spellChecker->suggestions();
    //if (sl.count() == 0) {

    action = new QAction(trUtf8("Undo\tCtrl+Z"), this);
    action->setShortcut(QKeySequence("Ctrl+Z"));
    connect(action, SIGNAL(triggered()), textEdit, SLOT(undo()));
    menu->addAction(action);
    action = new QAction(trUtf8("Redo\tCtrl+Shift+Z"), this);
    action->setShortcut(QKeySequence("Ctrl+Shift+Z"));
    connect(action, SIGNAL(triggered()), textEdit, SLOT(redo()));
    menu->addAction(action);
    action = new QAction("separator", this);
    action->setText("");
    action->setSeparator(true);
    menu->addAction(action);
    action = new QAction(trUtf8("Select All\tCtrl+A"), this);
    action->setShortcut(QKeySequence("Ctrl+A"));
    connect(action, SIGNAL(triggered()), textEdit, SLOT(selectAll()));
    menu->addAction(action);
    action = new QAction(trUtf8("Cut\tCtrl+X"), this);
    action->setShortcut(QKeySequence("Ctrl+X"));
    connect(action, SIGNAL(triggered()), textEdit, SLOT(cut()));
    menu->addAction(action);
    action = new QAction(trUtf8("Copy\tCtrl+C"), this);
    action->setShortcut(QKeySequence("Ctrl+C"));
    connect(action, SIGNAL(triggered()), textEdit, SLOT(copy()));
    menu->addAction(action);
    action = new QAction(trUtf8("Paste\tCtrl+V"), this);
    action->setShortcut(QKeySequence("Ctrl+V"));
    connect(action, SIGNAL(triggered()), textEdit, SLOT(paste()));
    menu->addAction(action);
    action = new QAction("separator", this);
    action->setText("");
    action->setSeparator(true);
    menu->addAction(action);
    action = new QAction(trUtf8("Larger Font\tCtrl++"), this);
    connect(action, SIGNAL(triggered()), this, SLOT(enlargeFont()));
    menu->addAction(action);
    action = new QAction(trUtf8("Smaller Font\tCtrl+-"), this);
    connect(action, SIGNAL(triggered()), this, SLOT(decreaseFont()));
    menu->addAction(action);

    //}
    if (sl.count() > 0)
        menu->addSeparator();
    foreach(QString str, sl) {
        QAction * action = menu->addAction(str);
        connect(action, SIGNAL(triggered()), this, SLOT(replaceWord()));
    }
示例#4
0
文件: speller.cpp 项目: Y-H/qupzilla
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 TextZone::contextMenuEvent(QContextMenuEvent *event)
{
    QTextCursor tCursor = this->textCursor();
    int tCursorPos = tCursor.position();
    int tCursorAnchor = tCursor.anchor();

    int minSelect = qMin(tCursorPos, tCursorAnchor);
    int maxSelect = qMax(tCursorPos, tCursorAnchor);

    QTextCursor cursor= this->cursorForPosition(event->pos());

    if(cursor.position() < minSelect || cursor.position() > maxSelect){
        this->setTextCursor(cursor);

    }


    QMenu menu(this);

    if(m_spellcheckBool){
        selectedWord.clear();


        cursor.select(QTextCursor::WordUnderCursor);


        selectedWord=cursor.selection().toPlainText();


        menu.addSeparator();

        bool isWellSpelled;
        if(textDocument->spellChecker()->spell(selectedWord) != 0)
            isWellSpelled = true;
        else
            isWellSpelled = false;


        if(!isWellSpelled){

            QStringList suggestions = textDocument->spellChecker()->suggest(selectedWord);

            QList<QAction *> suggestionWordsList;

            if(!suggestions.isEmpty())
                for(int i=0;i<suggestions.count();i++)
                {
                    QAction *suggestedWord = new QAction(this);
                    suggestedWord->setText(suggestions.at(i));
                    connect(suggestedWord, SIGNAL(triggered()),this, SLOT(replaceWord()));
                    suggestionWordsList.append(suggestedWord);
                }
            if(suggestions.isEmpty()){
                QAction *suggestedWord = new QAction(this);
                suggestedWord->setText(tr("No suggestion"));
                suggestedWord->setDisabled(true);
                suggestionWordsList.append(suggestedWord);
            }
            menu.addActions(suggestionWordsList);
        }
        if(!cursor.selection().isEmpty()){

            QTextCursor hyphenCursor = this->textCursor();
            int cursorMax = qMax(cursor.anchor(), cursor.position());
            hyphenCursor.setPosition(cursorMax, QTextCursor::MoveAnchor);
            hyphenCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);

            //            qDebug() << "anchor : "   + QString::number(cursor.anchor());
            //            qDebug() << "pos : "   + QString::number(cursor.position());

            //            qDebug() << "hyphenCursorSelection : " + hyphenCursor.selection().toPlainText();

            if(!isWellSpelled && !textDocument->spellChecker()->isInUserWordlist(selectedWord))
            {
                menu.addSeparator();
                menu.addAction(addToUserDictAct);

                if(!isWellSpelled && !textDocument->spellChecker()->isInUserWordlist(selectedWord)
                        && hyphenCursor.selection().toPlainText() == "-")
                {
                    int hyphenCursorMin = qMin(hyphenCursor.anchor(), hyphenCursor.position());
                    hyphenCursor.setPosition(hyphenCursorMin);
                    hyphenCursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor, 2);
                    selectedHyphenWord = selectedWord + hyphenCursor.selection().toPlainText();
                    if(selectedHyphenWord.right(1) == " ")
                        selectedHyphenWord.chop(1);
                    //                                    qDebug() << "selectedHyphenWord : " + selectedHyphenWord;
                    menu.addSeparator();
                    menu.addAction(addHyphenToUserDictAct);
                }
            }
            else if(textDocument->spellChecker()->isInUserWordlist(selectedWord)){
                menu.addSeparator();
                menu.addAction(removeFromUserDictAct);
            }
        }

        menu.addSeparator();
    }



    menu.addAction(boldAct);
    menu.addAction(italicAct);
    menu.addSeparator();
    //    menu.addMenu(alignmentGroup); // styles do that already
    menu.addMenu(stylesGroup);
    menu.addAction(spellcheckAct);
    menu.addSeparator();
    menu.addAction(cutAct);
    menu.addAction(copyAct);
    menu.addAction(pasteAct);
    menu.addAction(pasteWithoutFormattingAct);
    menu.addSeparator();
    menu.addAction(undoAct);
    menu.addAction(redoAct);
    menu.addSeparator();
    menu.addActions(m_actions);

    menu.exec(event->globalPos());
}