1 /****************************************************************************
3 ** Copyright (C) 2008 Trolltech ASA. All rights reserved.
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
24 function tr(s) { return s; }
27 function CircleWidget(parent)
29 QWidget.call(this, parent);
31 this.floatBased = false;
32 this.antialiased = false;
35 this.setBackgroundRole(QPalette.Base);
36 this.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding);
39 CircleWidget.prototype = new QWidget();
41 CircleWidget.prototype.setFloatBased = function(floatBased)
43 this.floatBased = floatBased;
47 CircleWidget.prototype.setAntialiased = function(antialiased)
49 this.antialiased = antialiased;
53 CircleWidget.prototype.getMinimumSizeHint = function()
55 return new QSize(50, 50);
58 CircleWidget.prototype.getSizeHint = function()
60 return new QSize(180, 180);
63 CircleWidget.prototype.nextAnimationFrame = function()
69 CircleWidget.prototype.paintEvent = function(/* event */)
71 var painter = new QPainter();
73 painter.setRenderHint(QPainter.Antialiasing, this.antialiased);
74 painter.translate(this.width / 2, this.height / 2);
76 for (var diameter = 0; diameter < 256; diameter += 9) {
77 var delta = Math.abs((this.frameNo % 128) - diameter / 2);
78 var alpha = 255 - (delta * delta) / 4 - diameter;
80 painter.setPen(new QPen(new QColor(0, diameter / 2, 127, alpha), 3));
82 if (this.floatBased) {
83 painter.drawEllipse(new QRectF(-diameter / 2.0, -diameter / 2.0,
86 painter.drawEllipse(new QRect(-diameter / 2, -diameter / 2,
96 function Window(parent)
98 QWidget.call(this, parent);
100 var aliasedLabel = this.createLabel(tr("Aliased"));
101 var antialiasedLabel = this.createLabel(tr("Antialiased"));
102 var intLabel = this.createLabel(tr("Int"));
103 var floatLabel = this.createLabel(tr("Float"));
105 var layout = new QGridLayout();
106 layout.addWidget(aliasedLabel, 0, 1);
107 layout.addWidget(antialiasedLabel, 0, 2);
108 layout.addWidget(intLabel, 1, 0);
109 layout.addWidget(floatLabel, 2, 0);
111 var timer = new QTimer(this);
113 for (var i = 0; i < 2; ++i) {
114 for (var j = 0; j < 2; ++j) {
115 var cw = new CircleWidget();
116 cw.setAntialiased(j != 0);
117 cw.setFloatBased(i != 0);
119 timer.timeout.connect(
120 cw, cw.nextAnimationFrame);
122 layout.addWidget(cw, i + 1, j + 1);
126 this.setLayout(layout);
128 this.windowTitle = tr("Concentric Circles");
131 Window.prototype = new QWidget();
133 Window.prototype.createLabel = function(text)
135 var label = new QLabel(text);
136 label.alignment = Qt.AlignCenter;
138 label.setFrameStyle(QFrame.Box | QFrame.Sunken);
142 var win = new Window();
144 QCoreApplication.exec();