本文整理汇总了C++中QTextDocumentFragment::toHtml方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocumentFragment::toHtml方法的具体用法?C++ QTextDocumentFragment::toHtml怎么用?C++ QTextDocumentFragment::toHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocumentFragment
的用法示例。
在下文中一共展示了QTextDocumentFragment::toHtml方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMimeDataFromSelection
QMimeData* QTextBrowserEx::createMimeDataFromSelection() const
{
QMimeData *data = new QMimeData();
QTextCursor txtCursor = textCursor();
QTextDocumentFragment htmlFrag = txtCursor.selection();
data->setHtml(htmlFrag.toHtml());
data->setText(htmlFrag.toPlainText());
QString html = htmlFrag.toHtml();
QList<QPair<QString,QTextCharFormat>> frags;
getSelectTextFragments(frags);
QList<QByteArray> lstFrags;
for(int i = 0; i < frags.count(); i++)
{
const QPair<QString,QTextCharFormat> &frag = frags.at(i);
QString txt = frag.first;
QTextCharFormat txtfmt = frag.second;
QByteArray buf;
QDataStream ds(&buf, QIODevice::WriteOnly);
ds << txt << txtfmt;
lstFrags.push_back(buf);
}
QByteArray fragsBuffer;
QDataStream dataStream(&fragsBuffer, QIODevice::WriteOnly);
dataStream << lstFrags;
data->setData(KTextEditMime, fragsBuffer);
return data;
}
示例2: updateInstrument
void EditStaff::updateInstrument()
{
setInterval(instrument.transpose());
QList<StaffNameDoc>& nl = instrument.shortNames();
QTextDocumentFragment df = nl.isEmpty() ? QTextDocumentFragment() : nl[0].name;
shortName->setHtml(df.toHtml());
nl = instrument.longNames();
df = nl.isEmpty() ? QTextDocumentFragment() : nl[0].name;
longName->setHtml(df.toHtml());
if (partName->text() == instrumentName->text()) // Updates part name is no custom name has been set before
partName->setText(instrument.trackName());
instrumentName->setText(instrument.trackName());
_minPitchA = instrument.minPitchA();
_maxPitchA = instrument.maxPitchA();
_minPitchP = instrument.minPitchP();
_maxPitchP = instrument.maxPitchP();
minPitchA->setText(midiCodeToStr(_minPitchA));
maxPitchA->setText(midiCodeToStr(_maxPitchA));
minPitchP->setText(midiCodeToStr(_minPitchP));
maxPitchP->setText(midiCodeToStr(_maxPitchP));
int numStr = instrument.stringData() ? instrument.stringData()->strings() : 0;
numOfStrings->setText(QString::number(numStr));
}
示例3: copyPlainText
/*! Copy text without images, but textual representations of the smileys. */
void InputTextWidget::copyPlainText()
{
QTextDocumentFragment selection = textCursor().selection();
if (!selection.isEmpty()) {
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(Smileypack::desmilify(selection.toHtml()));
}
}
示例4: cutPlainText
/*! Cut text without images, but textual representations of the smileys. */
void InputTextWidget::cutPlainText()
{
QTextDocumentFragment selection = textCursor().selection();
if(!selection.isEmpty()) {
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(EmoticonMenu::desmile(selection.toHtml()));
textCursor().removeSelectedText();
}
}
示例5: prepareTextFragment
QTextDocumentFragment EditWidget::prepareTextFragment(const QTextDocumentFragment &AFragment)
{
QTextDocumentFragment fragment;
if (!AFragment.isEmpty())
{
QMimeData data;
data.setHtml(AFragment.toHtml());
QTextDocument doc;
QMap<int,IMessageEditContentsHandler *> handlers = FMessageWidgets->editContentsHandlers();
for (QMap<int,IMessageEditContentsHandler *>::const_iterator it = handlers.constBegin(); it!=handlers.constEnd(); ++it)
if (it.value()->messageEditContentsInsert(it.key(),this,&data,&doc))
break;
if (isRichTextEnabled())
fragment = QTextDocumentFragment::fromHtml(doc.toHtml());
else
fragment = QTextDocumentFragment::fromPlainText(doc.toPlainText());
}
return fragment;
}
示例6: setText
void Text::setText(const QTextDocumentFragment& f)
{
setHtml(f.toHtml());
}
示例7: eventFilter
bool ChatTextEdit::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = (QKeyEvent *) event;
if (keyEvent->key() == Qt::Key_Up)
{
// Key up
QTextCursor cursor = textCursor();
int pos = cursor.position();
bool sel = keyEvent->modifiers() == Qt::ShiftModifier;
cursor.movePosition(QTextCursor::Up, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));
if (pos == cursor.position())
cursor.movePosition(QTextCursor::Start, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));
setTextCursor(cursor);
return true;
}
else if (keyEvent->key() == Qt::Key_Down)
{
// Key down
QTextCursor cursor = textCursor();
int pos = cursor.position();
bool sel = keyEvent->modifiers() == Qt::ShiftModifier;
cursor.movePosition(QTextCursor::Down, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));
if (pos == cursor.position())
cursor.movePosition(QTextCursor::End, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));
setTextCursor(cursor);
return true;
}
else if (keyEvent->nativeScanCode() == 36)
{
// Return pressed
if (Client::enterIsSend && !(keyEvent->modifiers() & Qt::ShiftModifier))
{
isComposing = false;
emit returnPressed();
return true;
}
}
else if (keyEvent->nativeScanCode() == 54 &&
keyEvent->modifiers() == Qt::ControlModifier)
{
// Copy
QTextCursor cursor = textCursor();
if (cursor.hasSelection())
{
QTextDocumentFragment selection = cursor.selection();
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(Utilities::htmlToWAText(selection.toHtml()));
QMaemo5InformationBox::information(this,"Copied");
return true;
}
}
else if (keyEvent->nativeScanCode() == 55 &&
keyEvent->modifiers() == Qt::ControlModifier)
{
// Paste event
QTextCursor cursor = textCursor();
QClipboard *clipboard = QApplication::clipboard();
cursor.insertHtml(Utilities::WATextToHtml(clipboard->text(),32,false));
return true;
}
else if (!isComposing)
{
isComposing = true;
emit composing();
}
else
{
lastKeyPressed = QDateTime::currentMSecsSinceEpoch();
composingTimer.start(2000);
}
}
else if (event->type() == QEvent::InputMethod)
{
QInputMethodEvent *inputEvent = (QInputMethodEvent *) event;
//Utilities::logData("Commit String: '" + inputEvent->commitString() + "'");
if (inputEvent->commitString() == "\n" && Client::enterIsSend)
{
// Let's hide the keyboard if it was shown
QTimer::singleShot(0,this,SLOT(closeKB()));
isComposing = false;
emit returnPressed();
return true;
}
}
return QTextEdit::eventFilter(obj,event);
}