本文整理汇总了C++中QPlainTextEdit::setTextCursor方法的典型用法代码示例。如果您正苦于以下问题:C++ QPlainTextEdit::setTextCursor方法的具体用法?C++ QPlainTextEdit::setTextCursor怎么用?C++ QPlainTextEdit::setTextCursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPlainTextEdit
的用法示例。
在下文中一共展示了QPlainTextEdit::setTextCursor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
int QScriptDebuggerCodeView::find(const QString &exp, int options)
{
Q_D(QScriptDebuggerCodeView);
QPlainTextEdit *ed = (QPlainTextEdit*)d->editor;
QTextCursor cursor = ed->textCursor();
if (options & 0x100) {
// start searching from the beginning of selection
if (cursor.hasSelection()) {
int len = cursor.selectedText().length();
cursor.clearSelection();
cursor.setPosition(cursor.position() - len);
ed->setTextCursor(cursor);
}
options &= ~0x100;
}
int ret = 0;
if (ed->find(exp, QTextDocument::FindFlags(options))) {
ret |= 0x1;
} else {
QTextCursor curse = cursor;
curse.movePosition(QTextCursor::Start);
ed->setTextCursor(curse);
if (ed->find(exp, QTextDocument::FindFlags(options)))
ret |= 0x1 | 0x2;
else
ed->setTextCursor(cursor);
}
return ret;
}
示例2:
void QsvTextOperationsWidget::setTextCursor(QTextCursor c)
{
QTextEdit *t = qobject_cast<QTextEdit*>(parent());
if (t) {
t->setTextCursor(c);
} else {
QPlainTextEdit *pt = qobject_cast<QPlainTextEdit*>(parent());
if (pt) {
pt->setTextCursor(c);
}
}
}
示例3: openUrlFile
void LiteDoc::openUrlFile(const QUrl &url)
{
QFileInfo info(url.toLocalFile());
if (!info.exists()) {
info.setFile(url.path());
}
QString ext = info.suffix().toLower();
if (ext == "html") {
QFile file(info.filePath());
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = file.readAll();
file.close();
if (info.fileName().compare("docs.html",Qt::CaseInsensitive) == 0) {
updateHtmlDoc(url,ba,QString(),false);
} else {
updateHtmlDoc(url,ba);
}
}
} else if (ext == "md") {
QFile file(info.filePath());
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = mdtohtml(file.readAll());
updateHtmlDoc(url,ba);
}
} else if (ext == "go") {
LiteApi::IEditor *editor = m_liteApp->fileManager()->openEditor(info.filePath());
if (editor) {
editor->setReadOnly(true);
QPlainTextEdit *ed = LiteApi::findExtensionObject<QPlainTextEdit*>(editor,"LiteApi.QPlainTextEdit");
if (ed && url.hasQueryItem("s")) {
QStringList pos = url.queryItemValue("s").split(":");
if (pos.length() == 2) {
bool ok = false;
int begin = pos.at(0).toInt(&ok);
if (ok) {
QTextCursor cur = ed->textCursor();
cur.setPosition(begin);
ed->setTextCursor(cur);
ed->centerCursor();
}
}
}
}
} else if (ext == "pdf") {
QDesktopServices::openUrl(info.filePath());
} else {
QFile file(info.filePath());
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = file.readAll();
updateTextDoc(url,ba,info.fileName());
}
}
}
示例4: insertTextAtLine
//-------------------------------------------------------------------------
void MainWindow::insertTextAtLine(int lineNr, const char* pText)
{
QPlainTextEdit *sourceCode = getCurrentSourceCode();
if (lineNr >= 0)
{
QTextCursor sourceCursor = sourceCode->textCursor();
sourceCursor.setPosition(sourceCode->document()->findBlockByLineNumber(lineNr).position());
sourceCode->setTextCursor(sourceCursor);
}
else
{
sourceCode->moveCursor(QTextCursor::StartOfLine);
}
sourceCode->insertPlainText(QString::fromUtf8(pText));
}
示例5: requestSetBlockSelection
void FakeVimProxy::requestSetBlockSelection(const QTextCursor &tc) {
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget);
if (!ed)
return;
QPalette pal = ed->parentWidget() != NULL ? ed->parentWidget()->palette()
: QApplication::palette();
m_blockSelection.clear();
m_clearSelection.clear();
QTextCursor cur = tc;
QTextEdit::ExtraSelection selection;
selection.format.setBackground( pal.color(QPalette::Base) );
selection.format.setForeground( pal.color(QPalette::Text) );
selection.cursor = cur;
m_clearSelection.append(selection);
selection.format.setBackground( pal.color(QPalette::Highlight) );
selection.format.setForeground( pal.color(QPalette::HighlightedText) );
int from = cur.positionInBlock();
int to = cur.anchor() - cur.document()->findBlock(cur.anchor()).position();
const int min = qMin(cur.position(), cur.anchor());
const int max = qMax(cur.position(), cur.anchor());
for ( QTextBlock block = cur.document()->findBlock(min);
block.isValid() && block.position() < max; block = block.next() ) {
cur.setPosition( block.position() + qMin(from, block.length()) );
cur.setPosition( block.position() + qMin(to, block.length()), QTextCursor::KeepAnchor );
selection.cursor = cur;
m_blockSelection.append(selection);
}
disconnect( ed, &QPlainTextEdit::selectionChanged,
this, &FakeVimProxy::updateBlockSelection );
ed->setTextCursor(tc);
connect( ed, &QPlainTextEdit::selectionChanged,
this, &FakeVimProxy::updateBlockSelection );
QPalette pal2 = ed->palette();
pal2.setColor(QPalette::Highlight, Qt::transparent);
pal2.setColor(QPalette::HighlightedText, Qt::transparent);
ed->setPalette(pal2);
updateExtraSelections();
}
示例6: findHelper
void FindEditor::findHelper(FindOption *opt)
{
bool bFocus = m_findEdit->hasFocus();
LiteApi::IEditor *editor = m_liteApp->editorManager()->currentEditor();
if (!editor) {
return;
}
LiteApi::ITextEditor *textEditor = LiteApi::getTextEditor(editor);
QTextCursor find;
if (textEditor) {
QPlainTextEdit *ed = LiteApi::getPlainTextEdit(editor);
if (ed) {
find = findEditor(ed->document(),ed->textCursor(),opt);
if (!find.isNull()) {
ed->setTextCursor(find);
}
}
} else {
QTextBrowser *ed = LiteApi::findExtensionObject<QTextBrowser*>(editor,"LiteApi.QTextBrowser");
if (ed) {
find = findEditor(ed->document(),ed->textCursor(),opt);
if (!find.isNull()) {
ed->setTextCursor(find);
}
}
}
if (find.isNull()) {
m_status->setText(tr("Not find"));
} else {
m_status->setText(QString("Ln:%1 Col:%2").
arg(find.blockNumber()+1).
arg(find.columnNumber()+1));
}
if (bFocus) {
m_findEdit->setFocus();
} else if (textEditor) {
textEditor->onActive();
}
}
示例7: replaceHelper
void FindEditor::replaceHelper(LiteApi::ITextEditor *editor, FindOption *opt, int replaceCount)
{
bool bFocus = m_replaceEdit->hasFocus();
QPlainTextEdit *ed = LiteApi::getPlainTextEdit(editor);
if (!ed) {
return;
}
QTextCursor find;
QTextCursor cursor = ed->textCursor();
int line = cursor.blockNumber();
int col = cursor.columnNumber();
Qt::CaseSensitivity cs = Qt::CaseInsensitive;
if (opt->matchCase) {
cs = Qt::CaseSensitive;
}
if ( cursor.hasSelection() ) {
QString text = cursor.selectedText();
if (opt->useRegexp) {
if (text.indexOf(QRegExp(opt->findText,cs),0) != -1) {
find = cursor;
}
} else {
if (text.indexOf(opt->findText,0,cs) != -1) {
find = cursor;
}
}
}
int number = 0;
bool wrap = opt->wrapAround;
do {
if (!find.isNull()) {
number++;
find.beginEditBlock();
QString text = find.selectedText();
if (opt->useRegexp) {
text.replace(QRegExp(opt->findText,cs),opt->replaceText);
} else {
text.replace(opt->findText,opt->replaceText);
}
find.removeSelectedText();
find.insertText(text);
find.endEditBlock();
ed->setTextCursor(find);
}
cursor = ed->textCursor();
find = findEditor(ed->document(),cursor,opt,false);
if (find.isNull() && wrap) {
wrap = false;
find = findEditor(ed->document(),cursor,opt,true);
}
if (opt->wrapAround && !wrap) {
if (find.blockNumber() > line ||
(find.blockNumber() >= line && find.columnNumber() > col) ) {
break;
}
}
if (replaceCount != -1 && number >= replaceCount) {
if (!find.isNull()) {
ed->setTextCursor(find);
m_status->setText(QString("Ln:%1 Col:%2").
arg(find.blockNumber()+1).
arg(find.columnNumber()+1));
} else {
m_status->setText(tr("Not find"));
}
break;
}
} while(!find.isNull());
if (replaceCount == -1) {
m_status->setText(QString("Replace:%1").arg(number));
}
if (bFocus) {
m_replaceEdit->setFocus();
} else if (editor) {
editor->onActive();
}
}
示例8: replaceHelper
void FindEditor::replaceHelper(LiteApi::ITextEditor *editor, FindOption *opt, int replaceCount)
{
bool bFocus = m_replaceEdit->hasFocus();
QPlainTextEdit *ed = LiteApi::getPlainTextEdit(editor);
if (!ed) {
return;
}
QTextCursor find;
QTextCursor cursor = ed->textCursor();
int startLine = cursor.blockNumber();
int startColumn = cursor.columnNumber();
Qt::CaseSensitivity cs = Qt::CaseInsensitive;
if (opt->matchCase) {
cs = Qt::CaseSensitive;
}
int from = cursor.position();
if ( cursor.hasSelection() ) {
// QString text = cursor.selectedText();
// if (opt->useRegexp) {
// if (text.indexOf(QRegExp(opt->findText,cs),0) != -1) {
// find = cursor;
// }
// } else {
// if (text.indexOf(opt->findText,0,cs) != -1) {
// find = cursor;
// }
// }
from = cursor.selectionStart();
startColumn -= cursor.selectedText().length();
}
int number = 0;
bool wrap = opt->wrapAround;
ed->textCursor().beginEditBlock();
do {
if (!find.isNull()) {
number++;
//find.beginEditBlock();
QString text = find.selectedText();
bool changed = find.blockNumber() == startLine && find.columnNumber() < startColumn;
if (changed) {
startColumn -= text.length();
}
if (opt->useRegexp) {
text.replace(QRegExp(opt->findText,cs),opt->replaceText);
} else {
text.replace(QRegExp(opt->findText,cs,QRegExp::FixedString),opt->replaceText);
}
find.removeSelectedText();
from = find.position()+ text.length();
find.insertText(text);
//find.endEditBlock();
//ed->setTextCursor(find);
if (changed) {
startColumn += text.length();
}
}
//cursor = ed->textCursor();
find = findEditorHelper(ed->document(),from,opt,false);
if (find.isNull() && wrap) {
wrap = false;
find = findEditorHelper(ed->document(),0,opt,true);
}
if (!find.isNull() && opt->wrapAround && !wrap) {
if (find.blockNumber() > startLine ||
(find.blockNumber() == startLine && (find.columnNumber()-find.selectedText().length()) >= startColumn) ) {
break;
}
}
if (replaceCount != -1 && number >= replaceCount) {
if (!find.isNull()) {
ed->setTextCursor(find);
m_status->setText(QString("Ln:%1 Col:%2").
arg(find.blockNumber()+1).
arg(find.columnNumber()+1));
} else {
m_status->setText(tr("Not found"));
}
break;
}
} while(!find.isNull());
ed->textCursor().endEditBlock();
if (replaceCount == -1) {
m_status->setText(QString("Replace:%1").arg(number));
}
if (bFocus) {
m_replaceEdit->setFocus();
} else if (editor) {
editor->onActive();
}
}
示例9: openUrlFile
void LiteDoc::openUrlFile(const QUrl &url)
{
QFileInfo info(url.toLocalFile());
if (!info.exists()) {
info.setFile(url.path());
}
QString ext = info.suffix().toLower();
if (ext == "html") {
QFile file(info.filePath());
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = file.readAll();
file.close();
if (info.fileName().compare("docs.html",Qt::CaseInsensitive) == 0) {
updateHtmlDoc(url,ba,QString(),false);
} else {
updateHtmlDoc(url,ba);
}
}
} else if (ext == "md") {
QFile file(info.filePath());
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = md2html(file.readAll());
updateHtmlDoc(url,ba);
}
} else if (ext == "go") {
LiteApi::IEditor *editor = m_liteApp->fileManager()->openEditor(info.filePath());
if (editor) {
editor->setReadOnly(true);
QPlainTextEdit *ed = LiteApi::findExtensionObject<QPlainTextEdit*>(editor,"LiteApi.QPlainTextEdit");
#if QT_VERSION >= 0x050000
if (ed && QUrlQuery(url).hasQueryItem("s")) {
QStringList pos = QUrlQuery(url).queryItemValue("s").split(":");
#else
if (ed && url.hasQueryItem("s")) {
QStringList pos = url.queryItemValue("s").split(":");
#endif
if (pos.length() == 2) {
bool ok = false;
int begin = pos.at(0).toInt(&ok);
if (ok) {
QTextCursor cur = ed->textCursor();
cur.setPosition(begin);
ed->setTextCursor(cur);
ed->centerCursor();
}
}
}
}
} else if (ext == "pdf") {
QDesktopServices::openUrl(info.filePath());
} else {
QFile file(info.filePath());
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = file.readAll();
updateTextDoc(url,ba,info.fileName());
}
}
}
void LiteDoc::updateTextDoc(const QUrl &url, const QByteArray &ba, const QString &header)
{
m_lastUrl = url;
QTextCodec *codec = QTextCodec::codecForUtfText(ba,QTextCodec::codecForName("utf-8"));
#if QT_VERSION >= 0x050000
QString html = codec->toUnicode(ba).toHtmlEscaped();
#else
QString html = Qt::escape(codec->toUnicode(ba));
#endif
QString data = m_templateData;
data.replace("{header}",header);
data.replace("{nav}","");
data.replace("{content}",QString("<pre>%1</pre>").arg(html));
m_docBrowser->setUrlHtml(url,data);
}