本文整理汇总了C++中QPlainTextEdit::centerCursor方法的典型用法代码示例。如果您正苦于以下问题:C++ QPlainTextEdit::centerCursor方法的具体用法?C++ QPlainTextEdit::centerCursor怎么用?C++ QPlainTextEdit::centerCursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPlainTextEdit
的用法示例。
在下文中一共展示了QPlainTextEdit::centerCursor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
}
}
示例2: 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);
}