本文整理汇总了C++中QTextImageFormat::hasProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextImageFormat::hasProperty方法的具体用法?C++ QTextImageFormat::hasProperty怎么用?C++ QTextImageFormat::hasProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextImageFormat
的用法示例。
在下文中一共展示了QTextImageFormat::hasProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getImageSize
static QSize getImageSize(QTextDocument *doc, const QTextImageFormat &format)
{
QImage image;
const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth);
const int width = qRound(format.width());
const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight);
const int height = qRound(format.height());
QSize size(width, height);
if (!hasWidth || !hasHeight) {
image = getImage(doc, format);
if (!hasWidth)
size.setWidth(image.width());
if (!hasHeight)
size.setHeight(image.height());
}
qreal scale = 1.0;
QPaintDevice *pdev = doc->documentLayout()->paintDevice();
if (pdev) {
extern int qt_defaultDpi();
if (image.isNull())
image = getImage(doc, format);
if (!image.isNull())
scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
}
size *= scale;
return size;
}
示例2: writeInlineCharacter
void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const
{
writer.writeStartElement(drawNS, QString::fromLatin1("frame"));
if (m_strategy == 0) {
// don't do anything.
}
else if (fragment.charFormat().isImageFormat()) {
QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
writer.writeAttribute(drawNS, QString::fromLatin1("name"), imageFormat.name());
// vvv Copy pasted mostly from Qt =================
QImage image;
QString name = imageFormat.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl::fromEncoded(name.toUtf8());
const QVariant data = m_document->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Image) {
image = qvariant_cast<QImage>(data);
} else if (data.type() == QVariant::ByteArray) {
image.loadFromData(data.toByteArray());
}
if (image.isNull()) {
QString context;
if (QTextImageHandler::externalLoader)
image = QTextImageHandler::externalLoader(name, context);
if (image.isNull()) { // try direct loading
name = imageFormat.name(); // remove qrc:/ prefix again
image.load(name);
}
}
// ^^^ Copy pasted mostly from Qt =================
if (! image.isNull()) {
QBuffer imageBytes;
QImageWriter imageWriter(&imageBytes, "png");
imageWriter.write(image);
QString filename = m_strategy->createUniqueImageName();
m_strategy->addFile(filename, QString::fromLatin1("image/png"), imageBytes.data());
// get the width/height from the format.
qreal width = (imageFormat.hasProperty(QTextFormat::ImageWidth)) ? imageFormat.width() : image.width();
writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width));
qreal height = (imageFormat.hasProperty(QTextFormat::ImageHeight)) ? imageFormat.height() : image.height();
writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height));
writer.writeStartElement(drawNS, QString::fromLatin1("image"));
writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename);
writer.writeEndElement(); // image
}
}
writer.writeEndElement(); // frame
}
示例3: insertImage
void KTextCursor::insertImage( const QString &name, const QTextImageFormat &format )
{
QTextImageFormat imageForamt = format;
imageForamt.setName(name);
if(!imageForamt.hasProperty(KImageKey))
{
imageForamt.setProperty(KImageKey, name);
}
if(moviePool()->insertMovie(name, name))
{
Q_D(KTextCursor);
imageForamt.setProperty(KAnimationImage,true);
document()->addResource(QTextDocument::ImageResource, QUrl(name), moviePool()->currentImage(name));
}
else
{
QImage image(name);
if(!image.isNull())
{
document()->addResource(QTextDocument::ImageResource,QUrl(name), image);
}
}
__super::insertImage(imageForamt);
}
示例4: getPixmapSize
static QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format)
{
QPixmap pm;
const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth);
const int width = qRound(format.width());
const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight);
const int height = qRound(format.height());
QSize size(width, height);
if (!hasWidth || !hasHeight) {
pm = getPixmap(doc, format);
const int pmWidth = pm.width() / pm.devicePixelRatio();
const int pmHeight = pm.height() / pm.devicePixelRatio();
if (!hasWidth) {
if (!hasHeight)
size.setWidth(pmWidth);
else
size.setWidth(qRound(height * (pmWidth / (qreal) pmHeight)));
}
if (!hasHeight) {
if (!hasWidth)
size.setHeight(pmHeight);
else
size.setHeight(qRound(width * (pmHeight / (qreal) pmWidth)));
}
}
qreal scale = 1.0;
QPaintDevice *pdev = doc->documentLayout()->paintDevice();
if (pdev) {
if (pm.isNull())
pm = getPixmap(doc, format);
if (!pm.isNull())
scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
}
size *= scale;
return size;
}
示例5: decodePublicKey
void ContactListEdit::decodePublicKey(const QTextImageFormat& storage,
IMailProcessor::TRecipientPublicKey* key) const
{
assert(storage.hasProperty(QTextImageFormat::UserProperty));
QVariant v = storage.property(QTextImageFormat::UserProperty);
QByteArray pkArray = v.toByteArray();
fc::ecc::public_key_data s;
assert(pkArray.size() == s.size());
memcpy(s.begin(), pkArray.data(), s.size());
*key = IMailProcessor::TRecipientPublicKey(s);
assert(key->valid());
}
示例6: emitFragment
void HtmlExporter::emitFragment( const QTextFragment &fragment, const QTextBlockFormat &blockFormat )
{
// kDebug() << "html" << html;
const QTextCharFormat format = fragment.charFormat();
bool closeAnchor = false;
bool anchorIsOpen = false;
if ( format.isAnchor() ) {
// const QStringList names = format.anchorNames();
// if (!names.isEmpty()) {
// html += QLatin1String("<a name=\"");
// html += names.at(0);
// html += QLatin1String("\" ");
// anchorIsOpen = true;
// }
const QString href = format.anchorHref();
if ( !href.isEmpty() ) {
// if (!anchorIsOpen) {
// html += QLatin1String("<a ");
// anchorIsOpen = true;
// }
html += QLatin1String( "<a href=\"" );
html += href;
html += QLatin1String( "\"" );
anchorIsOpen = true;
// closeAnchor = true;
// html += QLatin1String("\"");
}
if ( format.hasProperty( BilboTextFormat::AnchorTitle ) ) {
const QString title = format.stringProperty( BilboTextFormat::AnchorTitle );
if ( !title.isEmpty() ) {
html += QLatin1String( " title=\"" );
html += title;
html += QLatin1String( "\"" );
}
}
if ( format.hasProperty( BilboTextFormat::AnchorTarget ) ) {
const QString target = format.stringProperty( BilboTextFormat::AnchorTarget );
if ( !target.isEmpty() ) {
html += QLatin1String( " target=\"" );
html += target;
html += QLatin1String( "\"" );
}
}
if ( anchorIsOpen ) {
html += QLatin1String( ">" );
closeAnchor = true;
}
}
QList<tag> tags = emitCharFormatStyle( format, blockFormat );
// if ( !format.anchorHref().isNull() ) {
// html += QLatin1String(">");
// closeAnchor = true;
// }
// kDebug() << "tags count" << tags.count() << endl;
for ( int i = 0; i < tags.count(); ++i ) {
switch ( tags.at( i ) ) {
case span:
break; //Jump
// case h1:
// html += QLatin1String( "<h1>" );
// break;
// case h2:
// html += QLatin1String( "<h2>" );
// break;
// case h3:
// html += QLatin1String( "<h3>" );
// break;
// case h4:
// html += QLatin1String( "<h4>" );
// break;
// case h5:
// html += QLatin1String( "<h5>" );
// break;
case strong:
html += QLatin1String( "<strong>" );
break;
case em:
html += QLatin1String( "<em>" );
break;
case s:
html += QLatin1String( "<s>" );
break;
case u:
if ( !closeAnchor )
html += QLatin1String( "<u>" );
break;
case code:
html += QLatin1String( "<code>" );
break;
case sub:
html += QLatin1String( "<sub>" );
break;
case sup:
html += QLatin1String( "<sup>" );
break;
}
}
//.........这里部分代码省略.........