本文整理汇总了C++中QTextLength函数的典型用法代码示例。如果您正苦于以下问题:C++ QTextLength函数的具体用法?C++ QTextLength怎么用?C++ QTextLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QTextLength函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: KoTableStyle
void TestTableCellStyle::testMargin()
{
QTextTableFormat format1;
format1.setProperty(QTextFormat::FrameLeftMargin, 4.0);
format1.setProperty(QTextFormat::FrameRightMargin, 8.0);
format1.setProperty(QTextFormat::FrameTopMargin, 9.0);
format1.setProperty(QTextFormat::FrameBottomMargin, 3.0);
KoTableStyle *style = new KoTableStyle(format1);
QVERIFY(style);
QCOMPARE(style->leftMargin(), 4.0);
QCOMPARE(style->rightMargin(), 8.0);
QCOMPARE(style->topMargin(), 9.0);
QCOMPARE(style->bottomMargin(), 3.0);
style->setLeftMargin(QTextLength(QTextLength::FixedLength, 14.0));
style->setRightMargin(QTextLength(QTextLength::FixedLength, 18.0));
style->setTopMargin(QTextLength(QTextLength::FixedLength, 19.0));
style->setBottomMargin(QTextLength(QTextLength::FixedLength, 13.0));
QTextTableFormat format2;
style->applyStyle(format2);
QCOMPARE(format2.doubleProperty(QTextFormat::FrameLeftMargin), 14.0);
QCOMPARE(format2.doubleProperty(QTextFormat::FrameRightMargin), 18.0);
QCOMPARE(format2.doubleProperty(QTextFormat::FrameTopMargin), 19.0);
QCOMPARE(format2.doubleProperty(QTextFormat::FrameBottomMargin), 13.0);
}
示例2: CalculateTraining
// 4) TRAINING
void ResWaReport::BuildTrainingSection(QTextCursor& cursor)
{
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n\n4) TRAINING & IN-SERVICES\n");
// VALUES
int numTrainings;
int numAttendingTrainings;
CalculateTraining(numTrainings, numAttendingTrainings);
// cursor.insertText("\t\t\t# of trainings: " + QString::number(numTrainings) + "\n");
// cursor.insertText("\t\t\t# attending trainings: " + QString::number(numAttendingTrainings) + "\n");
QTextTableFormat tableFormat;
tableFormat.setHeaderRowCount(1);
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 35);
constraints << QTextLength(QTextLength::PercentageLength, 35);
tableFormat.setColumnWidthConstraints(constraints);
QTextTable *table = cursor.insertTable(2, 2, tableFormat);
// HEADERS
TextToCell(table, 0, 0, "# of trainings (observers)", &_tableTextFormat);
TextToCell(table, 0, 1, "# attending trainings (all people in room)", &_tableTextFormat);
// VALUES
TextToCell(table, 1, 0, QString::number(numTrainings), &_tableCellBlue);
TextToCell(table, 1, 1, QString::number(numAttendingTrainings), &_tableCellBlue);
}
示例3: QCOMPARE
void TestStyles::testStyleInheritance()
{
KoParagraphStyle style1;
style1.setTopMargin(QTextLength(QTextLength::FixedLength, 10.0));
QCOMPARE(style1.topMargin(), 10.0);
KoParagraphStyle style2;
style2.setParentStyle(&style1);
QCOMPARE(style2.topMargin(), 10.0);
style2.setTopMargin(QTextLength(QTextLength::FixedLength, 20.0));
QCOMPARE(style2.topMargin(), 20.0);
QCOMPARE(style1.topMargin(), 10.0);
style1.setTopMargin(QTextLength(QTextLength::FixedLength, 15.0));
QCOMPARE(style2.topMargin(), 20.0);
QCOMPARE(style1.topMargin(), 15.0);
style2.setTopMargin(QTextLength(QTextLength::FixedLength, 15.0)); // the same, resetting the difference.
QCOMPARE(style2.topMargin(), 15.0);
QCOMPARE(style1.topMargin(), 15.0);
style1.setTopMargin(QTextLength(QTextLength::FixedLength, 12.0)); // parent, so both are affected
QCOMPARE(style2.topMargin(), 12.0);
QCOMPARE(style1.topMargin(), 12.0);
}
示例4: KoTableStyle
void TestTableLayout::testTableWidth()
{
KoTableStyle *tableStyle = new KoTableStyle();
QVERIFY(tableStyle);
initTestSimple(2, 2, tableStyle);
/*
* Fixed width.
*
* Rules:
* - Table should have 1 rect.
* - Width of this rect should be 60 pt (fixed).
*/
tableStyle->setWidth(QTextLength(QTextLength::FixedLength, 60.0));
QTextTableFormat tableFormat = m_table->format();
tableStyle->applyStyle(tableFormat);
m_table->setFormat(tableFormat);
m_layout->layout();
QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.size(), 1);
QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.at(0).rect.width(), 60.0);
/*
* Relative width:
*
* Rules:
* - Table should have 1 rect.
* - Width of this rect should be 80 pt (40% of shape which is 200).
*/
tableStyle->setWidth(QTextLength(QTextLength::PercentageLength, 40.0));
tableStyle->applyStyle(tableFormat);
m_table->setFormat(tableFormat);
m_layout->layout();
QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.size(), 1);
QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.at(0).rect.width(), 80.0);
}
示例5: testChangeParent
void TestStyles::testChangeParent()
{
KoParagraphStyle style1;
style1.setTopMargin(QTextLength(QTextLength::FixedLength, 10.0));
KoParagraphStyle style2;
style2.setTopMargin(QTextLength(QTextLength::FixedLength, 20.0));
style2.setParentStyle(&style1);
QCOMPARE(style1.topMargin(), 10.0);
QCOMPARE(style2.topMargin(), 20.0);
KoParagraphStyle style3;
style3.setParentStyle(&style1);
QCOMPARE(style1.topMargin(), 10.0);
QCOMPARE(style3.topMargin(), 10.0);
// test that separating will leave the child with exactly the same dataset
// as it had before the inheritance
style3.setParentStyle(0);
QCOMPARE(style1.topMargin(), 10.0);
QCOMPARE(style3.topMargin(), 0.0); // we hadn't explicitly set the margin on style3
// test adding it to another will not destroy any data
style3.setParentStyle(&style1);
QCOMPARE(style1.topMargin(), 10.0); // from style1
QCOMPARE(style2.topMargin(), 20.0); // from style2
QCOMPARE(style3.topMargin(), 10.0); // inherited from style1
// Check that style3 now starts following the parent since it does not have
// the property set
style3.setParentStyle(&style2);
QCOMPARE(style3.topMargin(), 20.0); // inherited from style2
}
示例6: QTextLength
void KDReports::Frame::build( ReportBuilder& builder ) const
{
// prepare the frame
QTextFrameFormat format;
if ( d->m_width ) {
if ( d->m_widthUnit == Millimeters ) {
format.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) );
} else {
format.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) );
}
}
if ( d->m_height ) {
if ( d->m_heightUnit == Millimeters ) {
format.setHeight( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_height ) ) );
} else {
format.setHeight( QTextLength( QTextLength::PercentageLength, d->m_height ) );
}
}
format.setPadding( mmToPixels( padding() ) );
format.setBorder( d->m_border );
// TODO borderBrush like in AbstractTableElement
format.setPosition( QTextFrameFormat::InFlow );
QTextCursor& textDocCursor = builder.cursor();
QTextFrame *frame = textDocCursor.insertFrame(format);
QTextCursor contentsCursor = frame->firstCursorPosition();
ReportBuilder contentsBuilder( builder.currentDocumentData(),
contentsCursor, builder.report() );
contentsBuilder.copyStateFrom( builder );
foreach( const KDReports::ElementData& ed, d->m_elements )
{
switch ( ed.m_type ) {
case KDReports::ElementData::Inline:
contentsBuilder.addInlineElement( *ed.m_element );
break;
case KDReports::ElementData::Block:
contentsBuilder.addBlockElement( *ed.m_element, ed.m_align );
break;
case KDReports::ElementData::Variable:
contentsBuilder.addVariable( ed.m_variableType );
break;
}
}
textDocCursor.movePosition( QTextCursor::End );
}
示例7: testColumnWidthFixed
void TestTableLayout::testColumnWidthFixed()
{
KoTableStyle *tableStyle = new KoTableStyle;
tableStyle->setWidth(QTextLength(QTextLength::FixedLength, 150.0));
setupTest("merged text", "top right text", "mid right text", "bottom left text", "bottom mid text", "bottom right text", tableStyle);
KoTableColumnAndRowStyleManager styleManager = KoTableColumnAndRowStyleManager::getManager(m_table);
KoTableColumnStyle column1style;
column1style.setColumnWidth(2.3);
styleManager.setColumnStyle(0, column1style);
KoTableColumnStyle column2style;
column2style.setColumnWidth(122.5);
styleManager.setColumnStyle(1, column2style);
KoTableColumnStyle column3style;
column3style.setColumnWidth(362.9);
styleManager.setColumnStyle(2, column3style);
m_layout->layout();
QVERIFY(qAbs(QTextCursor(m_table->parentFrame()).block().layout()->lineAt(0).width() - 200.0) < ROUNDING); // table should grow to 200
QVERIFY(qAbs(mergedCellBlock().layout()->lineAt(0).width() - 124.8) < ROUNDING);
QVERIFY(qAbs(topRightCellBlock().layout()->lineAt(0).width() - 362.9) < ROUNDING);
QVERIFY(qAbs(bottomLeftCellBlock().layout()->lineAt(0).width() - 2.3) < ROUNDING);
QVERIFY(qAbs(bottomMidCellBlock().layout()->lineAt(0).width() - 122.5) < ROUNDING);
QVERIFY(qAbs(bottomRightCellBlock().layout()->lineAt(0).width() - 362.9) < ROUNDING);
}
示例8: tableCell
// TEXTCELL
void PrinterVisitor::visitTextCellNodeBefore(TextCell *node)
{
if( !ignore_ || firstChild_ )
{
++currentTableRow_;
table_->insertRows( currentTableRow_, 1 );
// first column
QTextTableCell tableCell( table_->cellAt( currentTableRow_, 0 ) );
if( tableCell.isValid() )
{
if( !node->ChapterCounterHtml().isNull() )
{
QTextCursor cursor( tableCell.firstCursorPosition() );
cursor.insertFragment( QTextDocumentFragment::fromHtml(
node->ChapterCounterHtml() ));
}
}
// second column
tableCell = table_->cellAt( currentTableRow_, 1 );
if( tableCell.isValid() )
{
QTextCursor cursor( tableCell.firstCursorPosition() );
if( node->isViewExpression() )
{
//view expression table
QTextTableFormat tableFormatExpression;
tableFormatExpression.setBorder( 0 );
tableFormatExpression.setColumns( 1 );
tableFormatExpression.setCellPadding( 2 );
// tableFormatExpression.setBackground( QColor(235, 235, 220) ); // 180, 180, 180
tableFormatExpression.setBackground( QColor(235, 0, 0) ); // 180, 180, 180
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatExpression.setColumnWidthConstraints(constraints);
cursor.insertTable( 1, 1, tableFormatExpression );
// QMessageBox::information(0,"uu2", node->text());
QString html = node->textHtml();
cursor.insertFragment( QTextDocumentFragment::fromHtml( html ));
}
else
{
QString html = node->textHtml();
html.remove( "file:///" );
printEditor_->document()->setTextWidth(700);
cursor.insertFragment(QTextDocumentFragment::fromHtml( html ));
// QMessageBox::information(0, "uu3", node->text());
}
}
if( firstChild_ )
firstChild_ = false;
}
}
示例9: if
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
{
static const int totalColumns = 3;
if (node->height() == 1) {
QTextBlockFormat blockFormat;
QTextCharFormat charFormat;
charFormat.setFontPointSize(11);
charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat);
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)));
QTextTableFormat tableFormat;
tableFormat.setCellPadding(0);
tableFormat.setCellSpacing(0);
tableFormat.setBorder(0);
QTextTable *table = cursor->insertTable(node->size() + 1, 2, tableFormat);
for (int i = 0; i < node->size(); i++) {
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
QTextCharFormat cellCharFormat;
cellCharFormat.setFontPointSize(9);
QTextTableCell cell = table->cellAt(i, 0);
cell.setFormat(cellCharFormat);
QTextCursor cellCursor = cell.firstCursorPosition();
cellCursor.insertText(QString("%1 ").arg(card->getNumber()));
cell = table->cellAt(i, 1);
cell.setFormat(cellCharFormat);
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(card->getName());
}
} else if (node->height() == 2) {
QTextBlockFormat blockFormat;
QTextCharFormat charFormat;
charFormat.setFontPointSize(14);
charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat);
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)));
QTextTableFormat tableFormat;
tableFormat.setCellPadding(10);
tableFormat.setCellSpacing(0);
tableFormat.setBorder(0);
QVector<QTextLength> constraints;
for (int i = 0; i < totalColumns; i++)
constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns);
tableFormat.setColumnWidthConstraints(constraints);
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
for (int i = 0; i < node->size(); i++) {
QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
}
}
cursor->movePosition(QTextCursor::End);
}
示例10: CALLS
// 2) CALLS
void ResWaReport::BuildCallsSection(QTextCursor& cursor)
{
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n\n2) CALLS (Information, Intake, and Referal Calls)\n", _headerFormat);
cursor.insertBlock();
cursor.movePosition(QTextCursor::End);
QTextTableFormat tableFormat;
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 40);
constraints << QTextLength(QTextLength::PercentageLength, 40);
tableFormat.setColumnWidthConstraints(constraints);
QTextTable *table = cursor.insertTable(1, 2, tableFormat);
TextToCell(table, 0, 0, "Total calls", &_tableTextFormat);
TextToCell(table, 0, 1, QString::number(_totalCalls), &_tableCellBlue);
}
示例11: QTextTableFormat
QTextTable *ChatAreaWidget::getMsgTable()
{
if (tableFrmt == nullptr)
{
tableFrmt = new QTextTableFormat();
tableFrmt->setCellSpacing(2);
tableFrmt->setBorderStyle(QTextFrameFormat::BorderStyle_None);
tableFrmt->setColumnWidthConstraints({QTextLength(QTextLength::FixedLength,nameWidth),
QTextLength(QTextLength::FixedLength,2),
QTextLength(QTextLength::PercentageLength,100),
QTextLength(QTextLength::FixedLength,2),
QTextLength(QTextLength::VariableLength,0)});
}
QTextCursor tc = textCursor();
tc.movePosition(QTextCursor::End);
QTextTable *chatTextTable = tc.insertTable(1, 5, *tableFrmt);
return chatTextTable;
}
示例12: QImage
QImage KoStyleThumbnailer::thumbnail(KoParagraphStyle *style, QSize size, bool recreateThumbnail, KoStyleThumbnailerFlags flags)
{
if ((flags & UseStyleNameText) && (!style || style->name().isNull())) {
return QImage();
} else if ((! (flags & UseStyleNameText)) && d->thumbnailText.isEmpty()) {
return QImage();
}
if (!size.isValid() || size.isNull()) {
size = d->defaultSize;
}
QString imageKey = "p_" + QString::number(reinterpret_cast<unsigned long>(style)) + "_" + QString::number(size.width()) + "_" + QString::number(size.height());
if (!recreateThumbnail && d->thumbnailCache.object(imageKey)) {
return QImage(*(d->thumbnailCache.object(imageKey)));
}
QImage *im = new QImage(size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
im->fill(QColor(Qt::transparent).rgba());
KoParagraphStyle *clone = style->clone();
//TODO: make the following real options
//we ignore these properties when the thumbnail would not be sufficient to preview properly the whole paragraph with margins.
clone->setMargin(QTextLength(QTextLength::FixedLength, 0));
clone->setPadding(0);
//
QTextCursor cursor(d->thumbnailHelperDocument);
cursor.select(QTextCursor::Document);
cursor.setBlockFormat(QTextBlockFormat());
cursor.setBlockCharFormat(QTextCharFormat());
cursor.setCharFormat(QTextCharFormat());
QTextBlock block = cursor.block();
clone->applyStyle(block, true);
QTextCharFormat format;
// Default to black as text color, to match what KoTextLayoutArea::paint(...)
// does, setting solid black if no brush is set. Otherwise the UI text color
// would be used, which might be too bright with dark UI color schemes
format.setForeground(QColor(Qt::black));
clone->KoCharacterStyle::applyStyle(format);
if (flags & UseStyleNameText) {
cursor.insertText(clone->name(), format);
} else {
cursor.insertText(d->thumbnailText, format);
}
layoutThumbnail(size, im, flags);
d->thumbnailCache.insert(imageKey, im);
delete clone;
return QImage(*im);
}
示例13: QTextLength
void KDReports::AbstractTableElement::fillTableFormat( QTextTableFormat& tableFormat, QTextCursor& textDocCursor ) const
{
if ( d->m_width ) {
if ( d->m_unit == Millimeters ) {
tableFormat.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) );
} else {
tableFormat.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) );
}
}
tableFormat.setBorder( border() );
#if QT_VERSION >= 0x040300
tableFormat.setBorderBrush( borderBrush() );
tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid );
#endif
tableFormat.setCellPadding( mmToPixels( padding() ) );
tableFormat.setCellSpacing( -1 ); // HTML-like table borders look so old century
if ( d->m_fontSpecified ) {
QTextCharFormat charFormat = textDocCursor.charFormat();
charFormat.setFont( d->m_defaultFont );
textDocCursor.setCharFormat( charFormat );
}
}
示例14: ignore_
/*!
* \author Anders Fernström
* \date 2005-12-19
*
* \brief The class constructor
*
* 2006-03-03 AF, Updated function so cells are printed in tables,
* so chapter numbers can be added to the left of the text. This
* change remade large part of this function (and the rest of the
* class).
*/
PrinterVisitor::PrinterVisitor( QTextDocument* doc, QPrinter* printer )
: ignore_(false), firstChild_(true), closedCell_(0), currentTableRow_(0), printer_(printer)
{
printEditor_ = new QTextEdit();
printEditor_->setDocument( doc );
// set table format
QTextTableFormat tableFormat;
tableFormat.setBorder( 0 );
tableFormat.setColumns( 2 );
tableFormat.setCellPadding( 5 );
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::FixedLength, 50)
<< QTextLength(QTextLength::VariableLength, 620);
tableFormat.setColumnWidthConstraints(constraints);
// insert the table
QTextCursor cursor = printEditor_->textCursor();
table_ = cursor.insertTable(1, 2, tableFormat);
}
示例15: QTextLength
void CreateBlogMsg::addPostSplitter()
{
QTextBlockFormat f = ui.msgEdit->textCursor().blockFormat();
QTextBlockFormat f1 = f;
f.setProperty( TextFormat::IsHtmlTagSign, true );
f.setProperty( QTextFormat::BlockTrailingHorizontalRulerWidth,
QTextLength( QTextLength::PercentageLength, 80 ) );
if ( ui.msgEdit->textCursor().block().text().isEmpty() ) {
ui.msgEdit->textCursor().mergeBlockFormat( f );
} else {
ui.msgEdit->textCursor().insertBlock( f );
}
ui.msgEdit->textCursor().insertBlock( f1 );
}