summaryrefslogtreecommitdiffstats
path: root/tests/QtGui/bug_1124.py
blob: 3f2e772a42dc77bafc5807c3f1bb467df9a3afc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
''' unit test for BUG #1124 '''

import unittest
from PySide import QtGui, QtCore
import itertools

class TestBug1124(unittest.TestCase):
    def test_bug_1124(self):
        a = QtGui.QApplication([])
        allBlack = QtGui.QPixmap(10, 6)
        halfHalf = QtGui.QPixmap(2, 2)

        hhp = QtGui.QPainter(halfHalf)
        hhp.fillRect(QtCore.QRect(0, 0, 1, 2), QtGui.QColor.fromRgbF(0, 1, 0))
        hhp.fillRect(QtCore.QRect(1, 0, 1, 2), QtGui.QColor.fromRgbF(0, 0, 1))
        del hhp

        fragments = []
        mf = lambda *a, **kw: fragments.append(QtGui.QPainter.PixmapFragment.create(*a, **kw))

        mf(QtCore.QPointF(1, 1), QtCore.QRectF(0, 0, 2, 2))
        mf(QtCore.QPointF(3, 1), QtCore.QRectF(0, 0, 2, 2), rotation=90)
        mf(QtCore.QPointF(5, 1), QtCore.QRectF(0, 0, 2, 2), rotation=180)
        mf(QtCore.QPointF(7, 1), QtCore.QRectF(0, 0, 1, 1), scaleX=2, scaleY=2)
        mf(QtCore.QPointF(9, 1), QtCore.QRectF(1, 0, 1, 1), scaleX=2, scaleY=2)
        mf(QtCore.QPointF(1, 3), QtCore.QRectF(0, 0, 2, 2), opacity=0.5)
        mf(QtCore.QPointF(4, 4), QtCore.QRectF(0, 0, 2, 2), scaleX=2, scaleY=2)
        mf(QtCore.QPointF(8, 4), QtCore.QRectF(0, 0, 2, 2), scaleX=2, scaleY=2, rotation=90, opacity=0.5)

        allBlack.fill(QtGui.QColor("black"))

        abp = QtGui.QPainter(allBlack)
        abp.drawPixmapFragments(fragments, halfHalf)
        del abp

        image = allBlack.toImage()

        colors = {"G": QtGui.QColor.fromRgbF(0, 1, 0).rgb(),
                  "B": QtGui.QColor.fromRgbF(0, 0, 1).rgb(),
                  "g": QtGui.QColor.fromRgbF(0, 0.499, 0).rgb(),
                  "b": QtGui.QColor.fromRgbF(0, 0, 0.499).rgb(),
                  "0": QtGui.QColor("black").rgb()}

        lines = ["GBGGBGGGBB",
                 "GBBBBGGGBB",
                 "gbGGBBgggg",
                 "gbGGBBgggg",
                 "00GGBBbbbb",
                 "00GGBBbbbb"]

        for x, y in itertools.product(range(10), range(6)):
            c = colors[lines[y][x]]
            assert c == image.pixel(QtCore.QPoint(x, y))

        del a

if __name__ == "__main__":
    unittest.main()