void QFormScriptRunner::QFormScriptRunnerPrivate::initializeEngine(QWidget *w, const WidgetList &children, QScriptEngine &scriptEngine) { // Populate the script variables. This pushes a context which must be popped. QScriptContext *ctx = scriptEngine.pushContext(); QScriptValue widgetObject = scriptEngine.newQObject(w); QScriptValue childrenArray = scriptEngine.newArray (children.size()); for(int i = 0; i < children.size(); i++) { childrenArray.setProperty(i, scriptEngine.newQObject(children[i])); } const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); ctx ->activationObject().setProperty(strings.scriptWidgetVariable, widgetObject); ctx ->activationObject().setProperty(strings.scriptChildWidgetsVariable, childrenArray); }
// This method performs intersection testing at the given XY coords, and returns true if // any intersections were found. It will break after processing the first pickable Window // it finds. bool WindowManager::pickAtXY(float x, float y, WidgetList& wl) { Intersections intr; osg::Camera* camera = _view->getCamera(); osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(camera->getGraphicsContext()); if (gw) { _view->computeIntersections(camera, osgUtil::Intersector::WINDOW, x, y, intr, _nodeMask); } if (!intr.empty()) { // Get the first Window at the XY coordinates; if you want a Window to be // non-pickable, set the NodeMask to something else. Window* activeWin = 0; // Iterate over every picked result and create a list of Widgets that belong // to that Window. for(Intersections::iterator i = intr.begin(); i != intr.end(); i++) { Window* win = dynamic_cast<Window*>(i->nodePath.back()->getParent(0)); // Make sure that our window is valid, and that our pick is within the // "visible area" of the Window. if( !win || (win->getVisibilityMode() == Window::VM_PARTIAL && !win->isPointerXYWithinVisible(x, y)) ) { continue; } // Set our activeWin, so that we know when we've got all the Widgets // that belong to it. if(!activeWin) activeWin = win; // If we've found a new Widnow, break out! else if(activeWin != win) break; Widget* widget = dynamic_cast<Widget*>(i->drawable.get()); if(!widget) continue; // We need to return a list of every Widget that was picked, so // that the handler can operate on it accordingly. else wl.push_back(widget); } if(wl.size()) { // Potentially VERY expensive; only to be used for debugging. :) if(_flags & WM_PICK_DEBUG) _updatePickWindow(&wl, x, y); return true; } } if(_flags & WM_PICK_DEBUG) _updatePickWindow(0, x, y); return false; }
bool Window::getFocusList(WidgetList& wl) const { for(ConstIterator i = begin(); i != end(); i++) if(i->valid()) { EmbeddedWindow* ew = dynamic_cast<EmbeddedWindow*>(i->get()); if(!ew) { if(i->get()->canFocus()) wl.push_back(i->get()); } else { if(ew->getWindow()) ew->getWindow()->getFocusList(wl); } } return wl.size() != 0; }
bool QFormScriptRunner::run(const DomWidget *domWidget, const QString &customWidgetScript, QWidget *widget, const WidgetList &children, QString *errorMessage) { typedef QList<DomScript*> DomScripts; const Options scriptOptions = m_impl->options(); if (scriptOptions & DisableScripts) return true; // get list const DomScripts domScripts = domWidget->elementScript(); // Concatenate snippets, starting with custom widget script QString script = customWidgetScript; if (script.isEmpty() && domScripts.empty()) return true; foreach (const DomScript *scriptSnippet, domScripts) { // Ensure new line if (!script.isEmpty() && !script.endsWith(QLatin1Char('\n'))) script += QLatin1Char('\n'); script += scriptSnippet->text(); } if (script.isEmpty()) return true; const bool rc = m_impl->run(script, widget, children, errorMessage); if (debugFormScriptRunner) { qDebug() << "For " << widget << " with " << children.size() << " children, ran: " << script; if (!rc) qDebug() << *errorMessage; } if (!rc) { if (!(scriptOptions & DisableWarnings)) { const QString message = QCoreApplication::tr("An error occurred while running the script for %1: %2\nScript: %3"). arg(widget->objectName()).arg(*errorMessage).arg(script); qWarning() << message; } } return rc; }
bool Window::setNextFocusable() { WidgetList focusList; if(!getFocusList(focusList)) return false; WidgetList::iterator w = focusList.begin(); // TODO: This needs to be a more complicated object, since the focus may be // in a child Window instead of a Widget. unsigned int focusedIndex = 0; for(unsigned int i = 0; w != focusList.end(); w++, i++) if(*w == _focused) { focusedIndex = i; break; } if(focusedIndex < focusList.size() - 1) _setFocused((++w)->get()); else _setFocused(focusList.front().get()); return true; }