当前位置: 首页>>代码示例>>C++>>正文


C++ QTextCursor::selectionStart方法代码示例

本文整理汇总了C++中QTextCursor::selectionStart方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::selectionStart方法的具体用法?C++ QTextCursor::selectionStart怎么用?C++ QTextCursor::selectionStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextCursor的用法示例。


在下文中一共展示了QTextCursor::selectionStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

bool	QsvTextOperationsWidget::issue_search( const QString &text, QTextCursor newCursor, QFlags<QTextDocument::FindFlag> findOptions, QLineEdit *l, bool moveCursor )
{
	QTextCursor c = m_document->find( text, newCursor, findOptions );
	bool found = ! c.isNull();

	//lets try again, from the start
	if (!found) {
		c.movePosition(findOptions.testFlag(QTextDocument::FindBackward)? QTextCursor::End : QTextCursor::Start);
		c = m_document->find(text, c, findOptions);
		found = ! c.isNull();
	}

	QPalette p = l->palette();
	if (found) {
		p.setColor(QPalette::Base, searchFoundColor);
	} else {
		if (!text.isEmpty())
			p.setColor(QPalette::Base, searchNotFoundColor);
		else
			p.setColor(QPalette::Base,
				l->style()->standardPalette().base().color()
			);
		c =  m_searchCursor;
	}
	l->setPalette(p);

	if (moveCursor){
		int start = c.selectionStart();
		int end   = c.selectionEnd();
		c.setPosition(end  ,QTextCursor::MoveAnchor);
		c.setPosition(start,QTextCursor::KeepAnchor);
		setTextCursor(c);
	}
	return found;
}
开发者ID:martinribelotta,项目名称:embedded-ide,代码行数:35,代码来源:qsvtextoperationswidget.cpp

示例2: displayTooltip

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>"));
        }
    }
}
开发者ID:maharajd,项目名称:BookReader,代码行数:60,代码来源:mainwindow.cpp

示例3: extendSelectionForEnvVar

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);
                }
            }
        }
    }
}
开发者ID:8c6794b6,项目名称:supercollider,代码行数:26,代码来源:gui_utilities.hpp

示例4: deleteTab

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();
    }
}
开发者ID:Megaxela,项目名称:SASM,代码行数:26,代码来源:codeeditor.cpp

示例5: updateLink

void GolangEdit::updateLink(const QTextCursor &_cursor)
{
    QTextCursor cursor = _cursor;
    LiteApi::selectWordUnderCursor(cursor);

    if (cursor.selectionStart() == cursor.selectionEnd()) {
        m_editor->clearLink();
        return;
    }

    if (m_linkCursor.selectionStart() == cursor.selectionStart() &&
            m_linkCursor.selectionEnd() == cursor.selectionEnd()) {
        if (m_lastLink.hasValidTarget()) {
            m_editor->showLink(m_lastLink);
        }
        return;
    }
    m_linkCursor = cursor;
    m_lastLink = LiteApi::Link();
    if (m_findLinkProcess->isRunning()) {
        m_findLinkProcess->kill();
        m_findLinkProcess->waitForFinished(100);
        //return;
    }
    QString cmd = LiteApi::liteide_stub_cmd(m_liteApp);
    QString src = cursor.document()->toPlainText();
    m_srcData = src.toUtf8();
    int offset = src.left(cursor.selectionStart()).length();
    QFileInfo info(m_editor->filePath());
    m_findLinkProcess->setEnvironment(LiteApi::getGoEnvironment(m_liteApp).toStringList());
    m_findLinkProcess->setWorkingDirectory(info.path());
    m_findLinkProcess->startEx(cmd,QString("type -cursor %1:%2 -cursor_stdin -def -info .").
                             arg(info.fileName()).
                               arg(offset));
}
开发者ID:jiangzhonghui,项目名称:liteide,代码行数:35,代码来源:golangedit.cpp

示例6: mouseMoveLineNumEvent

void CCodeEdit::mouseMoveLineNumEvent(QMouseEvent* event)
{
	QPoint pt(0, event->y());

	if( m_lineIconSize.width() < event->x() &&
		0 != (event->buttons()& Qt::LeftButton) )
	{
		QTextCursor cursor = textCursor();
		if( cursor.position() == cursor.selectionStart() )
		{
			// 選択開始位置より前を選択
			cursor.setPosition(cursor.selectionEnd());
			cursor.movePosition(QTextCursor::EndOfLine);
			cursor.setPosition(cursorForPosition(pt).position(), QTextCursor::KeepAnchor);
			cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
		}
		else
		{
			// 選択開始位置より後ろを選択
			cursor.setPosition(cursor.selectionStart());
			cursor.movePosition(QTextCursor::StartOfLine);
			cursor.setPosition(cursorForPosition(pt).position(), QTextCursor::KeepAnchor);
			cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
			cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
		}
		setTextCursor(cursor);
	}
}
开发者ID:sharkpp,项目名称:hspide,代码行数:28,代码来源:codeedit.cpp

示例7: mousePressEvent

 void mousePressEvent(QMouseEvent * event)
 {
     if( event->buttons() != Qt::LeftButton )
         return;
     if( event->modifiers() == Qt::ShiftModifier )
     {
         QTextCursor cur = d_codeEditor->textCursor();
         const int selStart = d_codeEditor->document()->findBlock( cur.selectionStart() ).blockNumber();
         const int selEnd = d_codeEditor->document()->findBlock( cur.selectionEnd() ).blockNumber();
         Q_ASSERT( selStart <= selEnd ); // bei position und anchor nicht erfllt
         const int clicked = d_codeEditor->lineAt( event->pos() );
         if( clicked <= selEnd )
         {
             if( cur.selectionStart() == cur.position() )
                 d_codeEditor->selectLines( selEnd, clicked );
             else
                 d_codeEditor->selectLines( selStart, clicked );
         }else
             d_codeEditor->selectLines( selStart, clicked );
     }else
     {
         // Beginne Drag
         d_start = d_codeEditor->lineAt( event->pos() );
         d_codeEditor->selectLines( d_start, d_start );
     }
 }
开发者ID:Wushaowei001,项目名称:NAF,代码行数:26,代码来源:CodeEditor.cpp

示例8: cursorPositionChanged

void TextEdit::cursorPositionChanged()
{
  //alignmentChanged(textEdit->alignment());
  QColor col = Qt::red;
  QTextCharFormat fmt;
  fmt.setForeground(col);
  QTextCursor cursor = textEdit->textCursor();
  cout<<"#TextEdit::cursorPositionChanged:";
  cout<<"cursor.selectionStart:"<<cursor.selectionStart()<<","<<cursor.selectionEnd();
  int selectionStart=cursor.selectionStart(),
      selectionEnd=cursor.selectionEnd();
  cursor.mergeCharFormat(fmt);
  colorChanged(col);

  if(!cursor.hasSelection()) return;
  QTextBlock block=cursor.block();
  int blockStart=block.position();
  QTextLayout* layout=cursor.block().layout();
  QTextLine layoutLine=layout->lineForTextPosition(selectionStart-blockStart);
  cout<<"layout line:";
  int lineNumber= layoutLine.lineNumber();
  QPoint blockOffset=layout->position().toPoint();
  QPoint lineOffset=layoutLine.position().toPoint();
  printPoint(blockOffset);
  printPoint(lineOffset);
  QPoint linePoint(blockOffset.x()+lineOffset.x(),blockOffset.y()+lineOffset.y());
  QPoint lineEndPoint=QPoint(linePoint.x()+PAGEWIDTH,linePoint.y());
//  cout<<"block:"<<rect.left()<<","<<rect.right()<<":"<<rect.top()<<","<<rect.bottom();
//  cout<<"blockstart:"<<blockStart;

//  int x=blockPoint.x()+(float)((selectionStart-blockStart)%LINELENGTH)/LINELENGTH*PAGEWIDTH;
//  int y=blockPoint.y()+((selectionStart-blockStart)/LINELENGTH+1)*LINEHEIGHT;
//  int x1=blockPoint.x()+(float)((selectionEnd-blockStart)%LINELENGTH)/LINELENGTH*PAGEWIDTH;
//  cout<<"block position:"<<blockPoint.x()<<","<<blockPoint.y();
//  cout<<"selection position:"<<x<<","<<y<<":"<<x1<<","<<y;
////  int y1=blockPoint.y()+((cursor.selectionEnd()-blockStart)/LINELENGTH+1)*15;
//  QPoint selectionPoint(x,y);
//  QPoint selectionEndPoint(x1,y);
  image->paintLine(linePoint,lineEndPoint);

//  int lineStart=blockStart,lineEnd;
//  for(int i=0;i<block.lineCount();i++){
//  QTextLine line = layout->lineAt(i);
//  qreal lineWidth=line.width(),lineHeight=line.height();
//  lineEnd=lineStart+line.textLength();
//  int a=line.textStart(),b=line.textLength()+a;
//  cout<<"line.cursorToX:"<<line.cursorToX(selectionStart)<<","<<line.cursorToX(selectionEnd);
//  cout<<"line.textstart:"<<a<<","<<b;
//  cout<<"line.width:"<<lineWidth<<" height:"<<lineHeight;
//  rect=line.naturalTextRect();
//  cout<<"line.naturaltextrect:"<<rect.left()<<":"<<rect.top()<<":"<<rect.right()<<":"<<rect.bottom();
//  lineStart=lineEnd;
//  }
}
开发者ID:counterstriker,项目名称:qtapplications,代码行数:54,代码来源:textedit.cpp

示例9: copyUpDown

void GenericCodeEditor::copyUpDown(bool up)
{
    // directly taken from qtcreator
    // Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
    // GNU Lesser General Public License
    QTextCursor cursor = textCursor();
    QTextCursor move = cursor;
    move.beginEditBlock();

    bool hasSelection = cursor.hasSelection();

    if (hasSelection) {
        move.setPosition(cursor.selectionStart());
        move.movePosition(QTextCursor::StartOfBlock);
        move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
        move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock,
                          QTextCursor::KeepAnchor);
    } else {
        move.movePosition(QTextCursor::StartOfBlock);
        move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
    }

    QString text = move.selectedText();

    if (up) {
        move.setPosition(cursor.selectionStart());
        move.movePosition(QTextCursor::StartOfBlock);
        move.insertBlock();
        move.movePosition(QTextCursor::Left);
    } else {
        move.movePosition(QTextCursor::EndOfBlock);
        if (move.atBlockStart()) {
            move.movePosition(QTextCursor::NextBlock);
            move.insertBlock();
            move.movePosition(QTextCursor::Left);
        } else {
            move.insertBlock();
        }
    }

    int start = move.position();
    move.clearSelection();
    move.insertText(text);
    int end = move.position();

    move.setPosition(start);
    move.setPosition(end, QTextCursor::KeepAnchor);

    move.endEditBlock();

    setTextCursor(move);
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:52,代码来源:editor.cpp

示例10: indent

void CodeEditer::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar)
{
	if (cursor.hasSelection()) {
		QTextBlock block = doc->findBlock(qMin(cursor.selectionStart(), cursor.selectionEnd()));
		const QTextBlock end = doc->findBlock(qMax(cursor.selectionStart(), cursor.selectionEnd())).next();
		do {
			indentBlock(doc, block, typedChar);
			block = block.next();
		} while (block.isValid() && block != end);
	} else {
		indentBlock(doc, cursor.block(), typedChar);
	}
}
开发者ID:rccoder,项目名称:codeview,代码行数:13,代码来源:linenumberarea.cpp

示例11: getTextDocument

void	QsvTextOperationsWidget::on_replaceOldText_returnPressed()
{
	if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ||
	    QApplication::keyboardModifiers().testFlag(Qt::AltModifier) ||
	    QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) ) {
		on_replaceAll_clicked();
		showReplace();
		return;
	}

	QTextCursor c = m_searchCursor;
	QTextDocument *doc = getTextDocument();
	if (!doc){
		qDebug("%s:%d - no document found, using a wrong class? wrong parent?", __FILE__,__LINE__);
		return;
	}
	c = doc->find( replaceFormUi->findText->text(), c, getReplaceFlags() );
	if (c.isNull())
		return;

	int start = c.selectionStart();
	int end   = c.selectionEnd();
	c.beginEditBlock();
	c.deleteChar();
	c.insertText( replaceFormUi->replaceText->text() );
	c.setPosition(start,QTextCursor::KeepAnchor);
	c.setPosition(end  ,QTextCursor::MoveAnchor);
	c.endEditBlock();
	setTextCursor( c );

	// is there any other apperance of this text?
	m_searchCursor = c;
	updateReplaceInput();
}
开发者ID:martinribelotta,项目名称:embedded-ide,代码行数:34,代码来源:qsvtextoperationswidget.cpp

示例12: editUncomment

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();
	}
}
开发者ID:jfmcarreira,项目名称:ktikz-old,代码行数:31,代码来源:tikzeditorview.cpp

示例13: disableFormattingSelectedText

void ClangFormat::disableFormattingSelectedText()
{
    TextEditor::TextEditorWidget *widget = TextEditor::TextEditorWidget::currentTextEditorWidget();
    if (!widget)
        return;

    const QTextCursor tc = widget->textCursor();
    if (!tc.hasSelection())
        return;

    // Insert start marker
    const QTextBlock selectionStartBlock = tc.document()->findBlock(tc.selectionStart());
    QTextCursor insertCursor(tc.document());
    insertCursor.beginEditBlock();
    insertCursor.setPosition(selectionStartBlock.position());
    insertCursor.insertText("// clang-format off\n");
    const int positionToRestore = tc.position();

    // Insert end marker
    QTextBlock selectionEndBlock = tc.document()->findBlock(tc.selectionEnd());
    insertCursor.setPosition(selectionEndBlock.position() + selectionEndBlock.length() - 1);
    insertCursor.insertText("\n// clang-format on");
    insertCursor.endEditBlock();

    // Reset the cursor position in order to clear the selection.
    QTextCursor restoreCursor(tc.document());
    restoreCursor.setPosition(positionToRestore);
    widget->setTextCursor(restoreCursor);

    // The indentation of these markers might be undesired, so reformat.
    // This is not optimal because two undo steps will be needed to remove the markers.
    const int reformatTextLength = insertCursor.position() - selectionStartBlock.position();
    BeautifierPlugin::formatCurrentFile(command(selectionStartBlock.position(),
                                                  reformatTextLength));
}
开发者ID:choenig,项目名称:qt-creator,代码行数:35,代码来源:clangformat.cpp

示例14: insert_head

void MarkdownEdit::insert_head(const QString &tag, bool blockStart)
{
    QTextCursor cur = m_ed->textCursor();
    cur.beginEditBlock();
    if (cur.hasSelection()) {
        QTextBlock begin = m_ed->document()->findBlock(cur.selectionStart());
        QTextBlock end = m_ed->document()->findBlock(cur.selectionEnd());
        if (end.position() == cur.selectionEnd()) {
            end = end.previous();
        }
        QTextBlock block = begin;
        do {
            if (block.text().length() > 0) {
                if (blockStart) {
                    cur.setPosition(block.position());
                } else {
                    QString text = block.text();
                    foreach(QChar c, text) {
                        if (!c.isSpace()) {
                            cur.setPosition(block.position()+text.indexOf(c));
                            break;
                        }
                    }
                }
                cur.insertText(tag);
            }
            block = block.next();
        } while(block.isValid() && block.position() <= end.position());
    } else {
开发者ID:bezigon,项目名称:liteide,代码行数:29,代码来源:markdownedit.cpp

示例15: textUnderCursor

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();
	}
}
开发者ID:quazaa-development-team,项目名称:quazaa,代码行数:27,代码来源:widgetreturnemittextedit.cpp


注:本文中的QTextCursor::selectionStart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。