Exemple #1
0
void tst_QFeedbackPlugin::testFileEffect()
{
    QFeedbackFileEffect fileEffect;
    QVERIFY(QFeedbackFileEffect::supportedMimeTypes().contains("x-test/this is a test"));

    QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped);

    fileEffect.setSource(QUrl("load")); // this should call load
    QVERIFY(fileEffect.state() == QFeedbackEffect::Loading);

    fileEffect.setSource(QUrl("ignored")); // not stopped, should fail
    QVERIFY(fileEffect.source() == QUrl("load"));

    QVERIFY(fileEffect.isLoaded());
    fileEffect.setLoaded(true); // should do nothing
    QVERIFY(fileEffect.isLoaded());
    QCOMPARE(fileEffect.duration(), 5678); // from the plugin

    fileEffect.unload(); // should fail, since we're not STOPPED (HMM!!)
    QVERIFY(fileEffect.isLoaded());

    fileEffect.stop();
    QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped);
    // Now we should be able to change things again

    // Make sure setting the source to the same thing is a noop
    fileEffect.setSource(fileEffect.source());
    QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped);

    // Now unload
    QVERIFY(fileEffect.isLoaded());
    fileEffect.unload();
    QVERIFY(!fileEffect.isLoaded());
    QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped);
    QCOMPARE(fileEffect.duration(), 0); // unloaded, shouldn't call?

    // Change the url
    fileEffect.setSource(QUrl("failload"));
    QVERIFY(!fileEffect.isLoaded());
    // Spinning the event loop is necessary for mmk to fail a load
    QTRY_COMPARE(fileEffect.state(), QFeedbackEffect::Stopped);
    QCOMPARE(fileEffect.duration(), 0); // unknown

    fileEffect.setSource(QUrl("load"));
    QVERIFY(fileEffect.isLoaded());
    QVERIFY(fileEffect.state() == QFeedbackEffect::Loading);
    fileEffect.start();
    QVERIFY(fileEffect.state() == QFeedbackEffect::Running);
    fileEffect.start();
    QVERIFY(fileEffect.state() == QFeedbackEffect::Running);
    fileEffect.stop();
    QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped);
    fileEffect.pause();
    QVERIFY(fileEffect.state() == QFeedbackEffect::Paused); // XXX this is a strange transition
}
void completeExample()
{
//! [Play the system theme button click effect]
    QFeedbackEffect::playThemeEffect(QFeedbackEffect::Press);
//! [Play the system theme button click effect]

//! [Play the system theme bounce effect]
    QFeedbackEffect::playThemeEffect(QFeedbackEffect::DragStart);
//! [Play the system theme bounce effect]

//! [Define a custom haptic effect]
    QFeedbackHapticsEffect rumble;
    rumble.setAttackIntensity(0.0);
    rumble.setAttackTime(250);
    rumble.setIntensity(1.0);
    rumble.setDuration(1000);
    rumble.setFadeTime(250);
    rumble.setFadeIntensity(0.0);
//! [Define a custom haptic effect]

//! [Start playing a custom haptic effect]
    rumble.start();
//! [Start playing a custom haptic effect]

//! [Pause a custom haptic effect]
    rumble.pause();
//! [Pause a custom haptic effect]

//! [Stop playing a custom haptic effect]
    rumble.stop();
//! [Stop playing a custom haptic effect]

//! [Query the state of a custom haptic effect]
    if (rumble.state() == QFeedbackEffect::Stopped)
        qDebug() << "The device has stopped rumbling!";
//! [Query the state of a custom haptic effect]

//! [Set the actuator which should play the custom effect]
    QFeedbackActuator *actuator = 0; // default system actuator
    QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators();
    foreach (QFeedbackActuator* temp, actuators) {
        if (temp->name() == "ExampleActuatorName") {
            actuator = temp;
        }
    }
    rumble.setActuator(actuator);
//! [Set the actuator which should play the custom effect]

//! [Play a haptic effect from a file]
    QFeedbackFileEffect hapticTune;
    hapticTune.setSource(QUrl::fromLocalFile("mySavedRumble.ivt"));
    hapticTune.load();
    hapticTune.start();
//! [Play a haptic effect from a file]
}