mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(avform): Added restoring selected region
This commit is contained in:
parent
1ddc1371a0
commit
1c5158213d
|
@ -243,6 +243,8 @@ void Settings::loadGlobal()
|
|||
s.beginGroup("Video");
|
||||
videoDev = s.value("videoDev", "").toString();
|
||||
camVideoRes = s.value("camVideoRes", QRect()).toRect();
|
||||
screenRegion = s.value("screenRegion", QRect()).toRect();
|
||||
screenGrabbed = s.value("screenGrabbed", false).toBool();
|
||||
camVideoFPS = s.value("camVideoFPS", 0).toUInt();
|
||||
s.endGroup();
|
||||
|
||||
|
@ -472,8 +474,10 @@ void Settings::saveGlobal()
|
|||
|
||||
s.beginGroup("Video");
|
||||
s.setValue("videoDev", videoDev);
|
||||
s.setValue("camVideoRes",camVideoRes);
|
||||
s.setValue("camVideoFPS",camVideoFPS);
|
||||
s.setValue("camVideoRes", camVideoRes);
|
||||
s.setValue("camVideoFPS", camVideoFPS);
|
||||
s.setValue("screenRegion", screenRegion);
|
||||
s.setValue("screenGrabbed", screenGrabbed);
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
|
@ -1412,6 +1416,28 @@ void Settings::setOutVolume(int volume)
|
|||
outVolume = volume;
|
||||
}
|
||||
|
||||
QRect Settings::getScreenRegion() const
|
||||
{
|
||||
return screenRegion;
|
||||
}
|
||||
|
||||
void Settings::setScreenRegion(const QRect &value)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
screenRegion = value;
|
||||
}
|
||||
|
||||
bool Settings::getScreenGrabbed() const
|
||||
{
|
||||
return screenGrabbed;
|
||||
}
|
||||
|
||||
void Settings::setScreenGrabbed(bool value)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
screenGrabbed = value;
|
||||
}
|
||||
|
||||
QRect Settings::getCamVideoRes() const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
|
|
@ -190,6 +190,12 @@ public:
|
|||
QString getVideoDev() const;
|
||||
void setVideoDev(const QString& deviceSpecifier);
|
||||
|
||||
QRect getScreenRegion() const;
|
||||
void setScreenRegion(const QRect &value);
|
||||
|
||||
bool getScreenGrabbed() const;
|
||||
void setScreenGrabbed(bool value);
|
||||
|
||||
QRect getCamVideoRes() const;
|
||||
void setCamVideoRes(QRect newValue);
|
||||
|
||||
|
@ -435,6 +441,8 @@ private:
|
|||
// Video
|
||||
QString videoDev;
|
||||
QRect camVideoRes;
|
||||
QRect screenRegion;
|
||||
bool screenGrabbed;
|
||||
unsigned short camVideoFPS;
|
||||
|
||||
struct friendProp
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
|
||||
AVForm::AVForm() :
|
||||
GenericForm(QPixmap(":/img/settings/av.png"))
|
||||
, subscribedToAudioIn{false}
|
||||
, camVideoSurface{nullptr}
|
||||
, subscribedToAudioIn(false)
|
||||
, camVideoSurface(nullptr)
|
||||
, camera(CameraSource::getInstance())
|
||||
{
|
||||
bodyUI = new Ui::AVSettings;
|
||||
|
@ -136,6 +136,14 @@ void AVForm::showEvent(QShowEvent* event)
|
|||
GenericForm::showEvent(event);
|
||||
}
|
||||
|
||||
void AVForm::open(const QString &devName, const VideoMode &mode)
|
||||
{
|
||||
QRect rect = mode.toRect();
|
||||
Settings::getInstance().setCamVideoRes(rect);
|
||||
Settings::getInstance().setCamVideoFPS(mode.FPS);
|
||||
camera.open(devName, mode);
|
||||
}
|
||||
|
||||
void AVForm::onVideoModesIndexChanged(int index)
|
||||
{
|
||||
if (index < 0 || index >= videoModes.size())
|
||||
|
@ -152,8 +160,15 @@ void AVForm::onVideoModesIndexChanged(int index)
|
|||
QString devName = videoDeviceList[devIndex].first;
|
||||
VideoMode mode = videoModes[index];
|
||||
|
||||
if (CameraDevice::isScreen(devName) && !mode.height && !mode.width)
|
||||
if (CameraDevice::isScreen(devName) && mode == VideoMode())
|
||||
{
|
||||
if (Settings::getInstance().getScreenGrabbed())
|
||||
{
|
||||
VideoMode mode(Settings::getInstance().getScreenRegion());
|
||||
open(devName, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber(this);
|
||||
|
||||
auto onGrabbed = [screenshotGrabber, devName, this] (QRect region)
|
||||
|
@ -161,19 +176,21 @@ void AVForm::onVideoModesIndexChanged(int index)
|
|||
VideoMode mode(region);
|
||||
mode.width = mode.width / 2 * 2;
|
||||
mode.height = mode.height / 2 * 2;
|
||||
camera.open(devName, mode);
|
||||
|
||||
Settings::getInstance().setScreenRegion(mode.toRect());
|
||||
Settings::getInstance().setScreenGrabbed(true);
|
||||
|
||||
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);
|
||||
Settings::getInstance().setScreenGrabbed(false);
|
||||
open(devName, mode);
|
||||
}
|
||||
|
||||
void AVForm::selectBestModes(QVector<VideoMode> &allVideoModes)
|
||||
|
@ -326,7 +343,8 @@ void AVForm::updateVideoModes(int curIndex)
|
|||
QVector<VideoMode> allVideoModes = CameraDevice::getVideoModes(devName);
|
||||
|
||||
qDebug("available Modes:");
|
||||
if (CameraDevice::isScreen(devName))
|
||||
bool isScreen = CameraDevice::isScreen(devName);
|
||||
if (isScreen)
|
||||
{
|
||||
// Add extra video mode to region selection
|
||||
allVideoModes.push_back(VideoMode());
|
||||
|
@ -343,18 +361,29 @@ void AVForm::updateVideoModes(int curIndex)
|
|||
}
|
||||
|
||||
int preferedIndex = searchPreferredIndex();
|
||||
if (preferedIndex!= -1)
|
||||
if (preferedIndex != -1)
|
||||
{
|
||||
bodyUI->videoModescomboBox->setCurrentIndex(preferedIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isScreen)
|
||||
{
|
||||
QRect rect = Settings::getInstance().getScreenRegion();
|
||||
VideoMode mode(rect);
|
||||
|
||||
Settings::getInstance().setScreenGrabbed(true);
|
||||
bodyUI->videoModescomboBox->setCurrentIndex(videoModes.size() - 1);
|
||||
open(devName, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the user hasn't set a preferred resolution yet,
|
||||
// we'll pick the resolution in the middle of the list,
|
||||
// and the best FPS for that resolution.
|
||||
// If we picked the lowest resolution, the quality would be awful
|
||||
// but if we picked the largest, FPS would be bad and thus quality bad too.
|
||||
int mid = videoModes.size() / 2;
|
||||
int mid = (videoModes.size() - 1) / 2;
|
||||
bodyUI->videoModescomboBox->setCurrentIndex(mid);
|
||||
}
|
||||
|
||||
|
@ -366,15 +395,19 @@ void AVForm::onVideoDevChanged(int index)
|
|||
return;
|
||||
}
|
||||
|
||||
Settings::getInstance().setScreenGrabbed(false);
|
||||
QString dev = videoDeviceList[index].first;
|
||||
Settings::getInstance().setVideoDev(dev);
|
||||
bool previouslyBlocked = bodyUI->videoModescomboBox->blockSignals(true);
|
||||
updateVideoModes(index);
|
||||
bodyUI->videoModescomboBox->blockSignals(previouslyBlocked);
|
||||
|
||||
if (Settings::getInstance().getScreenGrabbed())
|
||||
return;
|
||||
|
||||
int modeIndex = bodyUI->videoModescomboBox->currentIndex();
|
||||
VideoMode mode = VideoMode();
|
||||
if (0 < modeIndex || modeIndex < videoModes.size())
|
||||
if (0 < modeIndex && modeIndex < videoModes.size())
|
||||
mode = videoModes[modeIndex];
|
||||
|
||||
camera.open(dev, mode);
|
||||
|
|
|
@ -77,6 +77,7 @@ private:
|
|||
bool eventFilter(QObject *o, QEvent *e) final override;
|
||||
void hideEvent(QHideEvent* event) final override;
|
||||
void showEvent(QShowEvent*event) final override;
|
||||
void open(const QString &devName, const VideoMode &mode);
|
||||
|
||||
private:
|
||||
Ui::AVSettings *bodyUI;
|
||||
|
|
Loading…
Reference in New Issue
Block a user