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); }
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); }
void TestTableLayout::testTableAlignment() { KoTableStyle *tableStyle = new KoTableStyle(); QVERIFY(tableStyle); tableStyle->setWidth(QTextLength(QTextLength::FixedLength, 50.0)); tableStyle->setAlignment(Qt::AlignRight); initTestSimple(1, 2, tableStyle); m_layout->layout(); // Right aligned. /* * Cell 0,0 rules: * x = 150 = 200 - 50 (shape width - table width) * y = 0 (no borders/margins/paddings) * width = 50 / 2 = 25 (table width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ QTextTableCell cell1 = m_table->cellAt(0, 0); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell1), QRectF(150, 0, 25, 14.4)); /* * Cell 0,1 rules: * x = 175 = (200 - 50) + 25 ((shape width - table width) + column width) * y = 0 (no borders/margins/paddings) * width = 50 / 2 = 25 (table width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ QTextTableCell cell2 = m_table->cellAt(0, 1); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell2), QRectF(175, 0, 25, 14.4)); // Centered. tableStyle->setAlignment(Qt::AlignHCenter); QTextTableFormat tableFormat = m_table->format(); tableStyle->applyStyle(tableFormat); m_table->setFormat(tableFormat); m_layout->layout(); /* * Cell 0,0 rules: * x = 75 = (200 - 50) / 2 ((shape width - table width) / 2) * y = 0 (no borders/margins/paddings) * width = 50 / 2 = 25 (table width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ cell1 = m_table->cellAt(0, 0); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell1), QRectF(75, 0, 25, 14.4)); /* * Cell 0,1 rules: * x = 100 = ((200 - 50) / 2) + 25 (((shape width - table width) / 2) + column width) * y = 0 (no borders/margins/paddings) * width = 50 / 2 = 25 (table width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ cell2 = m_table->cellAt(0, 1); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell2), QRectF(100, 0, 25, 14.4)); // Left aligned. tableStyle->setAlignment(Qt::AlignLeft); tableFormat = m_table->format(); tableStyle->applyStyle(tableFormat); m_table->setFormat(tableFormat); m_layout->layout(); /* * Cell 0,0 rules: * x = 0 (no borders/margins/paddings) * y = 0 (no borders/margins/paddings) * width = 50 / 2 = 25 (table width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ cell1 = m_table->cellAt(0, 0); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell1), QRectF(0, 0, 25, 14.4)); /* * Cell 0,1 rules: * x = 50 / 2 = 25 (table width / number of columns) * y = 0 (no borders/margins/paddings) * width = 50 / 2 = 25 (table width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ cell2 = m_table->cellAt(0, 1); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell2), QRectF(25, 0, 25, 14.4)); // Justify aligned. tableStyle->setAlignment(Qt::AlignJustify); // Will overrule the explicitly set table width. tableFormat = m_table->format(); tableStyle->applyStyle(tableFormat); m_table->setFormat(tableFormat); m_layout->layout(); /* * Cell 0,0 rules: * x = 0 (no borders/margins/paddings) * y = 0 (no borders/margins/paddings) * width = 200 / 2 = 100 (shape width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ cell1 = m_table->cellAt(0, 0); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell1), QRectF(0, 0, 100, 14.4)); /* * Cell 0,1 rules: * x = 200 / 2 = 100 (shape width / number of columns) * y = 0 (no borders/margins/paddings) * width = 200 / 2 = 100 (shape width / number of columns) * height = 1 * 14.4 = 14.4 (number of lines * line height) */ cell2 = m_table->cellAt(0, 1); QCOMPARE(m_textLayout->m_tableLayout.cellContentRect(cell2), QRectF(100, 0, 100, 14.4)); cleanupTest(); }