本文整理汇总了C++中QMimeData::setHtml方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData::setHtml方法的具体用法?C++ QMimeData::setHtml怎么用?C++ QMimeData::setHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeData
的用法示例。
在下文中一共展示了QMimeData::setHtml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
NS_IMETHODIMP
nsClipboard::SetNativeClipboardData( nsITransferable *aTransferable,
QClipboard::Mode clipboardMode )
{
if (nullptr == aTransferable)
{
NS_WARNING("nsClipboard::SetNativeClipboardData(): no transferable!");
return NS_ERROR_FAILURE;
}
// get flavor list that includes all flavors that can be written (including
// ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanExport( getter_AddRefs(flavorList) );
if (NS_FAILED(rv))
{
NS_WARNING("nsClipboard::SetNativeClipboardData(): no FlavorsTransferable !");
return NS_ERROR_FAILURE;
}
QClipboard *cb = QGuiApplication::clipboard();
QMimeData *mimeData = new QMimeData;
uint32_t flavorCount = 0;
flavorList->Count(&flavorCount);
bool imageAdded = false;
for (uint32_t i = 0; i < flavorCount; ++i)
{
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i,getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
if (currentFlavor)
{
// flavorStr is the mime type
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
// Clip is the data which will be sent to the clipboard
nsCOMPtr<nsISupports> clip;
// len is the length of the data
uint32_t len;
// Unicode text?
if (!strcmp(flavorStr.get(), kUnicodeMime))
{
rv = aTransferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len);
nsCOMPtr<nsISupportsString> wideString;
wideString = do_QueryInterface(clip);
if (!wideString || NS_FAILED(rv))
continue;
nsAutoString utf16string;
wideString->GetData(utf16string);
QString str = QString::fromUtf16((const ushort*)utf16string.get());
// Add text to the mimeData
mimeData->setText(str);
}
// html?
else if (!strcmp(flavorStr.get(), kHTMLMime))
{
rv = aTransferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len);
nsCOMPtr<nsISupportsString> wideString;
wideString = do_QueryInterface(clip);
if (!wideString || NS_FAILED(rv))
continue;
nsAutoString utf16string;
wideString->GetData(utf16string);
QString str = QString::fromUtf16((const ushort*)utf16string.get());
// Add html to the mimeData
mimeData->setHtml(str);
}
// image?
else if (!imageAdded // image is added only once to the clipboard
&& (!strcmp(flavorStr.get(), kNativeImageMime)
|| !strcmp(flavorStr.get(), kPNGImageMime)
|| !strcmp(flavorStr.get(), kJPEGImageMime)
|| !strcmp(flavorStr.get(), kJPGImageMime)
|| !strcmp(flavorStr.get(), kGIFImageMime))
)
{
// Look through our transfer data for the image
static const char* const imageMimeTypes[] = {
kNativeImageMime, kPNGImageMime, kJPEGImageMime, kJPGImageMime, kGIFImageMime };
nsCOMPtr<nsISupportsInterfacePointer> ptrPrimitive;
for (uint32_t i = 0; !ptrPrimitive && i < ArrayLength(imageMimeTypes); i++)
{
aTransferable->GetTransferData(imageMimeTypes[i], getter_AddRefs(clip), &len);
ptrPrimitive = do_QueryInterface(clip);
}
if (!ptrPrimitive)
continue;
//.........这里部分代码省略.........