Пример #1
0
QString ScriptEditorWidget::textUnderCursor() const
{
	QString szWord;
	QTextCursor tc = textCursor();
	if(tc.atBlockStart())
		return QString();
	tc.clearSelection();
	tc.movePosition(QTextCursor::StartOfWord,QTextCursor::KeepAnchor);
	if(tc.atBlockStart())
	{
		szWord.append(tc.selectedText());
		tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor);
		szWord.append(tc.selectedText());
		if(tc.atBlockEnd()){
			return szWord;
		}
		tc.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor);
		szWord.append(tc.selectedText());
		if(szWord.right(1)!=".")
			szWord.chop(1);
		return szWord;
	}

	tc.movePosition(QTextCursor::PreviousCharacter,QTextCursor::KeepAnchor);
	szWord=tc.selectedText();
	if(szWord.left(1)==".")
	{
		tc.movePosition(QTextCursor::StartOfWord);
		tc.movePosition(QTextCursor::PreviousCharacter);
		tc.movePosition(QTextCursor::PreviousWord);
		tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor,1);
		szWord.prepend(tc.selectedText());
	} else szWord.remove(0,1);
	return szWord;
}
Пример #2
0
void MainWindow::displayTooltip(QMouseEvent *e)
{
    static bool isFirstTime = true;
    static int selectionStart;
    static QString selectedText;
    static bool isExisted = false; //мы выделяли существующее в словаре?
    bool isExist = false;
    int i;

    QPoint p = e->pos();

    QTextCursor tc = ui->textEdit->cursorForPosition(p);
    tc.select(QTextCursor::WordUnderCursor);

    if (selectionStart != tc.selectionStart()) {

        //проверяем, есть ли слово в словаре
        for(i = 0; i < bptr->getListWords().size(); i++)
        {
            if(!bptr->getListWords().at(i).word.compare(tc.selectedText(), Qt::CaseInsensitive))
            {
                isExist = true;
                break;
            }
            if(!bptr->getListWords().at(i).word.compare(selectedText, Qt::CaseInsensitive))
            {
                isExisted = true;
            }
        }

        if (!isFirstTime)
        {
            QToolTip::hideText();   //скрываем предыдущий тултип
            //Надо удалить выделение предыдущего слова
            QTextCursor tc(ui->textEdit->document());
            tc.setPosition(selectionStart);
            tc.select(QTextCursor::WordUnderCursor);

            if(isExisted)
                tc.insertHtml(QString("<u>" + selectedText + "</b>"));
            else
            {
                tc.insertHtml(QString(selectedText));
            }
            isExisted = false;
        }
        selectionStart = tc.selectionStart();
        selectedText = tc.selectedText();

        if (tc.selectedText().length() > 0 && isExist)
        {
//            QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
//                               ui->textEdit, ui->textEdit->cursorRect());
            QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
                               ui->textEdit, ui->textEdit->cursorRect(tc));
            isFirstTime = false;
            tc.insertHtml(QString("<b>" + tc.selectedText() + "</b>"));
        }
    }
}
/**
 * @brief Increases (or decreases) the indention of the selected text (if there is a text selected) in the noteTextEdit
 * @return
 */
bool QMarkdownTextEdit::increaseSelectedTextIndention( bool reverse )
{
    QTextCursor c = this->textCursor();
    QString selectedText = c.selectedText();

    if ( selectedText != "" )
    {
        // we need this strange newline character we are getting in the selected text for newlines
        QString newLine = QString::fromUtf8( QByteArray::fromHex( "e280a9" ) );
        QString newText;

        if ( reverse )
        {
            // unindent text
            newText = selectedText.replace( newLine + "\t", "\n" );

            // remove leading \t
            newText.replace( QRegularExpression( "^\\t" ), "" );
        }
        else
        {
            // indent text
            newText = selectedText.replace( newLine, "\n\t" ).prepend( "\t" );

            // remove trailing \t
            newText.replace( QRegularExpression( "\\t$" ), "" );
        }

        // insert the new text
        c.insertText( newText );

        // update the selection to the new text
        c.setPosition( c.position() - newText.size(), QTextCursor::KeepAnchor );
        this->setTextCursor( c );

        return true;
    }
    // if nothing was selected but we want to reverse the indention check if there is a \t in front or after the cursor and remove it if so
    else if ( reverse )
    {
        int pos = c.position();
        // check for \t in front of cursor
        c.setPosition( pos - 1, QTextCursor::KeepAnchor );
        if ( c.selectedText() != "\t" )
        {
            // (select to) check for \t after the cursor
            c.setPosition( pos );
            c.setPosition( pos + 1, QTextCursor::KeepAnchor );
        }

        if ( c.selectedText() == "\t" )
        {
            c.removeSelectedText();
        }

        return true;
    }

    return false;
}
Пример #4
0
void TextZone::preventDoubleSpace()
{

    QTextCursor *tCursor = new QTextCursor(document());
    int cursorPos = this->textCursor().position();
    QString prevChar;
    QString nextChar;

    if(this->textCursor().atBlockStart() == false){
        do {tCursor->setPosition(cursorPos);
            tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
            prevChar = tCursor->selectedText();
            if(prevChar == " "){
                tCursor->removeSelectedText();
                cursorPos -= 1;
            }
        }
        while(prevChar == " ");

    }
    if(this->textCursor().atBlockEnd() == false){
        do {tCursor->setPosition(cursorPos);
            tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
            nextChar = tCursor->selectedText();
            if(nextChar == " "){
                tCursor->removeSelectedText();
            }
        }
        while(nextChar == " ");

    }

    this->textCursor().insertText(" ");
}
Пример #5
0
void FindDialog::replace()
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->textCursor();
	Qt::CaseSensitivity cs = m_ignore_case->isChecked() ? Qt::CaseInsensitive : Qt::CaseSensitive;
	if (!m_regular_expressions->isChecked()) {
		if (QString::compare(cursor.selectedText(), text, cs) == 0) {
			cursor.insertText(m_replace_string->text());
			document->setTextCursor(cursor);
		}
	} else {
		QRegExp regex(text, cs, QRegExp::RegExp2);
		QString match = cursor.selectedText();
		if (regex.exactMatch(match)) {
			match.replace(regex, m_replace_string->text());
			cursor.insertText(match);
			document->setTextCursor(cursor);
		}
	}

	find();
}
Пример #6
0
/** context sensitive completion
 *  take current line, give list of completions (both atoms and files)
 *  thanks to Jan for crafting a proper interface wrapping SWI-Prolog available facilities
 */
QString Completion::initialize(int promptPosition, QTextCursor c, QStringList &strings) {
    QString rets;
    SwiPrologEngine::in_thread _int;
    try {
        int p = c.position();
        Q_ASSERT(p >= promptPosition);

        c.setPosition(promptPosition, c.KeepAnchor);
        QString left = c.selectedText();
        if (left.length()) {
            PlString Before(left.toStdWString().data());

            c.setPosition(p);
            c.movePosition(c.EndOfLine, c.KeepAnchor);
            QString after = c.selectedText();
            PlString After(after.toStdWString().data());

            PlTerm Completions, Delete, word;
            if (PlCall("prolog", "complete_input", PlTermv(Before, After, Delete, Completions)))
                for (PlTail l(Completions); l.next(word); )
                    strings.append(t2w(word));

            c.setPosition(p);
            rets = t2w(Delete);
        }
    }
    catch(PlException e) {
        qDebug() << t2w(e);
    }
    catch(...) {
        qDebug() << "...";
    }

    return rets;
}
Пример #7
0
void TikzEditorView::editUncomment()
{
	bool go = true;
	QTextCursor textCursor = m_tikzEditor->textCursor();
	if (textCursor.hasSelection())
	{
		textCursor.beginEditBlock();
		const int start = textCursor.selectionStart();
		int end = textCursor.selectionEnd() - 2;
		textCursor.setPosition(start, QTextCursor::MoveAnchor);
		textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
		while (textCursor.position() < end && go)
		{
			textCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
			if (textCursor.selectedText() == QLatin1String("% "))
			{
				textCursor.removeSelectedText();
				--end;
			}
			go = textCursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor);
		}
		textCursor.endEditBlock();
	}
	else
	{
		textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
		textCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
		if (textCursor.selectedText() == QLatin1String("% "))
			textCursor.removeSelectedText();
	}
}
QString CWidgetReturnEmitTextEdit::textUnderCursor() const
{
	QTextCursor tc = textCursor();
	tc.select(QTextCursor::WordUnderCursor);

	// Save selected positions of current word.
	int selectionStart = tc.selectionStart();
	int selectionEnd = tc.selectionEnd();

	// If selection is at beginning of text edit then there can't be a slash to check for
	if (selectionStart == 0)
		return tc.selectedText();

	// Modify selection to include previous character
	tc.setPosition(selectionStart - 1, QTextCursor::MoveAnchor);
	tc.setPosition(selectionEnd, QTextCursor::KeepAnchor);

	// If previous character was / return current selection for command completion
	if(tc.selectedText().startsWith('/'))
		return tc.selectedText();
	else {
		// Else restore original selection and return for nick completion
		tc.setPosition(selectionStart, QTextCursor::MoveAnchor);
		tc.setPosition(selectionEnd, QTextCursor::KeepAnchor);
		return tc.selectedText();
	}
}
Пример #9
0
void TCommandLine::mousePressEvent(QMouseEvent* event)
{
    if (event->button() == Qt::RightButton) {
        QTextCursor c = cursorForPosition(event->pos());
        c.select(QTextCursor::WordUnderCursor);

        if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) {
            char** sl;
            mHunspellSuggestionNumber = Hunspell_suggest(mpHunspell, &sl, c.selectedText().toLatin1().data());
            auto popup = new QMenu(this);
            for (int i = 0; i < mHunspellSuggestionNumber; i++) {
                QAction* pA;
                pA = popup->addAction(sl[i]);
                connect(pA, &QAction::triggered, this, &TCommandLine::slot_popupMenu);
            }
            mpHunspellSuggestionList = sl;
            mPopupPosition = event->pos();
            popup->popup(event->globalPos());
        }

        event->accept();
        return;
    }
    QPlainTextEdit::mousePressEvent(event);
}
Пример #10
0
void Notepad::showNotepadContextMenu(const QPoint &pt)
{
    // Set Notepad popup menu
    QMenu *menu = ui->notepadTextEdit->createStandardContextMenu();
    QTextCursor cur = ui->notepadTextEdit->textCursor();
    QAction* first = menu->actions().at(0);

    if (cur.hasSelection()) {
        // Get selected text
        //this->main->add_debug_output("Selected text: " + cur.selectedText());
        this->addr = cur.selectedText();
    } else {
        // Get word under the cursor
        cur.select( QTextCursor::WordUnderCursor);
        //this->main->add_debug_output("Word: " + cur.selectedText());
        this->addr = cur.selectedText();
    }
    ui->actionDisassmble_bytes->setText( "Disassemble bytes at: " + this->addr);
    ui->actionDisassmble_function->setText( "Disassemble function at: " + this->addr);
    ui->actionHexdump_bytes->setText( "Hexdump bytes at: " + this->addr);
    ui->actionCompact_Hexdump->setText( "Compact Hexdump at: " + this->addr);
    ui->actionHexdump_function->setText( "Hexdump function at: " + this->addr);
    menu->insertAction(first, ui->actionDisassmble_bytes);
    menu->insertAction(first, ui->actionDisassmble_function);
    menu->insertAction(first, ui->actionHexdump_bytes);
    menu->insertAction(first, ui->actionCompact_Hexdump);
    menu->insertAction(first, ui->actionHexdump_function);
    menu->insertSeparator(first);
    ui->notepadTextEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
    menu->exec(ui->notepadTextEdit->mapToGlobal(pt));
    delete menu;
    ui->notepadTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
}
Пример #11
0
QString AutoCompleter::replaceSelection(QTextCursor &cursor, const QString &textToInsert) const
{
    if (!cursor.hasSelection())
        return QString();
    if (isQuote(textToInsert) && m_surroundWithQuotes)
        return cursor.selectedText() + textToInsert;
    if (m_surroundWithBrackets)
        return surroundSelectionWithBrackets(textToInsert, cursor.selectedText());
    return QString();
}
Пример #12
0
QTextDocument *Exporter::prepareTextDoc(QTextDocument *textDoc)
{



    QTextDocument *textDocument = textDoc->clone(this);

    //    textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:19pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}");

    //cut blank spaces at the begining and end :



    QTextCursor *tCursor = new QTextCursor(textDocument);
    tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1);
    tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);

    while(tCursor->selectedText() == " "){
        tCursor->deleteChar();
        tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
    }

    tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
    tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);

    while(tCursor->selectedText() == " "){
        tCursor->deleteChar();
        tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
    }

    //set text config :

    QTextBlockFormat blockFormat;
    //    blockFormat.setBottomMargin(0);
    //    blockFormat.setTopMargin(0);
    //    blockFormat.setTextIndent(72);
    blockFormat.setLineHeight(200, QTextBlockFormat::ProportionalHeight);
    blockFormat.setAlignment(Qt::AlignJustify);
    //    QTextCharFormat charFormat;
    //    charFormat.setFontPointSize(12);
    //    charFormat.setFontFamily("Courrier");

    tCursor->select(QTextCursor::Document);
    tCursor->mergeBlockFormat(blockFormat);
    //    tCursor->mergeBlockCharFormat(charFormat);


    QRegExp reg("-qt-paragraph-type:.*;|margin-top:.*;|margin-bottom:.*;|margin-left:.*;|margin-right:.*;|-qt-block-indent:.*;|text-indent:.*;|font-family:.*;|font-size:.*;");
    reg.setMinimal(true);
    textDocument->setHtml(textDocument->toHtml().remove(reg));



    return textDocument;
}
Пример #13
0
int Editor::autoIndent()
{
    QTextCursor cur = this->textCursor();
    if(cur.selectedText().length() > 0) {
        return 0;
    }

    int col = cur.columnNumber();

    cur.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
    cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,col);
    QString text = cur.selectedText();
    cur.clearSelection();

    int stop = -1;
    int indent = -1;
    int slcm = text.indexOf("'");

    if(slcm > -1) {
        stop = slcm;
    }

    cur.beginEditBlock();

    cur.insertBlock();

    for(int n = 0; n <= stop || isspace(text[n].toLatin1()); n++) {
        if(n == slcm) {
            if(text.indexOf("''") > -1)
                cur.insertText("''");
            else
                cur.insertText("'");
        }
        else {
            cur.insertText(" ");
        }
    }

    if(indent > 0) {
        for(int n = 0; n < indent; n++) {
            cur.insertText(" ");
        }
    }

    this->setTextCursor(cur);
    cur.endEditBlock();

    return 1;
}
Пример #14
0
void Editor::findDialog()
{
    FindDialog dialog(this);

    // Get current selection and set default value.
    QTextCursor cursor = currentTextEdit()->textCursor();
    QString selection = cursor.selectedText();
    if( selection != "" ) {
        dialog.setSearchText(selection);
    }

    int result = dialog.exec();
    if( result == QDialog::Accepted ) {

        lastSearch = dialog.searchText();

        lastSearchOptions = 0;
        if( dialog.caseSensitive() ) lastSearchOptions |= QTextDocument::FindCaseSensitively;
        if( dialog.wholeWord() ) lastSearchOptions |= QTextDocument::FindWholeWords;
        if( dialog.direction() == FindDialog::Direction_Backward ) lastSearchOptions |= QTextDocument::FindBackward;

        if( !find(lastSearch, lastSearchOptions) ) {
            QMessageBox::information(this, tr("Find"), tr("String '%0' not found").arg(lastSearch));
        }
    }
}
Пример #15
0
void GenericCodeEditor::handleKeyBackspace(QKeyEvent * event, QTextCursor & textCursor, bool & updateCursor)
{
    if (event->modifiers() & Qt::META) {
        textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
        textCursor.removeSelectedText();
    } else {
        if ( !overwriteMode()
             || (textCursor.positionInBlock() == 0)
             || textCursor.hasSelection() ) {
            QPlainTextEdit::keyPressEvent(event);
        } else {
            // in overwrite mode, backspace should insert a space
            textCursor.beginEditBlock();
            textCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
            QString selectedText = textCursor.selectedText();
            if (selectedText == QStringLiteral(" ") ||
                selectedText == QStringLiteral("\t") ) {
                textCursor.clearSelection();
            } else {
                textCursor.insertText(QString(QChar(' ')));
                textCursor.movePosition(QTextCursor::PreviousCharacter);
            }
            textCursor.endEditBlock();
        }
        updateCursor = true;
    }
}
Пример #16
0
void DrugInputEdit::mouseReleaseEvent(QMouseEvent *event) {
    Q_UNUSED(event);
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::LineUnderCursor);
    QString name = tc.selectedText();
    emit drugNameChanged(name);
}
Пример #17
0
inline void extendSelectionForEnvVar(QPlainTextEdit * textEdit, QTextCursor selection)
{
    if (selection.hasSelection()) {
        if (selection.selectedText() == QStringLiteral("~")) {
            QTextCursor wordAfter(selection);
            wordAfter.movePosition(QTextCursor::NextCharacter);
            wordAfter.select(QTextCursor::WordUnderCursor);
            if ( wordAfter.hasSelection() && (selection.block() == wordAfter.block()) ) {
                selection.setPosition(selection.selectionStart());
                selection.setPosition(wordAfter.selectionEnd(), QTextCursor::KeepAnchor);
                textEdit->setTextCursor(selection);
            }
        } else {
            int positionBeforeSelection = selection.selectionStart() - 1;
            if (positionBeforeSelection >= 0) {
                QChar charBeforeSelection = textEdit->document()->characterAt(positionBeforeSelection);
                if (charBeforeSelection == QChar('~')) {
                    QTextCursor extendedSelection = textEdit->textCursor();
                    extendedSelection.setPosition(positionBeforeSelection);
                    extendedSelection.setPosition(selection.selectionEnd(), QTextCursor::KeepAnchor);
                    textEdit->setTextCursor(extendedSelection);
                }
            }
        }
    }
}
Пример #18
0
void ScCodeEditor::evaluateLine()
{
    QString text;

    // Try current selection
    QTextCursor cursor = textCursor();
    if (cursor.hasSelection())
        text = cursor.selectedText();
    else {
        text = cursor.block().text();

        if( mStepForwardEvaluation ) {
            QTextCursor newCursor = cursor;
            newCursor.movePosition(QTextCursor::NextBlock);
            setTextCursor(newCursor);
        }

        // Adjust cursor for code blinking:
        cursor.movePosition(QTextCursor::StartOfBlock);
        cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
    }

    if (text.isEmpty())
        return;

    text.replace( QChar( 0x2029 ), QChar( '\n' ) );

    Main::evaluateCode(text);

    blinkCode( cursor );
}
Пример #19
0
QString OutputWindowPlainTextEdit::identifierUnderCursor(const QPoint &widgetPos, QString *repository) const
{
    if (repository)
        repository->clear();
    // Get the blank-delimited word under cursor. Note that
    // using "SelectWordUnderCursor" does not work since it breaks
    // at delimiters like '/'. Get the whole line
    QTextCursor cursor = cursorForPosition(widgetPos);
    const int cursorDocumentPos = cursor.position();
    cursor.select(QTextCursor::BlockUnderCursor);
    if (!cursor.hasSelection())
        return QString();
    QString block = cursor.selectedText();
    // Determine cursor position within line and find blank-delimited word
    const int cursorPos = cursorDocumentPos - cursor.block().position();
    const int blockSize = block.size();
    if (cursorPos < 0 || cursorPos >= blockSize || block.at(cursorPos).isSpace())
        return QString();
    // Retrieve repository if desired
    if (repository)
        if (QTextBlockUserData *data = cursor.block().userData())
            *repository = static_cast<const RepositoryUserData*>(data)->repository();
    // Find first non-space character of word and find first non-space character past
    const int startPos = firstWordCharacter(block, cursorPos);
    int endPos = cursorPos;
    for ( ; endPos < blockSize && !block.at(endPos).isSpace(); endPos++) ;
    return endPos > startPos ? block.mid(startPos, endPos - startPos) : QString();
}
Пример #20
0
void CallTipsList::validateCursor()
{
    QTextCursor cursor = textEdit->textCursor();
    int currentPos = cursor.position();
    if (currentPos < this->cursorPos) {
        hide();
    }
    else {
        cursor.setPosition(this->cursorPos);
        cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
        QString word = cursor.selectedText();
        if (!word.isEmpty()) {
            // the following text might be an operator, brackets, ...
            const QChar underscore =  QLatin1Char('_');
            const QChar ch = word.at(0);
            if (!ch.isLetterOrNumber() && ch != underscore)
                word.clear();
        }
        if (currentPos > this->cursorPos+word.length()) {
            hide();
        }
        else if (!word.isEmpty()){
            // If the word is empty we should not allow to do a search,
            // otherwise we may select the next item which is not okay in this
            // context. This might happen if e.g. Shift is pressed.
            keyboardSearch(word);
        }
    }
}
Пример #21
0
void TextEditor::addSpellSuggestMenu(QMenu * menu, const QPoint& pos) {
    if(document()->isEmpty())
        return;

    if(!highlighter_->isEnabled())
        return;

    QTextCursor cursor = cursorForPosition(pos);
    cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
    cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);

    QString word = cursor.selectedText();

    if(word.isEmpty())
        return;

    if(!highlighter_->spellChecker()->hasErrors(word))
        return;

    QStringList suggestions = highlighter_->spellChecker()->suggest(word);

    if(suggestions.isEmpty()) {
        qDebug() << "no suggestions for" << word;
    }
    else {
        foreach(const QString& variant, suggestions) {
            QAction * act = menu->addAction(variant, this, SLOT(handleSuggestion()));
            act->setData(pos);
        }
    }
int QScriptDebuggerCodeView::find(const QString &exp, int options)
{
    Q_D(QScriptDebuggerCodeView);
    QPlainTextEdit *ed = (QPlainTextEdit*)d->editor;
    QTextCursor cursor = ed->textCursor();
    if (options & 0x100) {
        // start searching from the beginning of selection
        if (cursor.hasSelection()) {
            int len = cursor.selectedText().length();
            cursor.clearSelection();
            cursor.setPosition(cursor.position() - len);
            ed->setTextCursor(cursor);
        }
        options &= ~0x100;
    }
    int ret = 0;
    if (ed->find(exp, QTextDocument::FindFlags(options))) {
        ret |= 0x1;
    } else {
        QTextCursor curse = cursor;
        curse.movePosition(QTextCursor::Start);
        ed->setTextCursor(curse);
        if (ed->find(exp, QTextDocument::FindFlags(options)))
            ret |= 0x1 | 0x2;
        else
            ed->setTextCursor(cursor);
    }
    return ret;
}
Пример #23
0
void CodeEditor::deleteTab()
{
    QString deletion = "    ";

    QTextCursor cursor = textCursor();
    if (cursor.selectionEnd() - cursor.selectionStart() <= 0) {
        //delete 4 spaces (tab)
        cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, deletion.length());
        QString selected = cursor.selectedText();
        if (selected.startsWith(deletion))
            cursor.deletePreviousChar();
    } else {
        QTextBlock firstBlock = document()->findBlock(cursor.selectionStart());
        QTextBlock lastBlock = document()->findBlock(cursor.selectionEnd() - 1);

        cursor.setPosition(firstBlock.position());
        cursor.beginEditBlock();
        do {
            if (cursor.block().text().startsWith(deletion)) {
                cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, deletion.length());
                cursor.removeSelectedText();
            }
        } while (cursor.movePosition(QTextCursor::NextBlock) && cursor.position() <= lastBlock.position());
        cursor.endEditBlock();
    }
}
Пример #24
0
void SimPrologEdit::keyPressEvent(QKeyEvent *e)
{
    switch (e->key()) {

    case Qt::Key_F1: {
        QTextCursor c = textCursor();
        c.select(c.WordUnderCursor);
        QString s = c.selectedText();
        if (s.length())
            for (QWidget *w = this; w; w = w->parentWidget())
                if (auto m = qobject_cast<spqrMainWindow*>(w)) {
                    m->activate(m->t_helpdoc);
                    m->helpDoc()->setUrl(
                        QString("http://localhost:%1/search?for=%2&in=all&match=summary")
                                .arg(m->DOC_PORT).arg(s));
                    break;
                }
    }   break;

    case Qt::Key_Tab:
        e->ignore();
        return;
    case Qt::Key_Backtab:
        e->ignore();
        return;
    }

    SimPrologEditBase::keyPressEvent(e);
}
Пример #25
0
void ExpressTextEdit::mouseMoveEvent(QMouseEvent *e)
{
    QTextCursor cursor = cursorForPosition(e->pos());
    cursor.select(QTextCursor::WordUnderCursor);
    QString wordUnderCursor = cursor.selectedText();

    const EntityDescriptor * entityDescriptor = m_Registry->FindEntity(wordUnderCursor.toAscii());
    const TypeDescriptor * typeDescriptor = m_Registry->FindType(wordUnderCursor.toAscii());
    if (entityDescriptor )
    {
        std::string str;
        setToolTip(entityDescriptor->GenerateExpress(str));
        if (QApplication::overrideCursor()==0)
            QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
    }
    else if(typeDescriptor)
    {
        std::string str;
        setToolTip(typeDescriptor->GenerateExpress(str));
        if (QApplication::overrideCursor()==0)
            QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
    }
    else
    {
        setToolTip(QString());
        QApplication::restoreOverrideCursor();
    }
}
Пример #26
0
QString CodeArea::textUnderCursor() const
{
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::WordUnderCursor);

    return tc.selectedText();
}
Пример #27
0
void TCommandLine::spellCheck()
{
    if (!mpHost->mEnableSpellCheck) {
        return;
    }

    QTextCursor oldCursor = textCursor();
    QTextCharFormat f;
    auto cred = QColor(Qt::red);
    f.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
    f.setUnderlineColor(cred);
    QTextCursor c = textCursor();
    c.select(QTextCursor::WordUnderCursor);

    if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) {
        f.setFontUnderline(true);
        c.setCharFormat(f);
    } else {
        f.setFontUnderline(false);
        c.setCharFormat(f);
    }
    setTextCursor(c);
    f.setFontUnderline(false);
    oldCursor.setCharFormat(f);
    setTextCursor(oldCursor);
}
Пример #28
0
void RtfCssEditor::insertBrace() {
  if (c->widget() != this)
    return;
  QTextCursor tc = textCursor();
  int currentPos = tc.position();
  tc.movePosition(QTextCursor::Down);
  tc.select(QTextCursor::LineUnderCursor);
  if (tc.selectedText().isEmpty() == true) {
    tc.setPosition(currentPos);
    //if (QTextCursor::NextWord)
    tc.insertText("\n    \n}");
    /*tc.movePosition(QTextCursor::Left);
    tc.movePosition(QTextCursor::Left);*/
    tc.movePosition(QTextCursor::Left);
    tc.movePosition(QTextCursor::Left);
    setTextCursor(tc);
    QRect cr = cursorRect();
    cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
    c->complete(cr); // popup it up!
  }
  else {
    tc.setPosition(currentPos);
    tc.insertText("\n    ");
  }
  tc.movePosition(QTextCursor::EndOfWord);
  QRect cr = cursorRect();
  cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
  c->complete(cr); // popup it up!
    
}
Пример #29
0
void milxQtPythonConsole::executeLine(bool storeOnly)
{
    QTextCursor textCursor = this->textCursor();
    textCursor.movePosition(QTextCursor::End);

    // Select the text from the command prompt until the end of the block
    // and get the selected text.
    textCursor.setPosition(commandPromptPosition());
    textCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
    QString code = textCursor.selectedText();

    // i don't know where this trailing space is coming from, blast it!
    if (code.endsWith(" "))
    {
        code.truncate(code.length()-1);
    }

    if (!code.isEmpty())
    {
        // Update the history
        _history << code;
        _historyPosition = _history.count();
        _currentMultiLineCode += code + "\n";

        if (!storeOnly)
        {
            executeCode(_currentMultiLineCode);
            _currentMultiLineCode = "";
        }
    }
    // Insert a new command prompt
    appendCommandPrompt(storeOnly);

}
Пример #30
0
void MLEdit::contextMenuEvent(QContextMenuEvent* event)
{
  QMenu* menu=createStandardContextMenu();

  if (!isReadOnly())
  {
#ifdef HAVE_HUNSPELL
    // Save position so we know which word to replace
    myMenuPos = event->pos();

    // Get word under cursor
    QTextCursor cr = cursorForPosition(myMenuPos);
    cr.select(QTextCursor::WordUnderCursor);
    QString word = cr.selectedText();
    if (!word.isEmpty())
    {
      // Get spelling suggestions
      QStringList suggestions = mySpellChecker->getSuggestions(word);
      if (!suggestions.isEmpty())
      {
        // Add spelling suggestions at the top of the menu
        QAction* firstAction = menu->actions().first();
        foreach (QString w, suggestions)
        {
          QAction* a = new QAction(w, menu);
          connect(a, SIGNAL(triggered()), SLOT(replaceWord()));
          menu->insertAction(firstAction, a);
        }