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