本文整理汇总了C++中QTextCursor函数的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor函数的具体用法?C++ QTextCursor怎么用?C++ QTextCursor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QTextCursor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: EditorState
PersistentState::PersistentState(Editor *context) : EditorState(context) {
_mousePressed = false;
_mightStartDrag = false;
_persistentCursor = QTextCursor();
_dndFeedbackCursor = QTextCursor();
}
开发者ID:BackupTheBerlios,项目名称:devqt-svn,代码行数:7,代码来源:persistentstate.cpp
示例2: mouseMoveEvent
bool Document::eventFilter(QObject* watched, QEvent* event)
{
if (event->type() == QEvent::MouseMove) {
mouseMoveEvent(static_cast<QMouseEvent*>(event));
} else if (event->type() == QEvent::KeyPress && watched == m_text) {
int msecs = m_time.restart();
if (msecs < 30000) {
m_current_time += msecs;
}
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
if(key_event->key()==Qt::Key_Return)
{
QTextCursor testcursor(m_text->document());
testcursor.setPosition(m_text->textCursor().anchor());
int ancblock=testcursor.blockNumber();
testcursor.setPosition(m_text->textCursor().position());
int curblock=testcursor.blockNumber();
if(curblock==ancblock)
{
QString uprop=testcursor.blockFormat().stringProperty(QTextFormat::UserProperty);
if(uprop=="ATTRIBUTION" || uprop.startsWith("DIVIDER"))
{
testcursor.insertBlock(defaultFormatForBlock(""));
return true;
}
}
}
if (!key_event->text().isEmpty())
{
QTextCursor testcursor2=QTextCursor(m_text->textCursor());
if(testcursor2.anchor()==testcursor2.position()&&testcursor2.atBlockStart()&&testcursor2.blockFormat().stringProperty(QTextFormat::UserProperty).startsWith("DIVIDER"))
return true;
if(SmartQuotes::isEnabled()&&key_event->text()=="-")
{
QTextCursor testcursor=QTextCursor(m_text->document());
int ancpos=m_text->textCursor().anchor();
int curpos=m_text->textCursor().position();
testcursor.setPosition(ancpos<curpos?ancpos:curpos);
if(!testcursor.atBlockStart())
{
testcursor.movePosition(QTextCursor::Left,QTextCursor::KeepAnchor);
if(testcursor.selectedText()=="-")
{
testcursor.insertText(QString(QChar(0x2014)));
m_text->textCursor().removeSelectedText();
return true;
}
}
}
emit keyPressed(key_event->key());
}
if (SmartQuotes::isEnabled() && SmartQuotes::insert(m_text, key_event)) {
return true;
}
}
return QWidget::eventFilter(watched, event);
}
开发者ID:quickhand,项目名称:Prosit,代码行数:60,代码来源:document.cpp
示例3: rowEnd
/*!
\fn QTextCursor QTextTable::rowStart(const QTextCursor &cursor) const
Returns a cursor pointing to the start of the row that contains the
given \a cursor.
\sa rowEnd()
*/
QTextCursor QTextTable::rowStart(const QTextCursor &c) const
{
Q_D(const QTextTable);
QTextTableCell cell = cellAt(c);
if (!cell.isValid())
return QTextCursor();
int row = cell.row();
QTextDocumentPrivate *p = d->pieceTable;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), d->grid[row*d->nCols]);
return QTextCursor(p, it.position());
}
开发者ID:pk-codebox-evo,项目名称:remixos-usb-tool,代码行数:20,代码来源:qtexttable.cpp
示例4: QTextCursor
void RTF::Reader::read(QIODevice* device, QTextDocument* text)
{
try {
// Open file
m_text = 0;
if (!m_cursor.isNull()) {
m_cursor = QTextCursor();
}
m_text = text;
m_cursor = QTextCursor(m_text);
m_cursor.movePosition(QTextCursor::End);
m_token.setDevice(device);
setBlockDirection(Qt::LeftToRight);
// Check file type
m_token.readNext();
if (m_token.type() == StartGroupToken) {
pushState();
} else {
throw tr("Not a supported RTF file.");
}
m_token.readNext();
if (m_token.type() != ControlWordToken || m_token.text() != "rtf" || m_token.value() != 1) {
throw tr("Not a supported RTF file.");
}
// Parse file contents
while (!m_states.isEmpty() && m_token.hasNext()) {
m_token.readNext();
if ((m_token.type() != EndGroupToken) && !m_in_block) {
m_cursor.insertBlock();
m_in_block = true;
}
if (m_token.type() == StartGroupToken) {
pushState();
} else if (m_token.type() == EndGroupToken) {
popState();
} else if (m_token.type() == ControlWordToken) {
if (!m_state.ignore_control_word && functions.contains(m_token.text())) {
functions[m_token.text()].call(this, m_token);
}
} else if (m_token.type() == TextToken) {
if (!m_state.ignore_text) {
m_cursor.insertText(m_codec->toUnicode(m_token.text()));
}
}
}
} catch (const QString& error) {
m_error = error;
}
}
开发者ID:YAPLLE,项目名称:manual-indexing,代码行数:53,代码来源:rtf_reader.cpp
示例5: rowStart
/*!
\fn QTextCursor QTextTable::rowEnd(const QTextCursor &cursor) const
Returns a cursor pointing to the end of the row that contains the given
\a cursor.
\sa rowStart()
*/
QTextCursor QTextTable::rowEnd(const QTextCursor &c) const
{
Q_D(const QTextTable);
QTextTableCell cell = cellAt(c);
if (!cell.isValid())
return QTextCursor();
int row = cell.row() + 1;
int fragment = row < d->nRows ? d->grid[row*d->nCols] : d->fragment_end;
QTextDocumentPrivate *p = d->pieceTable;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment);
return QTextCursor(p, it.position() - 1);
}
开发者ID:pk-codebox-evo,项目名称:remixos-usb-tool,代码行数:21,代码来源:qtexttable.cpp
示例6: QTextCursor
QTextCursor DocumentHandler::textCursor() const
{
if (!m_doc)
return QTextCursor();
QTextCursor cursor = QTextCursor(m_doc);
if (m_selectionStart != m_selectionEnd) {
cursor.setPosition(m_selectionStart);
cursor.setPosition(m_selectionEnd, QTextCursor::KeepAnchor);
} else {
cursor.setPosition(m_cursorPosition);
}
return cursor;
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:14,代码来源:documenthandler.cpp
示例7: block
QTextCursor ScCodeEditor::selectionForPosition( int position )
{
QTextBlock block( textDocument()->findBlock(position) );
if (!block.isValid())
return QTextCursor();
int positionInBlock = position - block.position();
TokenIterator it = TokenIterator( block, positionInBlock );
if (it.type() == Token::Unknown) {
// Token is invalid, or Token::Unknown (i.e. punctuations).
// Prefer token at previous position.
TokenIterator alternativeIt = TokenIterator( block, positionInBlock - 1 );
if (alternativeIt.isValid())
it = alternativeIt;
}
if (it.isValid()) {
switch (it->type) {
case Token::OpeningBracket:
case Token::ClosingBracket:
{
BracketPair match;
matchBracket(it, match);
if (match.first.isValid() && match.second.isValid()) {
int start = match.first.position();
int end = match.second.position() + 1;
QTextCursor selection(textDocument());
if (it == match.second) {
selection.setPosition(start);
selection.setPosition(end, QTextCursor::KeepAnchor);
} else {
selection.setPosition(end);
selection.setPosition(start, QTextCursor::KeepAnchor);
}
return selection;
}
break;
}
default:
QTextCursor selection( textDocument() );
selection.setPosition( it.position() );
selection.setPosition( selection.position() + it->length, QTextCursor::KeepAnchor );
return selection;
}
}
return QTextCursor();
}
开发者ID:vanhuman,项目名称:supercollider-rvh,代码行数:50,代码来源:sc_editor.cpp
示例8: QTextCursor
void PersistentState::initialize() {
_dndFeedbackCursor = QTextCursor();
QTextCursor textCursor = editor()->textCursor();
if (textCursor.hasSelection()) {
_persistentCursor = textCursor;
textCursor.clearSelection();
editor()->setTextCursor(textCursor);
}
else
_persistentCursor = QTextCursor();
connect(editor(), SIGNAL(selectionChanged()), this, SLOT(editorSelectionChange()) );
}
开发者ID:BackupTheBerlios,项目名称:devqt-svn,代码行数:14,代码来源:persistentstate.cpp
示例9: QTextCursor
QTextCursor QTextEditProto::textCursor() const
{
QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject());
if (item)
return item->textCursor();
return QTextCursor();
}
开发者ID:AlFoX,项目名称:qt-client,代码行数:7,代码来源:qtexteditproto.cpp
示例10: QColor
void QScriptEdit::updateExtraSelections()
{
QList<QTextEdit::ExtraSelection> extraSelections;
{
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
extraSelections.append(selection);
}
if (m_executionLineNumber != -1) {
QTextEdit::ExtraSelection selection;
QColor lineColor;
if (m_executionLineNumberHasError)
lineColor = QColor(Qt::red);
else
lineColor = QColor(Qt::green).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
int blockNumber = m_executionLineNumber - m_baseLineNumber;
selection.cursor = QTextCursor(document()->findBlockByNumber(blockNumber));
selection.cursor.clearSelection();
extraSelections.append(selection);
}
setExtraSelections(extraSelections);
}
开发者ID:wpbest,项目名称:copperspice,代码行数:30,代码来源:qscriptedit.cpp
示例11: QTextCursor
void DocBlock::addLink(QUrl url)
{
myTextItem->setTextInteractionFlags(Qt::TextSelectableByKeyboard);
docType = Link;
path = url.toString();
QString str = path;
// add file icon
QTextCursor cursor = QTextCursor(myTextItem->document());
QFileInfo info(url.toLocalFile());
QFileIconProvider *provider = new QFileIconProvider();
QImage image(provider->icon(info).pixmap(16, 16).toImage());
cursor.document()->setPlainText(" ");
cursor.insertImage(image);
if (str.lastIndexOf("/") > -1)
str = str.right(str.size() - str.lastIndexOf("/") - 1);
QString html = "<a href=\""+path+"\">"+str+"</a>";
cursor.insertHtml(html);
if (arrow != 0) arrow->setColor(getHoverColor());
updateBlock(false);
}
开发者ID:fejo,项目名称:TrollEdit-1,代码行数:25,代码来源:doc_block.cpp
示例12: parentItem
void ElementTitle::startTextInteraction()
{
parentItem()->setSelected(true);
// Already interacting?
if (hasFocus())
return;
mOldText = toPlainText();
// Clear scene selection
//if (!(event->modifiers() & Qt::ControlModifier)) - was here.
scene()->clearSelection();
if (mReadOnly)
setTextInteractionFlags(Qt::TextBrowserInteraction);
else
setTextInteractionFlags(Qt::TextEditorInteraction);
setFocus(Qt::OtherFocusReason);
// Set full text selection
QTextCursor cursor = QTextCursor(document());
cursor.select(QTextCursor::Document);
setTextCursor(cursor);
setCursor(Qt::IBeamCursor);
}
开发者ID:ArtemKopylov,项目名称:qreal,代码行数:26,代码来源:elementTitle.cpp
示例13: textDocument
QTextCursor ScCodeEditor::regionAroundCursor(const QTextCursor & cursor)
{
int cursorPosition = cursor.position();
BracketPair bracketPair;
TokenIterator it = TokenIterator::rightOf( textDocument()->begin(), 0 );
while (it.isValid()) {
nextBracketPair(it, bracketPair);
if (bracketPair.first.isValid() && bracketPair.first.position() < cursorPosition)
{
if ( bracketPair.second.isValid() && bracketPair.second.position() >= cursorPosition
&& bracketPairDefinesRegion(bracketPair) )
{
QTextCursor regionCursor(QPlainTextEdit::document());
regionCursor.setPosition(bracketPair.first.position() + 1);
regionCursor.setPosition(bracketPair.second.position(), QTextCursor::KeepAnchor);
return regionCursor;
}
} else {
break;
}
it = bracketPair.second;
}
return QTextCursor();
}
开发者ID:vanhuman,项目名称:supercollider-rvh,代码行数:27,代码来源:sc_editor.cpp
示例14: file
QTextDocument *ReplaceDocument::fileDocument(const QString &fileName, QTextCursor &cursor, bool &crlf)
{
LiteApi::IEditor *editor = m_liteApp->editorManager()->findEditor(fileName,true);
if (editor) {
QPlainTextEdit *ed = LiteApi::getPlainTextEdit(editor);
if (ed) {
cursor = ed->textCursor();
return ed->document();
}
}
QFile file(fileName);
if (file.open(QFile::ReadOnly)) {
QByteArray data = file.readAll();
QString text = QString::fromUtf8(data);
int lf = text.indexOf('\n');
if (lf <= 0) {
crlf = false;
} else {
lf = text.indexOf(QRegExp("[^\r]\n"),lf-1);
if (lf >= 0) {
crlf = false;
} else {
crlf = true;
}
}
m_document = new QTextDocument(text);
cursor = QTextCursor(m_document);
return m_document;
}
return 0;
}
开发者ID:AChinaProgrammer,项目名称:liteide,代码行数:31,代码来源:replacedocument.cpp
示例15: QTextCursor
void MyTextEdit::highlightLines()
{
QList<QTextEdit::ExtraSelection> extraSelections;
if (!isReadOnly())
{
QTextEdit::ExtraSelection selection;
for(QMap<int, QColor>::const_iterator it = m_highlightedLines.begin(); it != m_highlightedLines.end(); ++it)
{
selection.format.setBackground(it.value());
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = QTextCursor(document());
selection.cursor.setPosition(document()->findBlockByLineNumber(it.key()).position());
extraSelections.append(selection);
}
selection.format.setBackground(QColor(Qt::yellow).lighter(170));
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
extraSelections.append(selection);
}
setExtraSelections(extraSelections);
}
开发者ID:vojtad,项目名称:rd2prog,代码行数:26,代码来源:MyTextEdit.cpp
示例16: setTextCursor
int CodeEditor::replaceAll( const QString &findText,const QString &replaceText,bool cased,bool wrap ){
QTextDocument::FindFlags flags=0;
if( cased ) flags|=QTextDocument::FindCaseSensitively;
if( wrap ){
QTextCursor cursor=textCursor();
setTextCursor( QTextCursor( document() ) );
if( !find( findText,flags ) ){
setTextCursor( cursor );
return 0;
}
}else{
if( !find( findText,flags ) ) return 0;
}
insertPlainText( replaceText );
int n=1;
while( findNext( findText,cased,false ) ){
insertPlainText( replaceText );
++n;
}
return n;
}
开发者ID:JochenHeizmann,项目名称:monkey,代码行数:27,代码来源:codeeditor.cpp
示例17: QTextCursor
//-----------------------------------------------------------------------------
int TextEdit::getFirstVisibleBlockId()
{
// Detect the first block for which bounding rect - once translated
// in absolute coordinated - is contained by the editor's text area
// Costly way of doing but since "blockBoundingGeometry(...)" doesn't
// exists for "QTextEdit"...
QTextCursor curs = QTextCursor(document());
curs.movePosition(QTextCursor::Start);
for(int i=0; i < document()->blockCount(); ++i)
{
QTextBlock block = curs.block();
QRect r1 = viewport()->geometry();
QRect r2 = document()->documentLayout()->blockBoundingRect(block).translated(
viewport()->geometry().x(), viewport()->geometry().y() - (
verticalScrollBar()->sliderPosition()
) ).toRect();
if (r1.contains(r2, true)) { return i; }
curs.movePosition(QTextCursor::NextBlock);
}
return 0;
}
开发者ID:ClinicalGraphics,项目名称:MathGL,代码行数:28,代码来源:textedit.cpp
示例18: setupTest
void TestTableLayout::testColumnWidthFixedShrink()
{
KoTableStyle *tableStyle = new KoTableStyle;
//tableStyle->setWidth(QTextLength(QTextLength::FixedLength, 200.0)); // no table-width defined
setupTest("merged text", "top right text", "mid right text", "bottom left text", "bottom mid text", "bottom right text", tableStyle);
KoTableColumnAndRowStyleManager styleManager = KoTableColumnAndRowStyleManager::getManager(m_table);
KoTableColumnStyle column1style;
column1style.setColumnWidth(2.3);
styleManager.setColumnStyle(0, column1style);
KoTableColumnStyle column2style;
column2style.setColumnWidth(122.5);
styleManager.setColumnStyle(1, column2style);
KoTableColumnStyle column3style;
column3style.setColumnWidth(362.9);
styleManager.setColumnStyle(2, column3style);
m_layout->layout();
QVERIFY(qAbs(QTextCursor(m_table->parentFrame()).block().layout()->lineAt(0).width() - 200.0) < ROUNDING); // table should grow to 200
QVERIFY(qAbs(mergedCellBlock().layout()->lineAt(0).width() - 26.5938) < ROUNDING);
QVERIFY(qAbs(topRightCellBlock().layout()->lineAt(0).width() - 267) < ROUNDING);
QVERIFY(qAbs(bottomMidCellBlock().layout()->lineAt(0).width() - 26.5938) < ROUNDING);
QVERIFY(qAbs(bottomRightCellBlock().layout()->lineAt(0).width() - 267) < ROUNDING);
}
开发者ID:abhishekmurthy,项目名称:Calligra,代码行数:28,代码来源:TestTableLayout.cpp
示例19: Q_UNUSED
void NumberedTextView::textChanged( int pos, int removed, int added )
{
Q_UNUSED( pos );
if ( removed == 0 && added == 0 )
return;
QTextBlock block = highlight.block();
QTextBlockFormat fmt = block.blockFormat();
QColor bg = view->palette().base().color();
fmt.setBackground( bg );
highlight.setBlockFormat( fmt );
int lineCount = 1;
for ( QTextBlock block = view->document()->begin();
block.isValid(); block = block.next(), ++lineCount )
{
if ( lineCount == markedLine )
{
fmt = block.blockFormat();
QColor bg = Qt::red;
fmt.setBackground( bg.light(150) );
highlight = QTextCursor( block );
highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
highlight.setBlockFormat( fmt );
break;
}
}
}
开发者ID:BurntBrunch,项目名称:rockbox-fft,代码行数:31,代码来源:numberedtextview.cpp
示例20: QTextCursor
void PlainTextViewWidget::clearSearch()
{
m_searchResults.clear();
m_currentSearchResult = QTextCursor();
ui->plainTextEdit->setExtraSelections(QList<QTextEdit::ExtraSelection>());
}
开发者ID:tomvodi,项目名称:QTail,代码行数:7,代码来源:PlainTextViewWidget.cpp
注:本文中的QTextCursor函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论