Skip to content

Commit

Permalink
Improve-ui (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
infra-monkey authored Feb 15, 2022
1 parent 7ffd432 commit 3f72f5c
Show file tree
Hide file tree
Showing 5 changed files with 413 additions and 226 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ set(QWebcamSettings_SRCS
helpers.cpp
)

# SET(KCM_CONFIG_FILE_NAME "kcmwebcamsettingsrc" CACHE STRING "the config file name for kcm_webcam_settings")

kauth_install_actions(kcm.webcam.settings.udevhelper udevhelper.actions)
add_executable(udevhelper UdevHelper.cpp UdevHelper.h helpers.cpp helpers.h)
target_link_libraries(udevhelper KF5::Auth)
Expand Down
37 changes: 30 additions & 7 deletions QWebcamSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ K_PLUGIN_CLASS_WITH_JSON(QWebcamSettings, "metadata.json")

QWebcamSettings::QWebcamSettings(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
, m_devicename_list_model(new QStringListModel(this))
{
qCDebug(webcam_settings_kcm) << "QWebcamSettings::QWebcamSettings";
KAboutData *aboutData = new KAboutData(QStringLiteral("kcm_webcam_settings"),
Expand All @@ -39,9 +40,8 @@ QWebcamSettings::QWebcamSettings(QObject *parent, const QVariantList &args)

setAboutData(aboutData);
setButtons(Apply | Default);
setNeedsSave(false);
populateDeviceList();
qCDebug(webcam_settings_kcm) << "QWebcamSettings::QWebcamSettings current format index = " << m_current_device->getFormatIndex() << "autofocus" << m_current_device->getAutoFocus();

}

void QWebcamSettings::save() {
Expand All @@ -59,6 +59,7 @@ void QWebcamSettings::save() {
devconf.writeEntry("VendorId",dev->getVideoDeviceVendorId());
devconf.writeEntry("ModelId",dev->getVideoDeviceModelId());
devconf.writePathEntry("Path",dev->getVideoDevicePath());
devconf.writeEntry("FormatIndex",dev->getFormatIndex());
devconf.writeEntry("CtrlBrightnessValue",dev->getBrightness());
devconf.writeEntry("CtrlBrightnessVisible",dev->getBrightnessVisible());
devconf.writeEntry("CtrlContrastValue",dev->getContrast());
Expand Down Expand Up @@ -118,6 +119,7 @@ void QWebcamSettings::load() {
if(dev->setAbsoluteZoom(devconf.readEntry("CtrlAbsoluteZoomValue").toDouble())){Q_EMIT absoluteZoomChanged();}
if(dev->setAutoFocus(devconf.readEntry("CtrlAutoFocusValue").toInt())){Q_EMIT autoFocusChanged();}
if(dev->setFocus(devconf.readEntry("CtrlAbsoluteFocusValue").toInt())){Q_EMIT focusChanged();}
if(dev->setFormatIndex(devconf.readEntry("FormatIndex").toInt())){Q_EMIT formatIndexChanged();}
}
}
setNeedsSave(false);
Expand Down Expand Up @@ -183,10 +185,30 @@ void QWebcamSettings::populateDeviceList() {
setDeviceIndex(0);
qCDebug(webcam_settings_kcm) << "QWebcamSettings::populateDeviceList current format index = " << m_current_device->getFormatIndex() << "autofocus" << m_current_device->getAutoFocus();
}


m_devicename_list_model->setStringList(m_devicename_list);
}

QStringListModel* QWebcamSettings::getDeviceList(){
this->engine()->rootContext()->setContextProperty("device_list_model", m_devicename_list_model);
return m_devicename_list_model;
}

QString QWebcamSettings::getSelectedDeviceName(){
qCDebug(webcam_settings_kcm) << "QWebcamSettings::getSelectedDeviceName " << m_current_device->getVideoDeviceName();
return m_current_device->getVideoDeviceName().simplified();
}

QString QWebcamSettings::getSelectedDevicePath(){
return m_current_device->getVideoDevicePath().simplified();
}

QString QWebcamSettings::getSelectedDeviceVendorId(){
return m_current_device->getVideoDeviceVendorId().simplified();
}

QString QWebcamSettings::getSelectedDeviceModelId(){
return m_current_device->getVideoDeviceModelId().simplified();
}

VideoDevice* QWebcamSettings::getDeviceFromIndex(int index) {
qCDebug(webcam_settings_kcm) << "QWebcamSettings::getDeviceFromIndex";
Expand All @@ -205,10 +227,12 @@ VideoDevice* QWebcamSettings::getDeviceFromIndex(int index) {


void QWebcamSettings::setDeviceIndex(int devindex) {
qCDebug(webcam_settings_kcm) << "QWebcamSettings::setDeviceIndex";
qCDebug(webcam_settings_kcm) << "QWebcamSettings::setDeviceIndex " << devindex;
m_device_index = devindex;
m_current_device = getDeviceFromIndex(devindex);
m_format_index = m_current_device->getFormatIndex();
qCDebug(webcam_settings_kcm) << "Selected device " << this->m_current_device->getVideoDeviceName();
qCDebug(webcam_settings_kcm) << "format index " << this->m_current_device->getFormatIndex();
Q_EMIT deviceIndexChanged();
Q_EMIT formatIndexChanged();
Q_EMIT absoluteZoomChanged();
Expand All @@ -223,11 +247,10 @@ void QWebcamSettings::setDeviceIndex(int devindex) {
}

void QWebcamSettings::setFormatIndex(int fmtindex) {
qCDebug(webcam_settings_kcm) << "QWebcamSettings::setFormatIndex";
bool save_needed = this->m_current_device->setFormatIndex(fmtindex);
Q_EMIT formatIndexChanged();
if (save_needed){setNeedsSave(true);}
qCDebug(webcam_settings_kcm) << "QWebcamSettings::setFormatIndex" << m_current_device->getCurrentFormatName() << m_current_device->getCurrentFormatWidth() << m_current_device->getCurrentFormatHeight();
qCDebug(webcam_settings_kcm) << "QWebcamSettings::setFormatIndex "<< fmtindex << m_current_device->getCurrentFormatName() << m_current_device->getCurrentFormatWidth() << m_current_device->getCurrentFormatHeight();
}

void QWebcamSettings::setAbsoluteZoom(double zoom) {
Expand Down
16 changes: 14 additions & 2 deletions QWebcamSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
#include <QStringList>
#include <KConfig>
#include <KConfigGroup>
#include <QStringListModel>
#include <QJSValue>

class QWebcamSettings : public KQuickAddons::ConfigModule
{
Q_OBJECT
Q_PROPERTY(QStringList device_list READ getDeviceList NOTIFY deviceIndexChanged)
Q_PROPERTY(QStringListModel* device_list_model READ getDeviceList NOTIFY deviceIndexChanged)
Q_PROPERTY(int deviceIndex READ getDeviceIndex WRITE setDeviceIndex NOTIFY deviceIndexChanged)
Q_PROPERTY(QString device_info_name READ getSelectedDeviceName NOTIFY deviceIndexChanged)
Q_PROPERTY(QString device_info_path READ getSelectedDevicePath NOTIFY deviceIndexChanged)
Q_PROPERTY(QString device_info_vendorid READ getSelectedDeviceVendorId NOTIFY deviceIndexChanged)
Q_PROPERTY(QString device_info_modelid READ getSelectedDeviceModelId NOTIFY deviceIndexChanged)


Q_PROPERTY(QStringList format_list READ getFormatList NOTIFY formatIndexChanged)
Q_PROPERTY(int formatIndex READ getFormatIndex WRITE setFormatIndex NOTIFY formatIndexChanged)
Expand Down Expand Up @@ -67,10 +74,14 @@ class QWebcamSettings : public KQuickAddons::ConfigModule
public:
QWebcamSettings(QObject *parent, const QVariantList &args);
virtual ~QWebcamSettings() override = default;
QStringList getDeviceList(){return m_devicename_list;};
QStringListModel* getDeviceList();
QStringList getFormatList(){return this->m_current_device->getFormatList();};
void populateDeviceList();
int getDeviceIndex(){return m_device_index;};
QString getSelectedDeviceName();
QString getSelectedDevicePath();
QString getSelectedDeviceVendorId();
QString getSelectedDeviceModelId();
int getFormatIndex(){return this->m_current_device->getFormatIndex();};
qreal getBrightness() {return this->m_current_device->getBrightness();};
qreal getBrightnessMin() {return this->m_current_device->getBrightnessMin();};
Expand Down Expand Up @@ -133,6 +144,7 @@ class QWebcamSettings : public KQuickAddons::ConfigModule
private:
VideoDevice* getDeviceFromIndex(int);
QStringList m_devicename_list;
QStringListModel *m_devicename_list_model;
QList<VideoDevice*> m_device_list;
VideoDevice *m_current_device;
QStringList m_current_format_list;
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.2
Release: 2
Version: 0.0.3
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
Loading

0 comments on commit 3f72f5c

Please sign in to comment.