| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <qwindow.h> |
| 30 | #include <qbackingstore.h> |
| 31 | #include <qpainter.h> |
| 32 | |
| 33 | #include <QtTest/QtTest> |
| 34 | |
| 35 | #include <QEvent> |
| 36 | |
| 37 | // For QSignalSpy slot connections. |
| 38 | Q_DECLARE_METATYPE(Qt::ScreenOrientation) |
| 39 | |
| 40 | class tst_QBackingStore : public QObject |
| 41 | { |
| 42 | Q_OBJECT |
| 43 | |
| 44 | private slots: |
| 45 | void flush(); |
| 46 | |
| 47 | void scrollRectInImage_data(); |
| 48 | void scrollRectInImage(); |
| 49 | }; |
| 50 | |
| 51 | void tst_QBackingStore::scrollRectInImage_data() |
| 52 | { |
| 53 | QTest::addColumn<QRect>(name: "rect" ); |
| 54 | QTest::addColumn<QPoint>(name: "offset" ); |
| 55 | |
| 56 | QTest::newRow(dataTag: "empty rect" ) << QRect() << QPoint(); |
| 57 | QTest::newRow(dataTag: "rect outside image" ) << QRect(-100, -100, 1000, 1000) << QPoint(10, 10); |
| 58 | QTest::newRow(dataTag: "scroll outside positive" ) << QRect(10, 10, 10, 10) << QPoint(1000, 1000); |
| 59 | QTest::newRow(dataTag: "scroll outside negative" ) << QRect(10, 10, 10, 10) << QPoint(-1000, -1000); |
| 60 | |
| 61 | QTest::newRow(dataTag: "sub-rect positive scroll" ) << QRect(100, 100, 50, 50) << QPoint(10, 10); |
| 62 | QTest::newRow(dataTag: "sub-rect negative scroll" ) << QRect(100, 100, 50, 50) << QPoint(-10, -10); |
| 63 | |
| 64 | QTest::newRow(dataTag: "positive vertical only" ) << QRect(100, 100, 50, 50) << QPoint(0, 10); |
| 65 | QTest::newRow(dataTag: "negative vertical only" ) << QRect(100, 100, 50, 50) << QPoint(0, -10); |
| 66 | QTest::newRow(dataTag: "positive horizontal only" ) << QRect(100, 100, 50, 50) << QPoint(10, 0); |
| 67 | QTest::newRow(dataTag: "negative horizontal only" ) << QRect(100, 100, 50, 50) << QPoint(-10, 0); |
| 68 | |
| 69 | QTest::newRow(dataTag: "whole rect positive" ) << QRect(0, 0, 250, 250) << QPoint(10, 10); |
| 70 | QTest::newRow(dataTag: "whole rect negative" ) << QRect(0, 0, 250, 250) << QPoint(-10, -10); |
| 71 | } |
| 72 | |
| 73 | QT_BEGIN_NAMESPACE |
| 74 | Q_GUI_EXPORT void qt_scrollRectInImage(QImage &, const QRect &, const QPoint &); |
| 75 | QT_END_NAMESPACE |
| 76 | |
| 77 | void tst_QBackingStore::scrollRectInImage() |
| 78 | { |
| 79 | QImage test(250, 250, QImage::Format_ARGB32_Premultiplied); |
| 80 | |
| 81 | QFETCH(QRect, rect); |
| 82 | QFETCH(QPoint, offset); |
| 83 | |
| 84 | qt_scrollRectInImage(test, rect, offset); |
| 85 | } |
| 86 | |
| 87 | class Window : public QWindow |
| 88 | { |
| 89 | public: |
| 90 | Window() |
| 91 | : backingStore(this) |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | void resizeEvent(QResizeEvent *) |
| 96 | { |
| 97 | backingStore.resize(size: size()); |
| 98 | } |
| 99 | |
| 100 | void exposeEvent(QExposeEvent *event) |
| 101 | { |
| 102 | QRect rect(QPoint(), size()); |
| 103 | |
| 104 | backingStore.beginPaint(rect); |
| 105 | |
| 106 | QPainter p(backingStore.paintDevice()); |
| 107 | p.fillRect(r: rect, c: Qt::white); |
| 108 | p.end(); |
| 109 | |
| 110 | backingStore.endPaint(); |
| 111 | |
| 112 | backingStore.flush(region: event->region().boundingRect()); |
| 113 | } |
| 114 | |
| 115 | private: |
| 116 | QBackingStore backingStore; |
| 117 | }; |
| 118 | |
| 119 | void tst_QBackingStore::flush() |
| 120 | { |
| 121 | Window window; |
| 122 | window.setGeometry(posx: 20, posy: 20, w: 200, h: 200); |
| 123 | window.showMaximized(); |
| 124 | |
| 125 | QTRY_VERIFY(window.isExposed()); |
| 126 | } |
| 127 | |
| 128 | #include <tst_qbackingstore.moc> |
| 129 | QTEST_MAIN(tst_QBackingStore); |
| 130 | |