Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+208
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* HMI Plugin for Observer Controller - Settings Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2018-01-17
|
||||
*/
|
||||
|
||||
#include "osc_settings.h"
|
||||
#include "ui_osc_settings.h"
|
||||
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
|
||||
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
#include <QDebug>
|
||||
|
||||
namespace OcSituationClient
|
||||
{
|
||||
|
||||
Settings::Settings(LtsSession::LtsSession *session, QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
||||
, m_mediaplayer(new QMediaPlayer(this))
|
||||
, m_ocGroupString(QStringLiteral("ObserverController"))
|
||||
, m_opSettings(LtsUtils::OperatorSettings::getInstance())
|
||||
, m_ui(new Ui::Settings)
|
||||
// , m_logger(getLogger("SettingsDialog"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
//optional
|
||||
session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitMapGuiIfc);
|
||||
|
||||
//connects
|
||||
connect(m_ui->pbSoundCheck, &LtsWidgets::LtsDragIcon::clicked, this, &Settings::onSoundCheck);
|
||||
connect(m_ui->pbResetRange, &LtsWidgets::LtsDragIcon::clicked, this, &Settings::onResetRange);
|
||||
connect(m_ui->slWarningRange, &QSlider::valueChanged, this, [this](int range)
|
||||
{
|
||||
m_ui->lblRange->setText(QString::number(range));
|
||||
});
|
||||
|
||||
#ifdef WIN32
|
||||
m_handler = CreateFile(L"\\\\.\\LCD",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0, NULL);
|
||||
m_monitorLightBrightness = getMonitorCurrentLightBrightness();
|
||||
connect(m_ui->slMonitorBrightness, &QSlider::valueChanged, this, [this](int range)
|
||||
{
|
||||
m_ui->lblMonitorBrightness->setText(QString::number(range));
|
||||
setMonitorLightBrightness(range);
|
||||
});
|
||||
if(m_monitorLightBrightness >= 0)
|
||||
{
|
||||
m_ui->slMonitorBrightness->setValue(m_monitorLightBrightness);
|
||||
}
|
||||
m_ui->lblMonitorBrightness->setText(QString::number(m_ui->slMonitorBrightness->value()));
|
||||
|
||||
connect(m_buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked,
|
||||
this, [this]()
|
||||
{
|
||||
//reset to old Value
|
||||
setMonitorLightBrightness(m_monitorLightBrightness);
|
||||
});
|
||||
#else
|
||||
m_ui->slMonitorBrightness->hide();
|
||||
m_ui->lblMonitorBrightness->hide();
|
||||
m_ui->LblMonitorBrightness->hide();
|
||||
#endif
|
||||
|
||||
connect(m_ui->cbxAcusticWarning, &LtsWidgets::LtsDragIcon::clicked, this, &Settings::slotChangesMade);
|
||||
connect(m_ui->cbxVisualWarning, &LtsWidgets::LtsDragIcon::clicked, this, &Settings::slotChangesMade);
|
||||
connect(m_ui->cbxOcSituationBorder, &LtsWidgets::LtsDragIcon::clicked, this, &Settings::slotChangesMade);
|
||||
connect(m_ui->cbxMovingMapToSelf, &LtsWidgets::LtsDragIcon::clicked, this, &Settings::slotChangesMade);
|
||||
//load OperatorSettings and set Ui Values
|
||||
loadOperatorSettings();
|
||||
|
||||
//set audio file
|
||||
m_mediaplayer->setMedia(QUrl(QLatin1String("qrc:/beep.wav")));
|
||||
m_mediaplayer->setVolume(100);
|
||||
|
||||
setOnlineHelpFilename(QStringLiteral("OC-Settings"));
|
||||
}
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
/*!
|
||||
* \brief Settings::setMonitorLightBrightness
|
||||
* this method set the light brightness of an windows os monitor
|
||||
* \warning this funcion work only for windows os
|
||||
* \param value
|
||||
*/
|
||||
void Settings::setMonitorLightBrightness(const int value)
|
||||
{
|
||||
#ifdef WIN32
|
||||
m_displayBrightness.ucDisplayPolicy = 0;
|
||||
m_displayBrightness.ucACBrightness = 0;
|
||||
m_displayBrightness.ucDCBrightness = value;
|
||||
DWORD ret = 0;
|
||||
DWORD nOutBufferSize = sizeof(m_displayBrightness);
|
||||
if(m_handler == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
m_handler = CreateFile(L"\\\\.\\LCD",
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
NULL);
|
||||
if(m_handler == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
qCritical()<<" couldn't CreateFile for setting monitor light brightness. Error: "<<GetLastError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!DeviceIoControl(m_handler,
|
||||
IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS,
|
||||
(DISPLAY_BRIGHTNESS*)&m_displayBrightness,
|
||||
nOutBufferSize,
|
||||
NULL,
|
||||
0,
|
||||
&ret,
|
||||
NULL))
|
||||
{
|
||||
qCritical()<<" couldn't set monitor light brightness. Error: "<<GetLastError();
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(value)
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Settings::getMonitorCurrentLightBrightness
|
||||
* get on win os monitor light brightness
|
||||
* \warning this funcion work only for windows os
|
||||
* \return
|
||||
*/
|
||||
int Settings::getMonitorCurrentLightBrightness()
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD ret;
|
||||
int nRes = DeviceIoControl(
|
||||
m_handler, // handle to device
|
||||
IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS , // dwIoControlCode
|
||||
NULL, // lpInBuffer
|
||||
0, // nInBufferSize
|
||||
(DISPLAY_BRIGHTNESS*)&m_displayBrightness, // output buffer
|
||||
sizeof(m_displayBrightness), // size of output buffer
|
||||
(LPDWORD) &ret, // bytes returned
|
||||
NULL // OVERLAPPED
|
||||
);
|
||||
if(nRes !=0)
|
||||
{
|
||||
const int l = m_displayBrightness.ucDCBrightness;
|
||||
return l;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Settings::onResetRange()
|
||||
{
|
||||
m_ui->slWarningRange->setValue(WARNINGRANGEDEFAULT);
|
||||
}
|
||||
|
||||
void Settings::onSoundCheck()
|
||||
{
|
||||
m_mediaplayer->play();
|
||||
}
|
||||
|
||||
void Settings::loadOperatorSettings()
|
||||
{
|
||||
// now set values
|
||||
m_ui->slWarningRange->setValue(m_opSettings->value(m_ocGroupString, QStringLiteral("WarningRange"), WARNINGRANGEDEFAULT).toInt());
|
||||
m_ui->cbxAcusticWarning->setChecked(m_opSettings->value(m_ocGroupString, QStringLiteral("AcousticWarning"), false).toBool());
|
||||
m_ui->cbxVisualWarning->setChecked(m_opSettings->value(m_ocGroupString, QStringLiteral("VisualWarning"), false).toBool());
|
||||
m_ui->cbxOcSituationBorder->setChecked(m_opSettings->value(m_ocGroupString, QStringLiteral("OcSituationBorder"), false).toBool());
|
||||
m_ui->cbxMovingMapToSelf->setChecked(m_opSettings->value(m_ocGroupString, QStringLiteral("MovingMapToSelf"), false).toBool());
|
||||
}
|
||||
|
||||
void Settings::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("Settings") );
|
||||
}
|
||||
|
||||
bool Settings::apply()
|
||||
{
|
||||
//write qsettings
|
||||
m_opSettings->setValue(m_ocGroupString, QStringLiteral("WarningRange"), m_ui->slWarningRange->value());
|
||||
m_opSettings->setValue(m_ocGroupString, QStringLiteral("AcousticWarning"), m_ui->cbxAcusticWarning->isChecked());
|
||||
m_opSettings->setValue(m_ocGroupString, QStringLiteral("VisualWarning"), m_ui->cbxVisualWarning->isChecked());
|
||||
m_opSettings->setValue(m_ocGroupString, QStringLiteral("OcSituationBorder"), m_ui->cbxOcSituationBorder->isChecked());
|
||||
m_opSettings->setValue(m_ocGroupString, QStringLiteral("MovingMapToSelf"), m_ui->cbxMovingMapToSelf->isChecked());
|
||||
|
||||
m_sitMapGuiIfc->ocSituationRange_show(m_ui->cbxOcSituationBorder->isChecked());
|
||||
|
||||
#ifdef WIN32
|
||||
m_monitorLightBrightness = getMonitorCurrentLightBrightness();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace OcSituationClient
|
||||
Reference in new issue
Block a user