void QDeclarativeTextEditPrivate::updateDefaultTextOption() { QTextOption opt = document->defaultTextOption(); int oldAlignment = opt.alignment(); opt.setAlignment((Qt::Alignment)(int)(hAlign | vAlign)); QTextOption::WrapMode oldWrapMode = opt.wrapMode(); if (wrap) opt.setWrapMode(QTextOption::WordWrap); else opt.setWrapMode(QTextOption::NoWrap); if (oldWrapMode == opt.wrapMode() && oldAlignment == opt.alignment()) return; document->setDefaultTextOption(opt); }
QSizeF QwtRichTextEngine::textSize( const QFont &font, int flags, const QString& text ) const { QwtRichTextDocument doc( text, flags, font ); QTextOption option = doc.defaultTextOption(); if ( option.wrapMode() != QTextOption::NoWrap ) { option.setWrapMode( QTextOption::NoWrap ); doc.setDefaultTextOption( option ); doc.adjustSize(); } return doc.size(); }
QSize QwtRichTextEngine::textSize(const QFont &font, int flags, const QString& text) const { QwtRichTextDocument doc(text, flags, font); #if QT_VERSION < 0x040000 doc.setWidth(QWIDGETSIZE_MAX); const int w = doc.widthUsed(); const int h = doc.height(); return QSize(w, h); #else // QT_VERSION >= 0x040000 #if QT_VERSION < 0x040200 /* Unfortunately offering the bounding rect calculation in the API of QTextDocument has been forgotten in Qt <= 4.1.x. It is planned to come with Qt 4.2.x. In the meantime we need a hack with a temporary QLabel, to reengineer the internal calculations. */ static int off = 0; static QLabel *label = NULL; if ( label == NULL ) { label = new QLabel; label->hide(); const char *s = "XXXXX"; label->setText(s); int w1 = label->sizeHint().width(); const QFontMetrics fm(label->font()); int w2 = fm.width(s); off = w1 - w2; } label->setFont(doc.defaultFont()); label->setText(text); int w = qwtMax(label->sizeHint().width() - off, 0); doc.setPageSize(QSize(w, QWIDGETSIZE_MAX)); int h = qRound(doc.documentLayout()->documentSize().height()); return QSize(w, h); #else // QT_VERSION >= 0x040200 #if QT_VERSION >= 0x040300 QTextOption option = doc.defaultTextOption(); if ( option.wrapMode() != QTextOption::NoWrap ) { option.setWrapMode(QTextOption::NoWrap); doc.setDefaultTextOption(option); doc.adjustSize(); } #endif return doc.size().toSize(); #endif #endif }
int TextOption::wrapMode ( lua_State * L ) //const { QTextOption* lhs = ValueInstaller2<QTextOption>::check( L, 1 ); Util::push( L, lhs->wrapMode() ); return 0; }