1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-11 00:39:59 +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.

61 lines
1.5 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(
2015-12-15 11:19:48 +00:00
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, bool default_)
: 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)
{
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());
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
2020-11-13 07:39:47 +00:00
return std::make_pair(static_cast<QWidget*>(nullptr), mWidget);
}
void CSMPrefs::BoolSetting::updateWidget()
{
if (mWidget)
{
mWidget->setCheckState(
Settings::Manager::getBool(getKey(), getParent()->getKey()) ? Qt::Checked : Qt::Unchecked);
}
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());
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);
}