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