QJSEngine* QtTouchViewInterface::engine() { QSGView* view = qobject_cast<QSGView*>(m_pageView->canvas()); if (view) return view->engine(); return 0; }
int main(int argc, char ** argv) { QApplication app(argc, argv); //![0] QStringList dataList; dataList.append("Item 1"); dataList.append("Item 2"); dataList.append("Item 3"); dataList.append("Item 4"); QSGView view; QDeclarativeContext *ctxt = view.rootContext(); ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); //![0] view.setSource(QUrl("qrc:view.qml")); view.show(); return app.exec(); }
void tst_qsganimatedimage::mirror_notRunning() { QFETCH(QUrl, fileUrl); QSGView *canvas = new QSGView; canvas->show(); canvas->setSource(fileUrl); QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(canvas->rootObject()); QVERIFY(anim); int width = anim->property("width").toInt(); QPixmap screenshot = canvas->renderPixmap(); QTransform transform; transform.translate(width, 0).scale(-1, 1.0); QPixmap expected = screenshot.transformed(transform); int frame = anim->currentFrame(); bool playing = anim->isPlaying(); bool paused = anim->isPlaying(); anim->setProperty("mirror", true); screenshot = canvas->renderPixmap(); QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved", SkipSingle); QCOMPARE(screenshot, expected); // mirroring should not change the current frame or playing status QCOMPARE(anim->currentFrame(), frame); QCOMPARE(anim->isPlaying(), playing); QCOMPARE(anim->isPaused(), paused); delete canvas; }
void tst_qsganimatedimage::mirror_running() { // test where mirror is set to true after animation has started QSGView *canvas = new QSGView; canvas->show(); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/hearts.qml")); QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(canvas->rootObject()); QVERIFY(anim); int width = anim->property("width").toInt(); QCOMPARE(anim->currentFrame(), 0); QPixmap frame0 = canvas->renderPixmap(); anim->setCurrentFrame(1); QPixmap frame1 = canvas->renderPixmap(); anim->setCurrentFrame(0); QSignalSpy spy(anim, SIGNAL(frameChanged())); anim->setPlaying(true); QTRY_VERIFY(spy.count() == 1); spy.clear(); anim->setProperty("mirror", true); QCOMPARE(anim->currentFrame(), 1); QPixmap frame1_flipped = canvas->renderPixmap(); QTRY_VERIFY(spy.count() == 1); spy.clear(); QCOMPARE(anim->currentFrame(), 0); // animation only has 2 frames, should cycle back to first QPixmap frame0_flipped = canvas->renderPixmap(); QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved", SkipSingle); QTransform transform; transform.translate(width, 0).scale(-1, 1.0); QPixmap frame0_expected = frame0.transformed(transform); QPixmap frame1_expected = frame1.transformed(transform); QCOMPARE(frame0_flipped, frame0_expected); QCOMPARE(frame1_flipped, frame1_expected); delete canvas; }
int main(int argc, char **argv) { QApplication app(argc, argv); if (app.arguments().count() < 2) { qDebug() << "Usage: accessebilityInspector [ ui-file | qml-file ] [Option]"; qDebug() << "Option:"; #ifdef QT_ACCESSIBILITY_INSPECTOR_SCENE_GRAPH qDebug() << "-qtquick1: Use QDeclarativeView instead of QSGView for rendering QML files"; #endif return 0; } QString fileName = app.arguments().at(1); QString mode; if (app.arguments().count() > 2) { mode = app.arguments().at(2); } QWidget *window; if (fileName.endsWith(".ui")) { QUiLoader loader; QFile file(fileName); file.open(QFile::ReadOnly); window = loader.load(&file, 0); } else if (fileName.endsWith(".qml")){ QUrl fileUrl; if (fileName.startsWith(":")) { // detect resources. QString name = fileName; name.remove(0, 2); // reomve ":/" fileUrl.setUrl(QLatin1String("qrc:/") + name); } else { fileUrl = QUrl::fromLocalFile(fileName); } #ifdef QT_ACCESSIBILITY_INSPECTOR_SCENE_GRAPH if (mode == QLatin1String("-qtquick1")) #endif { QDeclarativeView * declarativeView = new QDeclarativeView(); declarativeView->setSource(fileUrl); window = declarativeView; } #ifdef QT_ACCESSIBILITY_INSPECTOR_SCENE_GRAPH else { QSGView * sceneGraphView = new QSGView(); sceneGraphView->setSource(fileUrl); window = sceneGraphView; } #endif } else { qDebug() << "Error: don't know what to do with" << fileName; } AccessibilityInspector *accessibilityInspector = new AccessibilityInspector(); accessibilityInspector->inspectWindow(window); window->move(50, 50); window->show(); int ret = app.exec(); accessibilityInspector->saveWindowGeometry(); delete accessibilityInspector; return ret; }