本文整理汇总了C++中QMimeData::html方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData::html方法的具体用法?C++ QMimeData::html怎么用?C++ QMimeData::html使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeData
的用法示例。
在下文中一共展示了QMimeData::html方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getHtml
/**
* Returns HTML markup for selected text. If no text is selected, returns
* HTML markup for all text.
*/
QString PsiTextView::getHtml() const
{
PsiTextView *ptv = (PsiTextView *)this;
QTextCursor cursor = ptv->textCursor();
int position = ptv->verticalScrollBar()->value();
bool unselectAll = false;
if (!hasSelectedText()) {
ptv->selectAll();
unselectAll = true;
}
QMimeData *mime = createMimeDataFromSelection();
QString result = mime->html();
delete mime;
// we need to restore original position if selectAll()
// was called, because setTextCursor() (which is necessary
// to clear selection) will move vertical scroll bar
if (unselectAll) {
cursor.clearSelection();
ptv->setTextCursor(cursor);
ptv->verticalScrollBar()->setValue(position);
}
return result;
}
示例2: setHtml
void tst_QMimeData::setHtml() const
{
QMimeData mimeData;
// initial state
QVERIFY(mimeData.hasHtml() == false);
// add html, verify
mimeData.setHtml("ninjas");
QVERIFY(mimeData.hasHtml());
QCOMPARE(mimeData.html(), QLatin1String("ninjas"));
// reset html
mimeData.setHtml("pirates");
QVERIFY(mimeData.hasHtml());
QCOMPARE(mimeData.html(), QLatin1String("pirates"));
}
示例3: data
void tst_QMimeData::data() const
{
QMimeData mimeData;
// set text, verify
mimeData.setData("text/plain", "pirates");
QCOMPARE(mimeData.data("text/plain"), QByteArray("pirates"));
QVERIFY(mimeData.data("text/html").length() == 0);
// html time
mimeData.setData("text/html", "ninjas");
QCOMPARE(mimeData.data("text/html"), QByteArray("ninjas"));
QCOMPARE(mimeData.data("text/plain"), QByteArray("pirates")); // make sure text not damaged
QCOMPARE(mimeData.data("text/html"), mimeData.html().toLatin1());
}
示例4:
QDebug operator<<(QDebug d, const QMimeData &m)
{
QDebug nospace = d.nospace();
const QStringList formats = m.formats();
nospace << "QMimeData: " << formats.join(QStringLiteral(", ")) << '\n'
<< " Text=" << m.hasText() << " HTML=" << m.hasHtml()
<< " Color=" << m.hasColor() << " Image=" << m.hasImage()
<< " URLs=" << m.hasUrls() << '\n';
if (m.hasText())
nospace << " Text: '" << m.text() << "'\n";
if (m.hasHtml())
nospace << " HTML: '" << m.html() << "'\n";
if (m.hasColor())
nospace << " Color: " << qvariant_cast<QColor>(m.colorData()) << '\n';
if (m.hasImage())
nospace << " Image: " << qvariant_cast<QImage>(m.imageData()).size() << '\n';
if (m.hasUrls())
nospace << " URLs: " << m.urls() << '\n';
return d;
}
示例5: getTextHelper
QString PsiTextView::getTextHelper(bool html) const
{
PsiTextView *ptv = (PsiTextView *)this;
QTextCursor cursor = ptv->textCursor();
int position = ptv->verticalScrollBar()->value();
bool unselectAll = false;
if (!textCursor().hasSelection()) {
#if QT_VERSION == 0x040701
// workaround for crash when deleting last character with backspace (qt-4.7.1)
// http://bugreports.qt.nokia.com/browse/QTBUG-15857
QTextCursor tempCursor = QTextCursor(ptv->document());
tempCursor.movePosition(QTextCursor::Start);
ptv->setTextCursor(tempCursor);
#endif
ptv->selectAll();
unselectAll = true;
}
QMimeData *mime = createMimeDataFromSelection();
QString result;
if (html)
result = mime->html();
else
result = mime->text();
delete mime;
// we need to restore original position if selectAll()
// was called, because setTextCursor() (which is necessary
// to clear selection) will move vertical scroll bar
if (unselectAll) {
cursor.clearSelection();
ptv->setTextCursor(cursor);
ptv->verticalScrollBar()->setValue(position);
}
return result;
}