diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-02-20 02:49:46 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-02-20 02:49:46 +0300 |
commit | e2620fcbbe0ae5ac43565879f4b7243c367c84cf (patch) | |
tree | 39acff6d0c70aebf4f6813e1c9350873b04c63ed /src/gui/widgets/setupitem.cpp | |
parent | 0d2d350e8eb6f57be31f926897e39c6483eeee75 (diff) | |
download | manaverse-e2620fcbbe0ae5ac43565879f4b7243c367c84cf.tar.gz manaverse-e2620fcbbe0ae5ac43565879f4b7243c367c84cf.tar.bz2 manaverse-e2620fcbbe0ae5ac43565879f4b7243c367c84cf.tar.xz manaverse-e2620fcbbe0ae5ac43565879f4b7243c367c84cf.zip |
Move gui opacity option to visual settings page.
Add slider class for setup pages.
Diffstat (limited to 'src/gui/widgets/setupitem.cpp')
-rw-r--r-- | src/gui/widgets/setupitem.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 56ce0a25a..1d6bf5916 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -33,6 +33,7 @@ #include "gui/widgets/inttextfield.h" #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" +#include "gui/widgets/slider.h" #include "gui/widgets/tabbedarea.h" #include "gui/widgets/textfield.h" #include "gui/widgets/vertcontainer.h" @@ -588,3 +589,100 @@ void SetupItemDropDown::toWidget() mDropDown->setSelectedString(mValue); } + + + + + + +SetupItemSlider::SetupItemSlider(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, double min, double max, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mSlider(nullptr), + mMin(min), + mMax(max) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSlider::SetupItemSlider(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, double min, double max, + std::string def, bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mSlider(nullptr), + mMin(min), + mMax(max) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSlider::~SetupItemSlider() +{ + mHorizont = nullptr; + mWidget = nullptr; + mSlider = nullptr; + mLabel = nullptr; +} + +void SetupItemSlider::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mSlider = new Slider(mMin, mMax); + mSlider->setActionEventId(mEventName); + mSlider->addActionListener(mParent); + mSlider->setValue(atof(mValue.c_str())); + mSlider->setHeight(30); + + mWidget = mSlider; + mSlider->setWidth(150); + mSlider->setHeight(40); + mHorizont->add(mLabel); + mHorizont->add(mSlider, -10); + + mParent->getContainer()->add2(mHorizont, true, 4); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemSlider::fromWidget() +{ + if (!mSlider) + return; + + mValue = toString(mSlider->getValue()); +} + +void SetupItemSlider::toWidget() +{ + if (!mSlider) + return; + + mSlider->setValue(atof(mValue.c_str())); +} + +void SetupItemSlider::action(const gcn::ActionEvent &event A_UNUSED) +{ + fromWidget(); +} + +void SetupItemSlider::apply(std::string eventName) +{ + if (eventName != mEventName) + return; + + fromWidget(); + save(); +} |