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] }
void Notification::vibrate(int duration, int intensity) { QFeedbackHapticsEffect *haptic = new QFeedbackHapticsEffect(); haptic->setAttackIntensity(0.0); haptic->setAttackTime(100); haptic->setIntensity(intensity); haptic->setDuration(duration); haptic->setFadeTime(100); haptic->setFadeIntensity(0.0); haptic->start(); }
void tst_QFeedbackHapticsEffect::startStop() { qRegisterMetaType<QFeedbackEffect::ErrorType>("QFeedbackEffect::ErrorType"); if (QFeedbackActuator::actuators().isEmpty()) QSKIP("this test requires to have actuators", SkipAll); QFETCH(int, duration); QFETCH(qreal, intensity); QFETCH(int, attackTime); QFETCH(qreal, attackIntensity); QFETCH(int, fadeTime); QFETCH(qreal, fadeIntensity); QFETCH(int, period); QFeedbackHapticsEffect effect; QSignalSpy errorspy(&effect, SIGNAL(error(QFeedbackEffect::ErrorType))); QSignalSpy stateSpy(&effect, SIGNAL(stateChanged())); effect.setDuration(duration); effect.setIntensity(intensity); effect.setAttackTime(attackTime); effect.setAttackIntensity(attackIntensity); effect.setFadeTime(fadeTime); effect.setFadeIntensity(fadeIntensity); effect.setPeriod(period); QCOMPARE(effect.state(), QFeedbackHapticsEffect::Stopped); QVERIFY(stateSpy.isEmpty()); effect.start(); QVERIFY(errorspy.isEmpty()); // This seems a little risky QTRY_COMPARE(effect.state(), QFeedbackHapticsEffect::Running); QVERIFY(errorspy.isEmpty()); QCOMPARE(stateSpy.count(), 1); // stopped to start effect.pause(); QCOMPARE(effect.state(), QFeedbackHapticsEffect::Paused); QCOMPARE(stateSpy.count(), 2); effect.start(); QCOMPARE(effect.state(), QFeedbackHapticsEffect::Running); QCOMPARE(stateSpy.count(), 3); QTRY_COMPARE(effect.state(), QFeedbackHapticsEffect::Stopped); QVERIFY(errorspy.isEmpty()); QEXPECT_FAIL("", "No plugin API to report state changed to stopped :/", Continue); QCOMPARE(stateSpy.count(), 4); }
void tst_QFeedbackPlugin::testPlugin() { QFeedbackHapticsEffect testEffect; // first get the actuators. we want to use the test plugin actuator. QFeedbackActuator* testActuator; QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators(); QCOMPARE(actuators.count(), 2); QCOMPARE(actuators.at(0)->name(), QString("test plugin")); QCOMPARE(actuators.at(0)->id(), 0); QCOMPARE(actuators.at(1)->name(), QString("5555")); QCOMPARE(actuators.at(1)->id(), 1); // make sure we found the test actuator... testActuator = actuators.at(0); QCOMPARE(testActuator->name(), QString("test plugin")); QCOMPARE(testActuator->id(), 0); // test QVERIFY(testActuator->isCapabilitySupported(QFeedbackActuator::Period)); testActuator->setEnabled(true); QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false. testActuator->setEnabled(false); QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false. testActuator->setEnabled(true); QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false. QCOMPARE(testActuator->state(), QFeedbackActuator::Unknown); // and it always returns state = unknown. // XXX TODO: ensure that a "working" plugin returns real values.. // then, ensure that the test effect uses this actuator. testEffect.setActuator(testActuator); // it will do nothing, so stick some values in and play it. testEffect.setAttackIntensity(0.0); testEffect.setAttackTime(250); testEffect.setIntensity(1.0); testEffect.setDuration(100); testEffect.setFadeTime(250); testEffect.setFadeIntensity(0.0); testEffect.start(); QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Running); testEffect.pause(); QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Paused); testEffect.start(); QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Running); testEffect.stop(); QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Stopped); }
void tst_QFeedbackHapticsEffect::envelope() { QFETCH(int, duration); QFETCH(qreal, intensity); QFETCH(int, attackTime); QFETCH(qreal, attackIntensity); QFETCH(int, fadeTime); QFETCH(qreal, fadeIntensity); QFETCH(int, period); QFeedbackHapticsEffect effect; // actuators from other plugins need to be verified. effect.setDuration(duration); QCOMPARE(effect.duration(), duration); effect.setIntensity(intensity); QCOMPARE(effect.intensity(), intensity); effect.setAttackTime(attackTime); QCOMPARE(effect.attackTime(), attackTime); effect.setAttackIntensity(attackIntensity); QCOMPARE(effect.attackIntensity(), attackIntensity); effect.setFadeTime(fadeTime); QCOMPARE(effect.fadeTime(), fadeTime); effect.setFadeIntensity(fadeIntensity); QCOMPARE(effect.fadeIntensity(), fadeIntensity); effect.setPeriod(period); QCOMPARE(effect.period(), period); //test all the values at once QCOMPARE(effect.duration(), duration); QCOMPARE(effect.intensity(), intensity); QCOMPARE(effect.attackTime(), attackTime); QCOMPARE(effect.attackIntensity(), attackIntensity); QCOMPARE(effect.fadeTime(), fadeTime); QCOMPARE(effect.fadeIntensity(), fadeIntensity); QCOMPARE(effect.period(), period); }
void tst_QFeedbackHapticsEffect::startStop() { qRegisterMetaType<QFeedbackEffect::ErrorType>("QFeedbackEffect::ErrorType"); if (QFeedbackActuator::actuators().isEmpty()) QSKIP("this test requires to have actuators"); QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators(); QFETCH(int, duration); QFETCH(qreal, intensity); QFETCH(int, attackTime); QFETCH(qreal, attackIntensity); QFETCH(int, fadeTime); QFETCH(qreal, fadeIntensity); QFETCH(int, period); QFeedbackHapticsEffect effect; QSignalSpy errorspy(&effect, SIGNAL(error(QFeedbackEffect::ErrorType))); QSignalSpy stateSpy(&effect, SIGNAL(stateChanged())); effect.setDuration(duration); effect.setIntensity(intensity); effect.setAttackTime(attackTime); effect.setAttackIntensity(attackIntensity); effect.setFadeTime(fadeTime); effect.setFadeIntensity(fadeIntensity); effect.setPeriod(period); QCOMPARE(effect.state(), QFeedbackHapticsEffect::Stopped); QCOMPARE(effect.actuator(), actuators.at(0)); // Double set a few properties (shouldn't call the backend) effect.setAttackTime(attackTime); QVERIFY(effect.attackTime() == attackTime); effect.setFadeTime(fadeTime); QVERIFY(effect.fadeTime() == fadeTime); // Test setting to a non default actuator and then back again if (actuators.count() > 1) { effect.setActuator(actuators.at(1)); QCOMPARE(effect.actuator(), actuators.at(1)); effect.setActuator(0); QCOMPARE(effect.actuator(), actuators.at(0)); // noop effect.setActuator(actuators.at(0)); QCOMPARE(effect.actuator(), actuators.at(0)); } // Now start QVERIFY(stateSpy.isEmpty()); effect.start(); QVERIFY(errorspy.isEmpty()); // This seems a little risky QTRY_COMPARE(effect.state(), QFeedbackHapticsEffect::Running); QVERIFY(errorspy.isEmpty()); QCOMPARE(stateSpy.count(), 1); // stopped to start effect.pause(); QCOMPARE(effect.state(), QFeedbackHapticsEffect::Paused); QCOMPARE(stateSpy.count(), 2); // Now try to change a few properties (should be refused because of !Stopped) effect.setPeriod(period + 100); QVERIFY(effect.period() == period); QFeedbackActuator* actuator = effect.actuator(); effect.setActuator(0); QVERIFY(effect.actuator() == actuator); effect.start(); QCOMPARE(effect.state(), QFeedbackHapticsEffect::Running); QCOMPARE(stateSpy.count(), 3); QTRY_COMPARE(effect.state(), QFeedbackHapticsEffect::Stopped); QVERIFY(errorspy.isEmpty()); QCOMPARE(stateSpy.count(), 4); }