1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00
OpenMW/apps/opencs/model/prefs/boolsetting.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.3 KiB
C++
Raw Normal View History

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"
CSMPrefs::BoolSetting::BoolSetting(
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)
, mWidget(nullptr)
2015-12-10 12:28:48 +00:00
{
}
CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip(const std::string& tooltip)
{
mTooltip = tooltip;
return *this;
}
CSMPrefs::SettingWidgets CSMPrefs::BoolSetting::makeWidgets(QWidget* parent)
2015-12-10 12:28:48 +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());
mWidget->setToolTip(tooltip);
2015-12-10 12:28:48 +00:00
}
connect(mWidget, &QCheckBox::stateChanged, this, &BoolSetting::valueChanged);
2015-12-10 12:28:48 +00:00
return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget };
}
void CSMPrefs::BoolSetting::updateWidget()
{
if (mWidget)
{
2023-11-11 23:52:09 +00:00
mWidget->setCheckState(getValue() ? Qt::Checked : Qt::Unchecked);
}
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);
}