1
/***************************************************************************
2
* Copyright (C) 2012-2013 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Valle <emmanuel.lepage@savoirfairelinux.com >*
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
10
* This program 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 *
13
* GNU 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 "callviewoverlaytoolbar.h"
21
#include <QtGui/QPaintEvent>
22
#include <QtGui/QPainter>
23
#include <QtGui/QBrush>
25
#include <QtSvg/QSvgRenderer>
26
#include <QtGui/QHBoxLayout>
27
#include <QDebug> //TODO remove
30
#include <KStandardDirs>
35
#include "extendedaction.h"
37
const bool visibility[8][13] = { /*ROW = BUTTONS COLS=STATE*/
38
/* INCOMING RINGING CURRENT DIALING HOLD FAILURE BUSY TRANSFERRED TRANSF_HOLD OVER ERROR CONFERENCE CONFERENCE_HOLD:*/
39
/*PICKUP */ { true , true , false, false, false, false, false, false, false, false, false, false, false },
40
/*HOLD */ { false , false, true , false, false, false, false, true , false, false, false, true , false },
41
/*UNHOLD */ { false , false, false, false, true , false, false, false, false, false, false, false, false },
42
/*HANGUP */ { false , true , true , false, true , true , true , true , true , false, true , true , true },
43
/*MUTE */ { false , true , true , false, false, false, false, false, false, false, false, false, false },
44
/*TRANSFER */ { false , false, true , false, true , false, false, false, false, false, false, false, false },
45
/*RECORD */ { false , true , true , false, true , false, false, true , true , false, false, true , true },
46
/*REFUSE */ { true , false, false, false, false, false, false, false, false, false, false, false, false }
50
CallViewOverlayToolbar::CallViewOverlayToolbar(QWidget* parent) : QWidget(parent),m_pRightRender(0),m_pLeftRender(0)
52
m_pRightRender = new QSvgRenderer( KStandardDirs::locate("data","sflphone-client-kde/overlay_right_corner.svg") );
53
m_pLeftRender = new QSvgRenderer( KStandardDirs::locate("data","sflphone-client-kde/overlay_left_corner.svg" ) );
55
QHBoxLayout* layout = new QHBoxLayout(this);
57
m_pHold = createButton( SFLPhone::app()->getHoldAction() );
58
m_pUnhold = createButton( SFLPhone::app()->getUnholdAction() );
59
m_pMute = createButton( SFLPhone::app()->getMuteAction() );
60
m_pPickup = createButton( SFLPhone::app()->getPickupAction() );
61
m_pHangup = createButton( SFLPhone::app()->getHangupAction() );
62
m_pTransfer = createButton( SFLPhone::app()->getTransferAction() );
63
m_pRecord = createButton( SFLPhone::app()->getRecordAction() );
64
m_pRefuse = createButton( SFLPhone::app()->getRefuseAction() );
66
m_hButtons[ ActionButton::HOLD ] = m_pHold ;
67
m_hButtons[ ActionButton::UNHOLD ] = m_pUnhold ;
68
m_hButtons[ ActionButton::PICKUP ] = m_pPickup ;
69
m_hButtons[ ActionButton::HANGUP ] = m_pHangup ;
70
m_hButtons[ ActionButton::MUTE ] = m_pMute ;
71
m_hButtons[ ActionButton::TRANSFER ] = m_pTransfer;
72
m_hButtons[ ActionButton::RECORD ] = m_pRecord ;
73
m_hButtons[ ActionButton::REFUSE ] = m_pRefuse ;
75
layout->addWidget( m_pHangup );
76
layout->addWidget( m_pTransfer );
77
layout->addWidget( m_pMute );
78
layout->addWidget( m_pRecord );
79
layout->addWidget( m_pUnhold );
80
layout->addWidget( m_pHold );
81
layout->addWidget( m_pPickup );
82
layout->addWidget( m_pRefuse );
84
setMinimumSize(100,56);
85
} //CallViewOverlayToolbar
88
void CallViewOverlayToolbar::resizeEvent(QResizeEvent* event)
90
QWidget::resizeEvent(event);
94
void CallViewOverlayToolbar::paintEvent(QPaintEvent* event)
97
QPainter customPainter(this);
98
customPainter.setRenderHint(QPainter::Antialiasing);
99
QBrush b = customPainter.brush();
100
QPen p = customPainter.pen();
103
customPainter.setOpacity(0.5);
105
customPainter.setBrush (Qt::black);
106
customPainter.setPen (Qt::transparent);
107
customPainter.drawRect (QRect(3,10,width()-6,height()-16) );
108
customPainter.drawPie (QRect(width()-8-3,height()-10,8,8),270*16,90*16 );
109
customPainter.drawPie (QRect(3,height()-10,8,8),180*16,90*16 );
110
customPainter.drawRect (QRect(5+2,height()-6,width()-8-6,3) );
112
m_pLeftRender->render (&customPainter,QRect( 3,0,10,10) );
113
m_pRightRender->render(&customPainter,QRect( width()-13,0,10,10) );
116
///Create a toolbar button
117
ObserverToolButton* CallViewOverlayToolbar::createButton(ExtendedAction* action)
119
ObserverToolButton* b = new ObserverToolButton(this);
120
b->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
121
b->setIconSize(QSize(28,28));
122
b->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
123
b->setText(action->text());
125
b->setStyleSheet("margin-bottom:0px;margin-top:7px;font-weight:bold;background-color:transparent;color:#DDDDDD;padding-top:5px;");
126
b->setIcon(action->altIcon());
127
connect(action,SIGNAL(textChanged(QString)),b,SLOT(setNewText(QString)));
128
connect(b,SIGNAL(clicked()),action,SLOT(trigger()));
132
///Hide or show the toolbar and select visible actions
133
void CallViewOverlayToolbar::updateState(call_state state)
135
m_hButtons[ ActionButton::HOLD ]->setVisible(visibility[ ActionButton::HOLD ][state]);
136
m_hButtons[ ActionButton::UNHOLD ]->setVisible(visibility[ ActionButton::UNHOLD ][state]);
137
m_hButtons[ ActionButton::PICKUP ]->setVisible(visibility[ ActionButton::PICKUP ][state]);
138
m_hButtons[ ActionButton::HANGUP ]->setVisible(visibility[ ActionButton::HANGUP ][state]);
139
m_hButtons[ ActionButton::MUTE ]->setVisible(visibility[ ActionButton::MUTE ][state]);
140
m_hButtons[ ActionButton::TRANSFER ]->setVisible(visibility[ ActionButton::TRANSFER ][state]);
141
m_hButtons[ ActionButton::RECORD ]->setVisible(visibility[ ActionButton::RECORD ][state]);
142
m_hButtons[ ActionButton::REFUSE ]->setVisible(visibility[ ActionButton::REFUSE ][state]);
145
void CallViewOverlayToolbar::hideEvent(QHideEvent *)
147
emit visibilityChanged(false);
150
void CallViewOverlayToolbar::showEvent(QShowEvent *)
152
emit visibilityChanged(true);