mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(avform, screenshotgrabber): Added custom screen region selection
This commit is contained in:
parent
d781a4f762
commit
9cfd678c26
|
@ -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 <QShowEvent>
|
||||
#include <map>
|
||||
|
||||
|
||||
#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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -52,6 +52,7 @@ public slots:
|
|||
|
||||
signals:
|
||||
void screenshotTaken(const QPixmap &pixmap);
|
||||
void regionChosen(QRect region);
|
||||
void rejected();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue
Block a user