本文整理汇总了C++中QTextCursor::selectionEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::selectionEnd方法的具体用法?C++ QTextCursor::selectionEnd怎么用?C++ QTextCursor::selectionEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::selectionEnd方法的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;
}
示例2: textCursor
void
FormText::underline( bool on )
{
QTextCursor c = textCursor();
if( c.hasSelection() )
{
if( c.position() != c.selectionEnd() )
c.setPosition( c.selectionEnd() );
QTextCharFormat fmt = c.charFormat();
fmt.setFontUnderline( on );
textCursor().setCharFormat( fmt );
}
else
{
QFont f = font();
f.setUnderline( on );
setFont( f );
}
QRectF r = boundingRect();
r.moveTo( pos() );
d->m_proxy->setRect( r );
}
示例3: EnumEditor
void EditorUtil::EnumEditor(QPlainTextEdit *ed, EnumEditorProc proc, void *param)
{
if (!ed) {
return;
}
QTextCursor cur = ed->textCursor();
cur.beginEditBlock();
if (cur.hasSelection()) {
QTextBlock begin = ed->document()->findBlock(cur.selectionStart());
QTextBlock end = ed->document()->findBlock(cur.selectionEnd());
if (end.position() == cur.selectionEnd()) {
end = end.previous();
}
QTextBlock block = begin;
do {
if (block.text().length() > 0) {
proc(cur,block,param);
}
block = block.next();
} while(block.isValid() && block.position() <= end.position());
} else {
QTextBlock block = cur.block();
proc(cur,block,param);
}
cur.endEditBlock();
ed->setTextCursor(cur);
}
示例4: 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));
}
示例5: 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();
}
}
示例6: dragEnterEvent
void QConsoleWidget::dragEnterEvent(QDragEnterEvent *e){
TP::dragEnterEvent(e);
if(e->isAccepted()){/*调整选区为可编辑区域*/
QTextCursor tc = this->textCursor();
if (tc.hasSelection()) {
if (tc.selectionStart()>= this->promptEndPos_) {
return;
}
else {
if (tc.selectionEnd()<= this->promptEndPos_) {
tc.clearSelection();
this->setTextCursor(tc);
}
else {
auto se_ = tc.selectionEnd();
tc.setPosition(this->promptEndPos_);
tc.setPosition(se_,QTextCursor::KeepAnchor);
this->setTextCursor(tc);
}
}
}
}
}
示例7: contextAllowsElectricCharacters
bool GlslCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block()),
LanguageFeatures::defaultFeatures());
// XXX Duplicated from CppEditor::isInComment to avoid tokenizing twice
if (tk.isComment()) {
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (pos == tk.utf16charsEnd()) {
if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
return false;
const int state = cursor.block().userState() & 0xFF;
if (state > 0)
return false;
}
if (pos < tk.utf16charsEnd())
return false;
} else if (tk.isStringLiteral() || tk.isCharLiteral()) {
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (pos <= tk.utf16charsEnd())
return false;
}
return true;
}
示例8: contextAllowsElectricCharacters
bool CppAutoCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block()));
// XXX Duplicated from CPPEditor::isInComment to avoid tokenizing twice
if (tk.isComment()) {
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (pos == tk.end()) {
if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
return false;
const int state = cursor.block().userState() & 0xFF;
if (state > 0)
return false;
}
if (pos < tk.end())
return false;
}
else if (tk.is(T_STRING_LITERAL) || tk.is(T_WIDE_STRING_LITERAL)
|| tk.is(T_CHAR_LITERAL) || tk.is(T_WIDE_CHAR_LITERAL)) {
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (pos <= tk.end())
return false;
}
return true;
}
示例9: 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 {
示例10: 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;
// }
}
示例11: 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);
}
}
示例12: get_selection
static void get_selection(QTextEdit *wid, int *start, int *length)
{
QTextCursor cursor = wid->textCursor();
*start = cursor.selectionStart();
*length = cursor.selectionEnd() - *start;
}
示例13: 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);
}
}
}
}
}
示例14: setKey
template<> bool
QConsoleWidget::_pf<bool, SelectKeyPressedAll>(
QConsoleWidget * thisp,
QKeyEvent * e) {
auto resetSelect = [](QConsoleWidget * _thisp)->void{
QTextCursor textCursor = _thisp->textCursor();
auto epos = textCursor.selectionEnd();
textCursor.setPosition( _thisp->promptEndPos_);
textCursor.setPosition( epos, QTextCursor::KeepAnchor);
_thisp->setTextCursor(textCursor);
};
auto key_ = e->key();
switch (key_)
{
case Qt::Key_Shift:
case Qt::Key_Control:
case Qt::Key_Meta:
case Qt::Key_Alt:
case Qt::Key_CapsLock:
case Qt::Key_NumLock:
case Qt::Key_ScrollLock:
case Qt::Key_Up:
case Qt::Key_Down:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_PageDown:
case Qt::Key_PageUp:
case Qt::Key_Home:
case Qt::Key_End:return false;
}
if (e->modifiers() & Qt::ControlModifier) {
switch (key_)
{
case Qt::Key_C:
case Qt::Key_A:return false;
case Qt::Key_X:/*剪贴*/ {
class EventKey :public QKeyEvent {
public:
void setKey() { k = Qt::Key_C; }
};
EventKey * fk = (EventKey*)(e);
fk->setKey();
thisp->TP::keyPressEvent(fk);
resetSelect(thisp);
QTextCursor textCursor = thisp->textCursor();
textCursor.removeSelectedText();
thisp->setTextCursor(textCursor);
return true;
}
}
}
resetSelect(thisp);
return false;
}
示例15: isInCommentHelper
bool LuaAutoCompleter::isInCommentHelper(const QTextCursor &cursor, Token *retToken) const
{
LanguageFeatures features;
features.qtEnabled = false;
features.qtKeywordsEnabled = false;
features.qtMocRunEnabled = false;
features.cxx11Enabled = true;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const int prevState = BackwardsScanner::previousBlockState(cursor.block()) & 0xFF;
const QList<Token> tokens = tokenize(cursor.block().text(), prevState);
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (tokens.isEmpty() || pos < tokens.first().begin())
return prevState > 0;
if (pos >= tokens.last().end()) {
const Token tk = tokens.last();
if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
return true;
return tk.isComment() && (cursor.block().userState() & 0xFF);
}
Token tk = tokenAtPosition(tokens, pos);
if (retToken)
*retToken = tk;
return tk.isComment();
}