Skip to content

Commit

Permalink
RFE: update the controls on the fly when moving the sliders (#12)
Browse files Browse the repository at this point in the history
update to version 0.0.2 fix this fix
  • Loading branch information
infra-monkey authored Feb 9, 2022
1 parent 19cca0d commit 263d20c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
29 changes: 16 additions & 13 deletions QWebcamSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void QWebcamSettings::save() {
devconf.writePathEntry("Path",dev->getVideoDevicePath());
devconf.writeEntry("CtrlBrightnessValue",dev->getBrightness());
devconf.writeEntry("CtrlBrightnessVisible",dev->getBrightnessVisible());
devconf.writeEntry("CtrlContrastValue",dev->getBrightness());
devconf.writeEntry("CtrlContrastVisible",dev->getBrightnessVisible());
devconf.writeEntry("CtrlContrastValue",dev->getContrast());
devconf.writeEntry("CtrlContrastVisible",dev->getContrastVisible());
devconf.writeEntry("CtrlSharpnessValue",dev->getSharpness());
devconf.writeEntry("CtrlSharpnessVisible",dev->getSharpnessVisible());
devconf.writeEntry("CtrlSaturationValue",dev->getSaturation());
Expand Down Expand Up @@ -104,17 +104,20 @@ void QWebcamSettings::save() {

void QWebcamSettings::load() {
qCDebug(webcam_settings_kcm) << "QWebcamSettings::load load settings from config";
// populateDeviceList();
if (m_devices_available){
Q_EMIT deviceIndexChanged();
Q_EMIT formatIndexChanged();
Q_EMIT absoluteZoomChanged();
Q_EMIT brightnessChanged();
Q_EMIT contrastChanged();
Q_EMIT saturationChanged();
Q_EMIT sharpnessChanged();
Q_EMIT autoFocusChanged();
KConfig config("kcmwebcamsettingsrc");
for (VideoDevice * dev : m_device_list)
{
if (config.groupList().contains(dev->getVideoDeviceSerialId())){
KConfigGroup devconf(&config, dev->getVideoDeviceSerialId());
if(dev->setBrightness(devconf.readEntry("CtrlBrightnessValue").toDouble())){Q_EMIT brightnessChanged();}
if(dev->setContrast(devconf.readEntry("CtrlContrastValue").toDouble())){Q_EMIT contrastChanged();}
if(dev->setSharpness(devconf.readEntry("CtrlSharpnessValue").toDouble())){Q_EMIT sharpnessChanged();}
if(dev->setSaturation(devconf.readEntry("CtrlSaturationValue").toDouble())){Q_EMIT saturationChanged();}
if(dev->setAbsoluteZoom(devconf.readEntry("CtrlAbsoluteZoomValue").toDouble())){Q_EMIT absoluteZoomChanged();}
if(dev->setAutoFocus(devconf.readEntry("CtrlAutoFocusValue").toInt())){Q_EMIT autoFocusChanged();}
}
}
setNeedsSave(false);

}

Expand Down Expand Up @@ -226,7 +229,7 @@ void QWebcamSettings::setAbsoluteZoom(double zoom) {
qCDebug(webcam_settings_kcm) << "QWebcamSettings::setAbsoluteZoom value: " << QString::number(zoom);
bool save_needed = m_current_device->setAbsoluteZoom(zoom);
Q_EMIT absoluteZoomChanged();
if (save_needed){setNeedsSave(true);qCDebug(webcam_settings_kcm) << "QWebcamSettings::setAbsoluteZoom set save true: ";}
if (save_needed){setNeedsSave(true);}
}

void QWebcamSettings::setBrightness(double brightness) {
Expand Down
14 changes: 14 additions & 0 deletions VideoDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ bool VideoDevice::setBrightness(double value){
if (m_ctrl_brightness_visible && value != m_ctrl_brightness["value"]){
save_needed = true;
m_ctrl_brightness["value"] = value;
applyControlValue("brightness",QString::number(value));
}
return save_needed;
}
Expand All @@ -290,6 +291,7 @@ bool VideoDevice::setContrast(double value){
if (m_ctrl_contrast_visible && value != m_ctrl_contrast["value"]){
save_needed = true;
m_ctrl_contrast["value"] = value;
applyControlValue("contrast",QString::number(value));
}
return save_needed;
}
Expand All @@ -300,6 +302,7 @@ bool VideoDevice::setSharpness(double value){
if (m_ctrl_sharpness_visible && value != m_ctrl_sharpness["value"]){
save_needed = true;
m_ctrl_sharpness["value"] = value;
applyControlValue("sharpness",QString::number(value));
}
return save_needed;
}
Expand All @@ -310,6 +313,7 @@ bool VideoDevice::setSaturation(double value){
if (m_ctrl_saturation_visible && value != m_ctrl_saturation["value"]){
save_needed = true;
m_ctrl_saturation["value"] = value;
applyControlValue("saturation",QString::number(value));
}
return save_needed;
}
Expand All @@ -320,6 +324,7 @@ bool VideoDevice::setAbsoluteZoom(double value){
if (m_ctrl_zoom_absolute_visible && value != m_ctrl_zoom_absolute["value"]){
save_needed = true;
m_ctrl_zoom_absolute["value"] = value;
applyControlValue("zoom_absolute",QString::number(value));
}
return save_needed;
}
Expand All @@ -330,6 +335,7 @@ bool VideoDevice::setAutoFocus(int value){
if (m_ctrl_auto_focus_visible && value != m_ctrl_auto_focus["value"]){
save_needed = true;
m_ctrl_auto_focus["value"] = value;
applyControlValue("focus_automatic_continuous",QString::number(value));
}
return save_needed;
}
Expand Down Expand Up @@ -394,6 +400,14 @@ QString VideoDevice::getCtrlOptions(){
return ctrl_options;
}

void VideoDevice::applyControlValue(QString ctrl_name,QString value){
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue";
std::string cmd;
cmd = std::string("v4l2-ctl -d " + getVideoDevicePath().toStdString() + " --set-ctrl " + ctrl_name.toStdString() +"=" + value.toStdString());
exec_cmd(cmd);
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue: " << "v4l2-ctl -d " + getVideoDevicePath() + " --set-ctrl " + ctrl_name + "=" + value;
}

void VideoDevice::applyConfiguration(){
qCDebug(webcam_settings_kcm) << "VideoDevice::applyConfiguration";
std::string cmd;
Expand Down
1 change: 1 addition & 0 deletions VideoDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class VideoDevice : public QObject {
QString getUdevRule();

private:
void applyControlValue(QString,QString);
QString m_device_serial;
QString m_device_name;
QString m_device_vendor_id;
Expand Down
4 changes: 2 additions & 2 deletions kcm_webcam_settings.spec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%global kf5_version 5.85.0
%global qt5_version 5.15.2
Name: {{{ git_dir_name }}}
Version: 0.0.1
Release: 2
Version: 0.0.2
Release: 1
Summary: KDE Plasma system-settings module to configure your webcam
License: GPLv3+
URL: https://github.com/infra-monkey/kcm_webcam_settings
Expand Down

0 comments on commit 263d20c

Please sign in to comment.