forked from mirror/openmw-tes3mp
added integer settings
parent
c158224314
commit
c61d717e41
@ -0,0 +1,69 @@
|
||||
|
||||
#include "intsetting.hpp"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QSpinBox>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
#include "category.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
CSMPrefs::IntSetting::IntSetting (Category *parent, Settings::Manager *values,
|
||||
const std::string& key, const std::string& label, int default_)
|
||||
: Setting (parent, values, key, label), mMin (0), mMax (std::numeric_limits<int>::max()),
|
||||
mDefault (default_)
|
||||
{}
|
||||
|
||||
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setRange (int min, int max)
|
||||
{
|
||||
mMin = min;
|
||||
mMax = max;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setMin (int min)
|
||||
{
|
||||
mMin = min;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setMax (int max)
|
||||
{
|
||||
mMax = max;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setTooltip (const std::string& tooltip)
|
||||
{
|
||||
mTooltip = tooltip;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::pair<QWidget *, QWidget *> CSMPrefs::IntSetting::makeWidgets (QWidget *parent)
|
||||
{
|
||||
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
|
||||
QSpinBox *widget = new QSpinBox (parent);
|
||||
widget->setRange (mMin, mMax);
|
||||
widget->setValue (mDefault);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||
label->setToolTip (tooltip);
|
||||
widget->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (valueChanged (int)), this, SLOT (valueChanged (int)));
|
||||
|
||||
return std::make_pair (label, widget);
|
||||
}
|
||||
|
||||
void CSMPrefs::IntSetting::valueChanged (int value)
|
||||
{
|
||||
getValues().setInt (getKey(), getParent()->getKey(), value);
|
||||
getParent()->getState()->update (*this);
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#ifndef CSM_PREFS_INTSETTING_H
|
||||
#define CSM_PREFS_INTSETTING_H
|
||||
|
||||
#include "setting.hpp"
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class IntSetting : public Setting
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
int mMin;
|
||||
int mMax;
|
||||
std::string mTooltip;
|
||||
int mDefault;
|
||||
|
||||
public:
|
||||
|
||||
IntSetting (Category *parent, Settings::Manager *values,
|
||||
const std::string& key, const std::string& label, int default_);
|
||||
|
||||
IntSetting& setRange (int min, int max);
|
||||
|
||||
IntSetting& setMin (int min);
|
||||
|
||||
IntSetting& setMax (int max);
|
||||
|
||||
IntSetting& setTooltip (const std::string& tooltip);
|
||||
|
||||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged (int value);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,32 @@
|
||||
|
||||
#include "setting.hpp"
|
||||
|
||||
#include "category.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
Settings::Manager& CSMPrefs::Setting::getValues()
|
||||
{
|
||||
return *mValues;
|
||||
}
|
||||
|
||||
CSMPrefs::Setting::Setting (Category *parent, Settings::Manager *values,
|
||||
const std::string& key, const std::string& label)
|
||||
: QObject (parent->getState()), mParent (parent), mValues (values), mKey (key), mLabel (label)
|
||||
{}
|
||||
|
||||
CSMPrefs::Setting:: ~Setting() {}
|
||||
|
||||
const CSMPrefs::Category *CSMPrefs::Setting::getParent() const
|
||||
{
|
||||
return mParent;
|
||||
}
|
||||
|
||||
const std::string& CSMPrefs::Setting::getKey() const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
const std::string& CSMPrefs::Setting::getLabel() const
|
||||
{
|
||||
return mLabel;
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
#ifndef CSM_PREFS_SETTING_H
|
||||
#define CSM_PREFS_SETTING_H
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QWidget;
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
class Manager;
|
||||
}
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class Category;
|
||||
|
||||
class Setting : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Category *mParent;
|
||||
Settings::Manager *mValues;
|
||||
std::string mKey;
|
||||
std::string mLabel;
|
||||
|
||||
protected:
|
||||
|
||||
Settings::Manager& getValues();
|
||||
|
||||
public:
|
||||
|
||||
Setting (Category *parent, Settings::Manager *values, const std::string& key, const std::string& label);
|
||||
|
||||
virtual ~Setting();
|
||||
|
||||
/// Return label, input widget.
|
||||
///
|
||||
/// \note first can be a 0-pointer, which means that the label is part of the input
|
||||
/// widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent) = 0;
|
||||
|
||||
const Category *getParent() const;
|
||||
|
||||
const std::string& getKey() const;
|
||||
|
||||
const std::string& getLabel() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,40 @@
|
||||
|
||||
#include "page.hpp"
|
||||
|
||||
#include <QGridLayout>
|
||||
|
||||
#include "../../model/prefs/setting.hpp"
|
||||
#include "../../model/prefs/category.hpp"
|
||||
|
||||
CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent)
|
||||
: PageBase (category, parent)
|
||||
{
|
||||
QWidget *widget = new QWidget (parent);
|
||||
mGrid = new QGridLayout (widget);
|
||||
|
||||
for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter)
|
||||
addSetting (*iter);
|
||||
|
||||
setWidget (widget);
|
||||
}
|
||||
|
||||
void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting)
|
||||
{
|
||||
std::pair<QWidget *, QWidget *> widgets = setting->makeWidgets (this);
|
||||
|
||||
int next = mGrid->rowCount();
|
||||
|
||||
if (widgets.first)
|
||||
{
|
||||
mGrid->addWidget (widgets.first, next, 0);
|
||||
mGrid->addWidget (widgets.second, next, 1);
|
||||
}
|
||||
else if (widgets.second)
|
||||
{
|
||||
mGrid->addWidget (widgets.second, next, 0, next, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mGrid->addWidget (new QWidget (this), next, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef CSV_PREFS_PAGE_H
|
||||
#define CSV_PREFS_PAGE_H
|
||||
|
||||
#include "pagebase.hpp"
|
||||
|
||||
class QGridLayout;
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class Setting;
|
||||
}
|
||||
|
||||
namespace CSVPrefs
|
||||
{
|
||||
class Page : public PageBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QGridLayout *mGrid;
|
||||
|
||||
public:
|
||||
|
||||
Page (CSMPrefs::Category& category, QWidget *parent);
|
||||
|
||||
void addSetting (CSMPrefs::Setting *setting);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue