Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | bab169d | 2016-01-07 15:13:33 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* |
| 4 | * * |
| 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. * |
| 9 | * * |
| 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. * |
| 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 | |
| 19 | #include "videooverlay.h" |
| 20 | #include "ui_videooverlay.h" |
| 21 | |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 22 | #include "contactpicker.h" |
| 23 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 24 | #include "callmodel.h" |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 25 | #include "contactmethod.h" |
| 26 | #include "person.h" |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 27 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 28 | VideoOverlay::VideoOverlay(QWidget* parent) : |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 29 | QWidget(parent), |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 30 | ui(new Ui::VideoOverlay), |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 31 | transferDialog_(new CallUtilsDialog()), |
| 32 | qualityDialog_(new QualityDialog()) |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 33 | { |
| 34 | ui->setupUi(this); |
| 35 | |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 36 | ui->chatButton->setCheckable(true); |
| 37 | |
Edric Milaret | a3e4728 | 2015-10-23 15:20:30 -0400 | [diff] [blame] | 38 | actionModel_ = CallModel::instance().userActionModel(); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 39 | setAttribute(Qt::WA_NoSystemBackground); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 40 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 41 | ui->noMicButton->setCheckable(true); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 42 | |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 43 | QPixmap pixmap(":/images/video-conf/ic_high_quality_white.svg"); |
| 44 | QIcon qualityIcon(pixmap); |
| 45 | ui->qualityButton->setIcon(qualityIcon); |
| 46 | ui->qualityButton->setIconSize(pixmap.rect().size()); |
| 47 | |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 48 | connect(actionModel_,&UserActionModel::dataChanged, [=](const QModelIndex& tl, const QModelIndex& br) { |
| 49 | const int first(tl.row()),last(br.row()); |
| 50 | for(int i = first; i <= last;i++) { |
| 51 | const QModelIndex& idx = actionModel_->index(i,0); |
| 52 | switch (idx.data(UserActionModel::Role::ACTION).value<UserActionModel::Action>()) { |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 53 | case UserActionModel::Action::MUTE_AUDIO: |
| 54 | ui->noMicButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 55 | ui->noMicButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 56 | break; |
| 57 | case UserActionModel::Action::MUTE_VIDEO: |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 58 | ui->noVideoButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 59 | ui->noVideoButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 60 | break; |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 61 | case UserActionModel::Action::HOLD: |
| 62 | ui->holdButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 63 | ui->holdButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 64 | ui->onHoldLabel->setVisible(idx.data(Qt::CheckStateRole).value<bool>()); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 65 | break; |
Edric Milaret | a5fe70f | 2016-02-05 15:03:31 -0500 | [diff] [blame^] | 66 | case UserActionModel::Action::RECORD: |
| 67 | ui->recButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>()); |
| 68 | ui->recButton->setEnabled(idx.flags() & Qt::ItemIsEnabled); |
Edric Milaret | 5927d04 | 2015-06-15 12:45:29 -0400 | [diff] [blame] | 69 | default: |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | }); |
| 74 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 75 | connect(CallModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 76 | Q_UNUSED(previous) |
| 77 | Call* c = current.data(static_cast<int>(Call::Role::Object)).value<Call*>(); |
| 78 | if (c) { |
| 79 | if (c->hasParentCall()) { |
| 80 | ui->holdButton->hide(); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 81 | ui->transferButton->hide(); |
| 82 | ui->addPersonButton->hide(); |
| 83 | ui->chatButton->hide(); |
| 84 | |
| 85 | ui->joinButton->show(); |
| 86 | } else { |
| 87 | ui->holdButton->show(); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 88 | ui->transferButton->show(); |
| 89 | ui->addPersonButton->show(); |
| 90 | ui->chatButton->show(); |
| 91 | |
| 92 | ui->joinButton->hide(); |
| 93 | } |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 94 | if (auto contactMethod = c->peerContactMethod()) |
| 95 | ui->addToContactButton->setVisible(not contactMethod->contact() |
| 96 | || contactMethod->contact()->isPlaceHolder()); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 97 | } |
| 98 | }); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | VideoOverlay::~VideoOverlay() |
| 102 | { |
| 103 | delete ui; |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 104 | delete transferDialog_; |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 105 | delete qualityDialog_; |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void |
| 109 | VideoOverlay::setName(const QString& name) |
| 110 | { |
| 111 | ui->nameLabel->setText(name); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | VideoOverlay::setTime(const QString& time) |
| 116 | { |
| 117 | ui->timerLabel->setText(time); |
| 118 | } |
| 119 | |
| 120 | void |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 121 | VideoOverlay::on_hangupButton_clicked() |
| 122 | { |
| 123 | actionModel_->execute(UserActionModel::Action::HANGUP); |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 124 | ui->chatButton->setChecked(false); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void |
| 128 | VideoOverlay::on_chatButton_toggled(bool checked) |
| 129 | { |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 130 | emit setChatVisibility(checked); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 133 | void |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 134 | VideoOverlay::on_transferButton_clicked() |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 135 | { |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 136 | transferDialog_->setConfMode(false); |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 137 | auto pos = this->mapToGlobal(ui->transferButton->pos()); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 138 | transferDialog_->move(pos.x() |
| 139 | - transferDialog_->size().width()/2 |
| 140 | + ui->transferButton->size().width()/2, |
| 141 | pos.y() - (transferDialog_->height())); |
| 142 | transferDialog_->show(); |
| 143 | } |
| 144 | |
| 145 | void |
| 146 | VideoOverlay::on_addPersonButton_clicked() |
| 147 | { |
| 148 | transferDialog_->setConfMode(true); |
| 149 | auto pos = this->mapToGlobal(ui->addPersonButton->pos()); |
| 150 | transferDialog_->move(pos.x() |
| 151 | - transferDialog_->size().width()/2 |
| 152 | + ui->addPersonButton->size().width()/2, |
| 153 | pos.y() - (transferDialog_->height())); |
| 154 | transferDialog_->show(); |
| 155 | } |
| 156 | |
| 157 | void |
| 158 | VideoOverlay::on_holdButton_clicked() |
| 159 | { |
| 160 | actionModel_->execute(UserActionModel::Action::HOLD); |
| 161 | } |
| 162 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 163 | void |
| 164 | VideoOverlay::on_noMicButton_clicked() |
| 165 | { |
| 166 | actionModel_->execute(UserActionModel::Action::MUTE_AUDIO); |
| 167 | } |
| 168 | |
| 169 | void |
| 170 | VideoOverlay::on_noVideoButton_clicked() |
| 171 | { |
| 172 | actionModel_->execute(UserActionModel::Action::MUTE_VIDEO); |
| 173 | } |
| 174 | |
| 175 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 176 | void VideoOverlay::on_joinButton_clicked() |
| 177 | { |
| 178 | CallModel::instance().selectedCall()->joinToParent(); |
Edric Milaret | 5cbf2b6 | 2015-07-09 11:36:53 -0400 | [diff] [blame] | 179 | } |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 180 | |
| 181 | void |
| 182 | VideoOverlay::on_qualityButton_clicked() |
| 183 | { |
| 184 | auto pos = this->mapToGlobal(ui->qualityButton->pos()); |
| 185 | qualityDialog_->move(pos.x() |
| 186 | - qualityDialog_->size().width()/2 |
| 187 | + ui->qualityButton->size().width()/2, |
| 188 | pos.y() - (qualityDialog_->height())); |
| 189 | qualityDialog_->show(); |
| 190 | } |
Edric Milaret | 31484f1 | 2016-02-02 14:26:27 -0500 | [diff] [blame] | 191 | |
| 192 | void |
| 193 | VideoOverlay::on_addToContactButton_clicked() |
| 194 | { |
| 195 | QPoint globalPos = mapToGlobal(ui->addToContactButton->pos()); |
| 196 | if (auto contactMethod = CallModel::instance().selectedCall()->peerContactMethod()) { |
| 197 | ContactPicker contactPicker(contactMethod); |
| 198 | contactPicker.move(globalPos.x(), |
| 199 | globalPos.y() + ui->addToContactButton->height()); |
| 200 | contactPicker.exec(); |
| 201 | } |
| 202 | } |
Edric Milaret | a5fe70f | 2016-02-05 15:03:31 -0500 | [diff] [blame^] | 203 | |
| 204 | void |
| 205 | VideoOverlay::on_recButton_clicked() |
| 206 | { |
| 207 | actionModel_->execute(UserActionModel::Action::RECORD); |
| 208 | } |