Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 1 | /*************************************************************************** |
Anthony LĂ©onard | 2fde81d | 2017-04-17 10:06:55 -0400 | [diff] [blame] | 2 | * Copyright (C) 2017 by Savoir-faire Linux * |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* |
| 4 | * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 3 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 18 | **************************************************************************/ |
| 19 | |
| 20 | #include "qualitydialog.h" |
| 21 | #include "ui_qualitydialog.h" |
| 22 | |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 23 | #include <QSortFilterProxyModel> |
| 24 | #include <QBitmap> |
| 25 | #include <QPropertyAnimation> |
| 26 | #include <QGraphicsOpacityEffect> |
| 27 | |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 28 | #include "callmodel.h" |
| 29 | #include "account.h" |
Edric Milaret | e82782e | 2016-03-21 12:14:17 -0400 | [diff] [blame] | 30 | #include "codecmodel.h" |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 31 | |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 32 | QualityDialog::QualityDialog(QWidget *parent) : |
| 33 | QDialog(parent), |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 34 | ui(new Ui::QualityDialog), |
| 35 | spikeMask_(new QPixmap(":/images/spikeMask.png")) |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 36 | { |
| 37 | ui->setupUi(this); |
| 38 | |
| 39 | this->setWindowFlags(Qt::CustomizeWindowHint); |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 40 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup | Qt::NoDropShadowWindowHint); |
| 41 | |
| 42 | ui->spike->setMask(spikeMask_->mask()); |
| 43 | |
| 44 | effect_ = new QGraphicsOpacityEffect(this); |
| 45 | effect_->setOpacity(1.0); |
| 46 | setGraphicsEffect(effect_); |
| 47 | fadeAnim_ = new QPropertyAnimation(effect_, "opacity"); |
| 48 | fadeAnim_->setDuration(fadeOverlayTime_); |
| 49 | fadeAnim_->setStartValue(0.0); |
| 50 | fadeAnim_->setEndValue(1.0); |
| 51 | fadeAnim_->setEasingCurve(QEasingCurve::InExpo); |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | QualityDialog::~QualityDialog() |
| 55 | { |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 56 | delete effect_; |
| 57 | delete spikeMask_; |
| 58 | delete fadeAnim_; |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 59 | delete ui; |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | QualityDialog::on_autoCheckBox_toggled(bool checked) |
| 64 | { |
| 65 | setQuality(); |
| 66 | ui->qualitySlider->setEnabled(not checked); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | void |
| 71 | QualityDialog::on_qualitySlider_sliderReleased() |
| 72 | { |
| 73 | setQuality(); |
| 74 | } |
| 75 | |
| 76 | void QualityDialog::showEvent(QShowEvent* event) { |
| 77 | QWidget::showEvent(event); |
| 78 | ui->autoCheckBox->blockSignals(true); |
| 79 | const auto& call = CallModel::instance().selectedCall(); |
| 80 | if (const auto& codecModel = call->account()->codecModel()) { |
| 81 | const auto& videoCodecs = codecModel->videoCodecs(); |
| 82 | if (videoCodecs->rowCount() > 0) { |
| 83 | /* we only need to check the first codec since by default it is ON for all, and the |
| 84 | * client sets its ON or OFF for all codecs as well */ |
| 85 | const auto& idx = videoCodecs->index(0,0); |
| 86 | auto auto_quality_enabled = idx.data(static_cast<int>(CodecModel::Role::AUTO_QUALITY_ENABLED)).toString() == "true"; |
| 87 | ui->autoCheckBox->setChecked(auto_quality_enabled); |
| 88 | ui->qualitySlider->setEnabled(not auto_quality_enabled); |
| 89 | |
| 90 | // TODO: save the manual quality setting in the client and set the slider to that value here; |
| 91 | // the daemon resets the bitrate/quality between each call, and the default may be |
| 92 | // different for each codec, so there is no reason to check it here |
| 93 | } |
| 94 | } |
| 95 | ui->autoCheckBox->blockSignals(false); |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 96 | |
| 97 | emit(isVisible(true)); |
| 98 | |
| 99 | fadeAnim_->setDirection(QAbstractAnimation::Forward); |
| 100 | fadeAnim_->start(); |
| 101 | } |
| 102 | |
| 103 | void |
| 104 | QualityDialog::closeEvent(QCloseEvent* event) |
| 105 | { |
| 106 | Q_UNUSED(event) |
| 107 | emit(isVisible(false)); |
Edric Milaret | 864a205 | 2016-01-14 15:45:03 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void |
| 111 | QualityDialog::setQuality() |
| 112 | { |
| 113 | /* set auto quality true or false, also set the bitrate and quality values; |
| 114 | * the slider is from 0 to 100, use the min and max vals to scale each value accordingly */ |
| 115 | const auto& call = CallModel::instance().selectedCall(); |
| 116 | if (const auto& codecModel = call->account()->codecModel()) { |
| 117 | const auto& videoCodecs = codecModel->videoCodecs(); |
| 118 | |
| 119 | for (int i=0; i < videoCodecs->rowCount();i++) { |
| 120 | const auto& idx = videoCodecs->index(i,0); |
| 121 | |
| 122 | if (ui->autoCheckBox->isChecked()) { |
| 123 | videoCodecs->setData(idx, "true", CodecModel::Role::AUTO_QUALITY_ENABLED); |
| 124 | } else { |
| 125 | auto min_bitrate = idx.data(static_cast<int>(CodecModel::Role::MIN_BITRATE)).toInt(); |
| 126 | auto max_bitrate = idx.data(static_cast<int>(CodecModel::Role::MAX_BITRATE)).toInt(); |
| 127 | auto min_quality = idx.data(static_cast<int>(CodecModel::Role::MIN_QUALITY)).toInt(); |
| 128 | auto max_quality = idx.data(static_cast<int>(CodecModel::Role::MAX_QUALITY)).toInt(); |
| 129 | |
| 130 | double bitrate; |
| 131 | bitrate = min_bitrate + (double)(max_bitrate - min_bitrate)*(ui->qualitySlider->value()/100.0); |
| 132 | if (bitrate < 0) bitrate = 0; |
| 133 | |
| 134 | double quality; |
| 135 | // note: a lower value means higher quality |
| 136 | quality = (double)min_quality - (min_quality - max_quality)*(ui->qualitySlider->value()/100.0); |
| 137 | if (quality < 0) quality = 0; |
| 138 | |
| 139 | videoCodecs->setData(idx, "false", CodecModel::Role::AUTO_QUALITY_ENABLED); |
| 140 | videoCodecs->setData(idx, QString::number((int)bitrate), CodecModel::Role::BITRATE); |
| 141 | videoCodecs->setData(idx, QString::number((int)quality), CodecModel::Role::QUALITY); |
| 142 | } |
| 143 | } |
| 144 | codecModel << CodecModel::EditAction::SAVE; |
| 145 | } |
| 146 | } |