source: trunk/examples/script/context2d/environment.h@ 266

Last change on this file since 266 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 4.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef ENVIRONMENT_H
43#define ENVIRONMENT_H
44
45#include <qobject.h>
46#include <qlist.h>
47#include <qhash.h>
48#include <QTimerEvent>
49#include <QMouseEvent>
50#include <QKeyEvent>
51#include <QScriptEngine>
52#include <QScriptable>
53class QContext2DCanvas;
54
55//! [0]
56class Environment : public QObject
57{
58 Q_OBJECT
59 Q_PROPERTY(QScriptValue document READ document)
60public:
61 Environment(QObject *parent = 0);
62 ~Environment();
63
64 QScriptValue document() const;
65
66 void addCanvas(QContext2DCanvas *canvas);
67 QContext2DCanvas *canvasByName(const QString &name) const;
68 QList<QContext2DCanvas*> canvases() const;
69
70 QScriptValue evaluate(const QString &code,
71 const QString &fileName = QString());
72
73 QScriptValue toWrapper(QObject *object);
74
75 void handleEvent(QContext2DCanvas *canvas, QMouseEvent *e);
76 void handleEvent(QContext2DCanvas *canvas, QKeyEvent *e);
77
78 void reset();
79//! [0]
80
81 QScriptEngine *engine() const;
82
83//! [1]
84public slots:
85 int setInterval(const QScriptValue &expression, int delay);
86 void clearInterval(int timerId);
87
88 int setTimeout(const QScriptValue &expression, int delay);
89 void clearTimeout(int timerId);
90//! [1]
91
92//! [2]
93signals:
94 void scriptError(const QScriptValue &error);
95//! [2]
96
97protected:
98 void timerEvent(QTimerEvent *event);
99
100private:
101 QScriptValue eventHandler(QContext2DCanvas *canvas,
102 const QString &type, QScriptValue *who);
103 QScriptValue newFakeDomEvent(const QString &type,
104 const QScriptValue &target);
105 void maybeEmitScriptError();
106
107 QScriptEngine *m_engine;
108 QScriptValue m_originalGlobalObject;
109 QScriptValue m_document;
110 QList<QContext2DCanvas*> m_canvases;
111 QHash<int, QScriptValue> m_intervalHash;
112 QHash<int, QScriptValue> m_timeoutHash;
113};
114
115//! [3]
116class Document : public QObject
117{
118 Q_OBJECT
119public:
120 Document(Environment *env);
121 ~Document();
122
123public slots:
124 QScriptValue getElementById(const QString &id) const;
125 QScriptValue getElementsByTagName(const QString &name) const;
126
127 // EventTarget
128 void addEventListener(const QString &type, const QScriptValue &listener,
129 bool useCapture);
130};
131//! [3]
132
133class CanvasGradientPrototype : public QObject, public QScriptable
134{
135 Q_OBJECT
136protected:
137 CanvasGradientPrototype(QObject *parent = 0);
138public:
139 static void setup(QScriptEngine *engine);
140
141public slots:
142 void addColorStop(qreal offset, const QString &color);
143};
144
145#endif
Note: See TracBrowser for help on using the repository browser.