Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(avform, screenshotgrabber): Added custom screen region selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Diadlo committed Jun 25, 2016
1 parent d781a4f commit 9cfd678
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
#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"

#include <QDebug>
#include <QShowEvent>
#include <map>


#ifndef ALC_ALL_DEVICES_SPECIFIER
#define ALC_ALL_DEVICES_SPECIFIER ALC_DEVICE_SPECIFIER
#endif
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/widget/tool/screenshotgrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/widget/tool/screenshotgrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public slots:

signals:
void screenshotTaken(const QPixmap &pixmap);
void regionChosen(QRect region);
void rejected();

private:
Expand Down

0 comments on commit 9cfd678

Please sign in to comment.