本文整理汇总了C++中QTextImageFormat::setHeight方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextImageFormat::setHeight方法的具体用法?C++ QTextImageFormat::setHeight怎么用?C++ QTextImageFormat::setHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextImageFormat
的用法示例。
在下文中一共展示了QTextImageFormat::setHeight方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertFrame
bool Converter::convertFrame(const QDomElement &element)
{
QDomElement child = element.firstChildElement();
QDomElement suchild = element.lastChildElement("title");
/// svg:title alt && title
while (!child.isNull())
{
if (child.tagName() == QLatin1String("image"))
{
const QString href = child.attribute("href");
const QString xname = element.attribute("name");
QString alttitle = QString("Name:%1 - Ref:%2").arg(xname).arg(href);
if (suchild.tagName() == QLatin1String("title"))
{
alttitle.append(QString(" - Title:%1").arg(suchild.text()));
}
QTextImageFormat format;
format.setToolTip(alttitle);
format.setWidth(4.0/3.0*StyleParser::convertUnit(element.attribute("width")));
format.setHeight(4.0/3.0*StyleParser::convertUnit(element.attribute("height")));
format.setName(href);
format.setBackground(Qt::white);
m_Cursor->insertImage(format);
}
child = child.nextSiblingElement();
}
return true;
}
示例2: on_actionImage_triggered
/**
* Inserts an valid image
* Copies the specific image in the program folder
*/
void MainWindow::on_actionImage_triggered()
{
QString scriboDir = QDir::home().absolutePath() + QDir::separator() + "scribo";
if ( !QDir(scriboDir + QDir::separator() + "img").exists() )
QDir().mkdir(scriboDir + QDir::separator() + "img");
QString filePath = QFileDialog::getOpenFileName(this, tr("Select an image"),
QDir::home().absolutePath(), "Bitmap Files (*.bmp)\n"
"JPEG (*.jpg *jpeg)\n"
"GIF (*.gif)\n"
"PNG (*.png)");
QStringList list = filePath.split( "/" );
QString imageName = list.value(list.length() - 1 );
QString imagePath = scriboDir + QDir::separator() + "img" + QDir::separator() + imageName;
QFile::copy(filePath, imagePath);
QUrl Uri ( QString ( "file://%1" ).arg ( imagePath ) );
QImage image = QImageReader ( imagePath ).read();
QTextDocument * textDocument = ui->textEdit_mainWindow_surface->document();
textDocument->addResource( QTextDocument::ImageResource, Uri, QVariant ( image ) );
cursor = ui->textEdit_mainWindow_surface->textCursor();
QTextImageFormat imageFormat;
imageFormat.setWidth( image.width() );
imageFormat.setHeight( image.height() );
imageFormat.setName( Uri.toString() );
cursor.insertImage(imageFormat);
}
示例3: switch
void KDReports::TextDocumentData::updatePercentSize( QTextImageFormat& imageFormat, const QSizeF& size )
{
// "W50" means W=50%. "H60" means H=60%.
QString prop = imageFormat.property( ResizableImageProperty ).toString();
const qreal imageRatio = imageFormat.height() / imageFormat.width();
const qreal pageWidth = size.width();
const qreal pageHeight = size.height();
const qreal pageRatio = pageWidth ? pageHeight / pageWidth : 0;
if ( prop[0] == QLatin1Char( 'T' ) ) {
//qDebug() << "updatePercentSize fitToPage" << imageRatio << pageRatio;
if ( imageRatio < pageRatio ) {
prop = QString::fromLatin1( "W100" );
} else {
prop = QString::fromLatin1( "H100" );
}
}
const qreal percent = prop.mid( 1 ).toDouble();
switch ( prop[0].toLatin1() ) {
case 'W':
{
const qreal newWidth = pageWidth * percent / 100.0;
imageFormat.setWidth( newWidth );
imageFormat.setHeight( newWidth * imageRatio );
// ### I needed to add this -2 here for 100%-width images to fit in
if ( percent == 100.0 )
imageFormat.setWidth( imageFormat.width() - 2 );
}
break;
case 'H':
imageFormat.setHeight( pageHeight * percent / 100.0 );
// ### I needed to add -6 here for 100%-height images to fit in (with Qt-4.4)
// and it became -9 with Qt-4.5, and even QtSw doesn't know why.
// Task number 241890
if ( percent == 100.0 )
imageFormat.setHeight( imageFormat.height() - 10 );
imageFormat.setWidth( imageRatio ? imageFormat.height() / imageRatio : 0 );
//qDebug() << "updatePercentSize" << size << "->" << imageFormat.width() << "x" << imageFormat.height();
break;
default:
qWarning( "Unhandled image format property type - internal error" );
}
}
示例4: insertEmoji
void InputField::insertEmoji(EmojiPtr emoji, QTextCursor c) {
QTextImageFormat imageFormat;
int32 ew = ESize + st::emojiPadding * cIntRetinaFactor() * 2, eh = _st->font->height * cIntRetinaFactor();
imageFormat.setWidth(ew / cIntRetinaFactor());
imageFormat.setHeight(eh / cIntRetinaFactor());
imageFormat.setName(qsl("emoji://e.") + QString::number(emojiKey(emoji), 16));
imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline);
static QString objectReplacement(QChar::ObjectReplacementCharacter);
c.insertText(objectReplacement, imageFormat);
}
示例5: addImageToTextEdit
void Utils::addImageToTextEdit(const QString& fileName, QTextEdit* textEdit)
{
if (!fileName.isNull()) {
QTextCursor c(textEdit->document());
c.movePosition(QTextCursor::End);
QImage image;
image.load(fileName);
QTextImageFormat imageFormat;
float maxImageWidth = textEdit->width() / 2.f;
if (image.width() < maxImageWidth) {
imageFormat.setWidth(image.width());
imageFormat.setHeight(image.height());
} else {
imageFormat.setWidth(maxImageWidth);
imageFormat.setHeight(maxImageWidth / image.width() * image.height());
}
imageFormat.setName(fileName);
c.insertImage(imageFormat);
}
}
示例6: insertEmoji
void FlatTextarea::insertEmoji(EmojiPtr emoji, QTextCursor c) {
c.removeSelectedText();
QPixmap img(App::emojiSingle(emoji, _st.font->height));
QString url = qsl("emoji://e.") + QString::number(emojiKey(emoji), 16);
document()->addResource(QTextDocument::ImageResource, QUrl(url), QVariant(img));
QTextImageFormat imageFormat;
imageFormat.setWidth(img.width() / cIntRetinaFactor());
imageFormat.setHeight(img.height() / cIntRetinaFactor());
imageFormat.setName(url);
imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline);
c.insertImage(imageFormat);
}
示例7: insertImage
void TextEdit::insertImage( const QString & path ) {
QPair< QString, QSize > imgKey( this->p_->addImageResource( path ) );
QTextCursor cursor( this->textCursor() );
QTextImageFormat format;
format.setName( imgKey.first );
format.setToolTip( imgKey.first );
format.setWidth( imgKey.second.width() );
format.setHeight( imgKey.second.height() );
cursor.insertImage( format );
this->setTextCursor( cursor );
}
示例8: render
QTextImageFormat EpsRenderer::render(QTextDocument *document, const QUrl &url)
{
QTextImageFormat epsCharFormat;
QSizeF s = renderToResource(document, url);
QUrl internal = url;
internal.setScheme(QLatin1String("internal"));
if(s.isValid())
{
epsCharFormat.setName(internal.url());
epsCharFormat.setWidth(s.width());
epsCharFormat.setHeight(s.height());
}
return epsCharFormat;
}
示例9: refresh
void TextEmojiWrapper::refresh()
{
if(!p->document)
return;
if(!p->emojis)
return;
QTextDocument *document = p->document->textDocument();
document->clear();
QTextCursor cursor(document);
cursor.setPosition(0);
QString &text = p->text;
const QHash<QString,QString> &emojis = p->emojis->emojis();
for( int i=0; i<text.size(); i++ )
{
QString image;
for( int j=1; j<5; j++ )
{
QString emoji = text.mid(i,j);
if( !emojis.contains(emoji) )
continue;
image = emojis.value(emoji);
i += emoji.size()-1;
break;
}
if(image.isEmpty())
{
cursor.insertText(QString(text[i]));
}
else
{
QTextImageFormat format;
format.setName(AsemanDevices::localFilesPrePath()+image);
format.setHeight(18);
format.setWidth(18);
cursor.insertImage(format);
}
}
}
示例10: convertFrame
bool Converter::convertFrame( const QDomElement &element )
{
QDomElement child = element.firstChildElement();
while ( !child.isNull() ) {
if ( child.tagName() == QLatin1String( "image" ) ) {
const QString href = child.attribute( QStringLiteral("href") );
QTextImageFormat format;
format.setWidth( StyleParser::convertUnit( element.attribute( QStringLiteral("width") ) ) );
format.setHeight( StyleParser::convertUnit( element.attribute( QStringLiteral("height") ) ) );
format.setName( href );
mCursor->insertImage( format );
}
child = child.nextSiblingElement();
}
return true;
}
示例11: stressTestPaint
void QTextPanel::stressTestPaint()
{
/////////pageClear(); /* remove all if exist text */
QTextDocument *playdoc = new QTextDocument();
QTextCursor c(playdoc);
c.setPosition(0,QTextCursor::MoveAnchor);
int loop = -1;
c.beginEditBlock();
QStringList colorNames = QColor::colorNames();
foreach (QString name, colorNames) {
loop++;
if (loop != 0) {
c.insertBlock();
}
////////qDebug() << "### name ->" << name;
QPixmap e = createColorMaps( name );
playdoc->addResource(QTextDocument::ImageResource,QUrl(name),e);
QTextImageFormat format;
format.setName( name );
format.setHeight ( e.height() );
format.setWidth ( e.width() );
format.setToolTip(name);
c.insertImage( format );
c.insertText(QString(QChar::LineSeparator)); /* br */
////////////QTextBlockFormat bbformat = c.blockFormat();
/////////bbformat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
////////c.setBlockFormat(bbformat);
for (int i = 0; i < 15; ++i) {
c.insertText(name+ " .");
}
c.endEditBlock();
c.atBlockEnd();
}
示例12: displayAttachments
void MailViewer::displayAttachments(const MessageHeader& msg)
{
#if 0 //code doesn't yet work
QTextDocument* textDocument = ui->message_content->document();
QImage image;
int i = 1;
foreach (const bts::bitchat::attachment& attachment, msg.attachments)
{
image.fromData(attachment.body.data());
QUrl url(QString("attachment_image_%1").arg(i++));
textDocument->addResource( QTextDocument::ImageResource, url, QVariant ( image ) );
QTextCursor cursor = ui->message_content->textCursor();
QTextImageFormat imageFormat;
imageFormat.setWidth( image.width() );
imageFormat.setHeight( image.height() );
imageFormat.setName( url.toString() );
cursor.insertImage(imageFormat);
}
#endif
}
示例13: execute
/*!
* \class TextCursorInsertImage
* \author Anders Fernström
* \date 2005-11-18
*
* \brief Command for inserting an image
*/
void TextCursorInsertImage::execute()
{
QTextCursor cursor( document()->getCursor()->currentCell()->textCursor() );
if( !cursor.isNull() )
{
QImage* image = new QImage( filepath_ );
if( !image->isNull() )
{
QString imagename = document()->addImage( image );
QTextCursor cursor( document()->getCursor()->currentCell()->textCursor() );
if( !cursor.isNull() )
{
QTextEdit *editor = document()->getCursor()->currentCell()->textEdit();
if( editor )
{
// save text settings and set them after image have been inserted
QTextCharFormat format = cursor.charFormat();
if( editor->toPlainText().isEmpty() )
format = *document()->getCursor()->currentCell()->style()->textCharFormat();
QTextImageFormat imageformat;
imageformat.merge( format );
imageformat.setHeight( height_ );
imageformat.setWidth( width_ );
imageformat.setName( imagename );
cursor.insertImage( imageformat );
}
}
}
else
{
string str = string("Could not open image: ") + filepath_.toStdString().c_str();
throw runtime_error( str.c_str() );
}
}
}
示例14: processSpecialNodes
QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes()
{
switch (currentNode->id) {
case Html_body:
if (currentNode->charFormat.background().style() != Qt::NoBrush) {
QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
fmt.setBackground(currentNode->charFormat.background());
doc->rootFrame()->setFrameFormat(fmt);
const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush);
}
break;
case Html_ol:
case Html_ul: {
QTextListFormat::Style style = currentNode->listStyle;
if (currentNode->id == Html_ul && !currentNode->hasOwnListStyle && currentNode->parent) {
const QTextHtmlParserNode *n = &at(currentNode->parent);
while (n) {
if (n->id == Html_ul) {
style = nextListStyle(currentNode->listStyle);
}
if (n->parent)
n = &at(n->parent);
else
n = 0;
}
}
QTextListFormat listFmt;
listFmt.setStyle(style);
++indent;
if (currentNode->hasCssListIndent)
listFmt.setIndent(currentNode->cssListIndent);
else
listFmt.setIndent(indent);
List l;
l.format = listFmt;
l.listNode = currentNodeIdx;
lists.append(l);
compressNextWhitespace = true;
// broken html: <ul>Text here<li>Foo
const QString simpl = currentNode->text.simplified();
if (simpl.isEmpty() || simpl.at(0).isSpace())
return ContinueWithNextNode;
break;
}
case Html_table: {
Table t = scanTable(currentNodeIdx);
tables.append(t);
hasBlock = false;
return ContinueWithNextNode;
}
case Html_tr:
return ContinueWithNextNode;
case Html_img: {
QTextImageFormat fmt;
fmt.setName(currentNode->imageName);
fmt.merge(currentNode->charFormat);
if (currentNode->imageWidth >= 0)
fmt.setWidth(currentNode->imageWidth);
if (currentNode->imageHeight >= 0)
fmt.setHeight(currentNode->imageHeight);
cursor.insertImage(fmt, QTextFrameFormat::Position(currentNode->cssFloat));
cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
cursor.mergeCharFormat(currentNode->charFormat);
cursor.movePosition(QTextCursor::Right);
hasBlock = false;
return ContinueWithNextNode;
}
case Html_hr: {
QTextBlockFormat blockFormat = currentNode->blockFormat;
blockFormat.setTopMargin(topMargin(currentNodeIdx));
blockFormat.setBottomMargin(bottomMargin(currentNodeIdx));
blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, currentNode->width);
if (hasBlock && importMode == ImportToDocument)
cursor.mergeBlockFormat(blockFormat);
else
appendBlock(blockFormat);
hasBlock = false;
return ContinueWithNextNode;
}
default: break;
}
return ContinueWithCurrentNode;
}