0
|
1 |
/****************************************************************************
|
|
2 |
**
|
18
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the examples of the Qt Toolkit.
|
|
8 |
**
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows:
|
0
|
11 |
**
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
14 |
** met:
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer.
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
19 |
** the documentation and/or other materials provided with the
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
20 |
** distribution.
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
23 |
** products derived from this software without specific prior written
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
24 |
** permission.
|
0
|
25 |
**
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
0
|
37 |
** $QT_END_LICENSE$
|
|
38 |
**
|
|
39 |
****************************************************************************/
|
|
40 |
|
|
41 |
#include <QApplication>
|
|
42 |
#include <QUiLoader>
|
|
43 |
#include <QtScript>
|
|
44 |
#include <QWidget>
|
|
45 |
#include <QFile>
|
|
46 |
#include <QMainWindow>
|
|
47 |
#include <QLineEdit>
|
|
48 |
|
|
49 |
#ifndef QT_NO_SCRIPTTOOLS
|
|
50 |
#include <QScriptEngineDebugger>
|
|
51 |
#endif
|
|
52 |
|
|
53 |
int main(int argc, char **argv)
|
|
54 |
{
|
|
55 |
Q_INIT_RESOURCE(calculator);
|
|
56 |
|
|
57 |
QApplication app(argc, argv);
|
|
58 |
//! [0a]
|
|
59 |
QScriptEngine engine;
|
|
60 |
//! [0a]
|
|
61 |
|
|
62 |
#if !defined(QT_NO_SCRIPTTOOLS)
|
|
63 |
QScriptEngineDebugger debugger;
|
|
64 |
debugger.attachTo(&engine);
|
|
65 |
QMainWindow *debugWindow = debugger.standardWindow();
|
|
66 |
debugWindow->resize(1024, 640);
|
|
67 |
#endif
|
|
68 |
|
|
69 |
//! [0b]
|
|
70 |
QString scriptFileName(":/calculator.js");
|
|
71 |
QFile scriptFile(scriptFileName);
|
|
72 |
scriptFile.open(QIODevice::ReadOnly);
|
|
73 |
engine.evaluate(scriptFile.readAll(), scriptFileName);
|
|
74 |
scriptFile.close();
|
|
75 |
//! [0b]
|
|
76 |
|
|
77 |
//! [1]
|
|
78 |
QUiLoader loader;
|
|
79 |
QFile uiFile(":/calculator.ui");
|
|
80 |
uiFile.open(QIODevice::ReadOnly);
|
|
81 |
QWidget *ui = loader.load(&uiFile);
|
|
82 |
uiFile.close();
|
|
83 |
//! [1]
|
|
84 |
|
|
85 |
//! [2]
|
|
86 |
QScriptValue ctor = engine.evaluate("Calculator");
|
|
87 |
QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
|
|
88 |
QScriptValue calc = ctor.construct(QScriptValueList() << scriptUi);
|
|
89 |
//! [2]
|
|
90 |
|
|
91 |
#if !defined(QT_NO_SCRIPTTOOLS)
|
|
92 |
QLineEdit *display = qFindChild<QLineEdit*>(ui, "display");
|
|
93 |
QObject::connect(display, SIGNAL(returnPressed()),
|
|
94 |
debugWindow, SLOT(show()));
|
|
95 |
#endif
|
|
96 |
//! [3]
|
|
97 |
ui->show();
|
|
98 |
return app.exec();
|
|
99 |
//! [3]
|
|
100 |
}
|