2015-12-10 12:28:48 +00:00
|
|
|
#include "boolsetting.hpp"
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
2015-12-15 11:19:48 +00:00
|
|
|
#include <QMutexLocker>
|
2015-12-10 12:28:48 +00:00
|
|
|
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <apps/opencs/model/prefs/setting.hpp>
|
|
|
|
|
2015-12-10 12:28:48 +00:00
|
|
|
#include "category.hpp"
|
|
|
|
#include "state.hpp"
|
|
|
|
|
2022-07-11 16:41:07 +00:00
|
|
|
CSMPrefs::BoolSetting::BoolSetting(
|
2015-12-15 11:19:48 +00:00
|
|
|
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, bool default_)
|
2022-07-11 16:41:07 +00:00
|
|
|
: Setting(parent, mutex, key, label)
|
|
|
|
, mDefault(default_)
|
|
|
|
, mWidget(nullptr)
|
2015-12-10 12:28:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip(const std::string& tooltip)
|
|
|
|
{
|
|
|
|
mTooltip = tooltip;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<QWidget*, QWidget*> CSMPrefs::BoolSetting::makeWidgets(QWidget* parent)
|
|
|
|
{
|
2017-05-09 07:50:16 +00:00
|
|
|
mWidget = new QCheckBox(QString::fromUtf8(getLabel().c_str()), parent);
|
|
|
|
mWidget->setCheckState(mDefault ? Qt::Checked : Qt::Unchecked);
|
2015-12-10 12:28:48 +00:00
|
|
|
|
|
|
|
if (!mTooltip.empty())
|
|
|
|
{
|
|
|
|
QString tooltip = QString::fromUtf8(mTooltip.c_str());
|
2017-05-09 07:50:16 +00:00
|
|
|
mWidget->setToolTip(tooltip);
|
2015-12-10 12:28:48 +00:00
|
|
|
}
|
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(mWidget, &QCheckBox::stateChanged, this, &BoolSetting::valueChanged);
|
2015-12-10 12:28:48 +00:00
|
|
|
|
2020-11-13 07:39:47 +00:00
|
|
|
return std::make_pair(static_cast<QWidget*>(nullptr), mWidget);
|
2017-05-09 07:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::BoolSetting::updateWidget()
|
|
|
|
{
|
|
|
|
if (mWidget)
|
|
|
|
{
|
2022-07-11 16:41:07 +00:00
|
|
|
mWidget->setCheckState(
|
|
|
|
Settings::Manager::getBool(getKey(), getParent()->getKey()) ? Qt::Checked : Qt::Unchecked);
|
2017-05-09 07:50:16 +00:00
|
|
|
}
|
2015-12-10 12:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::BoolSetting::valueChanged(int value)
|
|
|
|
{
|
2015-12-15 11:19:48 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(getMutex());
|
2022-07-11 16:41:07 +00:00
|
|
|
Settings::Manager::setBool(getKey(), getParent()->getKey(), value);
|
2015-12-15 11:19:48 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 12:28:48 +00:00
|
|
|
getParent()->getState()->update(*this);
|
|
|
|
}
|