source: qutecom-coip/gui/src/call/callwidget.cpp @ 283:312974380d4f

Last change on this file since 283:312974380d4f was 283:312974380d4f, checked in by laurent <laurent@…>, 22 months ago

update gui

File size: 6.7 KB
Line 
1#include "callwidget.h"
2#include "ui_callwidget.h"
3
4CallWidget::CallWidget(TCallSession * tCallSession,QWidget *parent) 
5:QMainWindow(parent),_tCallSession(tCallSession),ui(new Ui::CallWidget)
6{
7        _timerIdProgressAnimation = 0; 
8        _timerIdSession = 0;
9        _durationSession = 0;
10       
11        _lastStatus = EnumPhoneCallState::PhoneCallStateIncoming;
12       
13   // ui->setupUi(this);
14
15        _labelMsg = new QLabel;
16        statusBar()->addWidget(_labelMsg);
17        _labelMsg->setText("New Call...");
18       
19        _remoteVideoFrame = QPixmap(":/qute.png");
20       
21        connect(_tCallSession,
22                                 SIGNAL(videoFrameReceivedSignal(QImage, QImage)),
23                                 SLOT(videoFrameReceivedSlot(QImage, QImage)));
24       
25        connect(_tCallSession,
26                                 SIGNAL(phoneCallStateChangedSignal(EnumPhoneCallState::PhoneCallState)),
27                                 SLOT(phoneCallStateChangedSlot(EnumPhoneCallState::PhoneCallState)));
28        _tCallSession->enableVideo(true);
29        show();
30}
31
32CallWidget::CallWidget(Contact contact,QWidget *parent) 
33:QMainWindow(parent),ui(new Ui::CallWidget)
34{
35        _timerIdProgressAnimation = 0;
36        _timerIdSession = 0;
37        _durationSession = 0;
38       
39        _lastStatus = EnumPhoneCallState::PhoneCallStateUnknown;
40       
41    ui->setupUi(this);
42       
43        _labelMsg = new QLabel;
44        statusBar()->addWidget(_labelMsg);
45        _labelMsg->setText("Dialing...");
46       
47        _remoteVideoFrame = QPixmap(":/qute.png");
48       
49        _tCallSession = Coip::self()->getTCallSessionManager().createTCallSession();
50       
51        connect(_tCallSession,
52                                 SIGNAL(videoFrameReceivedSignal(QImage, QImage)),
53                                 SLOT(videoFrameReceivedSlot(QImage, QImage)));
54       
55        connect(_tCallSession,
56                                 SIGNAL(phoneCallStateChangedSignal(EnumPhoneCallState::PhoneCallState)),
57                                 SLOT(phoneCallStateChangedSlot(EnumPhoneCallState::PhoneCallState)));
58       
59        _tCallSession->addContact(contact);
60        _tCallSession->enableVideo(true);
61        _tCallSession->start();
62
63        show();
64}
65
66CallWidget::~CallWidget()
67{
68    delete ui;
69        delete _tCallSession;
70}
71
72void CallWidget::changeEvent(QEvent *e)
73{
74    QMainWindow::changeEvent(e);
75    switch (e->type()) {
76    case QEvent::LanguageChange:
77        ui->retranslateUi(this);
78        break;
79    default:
80        break;
81    }
82}
83
84void CallWidget::paintEvent(QPaintEvent*)
85{
86        QPainter painter(this);
87        painter.setRenderHint(QPainter::Antialiasing, true);
88
89        if(!_remoteVideoFrame.isNull())
90        {
91                QPixmap pix = _remoteVideoFrame.scaled(ui->label->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
92                QRect re(0,0,pix.width(),pix.height());
93                re.moveCenter(ui->label->rect().center());
94                painter.drawPixmap(re,pix);
95        }
96               
97        if(!_localVideoFrame.isNull())
98                painter.drawPixmap(ui->label->pos(),_localVideoFrame.scaled(ui->label->size()/6,Qt::KeepAspectRatio,Qt::SmoothTransformation));
99       
100        if(_lastStatus != EnumPhoneCallState::PhoneCallStateTalking)
101        {
102                painter.fillRect(centralWidget()->rect(),QColor(30,30,30,200));
103       
104                if(!_timerIdProgressAnimation && (_lastStatus == EnumPhoneCallState::PhoneCallStateIncoming || _lastStatus == EnumPhoneCallState::PhoneCallStateHold))
105                {
106                        painter.setPen(QPen(QColor(255,255,255,200), 3));
107                        QRect re(0,0,50,50);
108                        re.moveCenter(centralWidget()->rect().center());
109                        painter.drawEllipse(re);
110               
111                        re.translate(re.width()/4, 0);
112                        painter.setBrush(QColor(255,255,255,200));
113                        painter.drawPie(re, 150 * 16, 60 * 16);
114                }
115        }       
116       
117        if(_timerIdProgressAnimation)
118        {
119                for (int i=0; i<9; i++)
120        {
121                        QColor color = Qt::white;
122                        color.setAlphaF(1.0f - (i/9.0f));
123                        painter.setPen(Qt::NoPen);
124                        painter.setBrush(color);
125                        painter.save();
126                        painter.translate(centralWidget()->rect().center());
127                        painter.rotate(_angleProgressAnimation - i*40.0f);
128                        painter.drawRect(QRectF(5.5, 0.9, 21.5, 5));
129                        painter.restore();
130        }
131        }
132}
133
134void CallWidget::mouseReleaseEvent(QMouseEvent *)
135{
136        if(_tCallSession->isStarted())
137        {
138                if(_lastStatus == EnumPhoneCallState::PhoneCallStateTalking)
139                {
140                        startProgressAnimation();
141                        _tCallSession->pause();
142                }
143                else if(_lastStatus == EnumPhoneCallState::PhoneCallStateHold)
144                {
145                        startProgressAnimation();
146                        _tCallSession->resume();
147                }
148                       
149        }
150        else if(_lastStatus == EnumPhoneCallState::PhoneCallStateIncoming)
151        {
152                startProgressAnimation();
153                _tCallSession->start();
154        }               
155}
156
157void CallWidget::timerEvent(QTimerEvent* event)
158{
159        if(event->timerId() == _timerIdProgressAnimation)
160        {
161                _angleProgressAnimation = (_angleProgressAnimation+30)%360;
162                update();
163        }
164        else if(event->timerId() == _timerIdSession)
165        {
166                _durationSession++;
167                QTime time;
168                setWindowTitle(time.addSecs(_durationSession).toString());
169        }
170}
171
172void CallWidget::startSessionTimer()
173{
174        _timerIdSession = startTimer(1000);
175}
176
177void CallWidget::stopSessionTimer()
178{
179        killTimer(_timerIdSession);
180}
181
182void CallWidget::startProgressAnimation()
183{
184        if(!_timerIdProgressAnimation)
185                _timerIdProgressAnimation = startTimer(100);
186}
187
188void CallWidget::stopProgressAnimation()
189{
190        if(_timerIdProgressAnimation)
191        {
192                killTimer(_timerIdProgressAnimation);
193                _timerIdProgressAnimation = 0;
194        }
195}
196
197
198void CallWidget::hangUpButtonClicked() {
199
200        _tCallSession->stop();
201}
202
203void CallWidget::videoFrameReceivedSlot(QImage remoteVideoFrame, QImage localVideoFrame) {
204
205        if(!remoteVideoFrame.isNull())
206                _remoteVideoFrame = QPixmap::fromImage(remoteVideoFrame);
207
208        if(!localVideoFrame.isNull())
209                _localVideoFrame = QPixmap::fromImage(localVideoFrame);
210
211        update();
212}
213
214void CallWidget::phoneCallStateChangedSlot(EnumPhoneCallState::PhoneCallState state) {
215       
216        _lastStatus = state;
217       
218        switch(state) {
219                        //case EnumPhoneCallState::PhoneCallStateUnknown:
220                case EnumPhoneCallState::PhoneCallStateClosed:
221                        stopProgressAnimation();
222                        stopSessionTimer();
223                        _labelMsg->setText("Closed...");                       
224                        break;
225                       
226                case EnumPhoneCallState::PhoneCallStateError:
227                        stopProgressAnimation();
228                        stopSessionTimer();
229                        _labelMsg->setText("Error...");                 
230                        break;
231                       
232                case EnumPhoneCallState::PhoneCallStateTalking:
233                        stopProgressAnimation();
234                        startSessionTimer();
235                        _labelMsg->setText("Talking...");
236                        break;
237                       
238                case EnumPhoneCallState::PhoneCallStateDialing:
239                        startProgressAnimation();
240                        _labelMsg->setText("Dialing...");
241                        break;
242                       
243                case EnumPhoneCallState::PhoneCallStateRinging:
244                        _labelMsg->setText("Ringing...");
245                        break;
246                       
247                case EnumPhoneCallState::PhoneCallStateHold:
248                        stopProgressAnimation();
249                        _labelMsg->setText("Hold...");
250                        break;
251                       
252                case EnumPhoneCallState::PhoneCallStateResumed:
253                        _labelMsg->setText("Resumed...");
254                        break;
255                       
256                case EnumPhoneCallState::PhoneCallStateMissed:
257                        stopProgressAnimation();
258                        _labelMsg->setText("Missed...");
259                        break;
260                       
261                case EnumPhoneCallState::PhoneCallStateRedirected:
262                        stopProgressAnimation();
263                        stopSessionTimer();
264                        _labelMsg->setText("Redirected...");
265                        break;
266                       
267                        //case EnumPhoneCallState::PhoneCallStateIncoming:
268                       
269                default:
270                        break;
271        }
272        update();
273}
274
275void CallWidget::closeEvent(QCloseEvent*)
276{
277        stopCallSessionSignal(_tCallSession);
278}
279
280void CallWidget::callButtonClickedSlot()
281{
282        _tCallSession->start();
283}
Note: See TracBrowser for help on using the repository browser.