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(
|
2023-11-15 08:26:59 +00:00
|
|
|
Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index)
|
2023-11-11 23:52:09 +00:00
|
|
|
: TypedSetting(parent, mutex, key, label, index)
|
2022-07-11 16:41:07 +00:00
|
|
|
, mWidget(nullptr)
|
2015-12-10 12:28:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip(const std::string& tooltip)
|
|
|
|
{
|
|
|
|
mTooltip = tooltip;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-11-10 12:28:10 +00:00
|
|
|
CSMPrefs::SettingWidgets CSMPrefs::BoolSetting::makeWidgets(QWidget* parent)
|
2015-12-10 12:28:48 +00:00
|
|
|
{
|
2023-11-10 12:09:37 +00:00
|
|
|
mWidget = new QCheckBox(getLabel(), parent);
|
2023-11-11 23:52:09 +00:00
|
|
|
mWidget->setCheckState(getValue() ? 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
|
|
|
|
2023-12-13 23:28:43 +00:00
|
|
|
return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget };
|
2017-05-09 07:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::BoolSetting::updateWidget()
|
|
|
|
{
|
|
|
|
if (mWidget)
|
|
|
|
{
|
2023-11-11 23:52:09 +00:00
|
|
|
mWidget->setCheckState(getValue() ? 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)
|
|
|
|
{
|
2023-11-11 23:52:09 +00:00
|
|
|
setValue(value != Qt::Unchecked);
|
2015-12-10 12:28:48 +00:00
|
|
|
getParent()->getState()->update(*this);
|
|
|
|
}
|