michael@0: /* michael@0: * michael@0: * Copyright 2013 Canonical Ltd. michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * michael@0: */ michael@0: michael@0: #include "vibration.h" michael@0: michael@0: void Vibration::vibrate(int, int, int mills) { michael@0: QSharedPointer vibrate = QSharedPointer::create(); michael@0: vibrate->setIntensity(1.0); michael@0: vibrate->setDuration(mills); michael@0: michael@0: vibrate->start(); michael@0: michael@0: _effects.append(vibrate); michael@0: } michael@0: michael@0: void Vibration::cancelVibration(int, int) { michael@0: _timers.clear(); michael@0: _effects.clear(); michael@0: } michael@0: michael@0: void Vibration::vibrateWithPattern(int, int, const QList &pattern, int repeat) { michael@0: QSharedPointer timer = QSharedPointer::create(); michael@0: QSharedPointer k = QSharedPointer::create(); michael@0: michael@0: QSharedPointer vibrate = QSharedPointer::create(); michael@0: vibrate->setIntensity(1.0); michael@0: michael@0: _effects.append(vibrate); michael@0: _timers.append(timer); michael@0: michael@0: timer->connect(timer.data(), &QTimer::timeout, [=, timer = timer.data()] () { michael@0: if (*k >= pattern.size()) { michael@0: if (repeat < 0 || repeat >= pattern.size()) { michael@0: timer->stop(); michael@0: return; michael@0: } michael@0: *k = repeat; michael@0: } michael@0: bool idle = (*k % 2 == 0); michael@0: if (!idle) { michael@0: vibrate->setDuration(pattern[*k]); michael@0: vibrate->start(); michael@0: } michael@0: timer->start(pattern[*k]); michael@0: (*k)++; michael@0: }); michael@0: timer->start(1); michael@0: }