Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Anthony LĂ©onard | 2fde81d | 2017-04-17 10:06:55 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015-2017 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 "videoview.h" |
| 20 | #include "ui_videoview.h" |
| 21 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 22 | #include "utils.h" |
| 23 | #include "lrcinstance.h" |
| 24 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 25 | #include <QGraphicsOpacityEffect> |
| 26 | #include <QPropertyAnimation> |
| 27 | #include <QDesktopWidget> |
| 28 | #include <QMenu> |
Edric Milaret | 303bbf1 | 2015-06-22 14:24:13 -0400 | [diff] [blame] | 29 | #include <QFileDialog> |
| 30 | #include <QMimeData> |
Nicolas Jager | e085451 | 2016-02-29 12:08:10 -0500 | [diff] [blame] | 31 | #include <QSplitter> |
Edric | b09982a | 2016-05-19 16:28:38 -0400 | [diff] [blame] | 32 | #include <QScreen> |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 33 | |
| 34 | #include <memory> |
| 35 | |
| 36 | #include "videooverlay.h" |
| 37 | #include "selectareadialog.h" |
| 38 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 39 | VideoView::VideoView(QWidget* parent) : |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 40 | QWidget(parent), |
| 41 | ui(new Ui::VideoView) |
| 42 | { |
| 43 | ui->setupUi(this); |
| 44 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 45 | overlay_ = new VideoOverlay(this); |
| 46 | auto effect = new QGraphicsOpacityEffect(overlay_); |
Andreas Traczyk | 8d5e549 | 2018-08-09 15:41:52 -0400 | [diff] [blame] | 47 | effect->setOpacity(maxOverlayOpacity_); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 48 | overlay_->setGraphicsEffect(effect); |
| 49 | fadeAnim_ = new QPropertyAnimation(this); |
| 50 | fadeAnim_->setTargetObject(effect); |
| 51 | fadeAnim_->setPropertyName("opacity"); |
| 52 | fadeAnim_->setDuration(fadeOverlayTime_); |
| 53 | fadeAnim_->setStartValue(effect->opacity()); |
| 54 | fadeAnim_->setEndValue(0); |
| 55 | fadeAnim_->setEasingCurve(QEasingCurve::OutQuad); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 56 | |
Andreas Traczyk | ca320d8 | 2018-08-09 18:02:07 -0400 | [diff] [blame] | 57 | // Setup the timer to start the fade when the mouse stops moving |
| 58 | this->setMouseTracking(true); |
| 59 | overlay_->setMouseTracking(true); |
| 60 | fadeTimer_.setSingleShot(true); |
| 61 | connect(&fadeTimer_, SIGNAL(timeout()), this, SLOT(fadeOverlayOut())); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 62 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 63 | this->setContextMenuPolicy(Qt::CustomContextMenu); |
| 64 | connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), |
| 65 | this, SLOT(showContextMenu(const QPoint&))); |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 66 | connect(overlay_, &VideoOverlay::setChatVisibility, [=](bool visible) { |
| 67 | emit this->setChatVisibility(visible); |
| 68 | }); |
Olivier SOLDANO | 2bcdfd7 | 2017-05-02 14:37:19 -0400 | [diff] [blame] | 69 | connect(overlay_, &VideoOverlay::videoCfgBtnClicked, [=](){emit videoSettingsClicked();}); |
Isa Nanic | ca027ab | 2018-12-19 16:54:05 -0500 | [diff] [blame] | 70 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | VideoView::~VideoView() |
| 74 | { |
| 75 | delete ui; |
Edric Milaret | 01f2384 | 2015-06-22 14:46:01 -0400 | [diff] [blame] | 76 | delete overlay_; |
Edric Milaret | 01f2384 | 2015-06-22 14:46:01 -0400 | [diff] [blame] | 77 | delete fadeAnim_; |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 81 | VideoView::resizeEvent(QResizeEvent* event) |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 82 | { |
Nicolas Jager | c7b8e4b | 2016-02-29 09:20:40 -0500 | [diff] [blame] | 83 | QRect& previewRect = ui->videoWidget->getPreviewRect(); |
| 84 | int deltaW = event->size().width() - event->oldSize().width(); |
| 85 | int deltaH = event->size().height() - event->oldSize().height(); |
| 86 | |
| 87 | QPoint previewCenter = ui->videoWidget->getPreviewRect().center(); |
Edric | b09982a | 2016-05-19 16:28:38 -0400 | [diff] [blame] | 88 | int cx = (event->oldSize().width()) / 2; |
| 89 | int cy = (event->oldSize().height()) / 2; |
Nicolas Jager | c7b8e4b | 2016-02-29 09:20:40 -0500 | [diff] [blame] | 90 | QPoint center = QPoint(cx, cy); |
| 91 | |
| 92 | // first we check if we want to displace the preview |
| 93 | if (previewRect.x() + deltaW > 0 && previewRect.y() + deltaH > 0) { |
| 94 | // then we check which way |
| 95 | if (center.x() - previewCenter.x() < 0 && center.y() - previewCenter.y() < 0) |
| 96 | ui->videoWidget->getPreviewRect().translate(deltaW, deltaH); |
| 97 | else if (center.x() - previewCenter.x() > 0 && center.y() - previewCenter.y() < 0) |
| 98 | ui->videoWidget->getPreviewRect().translate(0, deltaH); |
| 99 | else if (center.x() - previewCenter.x() < 0 && center.y() - previewCenter.y() > 0) |
| 100 | ui->videoWidget->getPreviewRect().translate(deltaW, 0); |
| 101 | } |
| 102 | |
| 103 | if (previewRect.left() <= 0) |
| 104 | previewRect.moveLeft(1); |
| 105 | |
| 106 | if (previewRect.right() >= width()) |
| 107 | previewRect.moveRight(width() - 1); |
| 108 | |
| 109 | if (previewRect.top() <= 0) |
| 110 | previewRect.moveTop(1); |
| 111 | |
| 112 | if (previewRect.bottom() >= height()) |
| 113 | previewRect.moveBottom(height() - 1); |
| 114 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 115 | overlay_->resize(this->size()); |
| 116 | overlay_->show(); |
| 117 | overlay_->raise(); |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | VideoView::enterEvent(QEvent* event) |
| 122 | { |
| 123 | Q_UNUSED(event) |
Andreas Traczyk | ca320d8 | 2018-08-09 18:02:07 -0400 | [diff] [blame] | 124 | showOverlay(); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void |
| 128 | VideoView::leaveEvent(QEvent* event) |
| 129 | { |
| 130 | Q_UNUSED(event) |
Andreas Traczyk | ca320d8 | 2018-08-09 18:02:07 -0400 | [diff] [blame] | 131 | fadeOverlayOut(); |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | VideoView::showOverlay() |
| 136 | { |
| 137 | fadeAnim_->stop(); |
| 138 | fadeAnim_->targetObject()->setProperty(fadeAnim_->propertyName(), fadeAnim_->startValue()); |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | VideoView::fadeOverlayOut() |
| 143 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 144 | if (!overlay_->isDialogVisible() && !overlay_->shouldShowOverlay()) { |
Nicolas Jager | 0a9fc60 | 2016-03-11 18:35:42 -0500 | [diff] [blame] | 145 | fadeAnim_->start(QAbstractAnimation::KeepWhenStopped); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 146 | } |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void |
Andreas Traczyk | 7cc79c0 | 2019-01-18 12:48:16 -0500 | [diff] [blame^] | 150 | VideoView::slotCallStatusChanged(const std::string& callId) |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 151 | { |
Andreas Traczyk | 7cc79c0 | 2019-01-18 12:48:16 -0500 | [diff] [blame^] | 152 | using namespace lrc::api::call; |
| 153 | auto call = LRCInstance::getCurrentCallModel()->getCall(callId); |
| 154 | switch (call.status) { |
| 155 | case Status::IN_PROGRESS: |
| 156 | { |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 157 | ui->videoWidget->show(); |
Andreas Traczyk | 7cc79c0 | 2019-01-18 12:48:16 -0500 | [diff] [blame^] | 158 | auto convInfo = Utils::getConversationFromCallId(call.id); |
| 159 | if (!convInfo.uid.empty()) { |
| 160 | auto contactInfo = LRCInstance::getCurrentAccountInfo().contactModel->getContact(convInfo.participants[0]); |
| 161 | auto contactName = Utils::bestNameForContact(contactInfo); |
| 162 | overlay_->setName(QString::fromStdString(contactName)); |
SĂ©bastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 163 | } |
Andreas Traczyk | 7cc79c0 | 2019-01-18 12:48:16 -0500 | [diff] [blame^] | 164 | return; |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 165 | } |
Andreas Traczyk | 7cc79c0 | 2019-01-18 12:48:16 -0500 | [diff] [blame^] | 166 | default: |
| 167 | emit closing(call.id); |
| 168 | break; |
| 169 | } |
| 170 | QObject::disconnect(timerConnection_); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void |
SĂ©bastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 174 | VideoView::showChatviewIfToggled() |
| 175 | { |
| 176 | emit setChatVisibility(overlay_->getShowChatView()); |
| 177 | } |
| 178 | |
| 179 | void |
Andreas Traczyk | 4b4bfde | 2018-12-19 09:53:22 -0500 | [diff] [blame] | 180 | VideoView::simulateShowChatview(bool checked) |
| 181 | { |
Andreas Traczyk | 14c3e86 | 2018-12-26 14:02:30 -0500 | [diff] [blame] | 182 | Q_UNUSED(checked); |
Andreas Traczyk | 4b4bfde | 2018-12-19 09:53:22 -0500 | [diff] [blame] | 183 | overlay_->simulateShowChatview(true); |
| 184 | } |
| 185 | |
| 186 | void |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 187 | VideoView::mouseDoubleClickEvent(QMouseEvent* e) { |
| 188 | QWidget::mouseDoubleClickEvent(e); |
| 189 | toggleFullScreen(); |
| 190 | } |
| 191 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 192 | void |
| 193 | VideoView::dragEnterEvent(QDragEnterEvent* event) |
Edric Milaret | 303bbf1 | 2015-06-22 14:24:13 -0400 | [diff] [blame] | 194 | { |
| 195 | if (event->mimeData()->hasUrls()) |
| 196 | event->acceptProposedAction(); |
| 197 | } |
| 198 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 199 | void |
| 200 | VideoView::dropEvent(QDropEvent* event) |
Edric Milaret | 303bbf1 | 2015-06-22 14:24:13 -0400 | [diff] [blame] | 201 | { |
| 202 | auto urls = event->mimeData()->urls(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 203 | auto selectedConvUid = LRCInstance::getSelectedConvUid(); |
| 204 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 205 | auto conversation = Utils::getConversationFromUid(selectedConvUid, *convModel); |
| 206 | auto callList = CallModel::instance().getActiveCalls(); |
| 207 | Call* thisCall = nullptr; |
| 208 | for (auto call : callList) { |
| 209 | if (call->historyId() == QString::fromStdString(conversation->callId)) { |
| 210 | thisCall = call; |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | if (thisCall) { |
| 215 | if (auto outVideo = thisCall->firstMedia<media::Video>(media::Media::Direction::OUT)) { |
Edric Milaret | 0e1074d | 2015-12-08 12:08:52 -0500 | [diff] [blame] | 216 | outVideo->sourceModel()->setFile(urls.at(0)); |
| 217 | } |
| 218 | } |
Edric Milaret | 303bbf1 | 2015-06-22 14:24:13 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 221 | void |
| 222 | VideoView::toggleFullScreen() |
| 223 | { |
SĂ©bastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 224 | emit toggleFullScreenClicked(); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void |
| 228 | VideoView::showContextMenu(const QPoint& pos) |
| 229 | { |
| 230 | QPoint globalPos = this->mapToGlobal(pos); |
| 231 | |
| 232 | QMenu menu; |
Andreas Traczyk | e86fb3c | 2018-08-02 17:38:34 -0400 | [diff] [blame] | 233 | media::Video* outVideo = nullptr; |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 234 | int activeIndex = -1; |
| 235 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 236 | auto selectedConvUid = LRCInstance::getSelectedConvUid(); |
| 237 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 238 | auto conversation = Utils::getConversationFromUid(selectedConvUid, *convModel); |
| 239 | auto callList = CallModel::instance().getActiveCalls(); |
| 240 | Call* thisCall = nullptr; |
| 241 | for (auto call : callList) { |
| 242 | if (call->historyId() == QString::fromStdString(conversation->callId)) { |
| 243 | thisCall = call; |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | if (thisCall) { |
| 248 | outVideo = thisCall->firstMedia<media::Video>(media::Media::Direction::OUT); |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 249 | if (outVideo) |
| 250 | activeIndex = outVideo->sourceModel()->activeIndex(); |
| 251 | } |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 252 | |
Edric Milaret | a3e4728 | 2015-10-23 15:20:30 -0400 | [diff] [blame] | 253 | for (auto device : Video::DeviceModel::instance().devices()) { |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 254 | std::unique_ptr<QAction> deviceAction(new QAction(device->name(), this)); |
| 255 | deviceAction->setCheckable(true); |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 256 | if (outVideo) |
| 257 | if (outVideo->sourceModel()->getDeviceIndex(device) == activeIndex) |
| 258 | deviceAction->setChecked(true); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 259 | auto ptr = deviceAction.release(); |
| 260 | menu.addAction(ptr); |
| 261 | connect(ptr, &QAction::toggled, [=](bool checked) { |
| 262 | if (checked == true) { |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 263 | if (outVideo) |
| 264 | outVideo->sourceModel()->switchTo(device); |
Edric Milaret | a3e4728 | 2015-10-23 15:20:30 -0400 | [diff] [blame] | 265 | Video::DeviceModel::instance().setActive(device); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 266 | } |
| 267 | }); |
| 268 | } |
| 269 | |
| 270 | menu.addSeparator(); |
| 271 | |
Edric Milaret | 53ac6e5 | 2015-09-14 13:37:06 -0400 | [diff] [blame] | 272 | auto shareAction = new QAction(tr("Share entire screen"), this); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 273 | menu.addAction(shareAction); |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 274 | shareAction->setCheckable(true); |
Edric Milaret | 53ac6e5 | 2015-09-14 13:37:06 -0400 | [diff] [blame] | 275 | auto shareAreaAction = new QAction(tr("Share screen area"), this); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 276 | menu.addAction(shareAreaAction); |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 277 | shareAreaAction->setCheckable(true); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 278 | connect(shareAreaAction, &QAction::triggered, [=]() { |
| 279 | SelectAreaDialog selec; |
| 280 | selec.exec(); |
| 281 | }); |
Edric Milaret | 53ac6e5 | 2015-09-14 13:37:06 -0400 | [diff] [blame] | 282 | auto shareFileAction = new QAction(tr("Share file"), this); |
Edric Milaret | 303bbf1 | 2015-06-22 14:24:13 -0400 | [diff] [blame] | 283 | menu.addAction(shareFileAction); |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 284 | shareFileAction->setCheckable(true); |
| 285 | |
| 286 | switch(activeIndex) { |
| 287 | |
| 288 | case Video::SourceModel::ExtendedDeviceList::SCREEN: |
| 289 | shareAction->setChecked(true); |
| 290 | break; |
| 291 | case Video::SourceModel::ExtendedDeviceList::FILE: |
| 292 | shareFileAction->setChecked(true); |
| 293 | break; |
| 294 | |
| 295 | } |
| 296 | |
| 297 | connect(shareAction, &QAction::triggered, [=]() { |
Edric | b09982a | 2016-05-19 16:28:38 -0400 | [diff] [blame] | 298 | if (outVideo) { |
| 299 | auto realRect = QApplication::desktop()->geometry(); |
| 300 | realRect.setWidth(static_cast<int>(realRect.width() * QApplication::primaryScreen()->devicePixelRatio())); |
| 301 | realRect.setHeight(static_cast<int>(realRect.height() * QApplication::primaryScreen()->devicePixelRatio())); |
| 302 | outVideo->sourceModel()->setDisplay(0, realRect); |
| 303 | } |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 304 | }); |
Edric Milaret | 303bbf1 | 2015-06-22 14:24:13 -0400 | [diff] [blame] | 305 | connect(shareFileAction, &QAction::triggered, [=]() { |
| 306 | QFileDialog dialog(this); |
| 307 | dialog.setFileMode(QFileDialog::AnyFile); |
| 308 | QStringList fileNames; |
| 309 | if (!dialog.exec()) |
| 310 | return; |
| 311 | fileNames = dialog.selectedFiles(); |
Edric Milaret | c4b1a10 | 2016-02-02 11:48:30 -0500 | [diff] [blame] | 312 | if (outVideo) |
| 313 | outVideo->sourceModel()->setFile(QUrl::fromLocalFile(fileNames.at(0))); |
Edric Milaret | 303bbf1 | 2015-06-22 14:24:13 -0400 | [diff] [blame] | 314 | }); |
Edric Milaret | 029b95a | 2015-06-09 09:51:44 -0400 | [diff] [blame] | 315 | |
| 316 | menu.exec(globalPos); |
| 317 | } |
| 318 | |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 319 | void |
Andreas Traczyk | a493d5b | 2019-01-09 20:14:29 -0500 | [diff] [blame] | 320 | VideoView::pushRenderer(const std::string& callId) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 321 | auto callModel = LRCInstance::getCurrentCallModel(); |
| 322 | |
| 323 | QObject::disconnect(videoStartedConnection_); |
Andreas Traczyk | 7cc79c0 | 2019-01-18 12:48:16 -0500 | [diff] [blame^] | 324 | QObject::disconnect(callStatusChangedConnection_); |
| 325 | |
Andreas Traczyk | a493d5b | 2019-01-09 20:14:29 -0500 | [diff] [blame] | 326 | if (!callModel->hasCall(callId)) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 327 | return; |
| 328 | } |
| 329 | |
Andreas Traczyk | a493d5b | 2019-01-09 20:14:29 -0500 | [diff] [blame] | 330 | auto call = callModel->getCall(callId); |
| 331 | |
| 332 | this->overlay_->callStarted(callId); |
| 333 | this->overlay_->setVideoMuteVisibility(!LRCInstance::getCurrentCallModel()->getCall(callId).isAudioOnly); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 334 | |
Andreas Traczyk | 7cc79c0 | 2019-01-18 12:48:16 -0500 | [diff] [blame^] | 335 | callStatusChangedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::callStatusChanged, |
| 336 | this, &VideoView::slotCallStatusChanged); |
| 337 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 338 | videoStartedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::remotePreviewStarted, |
| 339 | [this](const std::string& callId, Video::Renderer* renderer) { |
| 340 | Q_UNUSED(callId); |
| 341 | slotVideoStarted(renderer); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 342 | }); |
| 343 | ui->videoWidget->setPreviewDisplay(call.type != lrc::api::call::Type::CONFERENCE); |
| 344 | } |
| 345 | |
| 346 | void |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 347 | VideoView::slotVideoStarted(Video::Renderer* renderer) { |
| 348 | ui->videoWidget->show(); |
| 349 | ui->videoWidget->setDistantRenderer(renderer); |
| 350 | } |
Nicolas Jager | c7b8e4b | 2016-02-29 09:20:40 -0500 | [diff] [blame] | 351 | |
| 352 | void |
| 353 | VideoView::mousePressEvent(QMouseEvent* event) |
| 354 | { |
| 355 | QPoint clickPosition = event->pos(); |
| 356 | if (ui->videoWidget->getPreviewRect().contains(clickPosition)) { |
| 357 | QLine distance = QLine(clickPosition, ui->videoWidget->getPreviewRect().bottomRight()); |
| 358 | if (distance.dy() < resizeGrip_ and distance.dx() < resizeGrip_) { |
| 359 | QApplication::setOverrideCursor(Qt::SizeFDiagCursor); |
| 360 | resizingPreview_ = true; |
| 361 | } else { |
| 362 | originMouseDisplacement_ = event->pos() - ui->videoWidget->getPreviewRect().topLeft(); |
| 363 | QApplication::setOverrideCursor(Qt::SizeAllCursor); |
| 364 | draggingPreview_ = true; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | void |
| 370 | VideoView::mouseReleaseEvent(QMouseEvent* event) |
| 371 | { |
Edric Milaret | 6a785af | 2016-03-07 15:39:30 -0500 | [diff] [blame] | 372 | Q_UNUSED(event) |
| 373 | |
Nicolas Jager | c7b8e4b | 2016-02-29 09:20:40 -0500 | [diff] [blame] | 374 | draggingPreview_ = false; |
| 375 | resizingPreview_ = false; |
| 376 | QApplication::setOverrideCursor(Qt::ArrowCursor); |
| 377 | } |
| 378 | |
| 379 | void |
| 380 | VideoView::mouseMoveEvent(QMouseEvent* event) |
| 381 | { |
Andreas Traczyk | ca320d8 | 2018-08-09 18:02:07 -0400 | [diff] [blame] | 382 | // start/restart the timer after which the overlay will fade |
| 383 | if (fadeTimer_.isActive()) { |
| 384 | showOverlay(); |
| 385 | } else { |
| 386 | fadeTimer_.start(startfadeOverlayTime_); |
| 387 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 388 | |
Nicolas Jager | c7b8e4b | 2016-02-29 09:20:40 -0500 | [diff] [blame] | 389 | QRect& previewRect = ui->videoWidget->getPreviewRect(); |
| 390 | if (draggingPreview_) { |
| 391 | if (previewRect.left() > 0 |
| 392 | && previewRect.top() > 0 |
| 393 | && previewRect.right() < width() |
| 394 | && previewRect.bottom() < height()) { |
| 395 | |
| 396 | previewRect.moveTo(event->pos() - originMouseDisplacement_); |
| 397 | if (previewRect.left() <= 0) |
| 398 | previewRect.moveLeft(1); |
| 399 | |
| 400 | if (previewRect.right() >= width()) |
| 401 | previewRect.moveRight(width() - 1); |
| 402 | |
| 403 | if (previewRect.top() <= 0) |
| 404 | previewRect.moveTop(1); |
| 405 | |
| 406 | if (previewRect.bottom() >= height()) |
| 407 | previewRect.moveBottom(height() - 1); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | QLine distance = QLine(previewRect.topLeft(), event->pos()); |
| 412 | |
| 413 | if (resizingPreview_ |
| 414 | and distance.dx() > minimalSize_ |
| 415 | and distance.dy() > minimalSize_ |
| 416 | and geometry().contains(event->pos())) |
| 417 | previewRect.setBottomRight(event->pos()); |
| 418 | } |