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


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

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


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

示例1: showHelp

		void HelpViewer::showHelp(const String& org_url, String entry)
		{
			String url = org_url;
			String fragment;

			if (url.has('#'))
			{
				url = url.before("#");
				fragment = org_url.after("#");
			}

			QUrl qurl = QUrl::fromLocalFile((base_dir_ + url).c_str());
			if (fragment != "") qurl.setFragment(fragment.c_str());
 			browser_->setSource(qurl);

 			QTextCursor ct = browser_->textCursor();
 			if (!ct.atStart()) 
 			{
 				ct.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
				browser_->setTextCursor(ct);
 			}

			if (entry != "") browser_->find(entry.c_str(), QTextDocument::FindCaseSensitively);

			if (!isVisible())
			{
				show();
				setFloating(true);
				showMaximized();
			}
		}
开发者ID:PierFio,项目名称:ball,代码行数:31,代码来源:helpViewer.C

示例2: cursorPositionChangedSlot

void TextZone::cursorPositionChangedSlot()
{
    if (QApplication::mouseButtons() == Qt::NoButton) {
        centerCursor();
    }


    emit cursorPositionChanged(this->textCursor().position());



    // for textstyle :
    QTextCursor tCursor = this->textCursor();

    if((tCursor.atStart() == true
        || tCursor.position() == 1
        || tCursor.position() == 0) && tCursor.hasSelection() == false){
        this->changeTextStyleSlot(textStyles->defaultStyleIndex());
    }

    int currentStyleIndex = textStyles->compareStylesWithText(tCursor.charFormat(), tCursor.blockFormat());

    emit setStyleSelectionSignal(currentStyleIndex);


}
开发者ID:jwvdveen,项目名称:plume-creator-legacy,代码行数:26,代码来源:textzone.cpp

示例3: _DeleteCurrentLine

void CCodeEditor::_DeleteCurrentLine()
{
	QTextCursor currentCursor = this->textCursor();
	currentCursor.select(QTextCursor::BlockUnderCursor);
	currentCursor.removeSelectedText();
	++m_textChangeTime;
	if (currentCursor.atStart())
	{
		currentCursor.deleteChar();
		++m_textChangeTime;
	}
}
开发者ID:6VV,项目名称:TeachingBox,代码行数:12,代码来源:CCodeEditor.cpp

示例4: isAllSelected

    bool TextEditEx::isAllSelected()
    {
        QTextCursor cur = textCursor();
        if (!cur.hasSelection())
            return false;

        const int start = cur.selectionStart();
        const int end = cur.selectionEnd();
        cur.setPosition(start);
        if (cur.atStart())
        {
            cur.setPosition(end);
            return cur.atEnd();
        }
        else if (cur.atEnd())
        {
            cur.setPosition(start);
            return cur.atStart();
        }

        return false;
    }
开发者ID:13W,项目名称:icq-desktop,代码行数:22,代码来源:TextEditEx.cpp

示例5: selectLine

void QtUtils::selectLine(QTextEdit* ted, int line)
{
	QTextCursor tcur = ted->textCursor();
	tcur.beginEditBlock();
	tcur.clearSelection();
	tcur.movePosition(QTextCursor::Start);
	bool ok;
	ok = tcur.atStart();
	if (ok)
	{
		tcur.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor,line);
		tcur.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor,1);
	}
	tcur.endEditBlock();

	ted->setTextCursor(tcur);
	ted->ensureCursorVisible();
}
开发者ID:gqueiroz,项目名称:terrama2,代码行数:18,代码来源:QtUtils.cpp

示例6: insertFromMimeData

void TextZone::insertFromMimeData (const QMimeData *source )
{

    QTextCursor cursor = this->textCursor();

    int bottMargin;
    int textIndent;
    int leftMargin;
    Qt::Alignment textAlignment;
    int textHeight;
    QString fontFamily;

    if(cursor.atStart() == true
            || cursor.position() == 1
            || cursor.position() == 0){
        int defaultIndex = textStyles->defaultStyleIndex();
        bottMargin = textStyles->blockBottomMarginAt(defaultIndex);
        textIndent = textStyles->blockFirstLineIndentAt(defaultIndex);
        leftMargin = textStyles->blockLeftMarginAt(defaultIndex);
        textAlignment = textStyles->blockAlignmentTrueNameAt(defaultIndex);
        textHeight = textStyles->fontSizeAt(defaultIndex);
        fontFamily = textStyles->fontFamilyAt(defaultIndex);
    }
    else{

        bottMargin = cursor.blockFormat().bottomMargin();
        textIndent = cursor.blockFormat().textIndent();
        leftMargin = cursor.blockFormat().leftMargin();
        textAlignment = cursor.blockFormat().alignment();
        textHeight = cursor.charFormat().fontPointSize();
        fontFamily = cursor.charFormat().fontFamily();

    }

    if(source->hasHtml() && !forceCopyWithoutFormatting){

        QByteArray richtext;
        if (source->hasFormat(QLatin1String("text/rtf"))) {
            richtext = source->data(QLatin1String("text/rtf"));
        } else if (source->hasHtml()) {
            richtext = mimeToRtf(source);
        }

        QTextEdit *textEdit = new QTextEdit(0);

        RTF::Reader reader;
        QBuffer buffer(&richtext);
        buffer.open(QIODevice::ReadOnly);
        reader.read(&buffer, textEdit->textCursor());
        buffer.close();

        QString sourceString = textEdit->toHtml();
        sourceString.remove(QChar::ReplacementCharacter);
        sourceString.remove(QChar::ObjectReplacementCharacter);
        sourceString.remove(QChar::Null);



        //htmlText
        QTextDocument *document = new QTextDocument;
        document->setHtml(Utils::parseHtmlText(sourceString));
        QTextBlockFormat blockFormat;
        blockFormat.setBottomMargin(bottMargin);
        blockFormat.setTextIndent(textIndent);
        blockFormat.setLeftMargin(leftMargin);
        blockFormat.setAlignment(textAlignment);
        blockFormat.setRightMargin(0);
        QTextCharFormat charFormat;
        charFormat.setFontPointSize(textHeight);
        charFormat.setFontFamily(fontFamily);

        charFormat.setBackground(QBrush(Qt::NoBrush));
        charFormat.setForeground(QBrush(Qt::NoBrush));
        charFormat.setAnchor(false);
        charFormat.setUnderlineStyle(QTextCharFormat::NoUnderline);
        charFormat.setFontStrikeOut(false);

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

        tCursor->mergeCharFormat(charFormat);
        tCursor->mergeBlockFormat(blockFormat);

        QTextCursor cursor = this->textCursor();
        cursor.insertHtml(document->toHtml("utf-8"));
        qDebug() << "insertFromMimeData Html";

    }
    else if(source->hasText() || forceCopyWithoutFormatting){
        QTextDocument *document = new QTextDocument;
        document->setPlainText(qvariant_cast<QString>(source->text()));

        QTextBlockFormat blockFormat;
        blockFormat.setBottomMargin(bottMargin);
        blockFormat.setTextIndent(textIndent);
        blockFormat.setLeftMargin(leftMargin);
        blockFormat.setAlignment(textAlignment);
        blockFormat.setRightMargin(0);
        QTextCharFormat charFormat;
//.........这里部分代码省略.........
开发者ID:jwvdveen,项目名称:plume-creator-legacy,代码行数:101,代码来源:textzone.cpp

示例7: linkDialog

void Note::linkDialog() {
	QTextCursor textCursor = m_graphicsTextItem->textCursor();
	bool gotUrl = false;
	if (textCursor.anchor() == textCursor.selectionStart()) {
		// the selection returns empty since we're between characters
		// so select one character forward or one character backward 
		// to see whether we're in a url
		int wasAnchor = textCursor.anchor();
		bool atEnd = textCursor.atEnd();
		bool atStart = textCursor.atStart();
		if (!atStart) {
			textCursor.setPosition(wasAnchor - 1, QTextCursor::KeepAnchor);
			QString html = textCursor.selection().toHtml();
			if (UrlTag.indexIn(html) >= 0) {
				gotUrl = true;
			}
		}
		if (!gotUrl && !atEnd) {
			textCursor.setPosition(wasAnchor + 1, QTextCursor::KeepAnchor);
			QString html = textCursor.selection().toHtml();
			if (UrlTag.indexIn(html) >= 0) {
				gotUrl = true;
			}
		}
		textCursor.setPosition(wasAnchor, QTextCursor::MoveAnchor);
	}
	else {
		QString html = textCursor.selection().toHtml();
		DebugDialog::debug(html);
		if (UrlTag.indexIn(html) >= 0) {
			gotUrl = true;
		}
	}

	LinkDialog ld;
	QString originalText;
	QString originalUrl;
	if (gotUrl) {
		originalUrl = UrlTag.cap(1);
		ld.setUrl(originalUrl);
		QString html = m_graphicsTextItem->toHtml();

		// assumes html is in xml form
		QString errorStr;
		int errorLine;
		int errorColumn;

		QDomDocument domDocument;
		if (!domDocument.setContent(html, &errorStr, &errorLine, &errorColumn)) {
			return;
		}

		QDomElement root = domDocument.documentElement();
		if (root.isNull()) {
			return;
		}

		if (root.tagName() != "html") {
			return;
		}

		DebugDialog::debug(html);
		QList<QDomElement> aElements;
		findA(root, aElements);
		foreach (QDomElement a, aElements) {
			// TODO: if multiple hrefs point to the same url this will only find the first one
			QString href = a.attribute("href");
			if (href.isEmpty()) {
				href = a.attribute("HREF");
			}
			if (href.compare(originalUrl) == 0) {
				QString text;
				if (TextUtils::findText(a, text)) {
					ld.setText(text);
					break;
				}
				else {
					return;
				}
			}
		}
	}
开发者ID:bacchante95,项目名称:fritzing,代码行数:82,代码来源:note.cpp

示例8: keyPressEvent


//.........这里部分代码省略.........
				cursor.insertText(text, colorFormat(type_color));
				break;
			case t_KEYWORD:
				cursor.insertText(text, colorFormat(keyword_color));
				break;
			case t_DEFAULT:
				cursor.insertText(text, colorFormat(default_color));
			}

			cursor.setPosition(position);
			cursor.insertText(input->text());
			setTextCursor(cursor);
			return;
		}
	case Qt::Key_Delete:
		position = cursor.position();
		cursor.deleteChar();

		cursor.movePosition(QTextCursor::NoMove, QTextCursor::MoveAnchor);
		cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
		text = cursor.selectedText();
		cursor.setPosition(position);
		for (count = 0; count < exception->count(); count++) {
			if (text[0] == (*exception)[count][0]) {
				cursor.setPosition(position - 1);
			}
		}

		cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
		cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
		text = cursor.selectedText();
		break;
	case Qt::Key_Backspace:
		if (cursor.atStart()) {
			return;
		} else if (cursor.atBlockStart()) {
			position = cursor.position() - 1;
			cursor.deletePreviousChar();
			cursor.movePosition(QTextCursor::NoMove, QTextCursor::MoveAnchor);
			cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
			text = cursor.selectedText();

			std::cout << "debug_text   " << qPrintable(text) << std::endl;

			count = 0;
			while (count < text.size()) {
				if (text[count] == QChar('{')) {
					block_stack--;
				} else if (text[count] == QChar('}')) {
					block_stack++;
				}
				count++;
			}

			cursor.setPosition(position, QTextCursor::MoveAnchor);
			cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::MoveAnchor);
			cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
			text = cursor.selectedText();
		} else {
			position = cursor.position() - 1;
			cursor.deletePreviousChar();
			cursor.movePosition(QTextCursor::NoMove, QTextCursor::MoveAnchor);
			cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
			text = cursor.selectedText();

			for (count = 0; count < exception->count(); count++) {
开发者ID:sugie1616,项目名称:soeditor,代码行数:67,代码来源:sotextedit.cpp

示例9: prehandle

void CharacterHandler::prehandle()
{
	//
	// Получим необходимые значения
	//
	// ... курсор в текущем положении
	QTextCursor cursor = editor()->textCursor();
	// ... блок текста в котором находится курсор
	QTextBlock currentBlock = cursor.block();
	// ... текст блока
	QString currentBlockText = currentBlock.text().trimmed();

	//
	// Пробуем определить кто сейчас должен говорить
	//
	if (currentBlockText.isEmpty()) {
		QString previousCharacter, character;

		//
		// ... для этого ищем предпоследнего персонажа сцены
		//
		cursor.movePosition(QTextCursor::PreviousBlock);
		while (!cursor.atStart()
			   && ScenarioBlockStyle::forBlock(cursor.block()) != ScenarioBlockStyle::SceneHeading) {
			if (ScenarioBlockStyle::forBlock(cursor.block()) == ScenarioBlockStyle::Character) {
				//
				// Нашли предыдущего персонажа
				//
				if (previousCharacter.isEmpty()) {
					previousCharacter = CharacterParser::name(cursor.block().text());
				}
				//
				// Нашли потенциального говорящего
				//
				else {
					//
					// Выберем его в списке вариантов
					//
					character = CharacterParser::name(cursor.block().text());
					if (character != previousCharacter) {
						break;
					}
				}
			}

			cursor.movePosition(QTextCursor::PreviousBlock);
			cursor.movePosition(QTextCursor::StartOfBlock);
		}

		//
		// Показываем всплывающую подсказку
		//
		QAbstractItemModel* model = 0;
		if (!character.isEmpty()) {
			m_sceneCharactersModel->setStringList(QStringList() << character.toUpper());
			model = m_sceneCharactersModel;
		} else if (!previousCharacter.isEmpty()) {
			m_sceneCharactersModel->setStringList(QStringList() << previousCharacter.toUpper());
			model = m_sceneCharactersModel;
		} else {
			model = StorageFacade::characterStorage()->all();
		}
		editor()->complete(model, QString::null);
	}
}
开发者ID:Roger-Waters,项目名称:KITScenarist,代码行数:65,代码来源:CharacterHandler.cpp

示例10: handleOther

void CharacterHandler::handleOther(QKeyEvent*)
{
	//
	// Получим необходимые значения
	//
	// ... курсор в текущем положении
	QTextCursor cursor = editor()->textCursor();
	// ... блок текста в котором находится курсор
	QTextBlock currentBlock = cursor.block();
	// ... текст блока
	QString currentBlockText = currentBlock.text();
	// ... текст до курсора
	QString cursorBackwardText = currentBlock.text().left(cursor.positionInBlock());
	// ... текущая секция
	CharacterParser::Section currentSection = CharacterParser::section(cursorBackwardText);


	//
	// Получим модель подсказок для текущей секции и выведем пользователю
	//
	QAbstractItemModel* sectionModel = 0;
	//
	// ... в соответствии со введённым в секции текстом
	//
	QString sectionText;

	switch (currentSection) {
		case CharacterParser::SectionName: {
			QStringList sceneCharacters;
			//
			// Когда введён один символ имени пробуем оптимизировать поиск персонажей из текущей сцены
			//
			if (cursorBackwardText.length() < 2) {
				cursor.movePosition(QTextCursor::PreviousBlock);
				while (!cursor.atStart()
					   && ScenarioBlockStyle::forBlock(cursor.block()) != ScenarioBlockStyle::SceneHeading) {
					if (ScenarioBlockStyle::forBlock(cursor.block()) == ScenarioBlockStyle::Character) {
						const QString character = CharacterParser::name(cursor.block().text());
						const QString characterName = character.toUpper().simplified();
						if (character.startsWith(cursorBackwardText, Qt::CaseInsensitive)
							&& !sceneCharacters.contains(characterName)) {
							sceneCharacters.append(characterName);
						}
					} else if (ScenarioBlockStyle::forBlock(cursor.block()) == ScenarioBlockStyle::SceneCharacters) {
						const QStringList characters = SceneCharactersParser::characters(cursor.block().text());
						foreach (const QString& character, characters) {
							const QString characterName = character.toUpper().simplified();
							if (characterName.startsWith(cursorBackwardText, Qt::CaseInsensitive)
								&& !sceneCharacters.contains(characterName)) {
								sceneCharacters.append(characterName);
							}
						}
					}
					cursor.movePosition(QTextCursor::PreviousBlock);
					cursor.movePosition(QTextCursor::StartOfBlock);
				}
			}

			//
			// По возможности используем список персонажей сцены
			//
			if (!sceneCharacters.isEmpty()) {
				m_sceneCharactersModel->setStringList(sceneCharacters);
				sectionModel = m_sceneCharactersModel;
			} else {
				sectionModel = StorageFacade::characterStorage()->all();
			}
			sectionText = CharacterParser::name(currentBlockText);
			break;
		}

		case CharacterParser::SectionState: {
			sectionModel = StorageFacade::characterStateStorage()->all();
			sectionText = CharacterParser::state(currentBlockText);
			break;
		}

		default: {
			break;
		}
	}
开发者ID:Roger-Waters,项目名称:KITScenarist,代码行数:81,代码来源:CharacterHandler.cpp


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