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/horizontcontainer.h | 3 ++ src/gui/widgets/setupitem.cpp | 86 ++++++++++++++++++++++++++++++++++++- src/gui/widgets/setupitem.h | 29 +++++++++++++ src/gui/widgets/vertcontainer.cpp | 2 +- 4 files changed, 118 insertions(+), 2 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h index 4a959190e..80014c171 100644 --- a/src/gui/widgets/horizontcontainer.h +++ b/src/gui/widgets/horizontcontainer.h @@ -41,8 +41,11 @@ class HorizontContainer : public Container, public gcn::WidgetListener { public: HorizontContainer(int height, int spacing); + virtual void add(gcn::Widget *widget); + virtual void clear(); + void widgetResized(const gcn::Event &event); protected: 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); +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index 3396edea3..15d2d41ea 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -42,6 +42,7 @@ class CheckBox; class Configuration; class ContainerPlacer; +class DropDown; class EditDialog; class HorizontContainer; class IntTextField; @@ -241,4 +242,32 @@ class SetupItemLabel : public SetupItem bool mIsSeparator; }; +class SetupItemDropDown : public SetupItem +{ + public: + SetupItemDropDown(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + bool mainConfig = true); + + SetupItemDropDown(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + std::string def, bool mainConfig = true); + + ~SetupItemDropDown(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + gcn::ListModel *mModel; + DropDown *mDropDown; +}; + #endif diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp index d65274f20..ea6b4d520 100644 --- a/src/gui/widgets/vertcontainer.cpp +++ b/src/gui/widgets/vertcontainer.cpp @@ -49,7 +49,7 @@ void VertContainer::add(gcn::Widget *widget, bool resizable, int spacing) widget->setPosition(mLeftSpacing, mNextY); if (resizable) { - widget->setSize(getWidth() - mLeftSpacing, mVerticalItemSize); + widget->setSize(getWidth() - mLeftSpacing, mVerticalItemSize * 5); mResizableWidgets.push_back(widget); } else if (widget->getHeight() > mVerticalItemSize) -- cgit v1.2.3-70-g09d2