void
VBoxDbgConsoleOutput::appendText(const QString &rStr, bool fClearSelection)
{
    Assert(m_hGUIThread == RTThreadNativeSelf());

    if (rStr.isEmpty() || rStr.isNull() || !rStr.length())
        return;

    /*
     * Insert all in one go and make sure it's visible.
     *
     * We need to move the cursor and unselect any selected text before
     * inserting anything, otherwise, text will disappear.
     */
    QTextCursor Cursor = textCursor();
    if (!fClearSelection && Cursor.hasSelection())
    {
        QTextCursor SavedCursor = Cursor;
        Cursor.clearSelection();
        Cursor.movePosition(QTextCursor::End);

        Cursor.insertText(rStr);

        setTextCursor(SavedCursor);
    }
    else
    {
        if (Cursor.hasSelection())
            Cursor.clearSelection();
        if (!Cursor.atEnd())
            Cursor.movePosition(QTextCursor::End);

        Cursor.insertText(rStr);

        setTextCursor(Cursor);
        ensureCursorVisible();
    }
}
ParenMatching::ParenMatching(QTextCursor c)
    : onOpen(false)
{
    int save_p = c.position();
    QChar p = cc(c), q;
    QTextCursor::MoveOperation d = c.NoMove;

    if (p == '(') q = ')', d = c.Right, onOpen = true;
    if (p == '[') q = ']', d = c.Right, onOpen = true;
    if (p == '{') q = '}', d = c.Right, onOpen = true;

    if (d == c.NoMove && c.movePosition(c.Left)) {
        p = cc(c);
        if (p == ')') q = '(', d = c.Left;
        if (p == ']') q = '[', d = c.Left;
        if (p == '}') q = '{', d = c.Left;
    }

    if (d != c.NoMove) {
        int n = 0;
        while (c.movePosition(d)) {
            QChar z = cc(c);
            if (z == q) {
                if (n-- == 0) {
                    if (onOpen)
                        positions = range(save_p, c.position());
                    else
                        positions = range(c.position(), save_p - 1);
                    break;
                }
            }
            else if (z == p)
                ++n;
        }
    }

    c.setPosition(save_p);
}
예제 #3
0
/**
 * Duplicates the current line and inserts the copy below the line
 */
void HaiQTextEdit::duplicate_line() {
    QTextCursor cursor = textCursor();
    int pos(cursor.position());
    cursor.beginEditBlock();
    cursor.clearSelection();
    cursor.movePosition(QTextCursor::EndOfLine);
    cursor.select(QTextCursor::LineUnderCursor);
    QTextDocumentFragment text( cursor.selection() );
    cursor.clearSelection();
    cursor.insertText( QString(QChar::LineSeparator) );
    cursor.insertFragment( text );
    cursor.setPosition(pos);
    cursor.endEditBlock();
}
예제 #4
0
int CDlgAbout::AppendFile(QTextEdit* pEdit, const QString &szFile)
{
    QFile readme(szFile);
    if(readme.open(QFile::ReadOnly))
    {
        pEdit->append(readme.readAll());
        //把光标移动文档开始处  
        QTextCursor cursor =   pEdit->textCursor();
        cursor.movePosition(QTextCursor::Start);
        pEdit->setTextCursor(cursor);
        readme.close();
    }
    return 0;
}
예제 #5
0
/**
 * Deletes the current line
 */
void HaiQTextEdit::delete_current_line() {
    QTextCursor cursor = textCursor();
    cursor.beginEditBlock();
    cursor.clearSelection();
    cursor.movePosition(QTextCursor::StartOfLine);
    int pos(cursor.position());
    cursor.select(QTextCursor::LineUnderCursor);
    // remove line (and line feed char)
    cursor.removeSelectedText();
    cursor.deleteChar();
    // goto start of next line
    cursor.setPosition(pos);
    cursor.endEditBlock();
}
예제 #6
0
void FindDialog::replaceAll()
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextDocument::FindFlags flags;
	if (!m_ignore_case->isChecked()) {
		flags |= QTextDocument::FindCaseSensitively;
	}
	if (m_whole_words->isChecked()) {
		flags |= QTextDocument::FindWholeWords;
	}

	// Count instances
	int found = 0;
	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->textCursor();
	cursor.movePosition(QTextCursor::Start);
	forever {
		cursor = document->document()->find(text, cursor, flags);
		if (!cursor.isNull()) {
			found++;
		} else {
			break;
		}
	}
	if (found) {
		if (QMessageBox::question(this, tr("Question"), tr("Replace %n instance(s)?", "", found), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
			return;
		}
	} else {
		QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
		return;
	}

	// Replace instances
	QTextCursor start_cursor = document->textCursor();
	forever {
		cursor = document->document()->find(text, cursor, flags);
		if (!cursor.isNull()) {
			cursor.insertText(m_replace_string->text());
			document->setTextCursor(cursor);
		} else {
			break;
		}
	}
	document->setTextCursor(start_cursor);
}
예제 #7
0
static bool hasOnlyBlanksBeforeCursorInLine(QTextCursor textCursor)
{
    textCursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);

    const auto textBeforeCursor = textCursor.selectedText();

    const auto nonSpace = std::find_if(textBeforeCursor.cbegin(),
                                       textBeforeCursor.cend(),
    [] (const QChar &signBeforeCursor) {
        return !signBeforeCursor.isSpace();
    });

    return nonSpace == textBeforeCursor.cend();
}
void MarginWidget::mouseMoveEvent(QMouseEvent *event)
{
	QTextCursor textCursor = m_sourceViewer->cursorForPosition(QPoint(1, event->y()));
	int currentLine = textCursor.blockNumber();

	if (currentLine == m_lastClickedLine)
	{
		return;
	}

	textCursor.movePosition(((currentLine > m_lastClickedLine) ? QTextCursor::Up : QTextCursor::Down), QTextCursor::KeepAnchor, qAbs(m_lastClickedLine - currentLine));

	m_sourceViewer->setTextCursor(textCursor);
}
예제 #9
0
void QTerminal::doControlSeq(const QByteArray & seq) {
  switch (seq.right(1).at(0)) {
    case '@':
      this->insertPlainText(QString().fill(' ', seq.left(seq.length() - 1).toInt()));
      break;
    case 'C':
      for (int i = 0; i < seq.left(seq.length() - 1).toInt(); ++i) {
        if (this->textCursor().atEnd()) {
          this->insertPlainText(" ");
        } else {
          this->moveCursor(QTextCursor::Right, QTextCursor::MoveAnchor);
        }
      }
      break;
    case 'D':
      {
        QTextCursor cursor = this->textCursor();
        cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor,
            seq.left(seq.length() - 1).toInt());
      }
      break;
    case 'J':
      eraseDisplay(seq.left(seq.length() - 1).toInt());
      /* Perl would parse the number at the beginning of the string :-P */
      break;
    case 'K':
      eraseInLine(seq.left(seq.length() - 1).toInt());
      break;
    case 'P':
      deleteChars(seq.left(seq.length() - 1).toInt());
      break;
    case 'h':
      if (seq.left(seq.length() -1).toInt() == 4) {
        insertMode = true;
      } else {
        qDebug("No Can Do ESC [ %s", seq.constData());
      }
      break;
    case 'l':
      if (seq.left(seq.length() -1).toInt() == 4) {
        insertMode = false;
      } else {
        qDebug("No Can Do ESC [ %s", seq.constData());
      }
      break;
    default:
      qDebug("No Can Do ESC [ %s", seq.constData());
      break;
  }
}
예제 #10
0
QString textAt(QTextCursor tc, int pos, int length)
{
    if (pos < 0)
        pos = 0;
    tc.movePosition(QTextCursor::End);
    if (pos + length > tc.position())
        length = tc.position() - pos;

    tc.setPosition(pos);
    tc.setPosition(pos + length, QTextCursor::KeepAnchor);

    // selectedText() returns U+2029 (PARAGRAPH SEPARATOR) instead of newline
    return tc.selectedText().replace(QChar::ParagraphSeparator, QLatin1Char('\n'));
}
예제 #11
0
ResultItem* TextResultItem::updateFromResult(Cantor::Result* result)
{
    switch(result->type()) {
    case Cantor::TextResult::Type:
        {
            QTextCursor cursor = textCursor();
            cursor.movePosition(QTextCursor::Start);
            cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
            QString html = result->toHtml();
            if (html.isEmpty())
                cursor.removeSelectedText();
            else
                cursor.insertHtml(html);
            return this;
        }
    case Cantor::LatexResult::Type:
        setLatex(dynamic_cast<Cantor::LatexResult*>(result));
        return this;
    default:
        deleteLater();
        return create(parentEntry(), result);
    }
}
예제 #12
0
void MdiChild::removeSpacesAsTab(QTextCursor &cursor)
{
    QRegExp regex(" +");
    int spaces = cursor.columnNumber() % 4;
    if( spaces == 0 )
        spaces = 4;    
    if( cursor.columnNumber() < 4 )
        spaces = cursor.columnNumber();
    cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, spaces);
    if( regex.exactMatch(cursor.selectedText()) ) {
        cursor.removeSelectedText();
        setTextCursor(cursor);
    }
}
예제 #13
0
void MimeTextEdit::insertCompletion(const QString& completion)
{
	if (mCompleter->widget() != this)
		return;

	QTextCursor tc = textCursor();
	if (mCompleter->completionPrefix().length() > 0) {
		tc.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
	}
	tc.removeSelectedText();
	tc.insertText(mCompleterStartString+completion);
	mCompleterStartString.clear();
	setTextCursor(tc);
}
예제 #14
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 );
}
예제 #15
0
    void highlightMatches(const QString &pattern)
    {
        QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget);
        if (!ed)
            return;

        // Clear previous highlights.
        ed->selectAll();
        QTextCursor cur = ed->textCursor();
        QTextCharFormat fmt = cur.charFormat();
        fmt.setBackground(Qt::transparent);
        cur.setCharFormat(fmt);

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

        int a = cur.position();
        while ( !cur.isNull() ) {
            if ( cur.hasSelection() ) {
                fmt.setBackground(Qt::yellow);
                cur.setCharFormat(fmt);
            } 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;
        }
    }
예제 #16
0
파일: itemsync.cpp 프로젝트: hluk/CopyQ
void ItemSync::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette)
{
    ItemWidgetWrapper::highlight(re, highlightFont, highlightPalette);

    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_label->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_label->document()->find(re, cur);
            int b = cur.position();
            if (a == b) {
                cur.movePosition(QTextCursor::NextCharacter);
                cur = m_label->document()->find(re, cur);
                b = cur.position();
                if (a == b) break;
            }
            a = b;
        }
    }

    m_label->setExtraSelections(selections);

    update();
}
예제 #17
0
void GenericCodeEditor::gotoEmptyLineUpDown(bool up)
{
    static const QRegExp whiteSpaceLine("^\\s*$");

    const QTextCursor::MoveOperation direction = up ? QTextCursor::PreviousBlock
                                                    : QTextCursor::NextBlock;

    QTextCursor cursor = textCursor();
    cursor.beginEditBlock();

    bool cursorMoved = false;

    // find first non-whitespace line
    while ( cursor.movePosition(direction) ) {
        if ( !whiteSpaceLine.exactMatch(cursor.block().text()) )
            break;
    }

    // find first whitespace line
    while ( cursor.movePosition(direction) ) {
        if ( whiteSpaceLine.exactMatch(cursor.block().text()) ) {
            setTextCursor(cursor);
            cursorMoved = true;
            break;
        }
    }

    if (!cursorMoved) {
        const QTextCursor::MoveOperation startOrEnd = up ? QTextCursor::Start
                                                         : QTextCursor::End;

        cursor.movePosition(startOrEnd);
        setTextCursor(cursor);
    }

    cursor.endEditBlock();
}
예제 #18
0
void OpenedFile::replaceLine(const int line_number, const QString &new_line)
{
    QString old_text;
    QString new_text = new_line;
    QTextCursor parsingCursor = textCursor();
    int space_count = 0;

    parsingCursor.setPosition(0);

    while(parsingCursor.blockNumber() != line_number)
    {
        parsingCursor.movePosition(QTextCursor::Down);
    }

    parsingCursor.movePosition(QTextCursor::StartOfLine);
    parsingCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);

    old_text = parsingCursor.selectedText();

    while(old_text.startsWith(" "))
    {
        old_text.remove(0,1);
        space_count++;
    }

    while(space_count>0)
    {
        new_text.prepend(" ");
        space_count--;
    }
    new_text.remove(".0000");
    parsingCursor.insertText(new_text);
    parsingCursor.clearSelection();

    setTextCursor(parsingCursor);
}
예제 #19
0
void QSerialTerminal::flushText(QString& text, QTextCursor& cursor)
{
    if(text.size() == 0)
    {
        return;
    }

    if(!cursor.atEnd())
    {
        cursor.clearSelection();
        cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, text.size());
    }
    cursor.insertText(text);
    text.clear();
}
PythonTypeIn::PythonTypeIn()
{
    prompt(false);

    QTextCursor tc = textCursor();
    tc.movePosition(QTextCursor::End);
    tail_ = tc.position();

    setTabStopWidth(4);

    completer_ = new QCompleter(this);
    completer_->setWidget(this);

    QObject::connect(completer_, SIGNAL(activated(const QString &)), this, SLOT(insertCompletion(const QString &)));
}
예제 #21
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();

}
예제 #22
0
void PgxConsole::historyUpCommand()
{
    if(!history.isEmpty() && hit > 0) {
        QTextCursor cursor = textCursor();
        cursor.movePosition(QTextCursor::End);
        setTextCursor(cursor);
        cursor.select(QTextCursor::BlockUnderCursor);
        if(cursor.hasSelection()) {
            cursor.removeSelectedText();
            appendPlainText(history.at(--hit));
        }
        else
            insertPlainText(history.at(--hit));
    }
}
예제 #23
0
	bool find(const QString &str, QTextDocument::FindFlags options, QTextCursor::MoveOperation start = QTextCursor::NoMove)	{
		Q_UNUSED(str);
		if (start != QTextCursor::NoMove) {
			QTextCursor cursor = te->textCursor();
			cursor.movePosition(start);
			te->setTextCursor(cursor);
		}
		bool found = te->find(text, options);
		if (!found) {
			if (start == QTextCursor::NoMove)
				return find(text, options, options & QTextDocument::FindBackward ? QTextCursor::End : QTextCursor::Start);
			return false;
		}
		return true;
	}
예제 #24
0
void CodeEditor::completeText(const QString &text)
{
    textCursor().beginEditBlock();
    QTextCursor editingTextCursor = textCursor();

    editingTextCursor.setPosition(textCursor().selectionEnd());

    editingTextCursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
    editingTextCursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
    if(editingTextCursor.selectedText().contains('-'))
    {
        editingTextCursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
    }
    else
    {
        editingTextCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
    }
    editingTextCursor.removeSelectedText();

    editingTextCursor.insertText(text);
    setTextCursor(editingTextCursor);

    textCursor().endEditBlock();
}
예제 #25
0
void ModelFixForm::updateOutput(void)
{
	QTextCursor cursor;
	QString txt=output_txt->toPlainText();

	//Append both stdout and stderr
	txt.append(pgmodeler_cli_proc.readAllStandardOutput());
	txt.append(pgmodeler_cli_proc.readAllStandardError());
	output_txt->setPlainText(txt);

	//Moving the output to the last line
	cursor=output_txt->textCursor();
	cursor.movePosition(QTextCursor::End);
	output_txt->setTextCursor(cursor);
}
예제 #26
0
void TextFinder::loadTextFile()
{
    QFile inputFile(":/input.txt");
    inputFile.open(QIODevice::ReadOnly);

    QTextStream in(&inputFile);
    QString line = in.readAll();
    inputFile.close();

    ui->textEdit->setPlainText(line);
    QTextCursor cursor = ui->textEdit->textCursor();
    cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1);


}
예제 #27
0
void MainWindow::sendData(QByteArray data)
{
    _serial_port->write(data);
    _sent_data.append(data);
    //Clip the sent data (shown on GUI) to remain within max length
    if((_sent_data.size() - _sent_data_max_length) > 0)
        _sent_data.remove(0,_sent_data.size() - _sent_data_max_length);

    ui->sentDataTextEdit->setText(_sent_data);

    //Scroll to bottom of sent data box
    QTextCursor c = ui->sentDataTextEdit->textCursor();
    c.movePosition(QTextCursor::End);
    ui->sentDataTextEdit->setTextCursor(c);
}
예제 #28
0
void TerminalEdit::mousePressEvent(QMouseEvent *e)
{
    QPlainTextEdit::mousePressEvent(e);
    if (!m_bAutoPosCursor) {
        return;
    }
    if (!this->isReadOnly() && m_bFocusOut) {
        m_bFocusOut = false;
        QTextCursor cur = this->textCursor();
        if (!cur.hasSelection()) {
            cur.movePosition(QTextCursor::End);
            this->setTextCursor(cur);
        }
    }
}
예제 #29
0
    void appendMessage(const QString &text, OutputFormat format) final
    {
        const bool isTrace = (format == StdErrFormat
                              || format == StdErrFormatSameLine)
                          && (text.startsWith("Traceback (most recent call last):")
                              || text.startsWith("\nTraceback (most recent call last):"));

        if (!isTrace) {
            OutputFormatter::appendMessage(text, format);
            return;
        }

        const QTextCharFormat frm = charFormat(format);
        const Core::Id id(PythonErrorTaskCategory);
        QVector<Task> tasks;
        const QStringList lines = text.split('\n');
        unsigned taskId = unsigned(lines.size());

        for (const QString &line : lines) {
            const QRegularExpressionMatch match = filePattern.match(line);
            if (match.hasMatch()) {
                QTextCursor tc = plainTextEdit()->textCursor();
                tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
                tc.insertText('\n' + match.captured(1));
                tc.insertText(match.captured(2), linkFormat(frm, match.captured(2)));

                const auto fileName = FileName::fromString(match.captured(3));
                const int lineNumber = match.capturedRef(4).toInt();
                Task task(Task::Warning,
                                           QString(), fileName, lineNumber, id);
                task.taskId = --taskId;
                tasks.append(task);
            } else {
                if (!tasks.isEmpty()) {
                    Task &task = tasks.back();
                    if (!task.description.isEmpty())
                        task.description += ' ';
                    task.description += line.trimmed();
                }
                OutputFormatter::appendMessage('\n' + line, format);
            }
        }
        if (!tasks.isEmpty()) {
            tasks.back().type = Task::Error;
            for (auto rit = tasks.crbegin(), rend = tasks.crend(); rit != rend; ++rit)
                TaskHub::addTask(*rit);
        }
    }
예제 #30
0
ConsoleWidget::ConsoleWidget(ConsoleView& consoleView, ConsoleRoboCupCtrl& console, QString& output, ConsoleWidget*& consoleWidget) :
  consoleView(consoleView), console(console), output(output), consoleWidget(consoleWidget),
  canCopy(false), canUndo(false), canRedo(false)
{
  setFrameStyle(QFrame::NoFrame);
  setAcceptRichText(false);

  bool restoredCursor = false;
  if(consoleView.loadAndSaveOutput)
  {
    QSettings& settings = RoboCupCtrl::application->getLayoutSettings();
    settings.beginGroup(consoleView.fullName);
    output = settings.value("Output").toString();
    setPlainText(output);
    output.clear();

    int selectionStart = settings.value("selectionStart").toInt();
    int selectionEnd = settings.value("selectionEnd").toInt();
    if(selectionStart || selectionEnd)
    {
      QTextCursor cursor = textCursor();
      cursor.setPosition(selectionStart);
      cursor.setPosition(selectionEnd, QTextCursor::KeepAnchor);
      setTextCursor(cursor);
      restoredCursor = true;
    }
    QScrollBar* scrollBar = verticalScrollBar();
    scrollBar->setMaximum(settings.value("verticalScrollMaximum").toInt());
    scrollBar->setValue(settings.value("verticalScrollPosition").toInt());

    settings.endGroup();
  }
  else
  {
    setPlainText(output);
    output.clear();
  }
  if(!restoredCursor)
  {
    QTextCursor cursor = textCursor();
    cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
    setTextCursor(cursor);
  }

  connect(this, SIGNAL(copyAvailable(bool)), this, SLOT(copyAvailable(bool)));
  connect(this, SIGNAL(undoAvailable(bool)), this, SLOT(undoAvailable(bool)));
  connect(this, SIGNAL(redoAvailable(bool)), this, SLOT(redoAvailable(bool)));
}