~ubuntu-branches/debian/sid/sflphone/sid

« back to all changes in this revision

Viewing changes to kde/src/delegates/dialpaddelegate.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *   Copyright (C) 2013-2014 by Savoir-Faire Linux                          *
 
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 
4
 *                                                                          *
 
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.     *
 
9
 *                                                                          *
 
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.                        *
 
14
 *                                                                          *
 
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>
 
22
#include "lib/call.h"
 
23
#include "lib/callmodel.h"
 
24
 
 
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>();
 
29
 
 
30
void DialpadDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, uint rightPadding)
 
31
{
 
32
   int animStep(index.data(Call::Role::DTMFAnimState).toInt()),dialIdx(index.data(Call::Role::LastDTMFidx).toInt());
 
33
   if (animStep <= 0)
 
34
      return;
 
35
   painter->save();
 
36
   painter->setRenderHint(QPainter::Antialiasing, true );
 
37
 
 
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);
 
43
   int h = r.height();
 
44
 
 
45
   for (int i=0; i < 12;i++) {
 
46
      if (i == dialIdx) {
 
47
         painter->save();
 
48
         static QColor c("#dd0000");
 
49
         c.setAlpha(animStep*2);
 
50
         painter->setBrush(QBrush(c));
 
51
      }
 
52
      painter->drawRoundedRect(r.x()+(h/3)*(i%3),r.y()+(h/4)*(i/3)+2,h/3-2,h/4-2,2,2);
 
53
      if (i == dialIdx) {
 
54
         painter->restore();
 
55
      }
 
56
   }
 
57
   painter->restore();
 
58
 
 
59
   if (animStep == 50)
 
60
      m_sStep = 50;
 
61
 
 
62
   if (!m_spTimer) {
 
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()));
 
67
   }
 
68
   if (!m_spTimer->isActive() && animStep > 0)
 
69
      m_spTimer->start();
 
70
   m_slIndexes << index;
 
71
}
 
72
 
 
73
void DialpadDelegate::slotFade()
 
74
{
 
75
   m_sStep--;
 
76
 
 
77
   foreach(const QModelIndex& idx,m_slIndexes) {
 
78
      if (!idx.isValid() || idx.data(Call::Role::DTMFAnimState).toInt() == 0) {
 
79
         m_slIndexes.remove(idx);
 
80
      }
 
81
      else {
 
82
         CallModel::instance()->setData(idx,idx.data(Call::Role::DTMFAnimState).toInt() -1,Call::Role::DTMFAnimState);
 
83
      }
 
84
   }
 
85
   if ((m_sStep<=0) ||!m_slIndexes.size()) {
 
86
      m_spTimer->stop();
 
87
   }
 
88
}