1
/****************************************************************************
2
* Copyright (C) 2013-2014 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Lesser General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2.1 of the License, or (at your option) any later version. *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13
* Lesser General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17
***************************************************************************/
18
#include "dialpaddelegate.h"
19
#include <QtCore/QTimer>
20
#include <QtGui/QPainter>
21
#include <QtGui/QApplication>
23
#include "lib/callmodel.h"
25
QTimer* DialpadDelegate::m_spTimer = nullptr;
26
DialpadDelegate* DialpadDelegate::m_spInstance = nullptr;
27
int DialpadDelegate::m_sStep = 0;
28
QSet<QModelIndex> DialpadDelegate::m_slIndexes = QSet<QModelIndex>();
30
void DialpadDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, uint rightPadding)
32
int animStep(index.data(Call::Role::DTMFAnimState).toInt()),dialIdx(index.data(Call::Role::LastDTMFidx).toInt());
36
painter->setRenderHint(QPainter::Antialiasing, true );
38
const QRect r(option.rect.x()+option.rect.width()-option.rect.height()-8-rightPadding,option.rect.y()+2,option.rect.height()-4,option.rect.height()-4);
39
static QColor c1(Qt::black);
40
c1.setAlpha(animStep*1.5);
41
painter->setBrush(c1);
42
painter->setPen(Qt::NoPen);
45
for (int i=0; i < 12;i++) {
48
static QColor c("#dd0000");
49
c.setAlpha(animStep*2);
50
painter->setBrush(QBrush(c));
52
painter->drawRoundedRect(r.x()+(h/3)*(i%3),r.y()+(h/4)*(i/3)+2,h/3-2,h/4-2,2,2);
63
m_spTimer = new QTimer();
64
m_spTimer->setInterval(1000/60);
65
m_spInstance = new DialpadDelegate();
66
connect(m_spTimer,SIGNAL(timeout()),m_spInstance,SLOT(slotFade()));
68
if (!m_spTimer->isActive() && animStep > 0)
73
void DialpadDelegate::slotFade()
77
foreach(const QModelIndex& idx,m_slIndexes) {
78
if (!idx.isValid() || idx.data(Call::Role::DTMFAnimState).toInt() == 0) {
79
m_slIndexes.remove(idx);
82
CallModel::instance()->setData(idx,idx.data(Call::Role::DTMFAnimState).toInt() -1,Call::Role::DTMFAnimState);
85
if ((m_sStep<=0) ||!m_slIndexes.size()) {