20 m_pTurtle->setFixedSize(400, 400);
21 m_ptxt =
new QTextEdit;
23 QComboBox* pcbo =
new QComboBox;
26 lst <<
"Haus vom Nikolaus" <<
"Curly" <<
"Circle" <<
"Fantasy";
28 connect(pcbo, SIGNAL(activated(
int)), SLOT(slotApplyCode(
int)));
31 QJSValue scriptTurtle =
32 m_scriptEngine.newQObject(m_pTurtle);
33 m_scriptEngine.globalObject().setProperty(
"turtle", scriptTurtle);
35 QPushButton* pcmd =
new QPushButton(
"&Evaluate");
36 connect(pcmd, SIGNAL(clicked()), SLOT(slotEvaluate()));
38 QGridLayout* pgrdLayout =
new QGridLayout;
40 pgrdLayout->addWidget(pcbo, 0, 0);
41 pgrdLayout->addWidget(m_ptxt, 1, 0);
42 pgrdLayout->addWidget(m_pTurtle, 0, 1, 2, 1);
43 pgrdLayout->addWidget(pcmd, 2, 0, 1, 2);
44 setLayout(pgrdLayout);
48 void TurtleWorkArea::slotEvaluate()
51 m_scriptEngine.evaluate(m_ptxt->toPlainText());
52 if (result.isError()) {
53 QMessageBox::critical(0,
62 void TurtleWorkArea::slotApplyCode(
int n)
67 strCode =
"var k = 100;\n" 72 "turtle.forward(k);\n" 74 "turtle.forward(k);\n" 76 "turtle.forward(k);\n" 78 "turtle.forward(k);\n" 80 "turtle.forward(Math.sqrt(2)*k);\n" 82 "turtle.forward(k);\n" 84 "turtle.forward(Math.sqrt(2)*k);\n";
87 strCode =
"turtle.reset();\n" 88 "for (i = 0; i < 2; ++i) {\n" 89 " for(j = 0; j < 100; ++j) {\n" 90 " turtle.forward(15);\n" 91 " turtle.left(100 - j);\n" 93 " turtle.right(180);\n" 97 strCode =
"turtle.circle = function()\n" 99 " for (var i = 0; i < 360; ++i) {\n" 100 " this.forward(1);\n" 105 "turtle.circle();\n";
108 strCode =
"turtle.reset();\n" 109 "for (i = 0; i < 200; ++i) {\n" 110 " turtle.forward(i * 2);\n" 111 " turtle.left(91);\n" 114 m_ptxt->setPlainText(strCode);
TurtleWorkArea(QWidget *pwgt=0)