summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@digia.com>2014-11-18 14:58:34 +0200
committerJoni Poikelin <joni.poikelin@digia.com>2015-03-02 06:07:18 +0000
commitfc3733cba4652f2b8930c66665103fcb20874735 (patch)
treebe15cb90c11b9ea21e46e8491ac0f16d3c4f59f3 /tests
parentf9c70128bbb45ea4b206920dda7c330afa74916a (diff)
Fix drawing of background for multipage QTextTable cells
Task-number: QTBUG-31330 Change-Id: I0103919ee2864b7cd8bed41e6d6fe4ac5b84142e Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qtexttable/tst_qtexttable.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
index 9cc092d8ab..e542e8f3f7 100644
--- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
+++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
@@ -44,6 +44,11 @@
#ifndef QT_NO_WIDGETS
#include <qtextedit.h>
#endif
+#ifndef QT_NO_PRINTER
+#include <QPagedPaintDevice>
+#include <QPainter>
+#include <QPaintEngine>
+#endif
typedef QList<int> IntList;
@@ -96,6 +101,9 @@ private slots:
void QTBUG11282_insertBeforeMergedEnding();
#endif
void QTBUG22011_insertBeforeRowSpan();
+#ifndef QT_NO_PRINTER
+ void QTBUG31330_renderBackground();
+#endif
private:
QTextTable *create2x2Table();
@@ -1024,5 +1032,112 @@ void tst_QTextTable::QTBUG22011_insertBeforeRowSpan()
QCOMPARE(table->columns(), 6);
}
+#ifndef QT_NO_PRINTER
+namespace {
+class QTBUG31330_PaintDevice : public QPagedPaintDevice
+{
+public:
+ class PaintEngine : public QPaintEngine
+ {
+ public:
+ QList<QRectF> rects;
+
+ PaintEngine()
+ : QPaintEngine(0)
+ {}
+ virtual Type type() const
+ {
+ return User;
+ }
+ virtual bool begin(QPaintDevice *)
+ {
+ return true;
+ }
+ virtual bool end()
+ {
+ return true;
+ }
+ virtual void updateState(const QPaintEngineState &)
+ {}
+ virtual void drawRects(const QRect *, int)
+ {}
+ virtual void drawRects(const QRectF *r, int)
+ {
+ if (painter()->brush() == QBrush(Qt::green))
+ {
+ rects.append(*r);
+ }
+ }
+ virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
+ {}
+ };
+
+ int pages;
+ QPaintEngine* engine;
+
+ QTBUG31330_PaintDevice(QPaintEngine* engine)
+ : pages(1), engine(engine)
+ {
+ QPageLayout layout = pageLayout();
+ layout.setUnits(QPageLayout::Point);
+ setPageLayout(layout);
+ }
+ virtual int metric(PaintDeviceMetric metric) const
+ {
+ if (PdmDevicePixelRatio == metric)
+ return 1;
+ if (PdmDpiY == metric)
+ return 96;
+ if (PdmDpiX == metric)
+ return 96;
+ if (PdmHeight == metric)
+ return 1000;
+ if (PdmWidth == metric)
+ return 700;
+ return 900;
+ }
+ virtual QPaintEngine *paintEngine() const
+ {
+ return engine;
+ }
+ bool newPage()
+ {
+ ++pages;
+ return true;
+ }
+};
+}
+
+void tst_QTextTable::QTBUG31330_renderBackground()
+{
+ QTextDocument doc;
+ QTextCursor cursor(&doc);
+ QTextTable* table = cursor.insertTable(4, 2);
+
+ QTextTableCell cell = table->cellAt(3, 0);
+
+ QTextCharFormat cellFormat = cell.format();
+ cellFormat.setBackground(QBrush(Qt::green));
+ cell.setFormat(cellFormat);
+
+ QTextCursor tc = cell.firstCursorPosition();
+ for (int i = 0; i < 60; ++i) {
+ tc.insertBlock();
+ }
+ QTBUG31330_PaintDevice::PaintEngine engine;
+ QTBUG31330_PaintDevice paintDevice(&engine);
+ paintDevice.setPageSize(QPagedPaintDevice::A4);
+ doc.print(&paintDevice);
+
+ QVERIFY(paintDevice.pages >= 2);
+ QCOMPARE(engine.rects.count(), paintDevice.pages);
+ for (int i = 0; i < engine.rects.count(); ++i) {
+ QRectF rect = engine.rects[i];
+ QVERIFY(rect.top() > 0);
+ QVERIFY(rect.bottom() < 1000);
+ }
+}
+#endif
+
QTEST_MAIN(tst_QTextTable)
#include "tst_qtexttable.moc"