0
|
1 |
#!/usr/bin/env python
|
|
2 |
#############################################################################
|
|
3 |
##
|
|
4 |
## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
5 |
## All rights reserved.
|
|
6 |
## Contact: Nokia Corporation (qt-info@nokia.com)
|
|
7 |
##
|
|
8 |
## This file is part of the test suite of the Qt Toolkit.
|
|
9 |
##
|
|
10 |
## $QT_BEGIN_LICENSE:LGPL$
|
|
11 |
## No Commercial Usage
|
|
12 |
## This file contains pre-release code and may not be distributed.
|
|
13 |
## You may use this file in accordance with the terms and conditions
|
|
14 |
## contained in the Technology Preview License Agreement accompanying
|
|
15 |
## this package.
|
|
16 |
##
|
|
17 |
## GNU Lesser General Public License Usage
|
|
18 |
## Alternatively, this file may be used under the terms of the GNU Lesser
|
|
19 |
## General Public License version 2.1 as published by the Free Software
|
|
20 |
## Foundation and appearing in the file LICENSE.LGPL included in the
|
|
21 |
## packaging of this file. Please review the following information to
|
|
22 |
## ensure the GNU Lesser General Public License version 2.1 requirements
|
|
23 |
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
24 |
##
|
|
25 |
## In addition, as a special exception, Nokia gives you certain additional
|
|
26 |
## rights. These rights are described in the Nokia Qt LGPL Exception
|
|
27 |
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
28 |
##
|
|
29 |
## If you have questions regarding the use of this file, please contact
|
|
30 |
## Nokia at qt-info@nokia.com.
|
|
31 |
##
|
|
32 |
##
|
|
33 |
##
|
|
34 |
##
|
|
35 |
##
|
|
36 |
##
|
|
37 |
##
|
|
38 |
##
|
|
39 |
## $QT_END_LICENSE$
|
|
40 |
##
|
|
41 |
#############################################################################
|
|
42 |
|
|
43 |
import sys
|
|
44 |
from PyQt4.QtCore import *
|
|
45 |
from PyQt4.QtGui import *
|
|
46 |
from PyQt4.QtSvg import QSvgGenerator
|
|
47 |
|
|
48 |
if __name__ == "__main__":
|
|
49 |
|
|
50 |
app = QApplication(sys.argv)
|
|
51 |
|
|
52 |
#device = QSvgGenerator()
|
|
53 |
#device.setFileName("qpen-dashpattern.svg")
|
|
54 |
#device.setSize(QSize(216, 144))
|
|
55 |
#device.setResolution(72)
|
|
56 |
|
|
57 |
device = QImage(192, 144, QImage.Format_ARGB32)
|
|
58 |
device.fill(qRgba(0, 0, 0, 0))
|
|
59 |
|
|
60 |
#resolution = device.resolution() # dpi
|
|
61 |
#dpp = resolution / 72.0
|
|
62 |
|
|
63 |
p = QPainter()
|
|
64 |
p.begin(device)
|
|
65 |
|
|
66 |
width = 8
|
|
67 |
|
|
68 |
pen = QPen()
|
|
69 |
pen.setWidth(width)
|
|
70 |
pen.setDashPattern([4, 2])
|
|
71 |
pen.setCapStyle(Qt.FlatCap)
|
|
72 |
|
|
73 |
faded_pen = QPen()
|
|
74 |
faded_pen.setWidth(width)
|
|
75 |
faded_pen.setDashPattern([4, 2])
|
|
76 |
faded_pen.setColor(QColor(160, 160, 160))
|
|
77 |
faded_pen.setCapStyle(Qt.FlatCap)
|
|
78 |
|
|
79 |
font = QFont("Monospace")
|
|
80 |
font.setPointSize(12)
|
|
81 |
p.setFont(font)
|
|
82 |
p.setBrush(QColor(160, 0, 0))
|
|
83 |
|
|
84 |
for x in range(-6, 9):
|
|
85 |
|
|
86 |
if x % 4 == 0:
|
|
87 |
length = 6
|
|
88 |
else:
|
|
89 |
length = 2
|
|
90 |
|
|
91 |
p.drawLine(64 + x * width, 4, 64 + x * width, 4 + length)
|
|
92 |
p.drawLine(64 + x * width, 136, 64 + x * width, 136 - length)
|
|
93 |
|
|
94 |
offsets = (0, 2, 3.5, 4, 5, 6)
|
|
95 |
for i in range(len(offsets)):
|
|
96 |
|
|
97 |
offset = offsets[i]
|
|
98 |
pen.setDashOffset(offset)
|
|
99 |
|
|
100 |
p.setPen(faded_pen)
|
|
101 |
p.drawLine(64 - offset * width, 20 + (i * 20), 64, 20 + (i * 20))
|
|
102 |
|
|
103 |
p.setPen(pen)
|
|
104 |
p.drawLine(64, 20 + (i * 20), 128, 20 + (i * 20))
|
|
105 |
|
|
106 |
p.drawText(150, 25 + (i * 20), str(offset))
|
|
107 |
|
|
108 |
p.end()
|
|
109 |
device.save("qpen-dashpattern.png")
|
|
110 |
sys.exit()
|