diff options
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/horizontcontainer.cpp | 7 | ||||
-rw-r--r-- | src/gui/widgets/horizontcontainer.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/setupitem.cpp | 98 | ||||
-rw-r--r-- | src/gui/widgets/setupitem.h | 34 |
4 files changed, 140 insertions, 1 deletions
diff --git a/src/gui/widgets/horizontcontainer.cpp b/src/gui/widgets/horizontcontainer.cpp index c128ea550..5bf81c5d8 100644 --- a/src/gui/widgets/horizontcontainer.cpp +++ b/src/gui/widgets/horizontcontainer.cpp @@ -34,11 +34,16 @@ HorizontContainer::HorizontContainer(int height, int spacing): void HorizontContainer::add(gcn::Widget *widget) { + add(widget, mSpacing); +} + +void HorizontContainer::add(gcn::Widget *widget, int spacing) +{ if (!widget) return; Container::add(widget); - widget->setPosition(mLastX, mSpacing); + widget->setPosition(mLastX, spacing); mCount++; mLastX += widget->getWidth() + 2 * mSpacing; } diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h index 7439672dc..8e1d082ac 100644 --- a/src/gui/widgets/horizontcontainer.h +++ b/src/gui/widgets/horizontcontainer.h @@ -38,6 +38,8 @@ class HorizontContainer : public Container, public gcn::WidgetListener virtual void add(gcn::Widget *widget); + virtual void add(gcn::Widget *widget, int spacing); + virtual void clear(); void widgetResized(const gcn::Event &event); 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(); +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index 71856d6e2..220a55494 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -41,6 +41,7 @@ class EditDialog; class HorizontContainer; class IntTextField; class Label; +class Slider; class TextField; class SetupItem : public gcn::ActionListener @@ -264,4 +265,37 @@ class SetupItemDropDown : public SetupItem DropDown *mDropDown; }; +class SetupItemSlider : public SetupItem +{ + public: + SetupItemSlider(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, double min, double max, + bool mainConfig = true); + + SetupItemSlider(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, double min, double max, + std::string def, bool mainConfig = true); + + ~SetupItemSlider(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + Slider *mSlider; + double mMin; + double mMax; +}; + #endif |