videooverlay.cpp 6.74 KB
Newer Older
1
/***************************************************************************
2
 * Copyright (C) 2015-2016 by Savoir-faire Linux                                *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by    *
 * the Free Software Foundation; either version 3 of the License, or       *
 * (at your option) any later version.                                     *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License       *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 **************************************************************************/

#include "videooverlay.h"
#include "ui_videooverlay.h"

Edric Milaret's avatar
Edric Milaret committed
22 23
#include "contactpicker.h"

24
#include "callmodel.h"
Edric Milaret's avatar
Edric Milaret committed
25 26
#include "contactmethod.h"
#include "person.h"
27

28
VideoOverlay::VideoOverlay(QWidget* parent) :
29
    QWidget(parent),
30
    ui(new Ui::VideoOverlay),
Edric Milaret's avatar
Edric Milaret committed
31 32
    transferDialog_(new CallUtilsDialog()),
    qualityDialog_(new QualityDialog())
33 34 35
{
    ui->setupUi(this);

36 37
    ui->chatButton->setCheckable(true);

Edric Milaret's avatar
Edric Milaret committed
38
    actionModel_ = CallModel::instance().userActionModel();
39
    setAttribute(Qt::WA_NoSystemBackground);
40

41
    ui->noMicButton->setCheckable(true);
42

Edric Milaret's avatar
Edric Milaret committed
43 44 45 46 47
    QPixmap pixmap(":/images/video-conf/ic_high_quality_white.svg");
    QIcon qualityIcon(pixmap);
    ui->qualityButton->setIcon(qualityIcon);
    ui->qualityButton->setIconSize(pixmap.rect().size());

48 49 50 51 52
    connect(actionModel_,&UserActionModel::dataChanged, [=](const QModelIndex& tl, const QModelIndex& br) {
        const int first(tl.row()),last(br.row());
        for(int i = first; i <= last;i++) {
            const QModelIndex& idx = actionModel_->index(i,0);
            switch (idx.data(UserActionModel::Role::ACTION).value<UserActionModel::Action>()) {
53 54 55
            case UserActionModel::Action::MUTE_AUDIO:
                ui->noMicButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
                ui->noMicButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
56 57
                break;
            case UserActionModel::Action::MUTE_VIDEO:
58 59
                ui->noVideoButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
                ui->noVideoButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
60
                break;
61 62 63
            case UserActionModel::Action::HOLD:
                ui->holdButton->setChecked(idx.data(Qt::CheckStateRole).value<bool>());
                ui->holdButton->setEnabled(idx.flags() & Qt::ItemIsEnabled);
Edric Milaret's avatar
Edric Milaret committed
64
                ui->onHoldLabel->setVisible(idx.data(Qt::CheckStateRole).value<bool>());
65
                break;
66 67 68 69 70 71
            default:
                break;
            }
        }
    });

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    connect(CallModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex &current, const QModelIndex &previous) {
        Q_UNUSED(previous)
        Call* c = current.data(static_cast<int>(Call::Role::Object)).value<Call*>();
        if (c) {
            if (c->hasParentCall()) {
                ui->holdButton->hide();
                ui->transferButton->hide();
                ui->addPersonButton->hide();
                ui->chatButton->hide();

                ui->joinButton->show();
            } else {
                ui->holdButton->show();
                ui->transferButton->show();
                ui->addPersonButton->show();
                ui->chatButton->show();

                ui->joinButton->hide();
            }
Edric Milaret's avatar
Edric Milaret committed
91 92 93
            if (auto contactMethod =  c->peerContactMethod())
                ui->addToContactButton->setVisible(not contactMethod->contact()
                                                   || contactMethod->contact()->isPlaceHolder());
94 95
        }
    });
96 97 98 99 100
}

VideoOverlay::~VideoOverlay()
{
    delete ui;
101
    delete transferDialog_;
Edric Milaret's avatar
Edric Milaret committed
102
    delete qualityDialog_;
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
}

void
VideoOverlay::setName(const QString& name)
{
    ui->nameLabel->setText(name);
}

void
VideoOverlay::setTime(const QString& time)
{
    ui->timerLabel->setText(time);
}

void
VideoOverlay::on_hangupButton_clicked()
{
    actionModel_->execute(UserActionModel::Action::HANGUP);
121
    ui->chatButton->setChecked(false);
122 123 124 125 126
}

void
VideoOverlay::on_chatButton_toggled(bool checked)
{
127
    emit setChatVisibility(checked);
128 129
}

130
void
131
VideoOverlay::on_transferButton_clicked()
132
{
133
    transferDialog_->setConfMode(false);
134
    auto pos = this->mapToGlobal(ui->transferButton->pos());
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    transferDialog_->move(pos.x()
                          - transferDialog_->size().width()/2
                          + ui->transferButton->size().width()/2,
                          pos.y() - (transferDialog_->height()));
    transferDialog_->show();
}

void
VideoOverlay::on_addPersonButton_clicked()
{
    transferDialog_->setConfMode(true);
    auto pos = this->mapToGlobal(ui->addPersonButton->pos());
    transferDialog_->move(pos.x()
                          - transferDialog_->size().width()/2
                          + ui->addPersonButton->size().width()/2,
                          pos.y() - (transferDialog_->height()));
    transferDialog_->show();
}

void
VideoOverlay::on_holdButton_clicked()
{
    actionModel_->execute(UserActionModel::Action::HOLD);
}

160 161 162 163 164 165 166 167 168 169 170 171 172
void
VideoOverlay::on_noMicButton_clicked()
{
    actionModel_->execute(UserActionModel::Action::MUTE_AUDIO);
}

void
VideoOverlay::on_noVideoButton_clicked()
{
    actionModel_->execute(UserActionModel::Action::MUTE_VIDEO);
}


173 174 175
void VideoOverlay::on_joinButton_clicked()
{
    CallModel::instance().selectedCall()->joinToParent();
176
}
Edric Milaret's avatar
Edric Milaret committed
177 178 179 180 181 182 183 184 185 186 187

void
VideoOverlay::on_qualityButton_clicked()
{
    auto pos = this->mapToGlobal(ui->qualityButton->pos());
    qualityDialog_->move(pos.x()
              - qualityDialog_->size().width()/2
              + ui->qualityButton->size().width()/2,
              pos.y() - (qualityDialog_->height()));
    qualityDialog_->show();
}
Edric Milaret's avatar
Edric Milaret committed
188 189 190 191 192 193 194 195 196 197 198 199

void
VideoOverlay::on_addToContactButton_clicked()
{
    QPoint globalPos = mapToGlobal(ui->addToContactButton->pos());
    if (auto contactMethod = CallModel::instance().selectedCall()->peerContactMethod()) {
        ContactPicker contactPicker(contactMethod);
        contactPicker.move(globalPos.x(),
                           globalPos.y() + ui->addToContactButton->height());
        contactPicker.exec();
    }
}