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


C++ selectionStart函数代码示例

本文整理汇总了C++中selectionStart函数的典型用法代码示例。如果您正苦于以下问题:C++ selectionStart函数的具体用法?C++ selectionStart怎么用?C++ selectionStart使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: text

/** Remove any existing auto completion suggestion */
void HintingLineEdit::clearSuggestion() {
  if (!hasSelectedText())
    return;

  // Carefully cut out the selected text
  QString line = text();
  line = line.left(selectionStart()) +
         line.mid(selectionStart() + selectedText().length());
  setText(line);
}
开发者ID:mantidproject,项目名称:mantid,代码行数:11,代码来源:HintingLineEdit.cpp

示例2: data

QString ChatItem::selection() const
{
    if (selectionMode() == FullSelection)
        return data(MessageModel::DisplayRole).toString();
    if (selectionMode() == PartialSelection) {
        int start = qMin(selectionStart(), selectionEnd());
        int end   = start + qAbs(selectionStart() - selectionEnd());

        QTextCursor cSelect(document());
        cSelect.setPosition(start);
        cSelect.setPosition(end, QTextCursor::KeepAnchor);
        return cSelect.selectedText();
    }
    return QString();
}
开发者ID:arneboe,项目名称:ProjectTox-Qt-GUI,代码行数:15,代码来源:chatitem.cpp

示例3: document

QAbstractTextDocumentLayout::Selection ChatItem::selectionLayout() const
{
        QAbstractTextDocumentLayout::Selection selection;

        if (!hasSelection())
            return selection;

        int start;
        int end;

        if (selectionMode() == FullSelection) {
            start = 0;
            end = document()->characterCount()-1;
        }
        else {
            start = selectionStart();
            end   = selectionEnd();
        }

        QTextCursor c(document());
        c.setPosition(start);
        c.setPosition(end, QTextCursor::KeepAnchor);
        selection.cursor = c;

        return selection;
}
开发者ID:arneboe,项目名称:ProjectTox-Qt-GUI,代码行数:26,代码来源:chatitem.cpp

示例4: keyPressEvent

void CharLineEdit::keyPressEvent(QKeyEvent* event)
{
	bool handled = false;

	if (selectionStart() == -1)
	{
		switch (event->key())
		{
		case Qt::Key_Backspace:
			if (isAtEndOfSeparator())
			{
				// Delete separator characters in a single keypress.
				// Don't use setText This method maintains the undo history
				backspace();
				backspace();
				backspace();
				handled = true;
			}
			break;

		case Qt::Key_Delete:
			if (isAtStartOfSeparator())
			{
				del();
				del();
				del();
				handled = true;
			}
			break;

		case Qt::Key_Left:
			if (isAtEndOfSeparator())
			{
				cursorBackward(false, 3);
				handled = true;
			}
			break;

		case Qt::Key_Right:
			if (isAtStartOfSeparator())
			{
				cursorForward(false, 3);
				handled = true;
			}
			break;
		}
	}

	if (handled)
	{
		event->ignore();
	}
	else
	{
		QLineEdit::keyPressEvent(event);
	}

	emit keyPressed(event);
}
开发者ID:Cache22,项目名称:Launchy,代码行数:59,代码来源:CharLineEdit.cpp

示例5: textCursor

void ItemEditorWidget::search(const QRegExp &re)
{
    if ( !re.isValid() || re.isEmpty() )
        return;

    auto tc = textCursor();
    tc.setPosition(tc.selectionStart());
    setTextCursor(tc);
    findNext(re);
}
开发者ID:amosbird,项目名称:CopyQ,代码行数:10,代码来源:itemeditorwidget.cpp

示例6: selectedText

WT_USTRING WLineEdit::selectedText() const
{
  if (selectionStart() != -1) {
    WApplication *app = WApplication::instance();

    return WString::fromUTF8(UTF8Substr(text().toUTF8(), app->selectionStart(),
		    app->selectionEnd() - app->selectionStart()));
  } else
    return WString::Empty;
}
开发者ID:ChowZenki,项目名称:wt,代码行数:10,代码来源:WLineEdit.C

示例7: value

void HTMLTextFormControlElement::setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionState& exceptionState)
{
    if (start > end) {
        exceptionState.throwDOMException(IndexSizeError, "The provided start value (" + String::number(start) + ") is larger than the provided end value (" + String::number(end) + ").");
        return;
    }
    if (hasAuthorShadowRoot())
        return;

    String text = innerTextValue();
    unsigned textLength = text.length();
    unsigned replacementLength = replacement.length();
    unsigned newSelectionStart = selectionStart();
    unsigned newSelectionEnd = selectionEnd();

    start = std::min(start, textLength);
    end = std::min(end, textLength);

    if (start < end)
        text.replace(start, end - start, replacement);
    else
        text.insert(replacement, start);

    setInnerTextValue(text);

    // FIXME: What should happen to the value (as in value()) if there's no renderer?
    if (!renderer())
        return;

    subtreeHasChanged();

    if (equalIgnoringCase(selectionMode, "select")) {
        newSelectionStart = start;
        newSelectionEnd = start + replacementLength;
    } else if (equalIgnoringCase(selectionMode, "start"))
        newSelectionStart = newSelectionEnd = start;
    else if (equalIgnoringCase(selectionMode, "end"))
        newSelectionStart = newSelectionEnd = start + replacementLength;
    else {
        // Default is "preserve".
        long delta = replacementLength - (end - start);

        if (newSelectionStart > end)
            newSelectionStart += delta;
        else if (newSelectionStart > start)
            newSelectionStart = start;

        if (newSelectionEnd > end)
            newSelectionEnd += delta;
        else if (newSelectionEnd > start)
            newSelectionEnd = start + replacementLength;
    }

    setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirection);
}
开发者ID:Tkkg1994,项目名称:Platfrom-kccat6,代码行数:55,代码来源:HTMLTextFormControlElement.cpp

示例8: innerTextValue

void HTMLTextFormControlElement::setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionCode& ec)
{
    if (start > end) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    String text = innerTextValue();
    unsigned textLength = text.length();
    unsigned replacementLength = replacement.length();
    unsigned newSelectionStart = selectionStart();
    unsigned newSelectionEnd = selectionEnd();

    start = std::min(start, textLength);
    end = std::min(end, textLength);

    if (start < end)
        text.replace(start, end - start, replacement);
    else
        text.insert(replacement, start);

    setInnerTextValue(text);

    // FIXME: What should happen to the value (as in value()) if there's no renderer?
    if (!renderer())
        return;

    subtreeHasChanged();

    if (equalIgnoringCase(selectionMode, "select")) {
        newSelectionStart = start;
        newSelectionEnd = start + replacementLength;
    } else if (equalIgnoringCase(selectionMode, "start"))
        newSelectionStart = newSelectionEnd = start;
    else if (equalIgnoringCase(selectionMode, "end"))
        newSelectionStart = newSelectionEnd = start + replacementLength;
    else {
        // Default is "preserve".
        long delta = replacementLength - (end - start);

        if (newSelectionStart > end)
            newSelectionStart += delta;
        else if (newSelectionStart > start)
            newSelectionStart = start;

        if (newSelectionEnd > end)
            newSelectionEnd += delta;
        else if (newSelectionEnd > start)
            newSelectionEnd = start + replacementLength;
    }

    setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirection);
}
开发者ID:awong-chromium,项目名称:webkit,代码行数:53,代码来源:HTMLTextFormControlElement.cpp

示例9: UTF8Substr

WT_USTRING WLineEdit::selectedText() const
{
  if (selectionStart() != -1) {
    WApplication *app = WApplication::instance();

    std::string result = UTF8Substr(text().toUTF8(), app->selectionStart(),
				    app->selectionEnd() - app->selectionStart());
#ifdef WT_TARGET_JAVA
    return result;
#else
    return WString::fromUTF8(result);
#endif
  } else
    return WString::Empty;
}
开发者ID:quatmax,项目名称:wt,代码行数:15,代码来源:WLineEdit.C

示例10: textInteractionFlags

void KSqueezedTextLabel::mouseReleaseEvent(QMouseEvent* ev)
{
#if QT_VERSION >= 0x040700
    if (QApplication::clipboard()->supportsSelection() &&
        textInteractionFlags() != Qt::NoTextInteraction &&
        ev->button() == Qt::LeftButton &&
        !d->fullText.isEmpty() &&
        hasSelectedText()) {
        // Expand "..." when selecting with the mouse
        QString txt = selectedText();
        const QChar ellipsisChar(0x2026); // from qtextengine.cpp
        const int dotsPos = txt.indexOf(ellipsisChar);
        if (dotsPos > -1) {
            // Ex: abcde...yz, selecting de...y  (selectionStart=3)
            // charsBeforeSelection = selectionStart = 2 (ab)
            // charsAfterSelection = 1 (z)
            // final selection length= 26 - 2 - 1 = 23
            const int start = selectionStart();
            int charsAfterSelection = text().length() - start - selectedText().length();
            txt = d->fullText;
            // Strip markup tags
            if (textFormat() == Qt::RichText
                || (textFormat() == Qt::AutoText && Qt::mightBeRichText(txt))) {
                txt.replace(QRegExp(QStringLiteral("<[^>]*>")), QStringLiteral(""));
                // account for stripped characters
                charsAfterSelection -= d->fullText.length() - txt.length();
            }
            txt = txt.mid(selectionStart(), txt.length() - start - charsAfterSelection);
        }
        QApplication::clipboard()->setText(txt, QClipboard::Selection);
    } else
#endif
    {
        QLabel::mouseReleaseEvent(ev);
    }
}
开发者ID:crayonink,项目名称:calligra-2,代码行数:36,代码来源:ksqueezedtextlabel.cpp

示例11: text

void AnnotationDialog::CompletableLineEdit::selectPrevNextMatch( bool next )
{
    int itemStart = text().lastIndexOf( QRegExp(QString::fromLatin1("[!&|]")) ) +1;
    QString input = text().mid( itemStart );

    QList<QTreeWidgetItem*> items = m_listView->findItems( input, Qt::MatchContains, 0 );
    if ( items.isEmpty() )
        return;
    QTreeWidgetItem* item = items.at(0);

    if ( next )
        item = m_listView->itemBelow(item);
    else
        item = m_listView->itemAbove(item);

    if ( item )
        selectItemAndUpdateLineEdit( item, itemStart, text().left( selectionStart() ) );
}
开发者ID:astifter,项目名称:kphotoalbum-astifter-branch,代码行数:18,代码来源:CompletableLineEdit.cpp

示例12: getTokenUnderCursor

QPoint SyntaxLineEdit::getTokenUnderCursor()
{
    if (selectionStart() >= 0) return (QPoint(0,0));

    int pos = cursorPosition();
    int start = pos;
    int len = 0;

    while (start > 0 && token_chars_.contains(text().at(start -1))) {
        start--;
        len++;
    }
    while (pos < text().length() && token_chars_.contains(text().at(pos))) {
        pos++;
        len++;
    }

    return QPoint(start, len);
}
开发者ID:acaceres2176,项目名称:wireshark,代码行数:19,代码来源:syntax_line_edit.cpp

示例13: while

	QMap<int, QList<QRectF>> TextDocumentAdapter::GetTextPositions (const QString& text, Qt::CaseSensitivity cs)
	{
		const auto& pageSize = Doc_->pageSize ();
		const auto pageHeight = pageSize.height ();

		QTextEdit hackyEdit;
		hackyEdit.setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
		hackyEdit.setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
		hackyEdit.setFixedSize (Doc_->pageSize ().toSize ());
		hackyEdit.setDocument (Doc_.get ());
		Doc_->setPageSize (pageSize);

		const auto tdFlags = cs == Qt::CaseSensitive ?
				QTextDocument::FindCaseSensitively :
				QTextDocument::FindFlags ();

		QMap<int, QList<QRectF>> result;
		auto cursor = Doc_->find (text, 0, tdFlags);
		while (!cursor.isNull ())
		{
			auto endRect = hackyEdit.cursorRect (cursor);
			auto startCursor = cursor;
			startCursor.setPosition (cursor.selectionStart ());
			auto rect = hackyEdit.cursorRect (startCursor);

			const int pageNum = rect.y () / pageHeight;
			rect.moveTop (rect.y () - pageHeight * pageNum);
			endRect.moveTop (endRect.y () - pageHeight * pageNum);

			if (rect.y () != endRect.y ())
			{
				rect.setWidth (pageSize.width () - rect.x ());
				endRect.setX (0);
			}
			auto bounding = rect | endRect;

			result [pageNum] << bounding;

			cursor = Doc_->find (text, cursor, tdFlags);
		}
		return result;
	}
开发者ID:SboichakovDmitriy,项目名称:leechcraft,代码行数:42,代码来源:textdocumentadapter.cpp

示例14: selectionStart

bool WLineEdit::hasSelectedText() const
{
  return selectionStart() != -1;
}
开发者ID:ChowZenki,项目名称:wt,代码行数:4,代码来源:WLineEdit.C

示例15: selectedText

void KawaiiLineEdit::keyPressEvent(QKeyEvent *evt)
{
	if(!mRomajiMode)
		return QLineEdit::keyPressEvent(evt);

	if(evt->key() == Qt::Key_Backspace || evt->key() == Qt::Key_Delete)
	{
		if( mActiveText.isEmpty() )
		{
			if( !selectedText().isEmpty() )
			{
				mRealText.remove(selectionStart(), selectedText().length());
				mInsertPosition = selectionStart();
			}
			else if(evt->key() == Qt::Key_Delete) // Delete after the cursor
			{
				mRealText.remove(cursorPosition(), 1);
				mInsertPosition = cursorPosition();
			}
			else if(cursorPosition() > 0) // Delete character before cursor
			{
				mRealText.remove(cursorPosition() - 1, 1);
				mInsertPosition = cursorPosition() - 1;
			}

			evt->accept();
			updateText();
			return;
		}

		// Remove the last character in the string (if there is one)
		mActiveText.chop(1);

		evt->accept();
		updateText();

		return;
	}
	else if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return)
	{
		if( mActiveText.isEmpty() )
			return QLineEdit::keyPressEvent(evt);

		mRealText.insert(mInsertPosition, mDisplayText);
		mInsertPosition += mDisplayText.length();
		mDisplayMode = Hiragana;

		mDisplayText.clear();
		mActiveText.clear();

		evt->accept();
		updateText();

		setCursorPosition(mInsertPosition);

		return;
	}
	else if( !mActiveText.isEmpty() && (evt->key() == Qt::Key_Left ||
		evt->key() == Qt::Key_Right || evt->key() == Qt::Key_Home ||
		evt->key() == Qt::Key_End) )
	{
		evt->accept();
		return;
	}
	else if( !mActiveText.isEmpty() && evt->key() == Qt::Key_F7)
	{
		mDisplayMode = (mDisplayMode == Hiragana) ? Katakana : Hiragana;
		evt->accept();
		updateText();
		return;
	}

	// Normal key, clear the text first
	if( !evt->text().isEmpty() )
	{
		if( mActiveText.isEmpty() )
			mInsertPosition = cursorPosition();

		// If there is a selection, delete it
		if( !selectedText().isEmpty() && mActiveText.isEmpty() )
		{
			mRealText.remove(selectionStart(), selectedText().length());
			mInsertPosition = selectionStart();
		}

		mActiveText += evt->text();
		evt->accept();
		updateText();
		return;
	}

	QLineEdit::keyPressEvent(evt);
}
开发者ID:erikku,项目名称:frosty,代码行数:93,代码来源:LineEdit.cpp


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