void tst_QScriptEngineDebugger::widget() { #if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600 QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll); #endif QScriptEngine engine; QScriptEngineDebugger debugger; debugger.attachTo(&engine); QList<QScriptEngineDebugger::DebuggerWidget> widgets; widgets << QScriptEngineDebugger::ConsoleWidget << QScriptEngineDebugger::StackWidget << QScriptEngineDebugger::ScriptsWidget << QScriptEngineDebugger::LocalsWidget << QScriptEngineDebugger::CodeWidget << QScriptEngineDebugger::CodeFinderWidget << QScriptEngineDebugger::BreakpointsWidget << QScriptEngineDebugger::DebugOutputWidget << QScriptEngineDebugger::ErrorLogWidget; QList<QWidget*> lst; for (int i = 0; i < widgets.size(); ++i) { QScriptEngineDebugger::DebuggerWidget dw = widgets.at(i); QWidget *wid = debugger.widget(dw); QVERIFY(wid != 0); QCOMPARE(wid, debugger.widget(dw)); QVERIFY(lst.indexOf(wid) == -1); lst.append(wid); QCOMPARE(static_cast<QWidget *>(wid->parent()), (QWidget*)0); } }
MapleManager::MapleManager(Server* server, QWidget *widget) : QObject(server), m_status(ConnectionStatus::WAITIGN), m_launch_status(LaunchStatus::LAUNCHIGN), m_socket(0), m_relaunch(true), r_mode(MapleManager::RESIZE_MODE::AUTO) { m_server = server; m_widget = new ManagerWidget(widget); m_widget->installEventFilter(this); connect(m_widget,SIGNAL(save()),this,SLOT(saveSettings())); connect(m_widget,SIGNAL(load()),this,SLOT(loadSettings())); connect(m_widget,SIGNAL(showDBG(bool)),this,SLOT(showDBG(bool))); connect(m_widget,SIGNAL(relaunch(bool)),this,SLOT(setRelaunch(bool))); connect(m_widget,SIGNAL(s_changeTabName(QString)),this,SLOT(changeTabName(QString))); m_engine = new QScriptEngine(this); QScriptEngineDebugger *dbg = new QScriptEngineDebugger(this); dbg->attachTo(m_engine); m_widget->regiterDebugger((QWidget*)dbg->standardWindow()); ScriptFunctions::registerFuncions(m_engine); m_engine->globalObject().setProperty(API::Path,qApp->applicationDirPath()); m_engine->globalObject().setProperty(API::GUI,m_engine->newQObject(m_widget)); m_engine->globalObject().setProperty(API::Socket,m_engine->newQObject(this)); }
bool execute() { TFilePath fp; QString fileName = "helloworld.qs"; QFile scriptFile(QString::fromStdWString(fp.getWideString())); if (!scriptFile.open(QIODevice::ReadOnly)) { DVGui::MsgBox(DVGui::WARNING, QObject::tr("File not found")); return false; } else { QTextStream stream(&scriptFile); QString contents = stream.readAll(); scriptFile.close(); QScriptEngine myEngine; QScriptEngineDebugger debugger; debugger.attachTo(&myEngine); QScriptValue fFoo = myEngine.newFunction(foo); QScriptValue fGetLevel = myEngine.newFunction(getLevel); myEngine.globalObject().setProperty("foo", fFoo); myEngine.globalObject().setProperty("getLevel", fGetLevel); debugger.action(QScriptEngineDebugger::InterruptAction)->trigger(); myEngine.evaluate(contents, fileName); } return true; }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(tetrix); //! [1] QApplication app(argc, argv); QScriptEngine engine; QScriptValue Qt = engine.newQMetaObject(QtMetaObject::get()); Qt.setProperty("App", engine.newQObject(&app)); engine.globalObject().setProperty("Qt", Qt); //! [1] #ifndef QT_NO_SCRIPTTOOLS QScriptEngineDebugger debugger; debugger.attachTo(&engine); QMainWindow *debugWindow = debugger.standardWindow(); debugWindow->resize(1024, 640); #endif //! [2] evaluateFile(engine, ":/tetrixpiece.js"); evaluateFile(engine, ":/tetrixboard.js"); evaluateFile(engine, ":/tetrixwindow.js"); //! [2] //! [3] TetrixUiLoader loader; QFile uiFile(":/tetrixwindow.ui"); uiFile.open(QIODevice::ReadOnly); QWidget *ui = loader.load(&uiFile); uiFile.close(); QScriptValue ctor = engine.evaluate("TetrixWindow"); QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership); QScriptValue tetrix = ctor.construct(QScriptValueList() << scriptUi); //! [3] QPushButton *debugButton = qFindChild<QPushButton*>(ui, "debugButton"); #ifndef QT_NO_SCRIPTTOOLS QObject::connect(debugButton, SIGNAL(clicked()), debugger.action(QScriptEngineDebugger::InterruptAction), SIGNAL(triggered())); QObject::connect(debugButton, SIGNAL(clicked()), debugWindow, SLOT(show())); #else debugButton->hide(); #endif //! [4] ui->resize(550, 370); ui->show(); qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); return app.exec(); //! [4] }
bool QtScriptEngine::runScript(const QString& script, const QString& name, RunMode mode) { MyQScriptEngine engine(this); map<ADM_dynMuxer*, Muxer*> muxers; map<ADM_videoEncoder6*, VideoEncoder*> videoEncoders; #ifdef QT_SCRIPTTOOLS QScriptEngineDebugger debugger; if (mode == IScriptEngine::Debug || mode == IScriptEngine::DebugOnError) { debugger.attachTo(&engine); debugger.standardWindow()->setWindowTitle(QT_TR_NOOP("Avidemux Script Debugger")); debugger.standardWindow()->setWindowModality(Qt::ApplicationModal); if (mode == IScriptEngine::Debug) { debugger.action(QScriptEngineDebugger::InterruptAction)->trigger(); } } #endif this->registerAudioEncoderPlugins(&engine); this->registerMuxerPlugins(&engine, &muxers); this->registerVideoEncoderPlugins(&engine, &videoEncoders); this->registerVideoFilterPlugins(&engine); this->registerDialogClasses(&engine); this->registerScriptClasses(&engine, &muxers, &videoEncoders); QScriptValue result = engine.evaluate(script, name); bool success = false; if (engine.hasUncaughtException()) { QString errorDetails = (QString("Unable to process script.\n\nLine number: %1\n").arg( engine.uncaughtExceptionLineNumber()) + result.toString()); this->callEventHandlers(IScriptEngine::Error, NULL, -1, (QString("Script error ") + errorDetails).toUtf8().constData()); success = false; } else { this->callEventHandlers(IScriptEngine::Information, NULL, -1, (QString("Result: ") + result.toString()).toUtf8().constData()); success = true; } return success; }
int main(int argc, char **argv) { Q_INIT_RESOURCE(calculator); QApplication app(argc, argv); //! [0a] QScriptEngine engine; //! [0a] #if !defined(QT_NO_SCRIPTTOOLS) QScriptEngineDebugger debugger; debugger.attachTo(&engine); QMainWindow *debugWindow = debugger.standardWindow(); debugWindow->resize(1024, 640); #endif //! [0b] QString scriptFileName(":/calculator.js"); QFile scriptFile(scriptFileName); scriptFile.open(QIODevice::ReadOnly); engine.evaluate(scriptFile.readAll(), scriptFileName); scriptFile.close(); //! [0b] //! [1] QUiLoader loader; QFile uiFile(":/calculator.ui"); uiFile.open(QIODevice::ReadOnly); QWidget *ui = loader.load(&uiFile); uiFile.close(); //! [1] //! [2] QScriptValue ctor = engine.evaluate("Calculator"); QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership); QScriptValue calc = ctor.construct(QScriptValueList() << scriptUi); //! [2] #if !defined(QT_NO_SCRIPTTOOLS) QLineEdit *display = qFindChild<QLineEdit*>(ui, "display"); QObject::connect(display, SIGNAL(returnPressed()), debugWindow, SLOT(show())); #endif //! [3] ui->show(); return app.exec(); //! [3] }
// Perhaps shpw entire example for getting debugger up with script int main(int argv, char **args) { QApplication app(argv, args); QString fileName("helloscript.qs"); QFile scriptFile(fileName); scriptFile.open(QIODevice::ReadOnly); QTextStream stream(&scriptFile); QString contents = stream.readAll(); scriptFile.close(); QScriptEngine *engine = new QScriptEngine(); QScriptEngineDebugger *debugger = new QScriptEngineDebugger(); debugger->attachTo(engine); // Set up configuration with only stack and code QWidget *widget = new QWidget; //![0] QWidget *codeWindow = debugger->widget(QScriptEngineDebugger::CodeWidget); QWidget *stackWidget = debugger->widget(QScriptEngineDebugger::StackWidget); QLayout *layout = new QHBoxLayout; layout->addWidget(codeWindow); layout->addWidget(stackWidget); //![0] //![1] QAction *continueAction = debugger->action(QScriptEngineDebugger::ContinueAction); QAction *stepOverAction = debugger->action(QScriptEngineDebugger::StepOverAction); QAction *stepIntoAction = debugger->action(QScriptEngineDebugger::StepIntoAction); QToolBar *toolBar = new QToolBar; toolBar->addAction(continueAction); //![1] toolBar->addAction(stepOverAction); toolBar->addAction(stepIntoAction); layout->addWidget(toolBar); continueAction->setIcon(QIcon("copy.png")); debugger->setAutoShowStandardWindow(false); widget->setLayout(layout); widget->show(); QPushButton button; QScriptValue scriptButton = engine->newQObject(&button); engine->globalObject().setProperty("button", scriptButton); //![2] debugger->action(QScriptEngineDebugger::InterruptAction)->trigger(); engine->evaluate(contents, fileName); //![2] return app.exec(); }
void tst_QScriptEngineDebugger::standardObjects() { #if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600 QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll); #endif QScriptEngine engine; QScriptEngineDebugger debugger; debugger.attachTo(&engine); QMainWindow *win = debugger.standardWindow(); QCOMPARE(static_cast<QWidget *>(win->parent()), (QWidget*)0); QMenu *menu = debugger.createStandardMenu(); QCOMPARE(static_cast<QWidget *>(menu->parent()), (QWidget*)0); QToolBar *toolBar = debugger.createStandardToolBar(); QCOMPARE(static_cast<QWidget *>(toolBar->parent()), (QWidget*)0); QMenu *menu2 = debugger.createStandardMenu(win); QCOMPARE(static_cast<QWidget *>(menu2->parent()), (QWidget*)win); QVERIFY(menu2 != menu); QToolBar *toolBar2 = debugger.createStandardToolBar(win); QCOMPARE(static_cast<QWidget *>(toolBar2->parent()), (QWidget*)win); QVERIFY(toolBar2 != toolBar); delete menu; delete toolBar; }
static PyObject *meth_QScriptEngineDebugger_autoShowStandardWindow(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QScriptEngineDebugger *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QScriptEngineDebugger, &sipCpp)) { bool sipRes; Py_BEGIN_ALLOW_THREADS sipRes = sipCpp->autoShowStandardWindow(); Py_END_ALLOW_THREADS return PyBool_FromLong(sipRes); } }
bool JSScript::execute(TWScriptAPI *tw) const { QFile scriptFile(m_Filename); if (!scriptFile.open(QIODevice::ReadOnly)) { // handle error return false; } QTextStream stream(&scriptFile); stream.setCodec(m_Codec); QString contents = stream.readAll(); scriptFile.close(); QScriptEngine engine; QScriptValue twObject = engine.newQObject(tw); engine.globalObject().setProperty("TW", twObject); QScriptValue val; #if QT_VERSION >= 0x040500 QSETTINGS_OBJECT(settings); if (settings.value("scriptDebugger", false).toBool()) { QScriptEngineDebugger debugger; debugger.attachTo(&engine); val = engine.evaluate(contents, m_Filename); } else { val = engine.evaluate(contents, m_Filename); } #else val = engine.evaluate(contents, m_Filename); #endif if (engine.hasUncaughtException()) { tw->SetResult(engine.uncaughtException().toString()); return false; } else { if (!val.isUndefined()) { tw->SetResult(convertValue(val)); } return true; } }
void tst_QScriptEngineDebugger::debuggerSignals() { #if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600 QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll); #endif QScriptEngine engine; QScriptEngineDebugger debugger; debugger.attachTo(&engine); debugger.setAutoShowStandardWindow(false); QSignalSpy evaluationSuspendedSpy(&debugger, SIGNAL(evaluationSuspended())); QSignalSpy evaluationResumedSpy(&debugger, SIGNAL(evaluationResumed())); QObject::connect(&debugger, SIGNAL(evaluationSuspended()), debugger.action(QScriptEngineDebugger::ContinueAction), SLOT(trigger())); engine.evaluate("123"); QCOMPARE(evaluationSuspendedSpy.count(), 0); QCOMPARE(evaluationResumedSpy.count(), 0); engine.evaluate("debugger"); QCoreApplication::processEvents(); QCOMPARE(evaluationSuspendedSpy.count(), 1); QCOMPARE(evaluationResumedSpy.count(), 1); }
static PyObject *meth_QScriptEngineDebugger_detach(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QScriptEngineDebugger *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QScriptEngineDebugger, &sipCpp)) { Py_BEGIN_ALLOW_THREADS sipCpp->detach(); Py_END_ALLOW_THREADS Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QScriptEngineDebugger, sipName_detach, doc_QScriptEngineDebugger_detach); return NULL; }
void SmsScriptsManager::init() { #if SMS_USE_DEBUGGER QScriptEngineDebugger *debugger = new QScriptEngineDebugger(this); debugger->attachTo(Engine); debugger->standardWindow()->show(); #endif QString scriptPath = Application::instance()->pathsProvider()->profilePath() + QLatin1String("plugins/data/sms/scripts/gateway.js"); if (QFile::exists(scriptPath)) loadScript(scriptPath); else { scriptPath = Application::instance()->pathsProvider()->dataPath() + QLatin1String("plugins/data/sms/scripts/gateway.js"); if (QFile::exists(scriptPath)) loadScript(scriptPath); // TODO: maybe we should return here if no gateway.js was found? } // scripts from profile path can replace the ones from data path if the file name is the same loadScripts(QDir(Application::instance()->pathsProvider()->profilePath() + QLatin1String("plugins/data/sms/scripts"))); loadScripts(QDir(Application::instance()->pathsProvider()->dataPath() + QLatin1String("plugins/data/sms/scripts"))); }
void tst_QScriptEngineDebugger::action() { #if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600 QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll); #endif QScriptEngine engine; QScriptEngineDebugger debugger; debugger.attachTo(&engine); QList<QScriptEngineDebugger::DebuggerAction> actions; actions << QScriptEngineDebugger::InterruptAction << QScriptEngineDebugger::ContinueAction << QScriptEngineDebugger::StepIntoAction << QScriptEngineDebugger::StepOverAction << QScriptEngineDebugger::StepOutAction << QScriptEngineDebugger::RunToCursorAction << QScriptEngineDebugger::RunToNewScriptAction << QScriptEngineDebugger::ToggleBreakpointAction << QScriptEngineDebugger::ClearDebugOutputAction << QScriptEngineDebugger::ClearErrorLogAction << QScriptEngineDebugger::ClearConsoleAction << QScriptEngineDebugger::FindInScriptAction << QScriptEngineDebugger::FindNextInScriptAction << QScriptEngineDebugger::FindPreviousInScriptAction << QScriptEngineDebugger::GoToLineAction; QList<QAction*> lst; for (int i = 0; i < actions.size(); ++i) { QScriptEngineDebugger::DebuggerAction da = actions.at(i); QAction *act = debugger.action(da); QVERIFY(act != 0); QCOMPARE(act, debugger.action(da)); QCOMPARE(act->parent(), (QObject*)&debugger); QVERIFY(lst.indexOf(act) == -1); lst.append(act); } }
static PyObject *meth_QScriptEngineDebugger_attachTo(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QScriptEngine * a0; QScriptEngineDebugger *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ8", &sipSelf, sipType_QScriptEngineDebugger, &sipCpp, sipType_QScriptEngine, &a0)) { Py_BEGIN_ALLOW_THREADS sipCpp->attachTo(a0); Py_END_ALLOW_THREADS Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QScriptEngineDebugger, sipName_attachTo, NULL); return NULL; }
void tst_QScriptEngineDebugger::attachAndDetach() { #if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600 QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll); #endif { QScriptEngineDebugger debugger; QCOMPARE(debugger.state(), QScriptEngineDebugger::SuspendedState); debugger.attachTo(0); QScriptEngine engine; debugger.attachTo(&engine); QCOMPARE(debugger.state(), QScriptEngineDebugger::SuspendedState); } { QScriptEngineDebugger debugger; QScriptEngine engine; QScriptValue oldPrint = engine.globalObject().property("print"); QVERIFY(oldPrint.isFunction()); QVERIFY(!engine.globalObject().property("__FILE__").isValid()); QVERIFY(!engine.globalObject().property("__LINE__").isValid()); debugger.attachTo(&engine); QVERIFY(engine.globalObject().property("__FILE__").isUndefined()); QVERIFY(engine.globalObject().property("__LINE__").isNumber()); QVERIFY(!engine.globalObject().property("print").strictlyEquals(oldPrint)); debugger.detach(); QVERIFY(engine.globalObject().property("print").strictlyEquals(oldPrint)); QVERIFY(!engine.globalObject().property("__FILE__").isValid()); QVERIFY(!engine.globalObject().property("__LINE__").isValid()); } { QScriptEngineDebugger debugger; QScriptEngine engine; debugger.attachTo(&engine); debugger.detach(); QScriptEngine engine2; debugger.attachTo(&engine2); } { QScriptEngineDebugger debugger; QScriptEngine engine; debugger.attachTo(&engine); debugger.detach(); QScriptEngine engine2; debugger.attachTo(&engine2); debugger.detach(); } #ifndef Q_OS_WINCE // demands too much memory for WinCE { QScriptEngineDebugger debugger; QScriptEngine engine; debugger.attachTo(&engine); QScriptEngineDebugger debugger2; debugger2.attachTo(&engine); } #endif { QScriptEngine *engine = new QScriptEngine; QScriptEngineDebugger debugger; debugger.attachTo(engine); delete engine; QScriptEngine engine2; debugger.attachTo(&engine2); } }
MainWindow::MainWindow(QWidget* parent) : CGAL::Qt::DemosMainWindow(parent) { ui = new Ui::MainWindow; ui->setupUi(this); // remove the Load Script menu entry, when the demo has not been compiled with QT_SCRIPT_LIB #if !defined(QT_SCRIPT_LIB) ui->menuBar->removeAction(ui->actionLoad_Script); #endif // Save some pointers from ui, for latter use. sceneView = ui->sceneView; viewer = ui->viewer; // do not save the state of the viewer (anoying) viewer->setStateFileName(QString::null); // setup scene scene = new Scene(this); viewer->setScene(scene); { QShortcut* shortcut = new QShortcut(QKeySequence(Qt::ALT+Qt::Key_Q), this); connect(shortcut, SIGNAL(activated()), this, SLOT(setFocusToQuickSearch())); } proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(scene); connect(ui->searchEdit, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString))); sceneView->setModel(proxyModel); // setup the sceneview: delegation and columns sizing... sceneView->setItemDelegate(new SceneDelegate(this)); sceneView->header()->setStretchLastSection(false); sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); sceneView->header()->setSectionResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents); sceneView->header()->setSectionResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed); sceneView->header()->setSectionResizeMode(Scene::ABColumn, QHeaderView::Fixed); sceneView->header()->setSectionResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); sceneView->resizeColumnToContents(Scene::ColorColumn); sceneView->resizeColumnToContents(Scene::RenderingModeColumn); sceneView->resizeColumnToContents(Scene::ABColumn); sceneView->resizeColumnToContents(Scene::VisibleColumn); // setup connections connect(scene, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex & )), this, SLOT(updateInfo())); connect(scene, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex & )), this, SLOT(updateDisplayInfo())); connect(scene, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex & )), viewer, SLOT(updateGL())); connect(scene, SIGNAL(updated()), viewer, SLOT(updateGL())); connect(scene, SIGNAL(updated()), this, SLOT(selectionChanged())); connect(scene, SIGNAL(itemAboutToBeDestroyed(Scene_item*)), this, SLOT(removeManipulatedFrame(Scene_item*))); connect(scene, SIGNAL(updated_bbox()), this, SLOT(updateViewerBBox())); connect(scene, SIGNAL(selectionChanged(int)), this, SLOT(selectSceneItem(int))); connect(sceneView->selectionModel(), SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & ) ), this, SLOT(updateInfo())); connect(sceneView->selectionModel(), SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & ) ), this, SLOT(updateDisplayInfo())); connect(sceneView->selectionModel(), SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & ) ), this, SLOT(selectionChanged())); sceneView->setContextMenuPolicy(Qt::CustomContextMenu); connect(sceneView, SIGNAL(customContextMenuRequested(const QPoint & )), this, SLOT(showSceneContextMenu(const QPoint &))); connect(viewer, SIGNAL(selected(int)), this, SLOT(selectSceneItem(int))); connect(viewer, SIGNAL(selectedPoint(double, double, double)), this, SLOT(showSelectedPoint(double, double, double))); connect(viewer, SIGNAL(selectionRay(double, double, double, double, double, double)), scene, SIGNAL(selectionRay(double, double, double, double, double, double))); connect(viewer, SIGNAL(requestContextMenu(QPoint)), this, SLOT(contextMenuRequested(QPoint))); // The contextMenuPolicy of infoLabel is now the default one, so that one // can easily copy-paste its text. // connect(ui->infoLabel, SIGNAL(customContextMenuRequested(const QPoint & )), // this, SLOT(showSceneContextMenu(const QPoint &))); connect(ui->actionRecenterScene, SIGNAL(triggered()), viewer, SLOT(update())); connect(ui->actionAntiAliasing, SIGNAL(toggled(bool)), viewer, SLOT(setAntiAliasing(bool))); connect(ui->actionDraw_two_sides, SIGNAL(toggled(bool)), viewer, SLOT(setTwoSides(bool))); // add the "About CGAL..." and "About demo..." entries this->addAboutCGAL(); this->addAboutDemo(":/cgal/Polyhedron_3/about.html"); // Connect the button "addButton" with actionLoad ui->addButton->setDefaultAction(ui->actionLoad); // Same with "removeButton" and "duplicateButton" ui->removeButton->setDefaultAction(ui->actionErase); ui->duplicateButton->setDefaultAction(ui->actionDuplicate); // Connect actionQuit (Ctrl+Q) and qApp->quit() connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(quit())); // Connect "Select all items" connect(ui->actionSelect_all_items, SIGNAL(triggered()), this, SLOT(selectAll())); // Recent files menu this->addRecentFiles(ui->menuFile, ui->actionQuit); connect(this, SIGNAL(openRecentFile(QString)), this, SLOT(open(QString))); // Reset the "Operation menu" clearMenu(ui->menuOperations); #ifdef QT_SCRIPT_LIB std::cerr << "Enable scripts.\n"; script_engine = new QScriptEngine(this); qScriptRegisterMetaType<Scene_item*>(script_engine, myScene_itemToScriptValue, myScene_itemFromScriptValue); # ifdef QT_SCRIPTTOOLS_LIB QScriptEngineDebugger* debugger = new QScriptEngineDebugger(this); debugger->setObjectName("qt script debugger"); QAction* debuggerMenuAction = menuBar()->addMenu(debugger->createStandardMenu()); debuggerMenuAction->setText(tr("Qt Script &debug")); for(unsigned int i = 0; i < 9; ++i) { QDockWidget* dock = new QDockWidget(debug_widgets_names[i], this); dock->setObjectName(debug_widgets_names[i]); dock->setWidget(debugger->widget(debug_widgets[i])); this->addDockWidget(Qt::BottomDockWidgetArea, dock); dock->hide(); } debugger->setAutoShowStandardWindow(false); debugger->attachTo(script_engine); # endif // QT_SCRIPTTOOLS_LIB QScriptValue fun = script_engine->newFunction(myPrintFunction); script_engine->globalObject().setProperty("print", fun); // evaluate_script("print('hello', 'world', 'from QtScript!')"); QScriptValue mainWindowObjectValue = script_engine->newQObject(this); script_engine->globalObject().setProperty("main_window", mainWindowObjectValue); QScriptValue sceneObjectValue = script_engine->newQObject(scene); mainWindowObjectValue.setProperty("scene", sceneObjectValue); script_engine->globalObject().setProperty("scene", sceneObjectValue); QScriptValue viewerObjectValue = script_engine->newQObject(viewer); mainWindowObjectValue.setProperty("viewer", viewerObjectValue); script_engine->globalObject().setProperty("viewer", viewerObjectValue); QScriptValue cameraObjectValue = script_engine->newQObject(viewer->camera()); viewerObjectValue.setProperty("camera", cameraObjectValue); script_engine->globalObject().setProperty("camera", cameraObjectValue); evaluate_script("var plugins = new Array();"); # ifdef QT_SCRIPTTOOLS_LIB QScriptValue debuggerObjectValue = script_engine->newQObject(debugger); script_engine->globalObject().setProperty("debugger", debuggerObjectValue); # endif #endif readSettings(); // Among other things, the column widths are stored. // Load plugins, and re-enable actions that need it. loadPlugins(); // Setup the submenu of the View menu that can toggle the dockwidgets Q_FOREACH(QDockWidget* widget, findChildren<QDockWidget*>()) { ui->menuDockWindows->addAction(widget->toggleViewAction()); }
void setup::setCurrentIndex(XTreeWidgetItem* item) { QString uiName = item->data(0, Xt::RawRole).toString(); QString label = "<span style=\" font-size:14pt; font-weight:600;\">%1</span></p></body></html>"; if (_itemMap.contains(uiName) && _itemMap.value(uiName).index >= 0) { _stack->setCurrentIndex(_itemMap.value(uiName).index); _stackLit->setText(label.arg(item->text(0))); return; } else if (_itemMap.contains(uiName) && !item->isDisabled()) { // First look for a class... QWidget *w = xtGetScreen(uiName, this); if (w) _itemMap[uiName].implementation = w; else { // No class, so look for an extension XSqlQuery screenq; screenq.prepare("SELECT * " " FROM uiform " " WHERE((uiform_name=:uiform_name)" " AND (uiform_enabled))" " ORDER BY uiform_order DESC" " LIMIT 1;"); screenq.bindValue(":uiform_name", uiName); screenq.exec(); if (screenq.first()) { QUiLoader loader; QByteArray ba = screenq.value("uiform_source").toByteArray(); QBuffer uiFile(&ba); if (!uiFile.open(QIODevice::ReadOnly)) QMessageBox::critical(0, tr("Could not load UI"), tr("<p>There was an error loading the UI Form " "from the database.")); w = loader.load(&uiFile); w->setObjectName(uiName); uiFile.close(); // Load scripts if applicable XSqlQuery scriptq; scriptq.prepare("SELECT script_source, script_order" " FROM script" " WHERE((script_name=:script_name)" " AND (script_enabled))" " ORDER BY script_order;"); scriptq.bindValue(":script_name", uiName); scriptq.exec(); QScriptEngine* engine = new QScriptEngine(); if (_preferences->boolean("EnableScriptDebug")) { QScriptEngineDebugger* debugger = new QScriptEngineDebugger(this); debugger->attachTo(engine); } omfgThis->loadScriptGlobals(engine); QScriptValue mywindow = engine->newQObject(w); engine->globalObject().setProperty("mywindow", mywindow); while(scriptq.next()) { QString script = scriptHandleIncludes(scriptq.value("script_source").toString()); QScriptValue result = engine->evaluate(script, uiName); if (engine->hasUncaughtException()) { int line = engine->uncaughtExceptionLineNumber(); qDebug() << "uncaught exception at line" << line << ":" << result.toString(); } } _itemMap[uiName].implementation = engine; } } if (w) { // Hide buttons out of context here QWidget* close = w->findChild<QWidget*>("_close"); if (close) close->hide(); QWidget* buttons = w->findChild<QDialogButtonBox*>(); if (buttons) buttons->hide(); //Set mode if applicable int mode = _itemMap.value(uiName).mode; if (mode && w->inherits("XDialog")) { XWidget* x = dynamic_cast<XWidget*>(w); ParameterList params; if (mode == cEdit) params.append("mode", "edit"); else if (mode == cView) params.append("mode", "view"); if (x) x->set(params); } int idx = _stack->count(); _itemMap[uiName].index = idx; _stack->addWidget(w); _stack->setCurrentIndex(idx); _stackLit->setText(label.arg(item->text(0))); return; } } // Nothing here so try the next one XTreeWidgetItem* next = dynamic_cast<XTreeWidgetItem*>(_tree->itemBelow(item)); if (next) setCurrentIndex(next); }