added bool settings
parent
9ca5a1b647
commit
b0fb6d56f1
@ -0,0 +1,42 @@
|
||||
|
||||
#include "boolsetting.hpp"
|
||||
|
||||
#include <QCheckBox>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
#include "category.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
CSMPrefs::BoolSetting::BoolSetting (Category *parent, Settings::Manager *values,
|
||||
const std::string& key, const std::string& label, bool default_)
|
||||
: Setting (parent, values, key, label), mDefault (default_)
|
||||
{}
|
||||
|
||||
CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip (const std::string& tooltip)
|
||||
{
|
||||
mTooltip = tooltip;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::pair<QWidget *, QWidget *> CSMPrefs::BoolSetting::makeWidgets (QWidget *parent)
|
||||
{
|
||||
QCheckBox *widget = new QCheckBox (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
widget->setCheckState (mDefault ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||
widget->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (stateChanged (int)), this, SLOT (valueChanged (int)));
|
||||
|
||||
return std::make_pair (static_cast<QWidget *> (0), widget);
|
||||
}
|
||||
|
||||
void CSMPrefs::BoolSetting::valueChanged (int value)
|
||||
{
|
||||
getValues().setBool (getKey(), getParent()->getKey(), value);
|
||||
getParent()->getState()->update (*this);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef CSM_PREFS_BOOLSETTING_H
|
||||
#define CSM_PREFS_BOOLSETTING_H
|
||||
|
||||
#include "setting.hpp"
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class BoolSetting : public Setting
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
std::string mTooltip;
|
||||
bool mDefault;
|
||||
|
||||
public:
|
||||
|
||||
BoolSetting (Category *parent, Settings::Manager *values,
|
||||
const std::string& key, const std::string& label, bool default_);
|
||||
|
||||
BoolSetting& setTooltip (const std::string& tooltip);
|
||||
|
||||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged (int value);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue