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