Esempio n. 1
0
QList<PreTeXFileType::AutocompletionItem> PreTeXFileType::createAutocompletionItemList(
        BAbstractCodeEditorDocument *doc, QTextCursor cursor)
{
    QList<AutocompletionItem> list;
    if (!doc || cursor.isNull())
        return list;
    cursor.select(QTextCursor::WordUnderCursor);
    if (!cursor.hasSelection())
        return list;
    QString word = cursor.selectedText();
    list << builtinFunctionAutocompletionItemListForWord(word);
    return list;
}
Esempio n. 2
0
bool FindDialog::find() {
    QTextEdit* textEdit = getCurrentTextEdit();
    if (textEdit == NULL) return false;
    int from = textEdit->textCursor().selectionEnd();
    QTextCursor cursor = textEdit->document()->find(ui->findString->text(), from);
    if (!cursor.isNull()) {
        textEdit->setTextCursor(cursor);
        return true;
    }
    else {
        return false;
    }
}
Esempio n. 3
0
void LineIndicator::mouseMoveEvent( QMouseEvent *e )
{
    QTextCursor cursor = mEditor->cursorForPosition(QPoint(0, e->pos().y()));
    if(cursor.isNull() || cursor.position() == mLastCursorPos)
        return;
    QTextCursor origCursor = mEditor->textCursor();
    origCursor.setPosition( cursor.position(), QTextCursor::KeepAnchor );
    mEditor->setTextCursor(origCursor);
    mLastCursorPos = cursor.position();
    // The selectionChanged() signal of the editor does not always fire here!
    // Qt bug?
    update();
}
Esempio n. 4
0
void MainWindow::insertCustomer(const QString &customer){
    if (customer.isEmpty())
        return;
    QStringList customerList = customer.split(", ");
    QTextDocument *document = chatbox->document();
    QTextCursor cursor = document->find("NAME");
    if (!cursor.isNull()) {
        cursor.beginEditBlock();
        cursor.insertText(customerList.at(0));
        QTextCursor oldcursor = cursor;
        cursor = document->find("ADDRESS");
        if (!cursor.isNull()) {
            for (int i = 1; i < customerList.size(); ++i) {
                cursor.insertBlock();
                cursor.insertText(customerList.at(i));
            }
            cursor.endEditBlock();
        }
        else
            oldcursor.endEditBlock();
    }
}
Esempio n. 5
0
void FindEditor::findHelper(FindOption *opt)
{
    bool bFocus = m_findEdit->hasFocus();
    LiteApi::IEditor *editor = m_liteApp->editorManager()->currentEditor();
    if (!editor) {
        return;
    }
    LiteApi::ITextEditor *textEditor = LiteApi::getTextEditor(editor);
    QTextCursor find;
    if (textEditor) {
        QPlainTextEdit *ed = LiteApi::getPlainTextEdit(editor);
        if (ed) {
            find = findEditor(ed->document(),ed->textCursor(),opt);
            if (!find.isNull()) {
                ed->setTextCursor(find);
            }
        }
    } else {
        QTextBrowser *ed = LiteApi::findExtensionObject<QTextBrowser*>(editor,"LiteApi.QTextBrowser");
        if (ed) {
            find = findEditor(ed->document(),ed->textCursor(),opt);
            if (!find.isNull()) {
                ed->setTextCursor(find);
            }
        }
    }
    if (find.isNull()) {
        m_status->setText(tr("Not find"));
    } else {
        m_status->setText(QString("Ln:%1 Col:%2").
                              arg(find.blockNumber()+1).
                              arg(find.columnNumber()+1));
    }
    if (bFocus) {
        m_findEdit->setFocus();
    } else if (textEditor) {
        textEditor->onActive();
    }
}
Esempio n. 6
0
// 
// Replace text if doreplace is true, otherwise only do "find next"
// Returns true if the find next failed (end of document)
//
bool MibEditor::Replace(bool doreplace)
{
    QTextCursor tc;

    ff = 0;
    find_string = replace_uid.comboFind->currentText(); 
    if (!find_strings.contains(find_string))
        find_strings.append(find_string);
    replace_string = replace_uid.comboReplace->currentText();
    if (!replace_strings.contains(replace_string))
            replace_strings.append(replace_string);

    if (replace_uid.checkWords->isChecked())
        ff |= QTextDocument::FindWholeWords;
    if (replace_uid.checkCase->isChecked())
        ff |= QTextDocument::FindCaseSensitively;
    if (replace_uid.checkBackward->isChecked())
        ff |= QTextDocument::FindBackward;

    tc = s->MainUI()->MIBFile->textCursor();
    if(doreplace && !tc.isNull() && tc.hasSelection() && 
       (tc.selectedText().compare(find_string, 
                                  (replace_uid.checkCase->isChecked()?
                                  Qt::CaseSensitive:Qt::CaseInsensitive))==0))
        tc.insertText(replace_uid.comboReplace->currentText());

    tc = s->MainUI()->MIBFile->document()->find(find_string,
                                                s->MainUI()->MIBFile->textCursor(),
                                                ff);

    if (!tc.isNull())
    {
        s->MainUI()->MIBFile->setTextCursor(tc);
        tc.select(QTextCursor::WordUnderCursor);
    }

    return (tc.isNull()?true:false);
}
Esempio n. 7
0
bool ConsoleWriter::findOnce(QString find, bool regex, int options) {
  QTextCursor cursor = textCursor();
  QTextDocument::FindFlag opts = (QTextDocument::FindFlag)options;

  if (regex) cursor = document()->find(QRegExp(find), cursor, opts);
  else cursor = document()->find(find, cursor, opts);

  if (!cursor.isNull()) {
    setTextCursor(cursor);
    return true;
  }

  return false;
}
void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const
{
    if (_cursor.isNull())
        return;

    QTextDocumentPrivate *destPieceTable = _cursor.d->priv;
    destPieceTable->beginEditBlock();

    QTextCursor sourceCursor(doc);
    sourceCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
    QTextCopyHelper(sourceCursor, _cursor, importedFromPlainText, _cursor.charFormat()).copy();

    destPieceTable->endEditBlock();
}
Esempio n. 9
0
void ScCodeEditor::mouseDoubleClickEvent( QMouseEvent * e )
{
    if (e->button() == Qt::LeftButton) {
        QTextCursor cursor = cursorForPosition(e->pos());
        QTextCursor selection = selectionForPosition( cursor.position() );

        if (!selection.isNull()) {
            mMouseBracketMatch = true;
            setTextCursor(selection);
            return;
        }
    }

    GenericCodeEditor::mouseDoubleClickEvent(e);
}
Esempio n. 10
0
void MainWindow::addParagraph(const QString &paragraph){
    if (paragraph.isEmpty())
        return;
    QTextDocument *document = chatbox->document();
    QTextCursor cursor = document->find(tr("Yours sincerely,"));
    if (cursor.isNull())
        return;
    cursor.beginEditBlock();
    cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor, 2);
    cursor.insertBlock();
    cursor.insertText(paragraph);
    cursor.insertBlock();
    cursor.endEditBlock();

}
void ScCodeEditor::mouseDoubleClickEvent( QMouseEvent * e )
{
    // Always pass to superclass so as to handle line selection on triple click
    GenericCodeEditor::mouseDoubleClickEvent(e);

    if (e->button() == Qt::LeftButton) {
        QTextCursor cursor = cursorForPosition(e->pos());
        QTextCursor selection = selectionForPosition( cursor.position() );

        if (!selection.isNull()) {
            mMouseBracketMatch = true;
            setTextCursor(selection);
            return;
        }
    }
}
Esempio n. 12
0
QTextCursor FindDialog::replace(const QTextCursor &start, QTextDocument *doc, int startPos, int endPos) {
   QTextCursor result = find(start, doc);

   if (!result.isNull()) {
      if ((endPos > 0 && result.selectionEnd() > endPos) || 
          (startPos > 0 && result.selectionStart() < startPos)) {
         result = QTextCursor(); // null cursor
      } else {
         result.removeSelectedText();
         result.insertText(getReplaceString());
         //result.setPosition(result.position() + getReplaceString().length());
      }
   }
   
   return result;
}
Esempio n. 13
0
File: text.cpp Progetto: iphydf/qTox
void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
{
    if (!cursor.isNull()) {
        cursor.beginEditBlock();
        cursor.setPosition(point.first);
        cursor.setPosition(point.first + point.second, QTextCursor::KeepAnchor);
        cursor.endEditBlock();

        QTextCharFormat format;
        format.setBackground(QBrush(QColor(COLOR_HIGHLIGHT)));
        cursor.mergeCharFormat(format);

        regenerate();
        update();
    }
}
Esempio n. 14
0
void PlainTextViewWidget::gotoLastResult()
{
   if (m_searchResults.isEmpty()) {
      return;
   }

   QTextCursor cursor = m_searchResults.last();
   if (cursor == m_currentSearchResult) {
      return;
   }
   m_currentSearchResult = cursor;

   if (!cursor.isNull()) {
      jumpToHighlightResult(cursor);
   }
}
Esempio n. 15
0
QTextCursor FindEditor::findEditor(QTextDocument *doc, const QTextCursor &cursor, FindOption *opt, bool wrap)
{
    QTextDocument::FindFlags flags = 0;
    if (opt->backWard) {
        flags |= QTextDocument::FindBackward;
    }
    if (opt->matchCase) {
        flags |= QTextDocument::FindCaseSensitively;
    }
    if (opt->matchWord) {
        flags |= QTextDocument::FindWholeWords;
    }
    Qt::CaseSensitivity cs = Qt::CaseInsensitive;
    if (opt->matchCase) {
        cs = Qt::CaseSensitive;
    }
    int from = cursor.position();
    if (cursor.hasSelection()) {
        if (opt->backWard) {
            from = cursor.selectionStart();
        } else {
            from = cursor.selectionEnd();
        }
    }

    QTextCursor find;
    if (opt->useRegexp) {
        find = doc->find(QRegExp(opt->findText,cs),from,flags);
    } else {
        find = doc->find(opt->findText,from,flags);
    }

    if (find.isNull() && opt->wrapAround && wrap) {
        if (opt->backWard) {
            from = doc->lastBlock().position()+doc->lastBlock().length();
        } else {
            from = 0;
        }
        if (opt->useRegexp) {
            find = doc->find(QRegExp(opt->findText,cs),from,flags);
        } else {
            find = doc->find(opt->findText,from,flags);
        }
    }
    return find;
}
Esempio n. 16
0
void SpellChecker::changeAll()
{
	QString replacement = m_suggestion->text();

	QTextCursor cursor = m_cursor;
	cursor.movePosition(QTextCursor::Start);
	forever {
		cursor = m_document->document()->find(m_word, cursor, QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords);
		if (!cursor.isNull()) {
			cursor.insertText(replacement);
		} else {
			break;
		}
	}

	check();
}
void	QsvTextOperationsWidget::on_replaceAll_clicked()
{
	// WHY NOT HIDING THE WIDGET?
	// it seems that if you hide the widget, when the replace all action
	// is triggered by pressing control+enter on the replace widget
	// eventually an "enter event" is sent to the text eidtor.
	// the work around is to update the transparency of the widget, to let the user
	// see the text bellow the widget

	//showReplaceWidget();
	m_replace->hide();

	int replaceCount = 0;
	//        replaceWidget->setWidgetTransparency( 0.2 );
	QTextCursor c = getTextCursor();
	c = getTextDocument()->find( replaceFormUi->replaceText->text(), c, getReplaceFlags() );

	while (!c.isNull())
	{
		setTextCursor( c );
		QMessageBox::StandardButton button = QMessageBox::question( qobject_cast<QWidget*>(parent()), tr("Replace all"), tr("Replace this text?"),
			QMessageBox::Yes | QMessageBox::Ignore | QMessageBox::Cancel );

		if (button == QMessageBox::Cancel)
		{
			break;

		}
		else if (button == QMessageBox::Yes)
		{
			c.beginEditBlock();
			c.deleteChar();
			c.insertText( replaceFormUi->replaceText->text() );
			c.endEditBlock();
			setTextCursor( c );
			replaceCount++;
		}

		c = getTextDocument()->find( replaceFormUi->replaceText->text(), c, getReplaceFlags() );
	}
	// replaceWidget->setWidgetTransparency( 0.8 );
	m_replace->show();

	QMessageBox::information( 0, tr("Replace all"), tr("%1 replacement(s) made").arg(replaceCount) );
}
Esempio n. 18
0
	bool FindDialog::find(const QTextCursor cc, const QTextDocument::FindFlag dir)
	{
		assert(editor);
		
		//if (cc.hasSelection())
		
		QTextDocument::FindFlags flags(dir);
		QTextCursor nc;
		
		// search text
		if (wholeWordsCheckBox->isChecked())
			flags |= QTextDocument::FindWholeWords;
		if (regularExpressionsCheckBox->isChecked())
		{
			Qt::CaseSensitivity cs;
			if (caseCheckBox->isChecked())
				cs = Qt::CaseSensitive;
			else
				cs = Qt::CaseInsensitive;
			nc = editor->document()->find(QRegExp(findLineEdit->text(), cs), cc ,flags);
		}
		else
		{
			if (caseCheckBox->isChecked())
				flags |= QTextDocument::FindCaseSensitively;
			nc = editor->document()->find(findLineEdit->text(), cc ,flags);
		}
		
		// do something with found text
		if (nc.isNull())
		{
			nc = QTextCursor(editor->document());
			if (dir == QTextDocument::FindBackward)
				nc.movePosition(QTextCursor::End);
			warningText->setText(tr("End of document reached!"));
			editor->setTextCursor(nc);
			return false;
		}
		else
		{
			warningText->setText("");
			editor->setTextCursor(nc);
			return true;
		}
	}
Esempio n. 19
0
bool TikzEditorView::search(const QString &text, bool isCaseSensitive,
    bool findWholeWords, bool forward, bool startAtCursor)
{
	bool isFound = false;

	QTextDocument::FindFlags flags = 0;
	if (isCaseSensitive) flags |= QTextDocument::FindCaseSensitively;
	if (findWholeWords) flags |= QTextDocument::FindWholeWords;

	QTextCursor textCursor = m_tikzEditor->textCursor();
	if (!startAtCursor)
	{
		if (forward) textCursor.movePosition(QTextCursor::Start);
		else textCursor.movePosition(QTextCursor::End);
		m_tikzEditor->setTextCursor(textCursor);
	}
	else
		textCursor.setPosition(textCursor.selectionStart());
	if (!forward) flags |= QTextDocument::FindBackward;
	else textCursor.movePosition(QTextCursor::Right);
	const QTextCursor found = m_tikzEditor->document()->find(text, textCursor, flags);

	if (found.isNull())
	{
		const QString msg = (forward) ?
		    tr("End of document reached.\n\nContinue from the beginning?")
		    : tr("Beginning of document reached.\n\nContinue from the end?");
		const int ret = QMessageBox::warning(this, "Find", msg,
		    QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
		if (ret == QMessageBox::Yes)
		{
			return search(text, isCaseSensitive, findWholeWords, forward, false);
		}
	}
	else
	{
		m_tikzEditor->setTextCursor(found);
		emit setSearchFromBegin(false);
		isFound = true;
	}
	m_tikzEditor->viewport()->repaint();
	return isFound;
}
Esempio n. 20
0
void CodeEditor::findText(QString text, int dir){
    QTextCursor cursor = textCursor();
    if(dir==0 || dir==-1){
        cursor.movePosition(cursor.PreviousWord);
    }
    QTextDocument* d = document();
    QTextCursor p;
    if(dir==-1){
        p = d->find(text,cursor,d->FindBackward);
    }
    else{
        p = d->find(text,cursor);
    }
    qDebug() << text << "Found...";
    qDebug() << p.blockNumber();
    if(!p.isNull()){
        setTextCursor(p);
    }
}
Esempio n. 21
0
    /*
     * \author Anders Fernstrom
     * \date 2005-12-12
     * \date 2005-12-15 (update)
     *
     * \brief Select next (if any) field in current command
     *
     * 2005-12-15 AF, implemented function
     *
     * \return TURE if a field is selected
     */
    bool CommandCompletion::nextField( QTextCursor &cursor )
    {
        // check if cursor is okej
        if( !cursor.isNull() )
        {
            if( currentCommand_ >= 0 && currentCommand_ < currentList_->size() )
            {
                QString command = currentList_->at( currentCommand_ );

                if( commands_.contains( command ))
                {
                    if( currentField_ < (commands_[command]->numbersField() - 1) )
                    {
                        //next field
                        currentField_++;
                        QString fieldID;
                        fieldID.setNum( currentField_ );
                        fieldID = "$" + fieldID;
                        QString field = commands_[command]->datafield( fieldID );

                        if( !field.isNull() )
                        {
                            // get text in editor
                            cursor.setPosition( commandStartPos_ );
                            cursor.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
                            QString text = cursor.selectedText();

                            int pos = text.indexOf( field, 0 );
                            if( pos >= 0 )
                            {
                                // select field
                                cursor.setPosition( commandStartPos_ + pos );
                                cursor.setPosition( commandStartPos_ + pos + field.size(), QTextCursor::KeepAnchor );
                                return true;
                            }
                        }
                    }
                }
            }
        }

        return false;
    }
Esempio n. 22
0
/** Called when the user selects a different item in the content topic tree */
void
HelpBrowser::searchItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev)
{
  QList<QTreeWidgetItem *> selected = ui.treeContents->selectedItems();
  /* Deselect the selection in the contents tree */
  if (!selected.isEmpty()) {
    ui.treeContents->setItemSelected(selected[0], false);
  }

  /* Change to selected page */
  currentItemChanged(current, prev);

  /* Highlight search phrase */
  QTextCursor found;
  QTextDocument::FindFlags flags = QTextDocument::FindWholeWords;
  found = ui.txtBrowser->document()->find(_lastSearch, 0, flags);
  if (!found.isNull()) {
    ui.txtBrowser->setTextCursor(found);
  }
}
Esempio n. 23
0
QTextCursor FindDialog::find(const QTextCursor &start, const QTextDocument *doc) {
   if (start.isNull())
      return start;

   const QString &searchString = getSearchString();
   
   QTextDocument::FindFlags findFlags = 0;
   if (findBackwards())
      findFlags |= QTextDocument::FindBackward;
   if (caseSensitive())
      findFlags |= QTextDocument::FindCaseSensitively;
   if (wholeWordsOnly())
      findFlags |= QTextDocument::FindWholeWords;
   
   if (regularExpression())
      return doc->find(QRegExp(searchString), start, findFlags);

   // plain-text search
   return doc->find(searchString, start, findFlags);
}
Esempio n. 24
0
    void highlightMatches(const QString &pattern)
    {
        QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget);
        if (!ed)
            return;

        QTextCursor cur = ed->textCursor();

        QTextEdit::ExtraSelection selection;
        selection.format.setBackground(Qt::yellow);
        selection.format.setForeground(Qt::black);

        // Highlight matches.
        QTextDocument *doc = ed->document();
        QRegExp re(pattern);
        cur = doc->find(re);

        m_searchSelection.clear();

        int a = cur.position();
        while ( !cur.isNull() ) {
            if ( cur.hasSelection() ) {
                selection.cursor = cur;
                m_searchSelection.append(selection);
            } else {
                cur.movePosition(QTextCursor::NextCharacter);
            }
            cur = doc->find(re, cur);
            int b = cur.position();
            if (a == b) {
                cur.movePosition(QTextCursor::NextCharacter);
                cur = doc->find(re, cur);
                b = cur.position();
                if (a == b) break;
            }
            a = b;
        }

        updateExtraSelections();
    }
Esempio n. 25
0
void ItemText::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette)
{
    m_searchTextDocument.clear();
    if ( re.isEmpty() ) {
        setDocument(&m_textDocument);
    } else {
        bool plain = m_textFormat == Qt::PlainText;
        const QString &text = plain ? m_textDocument.toPlainText() : m_textDocument.toHtml();
        if (plain)
            m_searchTextDocument.setPlainText(text);
        else
            m_searchTextDocument.setHtml(text);

        QTextCursor cur = m_searchTextDocument.find(re);
        int a = cur.position();
        while ( !cur.isNull() ) {
            QTextCharFormat fmt = cur.charFormat();
            if ( cur.hasSelection() ) {
                fmt.setBackground( highlightPalette.base() );
                fmt.setForeground( highlightPalette.text() );
                fmt.setFont(highlightFont);
                cur.setCharFormat(fmt);
            } else {
                cur.movePosition(QTextCursor::NextCharacter);
            }
            cur = m_searchTextDocument.find(re, cur);
            int b = cur.position();
            if (a == b) {
                cur.movePosition(QTextCursor::NextCharacter);
                cur = m_searchTextDocument.find(re, cur);
                b = cur.position();
                if (a == b) break;
            }
            a = b;
        }
        setDocument(&m_searchTextDocument);
    }

    update();
}
Esempio n. 26
0
bool SourceWindow::wordAtPoint(const QPoint& p, QString& word, QRect& r)
{
    QTextCursor cursor = cursorForPosition(viewport()->mapFrom(this, p));
    if (cursor.isNull())
	return false;

    cursor.select(QTextCursor::WordUnderCursor);
    word = cursor.selectedText();

    if (word.isEmpty())
	return false;

    // keep only letters and digits
    QRegExp w("[\\dA-Za-z_]+");
    if (w.indexIn(word) < 0)
	return false;
    word = w.cap();

    r = QRect(p, p);
    r.adjust(-5,-5,5,5);
    return true;
}
Esempio n. 27
0
void ItemNotes::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette)
{
    m_childItem->setHighlight(re, highlightFont, highlightPalette);

    if (m_notes != NULL) {
        QList<QTextEdit::ExtraSelection> selections;

        if ( !re.isEmpty() ) {
            QTextEdit::ExtraSelection selection;
            selection.format.setBackground( highlightPalette.base() );
            selection.format.setForeground( highlightPalette.text() );
            selection.format.setFont(highlightFont);

            QTextCursor cur = m_notes->document()->find(re);
            int a = cur.position();
            while ( !cur.isNull() ) {
                if ( cur.hasSelection() ) {
                    selection.cursor = cur;
                    selections.append(selection);
                } else {
                    cur.movePosition(QTextCursor::NextCharacter);
                }
                cur = m_notes->document()->find(re, cur);
                int b = cur.position();
                if (a == b) {
                    cur.movePosition(QTextCursor::NextCharacter);
                    cur = m_notes->document()->find(re, cur);
                    b = cur.position();
                    if (a == b) break;
                }
                a = b;
            }
        }

        m_notes->setExtraSelections(selections);
    }

    update();
}
void ShowChangesCommand::checkAndRemoveAnchoredShapes(int position, int length)
{
    KoInlineTextObjectManager *inlineObjectManager
                = KoTextDocument(m_document).inlineTextObjectManager();
    Q_ASSERT(inlineObjectManager);

    QTextCursor cursor = m_textEditor->document()->find(QString(QChar::ObjectReplacementCharacter), position);
    while(!cursor.isNull() && cursor.position() < position + length) {
        QTextCharFormat fmt = cursor.charFormat();
        KoInlineObject *object = inlineObjectManager->inlineTextObject(fmt);
        Q_ASSERT(object);
        /* FIXME
        KoTextAnchor *anchor = dynamic_cast<KoTextAnchor *>(object);
        if (!anchor)
            continue;

        KUndo2Command *shapeCommand = m_canvas->shapeController()->removeShape(anchor->shape());
        shapeCommand->redo();
        m_shapeCommands.push_front(shapeCommand);
        */
    }
}
void ShowChangesCommand::checkAndAddAnchoredShapes(int position, int length)
{
    KoInlineTextObjectManager *inlineObjectManager
                = KoTextDocument(m_document).inlineTextObjectManager();
    Q_ASSERT(inlineObjectManager);

    QTextCursor cursor = m_textEditor->document()->find(QString(QChar::ObjectReplacementCharacter), position);
    while(!cursor.isNull() && cursor.position() < position + length) {
        QTextCharFormat fmt = cursor.charFormat();
        KoInlineObject *object = inlineObjectManager->inlineTextObject(fmt);
        Q_ASSERT(object);
/* FIXME
        KoTextAnchor *anchor = dynamic_cast<KoTextAnchor *>(object);
        if (!anchor) {
            continue;
        }
        */
#if 0
        // TODO -- since March 2010...
        KoTextDocumentLayout *lay = qobject_cast<KoTextDocumentLayout*>(m_document->documentLayout());

        KoShapeContainer *container = dynamic_cast<KoShapeContainer *>(lay->shapeForPosition(i));

        // a very ugly hack. Since this class is going away soon, it should be okay
        if (!container)
            container = dynamic_cast<KoShapeContainer *>((lay->shapes()).at(0));

        if (container) {
            container->addShape(anchor->shape());
            KUndo2Command *shapeCommand = m_canvas->shapeController()->addShapeDirect(anchor->shape());
            shapeCommand->redo();
            m_shapeCommands.push_front(shapeCommand);
        }
#endif
        cursor = m_textEditor->document()->find(QString(QChar::ObjectReplacementCharacter), position);
    }
}
Esempio n. 30
0
void ScCodeEditor::evaluateRegion()
{
    QString text;

    // Try current selection
    QTextCursor cursor = textCursor();
    if (cursor.hasSelection())
        text = cursor.selectedText();
    else {
        // If no selection, try current region
        cursor = currentRegion();
        if (!cursor.isNull()) {
            text = cursor.selectedText();
        } else {
            // If no current region, try current line
            cursor = textCursor();
            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 );
}