diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index f47e8a8bd..3f9422d8f 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -25,6 +25,7 @@ #include "src/video/cameradevice.h" #include "src/video/videosurface.h" #include "src/widget/translator.h" +#include "src/widget/tool/screenshotgrabber.h" #include "src/core/core.h" #include "src/core/coreav.h" @@ -32,6 +33,7 @@ #include #include + #ifndef ALC_ALL_DEVICES_SPECIFIER #define ALC_ALL_DEVICES_SPECIFIER ALC_DEVICE_SPECIFIER #endif @@ -150,6 +152,25 @@ void AVForm::onVideoModesIndexChanged(int index) QString devName = videoDeviceList[devIndex].first; VideoMode mode = videoModes[index]; + if (CameraDevice::isScreen(devName) && !mode.height && !mode.width) + { + ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber(this); + + auto onGrabbed = [screenshotGrabber, devName, this] (QRect region) + { + VideoMode mode(region); + mode.width = mode.width / 2 * 2; + mode.height = mode.height / 2 * 2; + camera.open(devName, mode); + delete screenshotGrabber; + }; + + connect(screenshotGrabber, &ScreenshotGrabber::regionChosen, this, onGrabbed, Qt::QueuedConnection); + + screenshotGrabber->showGrabber(); + return; + } + Settings::getInstance().setCamVideoRes(mode.toRect()); Settings::getInstance().setCamVideoFPS(mode.FPS); camera.open(devName, mode); @@ -282,11 +303,15 @@ void AVForm::fillScreenModesComboBox() QString pixelFormat = CameraDevice::getPixelFormatString(mode.pixel_format); qDebug("%dx%d+%d,%d FPS: %f, pixel format: %s\n", mode.width, mode.height, mode.x, mode.y, mode.FPS, pixelFormat.toStdString().c_str()); - QString name = QString("Screen %1").arg(i + 1); + QString name; + if (mode.width && mode.height) + name = QString("Screen %1").arg(i + 1); + else + name = tr("Select region"); + bodyUI->videoModescomboBox->addItem(name); } - bodyUI->videoModescomboBox->addItem(tr("Select region")); bodyUI->videoModescomboBox->blockSignals(previouslyBlocked); } @@ -303,6 +328,8 @@ void AVForm::updateVideoModes(int curIndex) qDebug("available Modes:"); if (CameraDevice::isScreen(devName)) { + // Add extra video mode to region selection + allVideoModes.push_back(VideoMode()); videoModes = allVideoModes; fillScreenModesComboBox(); } diff --git a/src/widget/tool/screenshotgrabber.cpp b/src/widget/tool/screenshotgrabber.cpp index 22b26329a..56e16901f 100644 --- a/src/widget/tool/screenshotgrabber.cpp +++ b/src/widget/tool/screenshotgrabber.cpp @@ -131,6 +131,7 @@ void ScreenshotGrabber::acceptRegion() if (rect.width() < 1 || rect.height() < 1) return; + emit regionChosen(rect); qDebug() << "Screenshot accepted, chosen region" << rect; emit screenshotTaken(this->screenGrab.copy(rect)); this->window->close(); diff --git a/src/widget/tool/screenshotgrabber.h b/src/widget/tool/screenshotgrabber.h index 0a0a36b62..e983aba13 100644 --- a/src/widget/tool/screenshotgrabber.h +++ b/src/widget/tool/screenshotgrabber.h @@ -52,6 +52,7 @@ public slots: signals: void screenshotTaken(const QPixmap &pixmap); + void regionChosen(QRect region); void rejected(); private: