Skip to content
Snippets Groups Projects
Commit c4b1a103 authored by Edric Milaret's avatar Edric Milaret Committed by gerrit2
Browse files

videoview: fix selection of source

ALso litle code refactoring

Change-Id: I01de12122a7c4b6bb980031033329528c5ea6426
Tuleap: #317
parent 6b68a489
No related branches found
No related tags found
No related merge requests found
...@@ -168,21 +168,27 @@ VideoView::showContextMenu(const QPoint& pos) ...@@ -168,21 +168,27 @@ VideoView::showContextMenu(const QPoint& pos)
QPoint globalPos = this->mapToGlobal(pos); QPoint globalPos = this->mapToGlobal(pos);
QMenu menu; QMenu menu;
Media::Video* outVideo = nullptr;
int activeIndex = -1;
if (auto call = CallModel::instance().selectedCall()) {
outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT);
if (outVideo)
activeIndex = outVideo->sourceModel()->activeIndex();
}
for (auto device : Video::DeviceModel::instance().devices()) { for (auto device : Video::DeviceModel::instance().devices()) {
std::unique_ptr<QAction> deviceAction(new QAction(device->name(), this)); std::unique_ptr<QAction> deviceAction(new QAction(device->name(), this));
deviceAction->setCheckable(true); deviceAction->setCheckable(true);
if (device == Video::DeviceModel::instance().activeDevice()) if (outVideo)
if (outVideo->sourceModel()->getDeviceIndex(device) == activeIndex)
deviceAction->setChecked(true); deviceAction->setChecked(true);
auto ptr = deviceAction.release(); auto ptr = deviceAction.release();
menu.addAction(ptr); menu.addAction(ptr);
connect(ptr, &QAction::toggled, [=](bool checked) { connect(ptr, &QAction::toggled, [=](bool checked) {
if (checked == true) { if (checked == true) {
if (auto call = CallModel::instance().selectedCall()) { if (outVideo)
if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
outVideo->sourceModel()->switchTo(device); outVideo->sourceModel()->switchTo(device);
}
}
Video::DeviceModel::instance().setActive(device); Video::DeviceModel::instance().setActive(device);
} }
}); });
...@@ -192,21 +198,33 @@ VideoView::showContextMenu(const QPoint& pos) ...@@ -192,21 +198,33 @@ VideoView::showContextMenu(const QPoint& pos)
auto shareAction = new QAction(tr("Share entire screen"), this); auto shareAction = new QAction(tr("Share entire screen"), this);
menu.addAction(shareAction); menu.addAction(shareAction);
connect(shareAction, &QAction::triggered, [=]() { shareAction->setCheckable(true);
if (auto call = CallModel::instance().selectedCall()) {
if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
outVideo->sourceModel()->setDisplay(0, QApplication::desktop()->rect());
}
}
});
auto shareAreaAction = new QAction(tr("Share screen area"), this); auto shareAreaAction = new QAction(tr("Share screen area"), this);
menu.addAction(shareAreaAction); menu.addAction(shareAreaAction);
shareAreaAction->setCheckable(true);
connect(shareAreaAction, &QAction::triggered, [=]() { connect(shareAreaAction, &QAction::triggered, [=]() {
SelectAreaDialog selec; SelectAreaDialog selec;
selec.exec(); selec.exec();
}); });
auto shareFileAction = new QAction(tr("Share file"), this); auto shareFileAction = new QAction(tr("Share file"), this);
menu.addAction(shareFileAction); menu.addAction(shareFileAction);
shareFileAction->setCheckable(true);
switch(activeIndex) {
case Video::SourceModel::ExtendedDeviceList::SCREEN:
shareAction->setChecked(true);
break;
case Video::SourceModel::ExtendedDeviceList::FILE:
shareFileAction->setChecked(true);
break;
}
connect(shareAction, &QAction::triggered, [=]() {
if (outVideo)
outVideo->sourceModel()->setDisplay(0, QApplication::desktop()->rect());
});
connect(shareFileAction, &QAction::triggered, [=]() { connect(shareFileAction, &QAction::triggered, [=]() {
QFileDialog dialog(this); QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::AnyFile); dialog.setFileMode(QFileDialog::AnyFile);
...@@ -214,11 +232,8 @@ VideoView::showContextMenu(const QPoint& pos) ...@@ -214,11 +232,8 @@ VideoView::showContextMenu(const QPoint& pos)
if (!dialog.exec()) if (!dialog.exec())
return; return;
fileNames = dialog.selectedFiles(); fileNames = dialog.selectedFiles();
if (auto call = CallModel::instance().selectedCall()) { if (outVideo)
if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
outVideo->sourceModel()->setFile(QUrl::fromLocalFile(fileNames.at(0))); outVideo->sourceModel()->setFile(QUrl::fromLocalFile(fileNames.at(0)));
}
}
}); });
menu.exec(globalPos); menu.exec(globalPos);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment