本文整理汇总了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);
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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() ) );
}
示例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);
}
示例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;
}
示例14: selectionStart
bool WLineEdit::hasSelectedText() const
{
return selectionStart() != -1;
}
示例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);
}