Debian Codegraph @

examples/script/context2d/window.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50
51 #include "window.h"cxx . . $ `<file>/examples/script/context2d/window.h`/
52 #include "environment.h"cxx . . $ `<file>/examples/script/context2d/environment.h`/
53 #include "context2d.h"cxx . . $ `<file>/examples/script/context2d/context2d.h`/
54 #include "qcontext2dcanvas.h"cxx . . $ `<file>/examples/script/context2d/qcontext2dcanvas.h`/
55 #include <QHBoxLayout>
56 #include <QListWidget>
57 #include <QDir>
58 #include <QMessageBox>
59
60 #ifndef QT_NO_SCRIPTTOOLS
61 #include <QAction>
62 #include <QApplication>
63 #include <QMainWindow>
64 #include <QPushButton>
65 #include <QVBoxLayout>
66 #include <QScriptEngineDebugger>cxx . . $ `<file>/include/QtScriptTools/QScriptEngineDebugger`/
67 #endif
68
69 static QStringcxx . . $ QString# scriptsDircxx . . $ scriptsDir(4365c3963150523e).()
70 {
71 if (QFilecxx . . $ QFile#::existscxx . . $ QFile#exists(e1defb592416720d).("./scripts"cxx . . $ QString#QString(85c52e162fed56f9).))
72 return "./scripts"cxx . . $ QString#QString(85c52e162fed56f9).;
73 return ":/scripts"cxx . . $ QString#QString(85c52e162fed56f9).;
74 }
75
76 //! [0]
77 Windowcxx . . $ Window#::Windowcxx . . $ Window#Window(108f35f7aa7f3cf9).(QWidgetcxx . . $ QWidget# *parent)
78 : QWidgetcxx . . $ QWidget#QWidget(872e7b0c281abd8d).(parent)
79 #ifndef QT_NO_SCRIPTTOOLS
80 , m_debuggercxx . . $ Window#m_debugger.(0), m_debugWindowcxx . . $ Window#m_debugWindow.(0)
81 #endif
82 {
83 m_envcxx . . $ Window#m_env. = new Environmentcxx . . $ Environment#Environment(749de1b6ae65bddd).(this);
84 QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(158df1d9a01a3410).(m_envcxx . . $ Window#m_env., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(scriptError(QScriptValue)),
85 this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(reportScriptError(QScriptValue)));
86
87 Context2Dcxx . . $ Context2D# *context = new Context2Dcxx . . $ Context2D#(this);
88 context->setSizecxx . . $ Context2D#setSize(3e454b8ccf442868).(150, 150);
89 m_canvascxx . . $ Window#m_canvas. = new QContext2DCanvascxx . . $ QContext2DCanvas#QContext2DCanvas(182a100ef27846f5).(context, m_envcxx . . $ Window#m_env., this);
90 m_canvascxx . . $ Window#m_canvas.->setFixedSizecxx . . $ QWidget#setFixedSize(1c5f201b4c2f0aba).(context->sizecxx . . $ Context2D#size(4b3b776e5ee2b367).());
91 m_canvascxx . . $ Window#m_canvas.->setObjectNamecxx . . $ QObject#setObjectName(3520e46b33348bf6).("tutorial"cxx . . $ QString#QString(85c52e162fed56f9).);
92 m_envcxx . . $ Window#m_env.->addCanvascxx . . $ Environment#addCanvas(d906aada46f7dd30).(m_canvascxx . . $ Window#m_canvas.);
93 //! [0]
94
95 #ifndef QT_NO_SCRIPTTOOLS
96 QVBoxLayoutcxx . . $ QVBoxLayout# *vbox = new QVBoxLayoutcxx . . $ QVBoxLayout#();
97 vbox->addWidgetcxx . . $ QBoxLayout#addWidget(d39963fa34d6acb).(m_canvascxx . . $ Window#m_canvas.);
98 m_debugButtoncxx . . $ Window#m_debugButton. = new QPushButtoncxx . . $ QPushButton#QPushButton(90d5708627041e22).(trcxx . . $ Window#tr(75d9f1c324b4579d).("Run in Debugger"));
99 connectcxx . . $ QObject#connect(158df1d9a01a3410).(m_debugButtoncxx . . $ Window#m_debugButton., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(clicked()), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(runInDebugger()));
100 vbox->addWidgetcxx . . $ QBoxLayout#addWidget(d39963fa34d6acb).(m_debugButtoncxx . . $ Window#m_debugButton.);
101 #endif
102
103 QHBoxLayoutcxx . . $ QHBoxLayout# *hbox = new QHBoxLayoutcxx . . $ QHBoxLayout#(this);
104 m_viewcxx . . $ Window#m_view. = new QListWidgetcxx . . $ QListWidget#QListWidget(108f35f7aa7f3cf9).(this);
105 m_viewcxx . . $ Window#m_view.->setEditTriggerscxx . . $ QAbstractItemView#setEditTriggers(cbe1d262190fb0b).(QAbstractItemViewcxx . . $ QFlags#QFlags(93d577a3e9528307).::NoEditTriggerscxx . . $ QAbstractItemView#NoEditTriggers.);
106 hbox->addWidgetcxx . . $ QBoxLayout#addWidget(d39963fa34d6acb).(m_viewcxx . . $ Window#m_view.);
107 #ifndef QT_NO_SCRIPTTOOLS
108 hbox->addLayoutcxx . . $ QBoxLayout#addLayout(ecefce2409e37794).(vbox);
109 #else
110 hbox->addWidget(m_canvas);
111 #endif
112
113 //! [1]
114 QDircxx . . $ QDir# dircxx . . $ QDir#QDir(3520e46b33348bf6).(scriptsDircxx . . $ scriptsDir(4365c3963150523e).());
115 QFileInfoListcxx . . $ QFileInfoList# entries = dir.entryInfoListcxx . . $ QDir#entryInfoList(c27c6007baf71ed0).(QStringListcxx . . $ QStringList#QStringList(ced63f7c635d850d).() <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "*.js"cxx . . $ QString#QString(85c52e162fed56f9).);
116 for (int i = 0; i < entries.sizecxx . . $ QList#size(ea6fe5115c70a13f).(); ++i)
117 m_viewcxx . . $ Window#m_view.->addItemcxx . . $ QListWidget#addItem(3520e46b33348bf6).(entries.atcxx . . $ QList#at(e2681f9bb6b2f357).(i).fileNamecxx . . $ QFileInfo#fileName(6ef7b6c27b00b43d).());
118 connectcxx . . $ QObject#connect(158df1d9a01a3410).(m_viewcxx . . $ Window#m_view., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
119 this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(selectScript(QListWidgetItem*)));
120 //! [1]
121
122 setWindowTitlecxx . . $ QWidget#setWindowTitle(3520e46b33348bf6).(trcxx . . $ Window#tr(75d9f1c324b4579d).("Context 2D"));
123 }
124
125 //! [2]
126 void Windowcxx . . $ Window#::selectScriptcxx . . $ Window#selectScript(13c1c8ad030616f4).(QListWidgetItemcxx . . $ QListWidgetItem# *item)
127 {
128 QStringcxx . . $ QString# fileName = item->textcxx . . $ QListWidgetItem#text(6ef7b6c27b00b43d).();
129 runScriptcxx . . $ Window#runScript(37c160c81b6367f7).(fileName, /*debug=*/false);
130 }
131 //! [2]
132
133 void Windowcxx . . $ Window#::reportScriptErrorcxx . . $ Window#reportScriptError(6b35c8bde2804237).(const QScriptValuecxx . . $ QScriptValue# &error)
134 {
135 QMessageBoxcxx . . $ QMessageBox#::warningcxx . . $ QMessageBox#warning(a9e3742e6f7b4147).(this, trcxx . . $ Window#tr(75d9f1c324b4579d).("Context 2D"), trcxx . . $ Window#tr(75d9f1c324b4579d).("Line %0: %1")
136 .argcxx . . $ QString#arg(64ab2ed17cc11715).(error.propertycxx . . $ QScriptValue#property(cc0ed881c2909ea3).("lineNumber"cxx . . $ QString#QString(85c52e162fed56f9).).toInt32cxx . . $ QScriptValue#toInt32(455f465bc33b4cdf).())
137 .argcxx . . $ QString#arg(bc823072288cbbb5).(error.toStringcxx . . $ QScriptValue#toString(6ef7b6c27b00b43d).()));
138 }
139
140 #ifndef QT_NO_SCRIPTTOOLS
141 //! [3]
142 void Windowcxx . . $ Window#::runInDebuggercxx . . $ Window#runInDebugger(49f6e7a06ebc5aa8).()
143 {
144 QListWidgetItemcxx . . $ QListWidgetItem# *item = m_viewcxx . . $ Window#m_view.->currentItemcxx . . $ QListWidget#currentItem(a843e491ce3ee2b1).();
145 if (item) {
146 QStringcxx . . $ QString# fileName = item->textcxx . . $ QListWidgetItem#text(6ef7b6c27b00b43d).();
147 runScriptcxx . . $ Window#runScript(37c160c81b6367f7).(fileName, /*debug=*/true);
148 }
149 }
150 //! [3]
151 #endif
152
153 //! [4]
154 void Windowcxx . . $ Window#::runScriptcxx . . $ Window#runScript(37c160c81b6367f7).(const QStringcxx . . $ QString# &fileName, bool debug)
155 {
156 QFilecxx . . $ QFile# filecxx . . $ QFile#QFile(3520e46b33348bf6).(scriptsDircxx . . $ scriptsDir(4365c3963150523e).() +cxx . . $ operator+(3d22f08efddf8107). "/" +cxx . . $ operator+(fab9b4f80031f353). fileName);
157 file.opencxx . . $ QFile#open(dca164408be960c8).(QIODevicecxx . . $ QFlags#QFlags(93d577a3e9528307).::ReadOnlycxx . . $ QIODevice#ReadOnly.);
158 QStringcxx . . $ QString# contents = filecxx . . $ QString#QString(45672f3c6961a244)..readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).();
159 file.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).();
160 m_envcxx . . $ Window#m_env.->resetcxx . . $ Environment#reset(49f6e7a06ebc5aa8).();
161
162 #ifndef QT_NO_SCRIPTTOOLS
163 if (debug) {
164 if (!m_debuggercxx . . $ Window#m_debugger.) {
165 m_debuggercxx . . $ Window#m_debugger. = new QScriptEngineDebuggercxx . . $ QScriptEngineDebugger#QScriptEngineDebugger(749de1b6ae65bddd).(this);
166 m_debugWindowcxx . . $ Window#m_debugWindow. = m_debuggercxx . . $ Window#m_debugger.->standardWindowcxx . . $ QScriptEngineDebugger#standardWindow(f196da0a5fa05375).();
167 m_debugWindowcxx . . $ Window#m_debugWindow.->setWindowModalitycxx . . $ QWidget#setWindowModality(3df99ed04a148acc).(Qtcxx . . $ Qt/::ApplicationModalcxx . . $ Qt/ApplicationModal.);
168 m_debugWindowcxx . . $ Window#m_debugWindow.->resizecxx . . $ QWidget#resize(3e454b8ccf442868).(1280, 704);
169 }
170 m_debuggercxx . . $ Window#m_debugger.->attachTocxx . . $ QScriptEngineDebugger#attachTo(d3e0164fcca5dac6).(m_envcxx . . $ Window#m_env.->enginecxx . . $ Environment#engine(18bf45d2c163ce9b).());
171 m_debuggercxx . . $ Window#m_debugger.->actioncxx . . $ QScriptEngineDebugger#action(d2acf4bc32070020).(QScriptEngineDebuggercxx . . $ QScriptEngineDebugger#::InterruptActioncxx . . $ QScriptEngineDebugger#InterruptAction.)->triggercxx . . $ QAction#trigger(49f6e7a06ebc5aa8).();
172 } else {
173 if (m_debuggercxx . . $ Window#m_debugger.)
174 m_debuggercxx . . $ Window#m_debugger.->detachcxx . . $ QScriptEngineDebugger#detach(49f6e7a06ebc5aa8).();
175 }
176 #else
177 Q_UNUSED(debug);
178 #endif
179
180 QScriptValuecxx . . $ QScriptValue# ret = m_envcxx . . $ Window#m_env.->evaluatecxx . . $ Environment#evaluate(b0ff8ca0890150ef).(contents, fileName);
181
182 #ifndef QT_NO_SCRIPTTOOLS
183 if (m_debugWindowcxx . . $ Window#m_debugWindow.)
184 m_debugWindowcxx . . $ Window#m_debugWindow.->hidecxx . . $ QWidget#hide(49f6e7a06ebc5aa8).();
185 #endif
186
187 if (ret.isErrorcxx . . $ QScriptValue#isError(50ce9a9e25b4a850).())
188 reportScriptErrorcxx . . $ Window#reportScriptError(6b35c8bde2804237).(ret);
189 }
190 //! [4]