From b1f8a2eaab592b59b5946bdbe38f0d8f775cc434 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 23:04:44 +0300 Subject: Add drop down widget for setup pages. Known issue: popup listbox drawed under other widgets. --- src/gui/widgets/setupitem.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) (limited to 'src/gui/widgets/setupitem.cpp') diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index fd2c937dc..698e133dd 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -28,6 +28,7 @@ #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" +#include "gui/widgets/dropdown.h" #include "gui/widgets/horizontcontainer.h" #include "gui/widgets/inttextfield.h" #include "gui/widgets/label.h" @@ -330,7 +331,6 @@ void SetupItemTextField::apply(std::string eventName) save(); } - SetupItemIntTextField::SetupItemIntTextField(std::string text, std::string description, std::string keyName, @@ -454,6 +454,8 @@ void SetupItemIntTextField::apply(std::string eventName) save(); } + + SetupItemLabel::SetupItemLabel(std::string text, std::string description, SetupTabScroll *parent, bool separator) : SetupItem(text, description, "", parent, "", "", true), @@ -505,3 +507,85 @@ void SetupItemLabel::action(const gcn::ActionEvent &event A_UNUSED) void SetupItemLabel::apply(std::string eventName A_UNUSED) { } + + +SetupItemDropDown::SetupItemDropDown(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(0), + mLabel(0), + mModel(model), + mDropDown(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemDropDown::SetupItemDropDown(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(0), + mLabel(0), + mModel(model), + mDropDown(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemDropDown::~SetupItemDropDown() +{ + mHorizont = 0; + mWidget = 0; + mModel = 0; + mDropDown = 0; + mLabel = 0; +} + +void SetupItemDropDown::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mDropDown = new DropDown(mModel); + mDropDown->setActionEventId(mEventName); + mDropDown->addActionListener(mParent); + + mWidget = mDropDown; +// mTextField->setWidth(50); + mHorizont->add(mLabel); + mHorizont->add(mDropDown); + + mParent->getContainer()->add(mHorizont, true, 4); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemDropDown::fromWidget() +{ + if (!mDropDown) + return; + + mValue = mDropDown->getSelectedString(); +} + +void SetupItemDropDown::toWidget() +{ + if (!mDropDown) + return; + + mDropDown->setSelectedString(mValue); +} -- cgit v1.2.3-60-g2f50