mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 21:56:45 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			57 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| 
 | |
| #include "boolsetting.hpp"
 | |
| 
 | |
| #include <QCheckBox>
 | |
| #include <QMutexLocker>
 | |
| 
 | |
| #include <components/settings/settings.hpp>
 | |
| 
 | |
| #include "category.hpp"
 | |
| #include "state.hpp"
 | |
| 
 | |
| CSMPrefs::BoolSetting::BoolSetting (Category *parent, Settings::Manager *values,
 | |
|   QMutex *mutex, const std::string& key, const std::string& label, bool default_)
 | |
| : Setting (parent, values, mutex, key, label),  mDefault (default_), mWidget(0)
 | |
| {}
 | |
| 
 | |
| 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);
 | |
| 
 | |
|     if (!mTooltip.empty())
 | |
|     {
 | |
|         QString tooltip = QString::fromUtf8 (mTooltip.c_str());
 | |
|         mWidget->setToolTip (tooltip);
 | |
|     }
 | |
| 
 | |
|     connect (mWidget, SIGNAL (stateChanged (int)), this, SLOT (valueChanged (int)));
 | |
| 
 | |
|     return std::make_pair (static_cast<QWidget *> (0), mWidget);
 | |
| }
 | |
| 
 | |
| void CSMPrefs::BoolSetting::updateWidget()
 | |
| {
 | |
|     if (mWidget)
 | |
|     {
 | |
|         mWidget->setCheckState(getValues().getBool(getKey(), getParent()->getKey())
 | |
|             ? Qt::Checked
 | |
|             : Qt::Unchecked);
 | |
|     }
 | |
| }
 | |
| 
 | |
| void CSMPrefs::BoolSetting::valueChanged (int value)
 | |
| {
 | |
|     {
 | |
|         QMutexLocker lock (getMutex());
 | |
|         getValues().setBool (getKey(), getParent()->getKey(), value);
 | |
|     }
 | |
| 
 | |
|     getParent()->getState()->update (*this);
 | |
| }
 |