diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-02-27 02:44:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-02-27 02:45:53 +0300 |
commit | 481bbd254103fc9d6dc98b19a5226f8868c8c5d9 (patch) | |
tree | 426856951ad81ccb69b43fc53a2ae76861f30fff /src/gui/widgets | |
parent | e5272cde78d23a297dad05976e8579b3e5759de4 (diff) | |
download | manaverse-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.tar.gz manaverse-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.tar.bz2 manaverse-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.tar.xz manaverse-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.zip |
Add sliderlist setup item.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/namesmodel.cpp | 51 | ||||
-rw-r--r-- | src/gui/widgets/namesmodel.h | 45 | ||||
-rw-r--r-- | src/gui/widgets/setupitem.cpp | 103 | ||||
-rw-r--r-- | src/gui/widgets/setupitem.h | 37 |
4 files changed, 236 insertions, 0 deletions
diff --git a/src/gui/widgets/namesmodel.cpp b/src/gui/widgets/namesmodel.cpp new file mode 100644 index 000000000..abfcd6def --- /dev/null +++ b/src/gui/widgets/namesmodel.cpp @@ -0,0 +1,51 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/widgets/namesmodel.h" + +#include "logger.h" + +#include "utils/gettext.h" + +#include <guichan/exception.hpp> +#include <guichan/font.hpp> + +#include "debug.h" + +NamesModel::NamesModel() +{ +} + +NamesModel::~NamesModel() +{ +} + +int NamesModel::getNumberOfElements() +{ + return static_cast<int>(mNames.size()); +} + +std::string NamesModel::getElementAt(int i) +{ + if (i >= getNumberOfElements() || i < 0) + return _("???"); + + return mNames[i]; +} diff --git a/src/gui/widgets/namesmodel.h b/src/gui/widgets/namesmodel.h new file mode 100644 index 000000000..3f9f10b52 --- /dev/null +++ b/src/gui/widgets/namesmodel.h @@ -0,0 +1,45 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_WIDGETS_NAMESMODEL_H +#define GUI_WIDGETS_NAMESMODEL_H + +//#include "guichanfwd.h" + +#include <guichan/listmodel.hpp> + +#include <vector> + +class NamesModel : public gcn::ListModel +{ + public: + NamesModel(); + + virtual ~NamesModel(); + + virtual int getNumberOfElements(); + + virtual std::string getElementAt(int i); + + protected: + std::vector<std::string> mNames; +}; + +#endif diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 8987719da..581002a58 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -35,6 +35,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/slider.h" +#include "gui/widgets/sliderlist.h" #include "gui/widgets/tabbedarea.h" #include "gui/widgets/textfield.h" #include "gui/widgets/vertcontainer.h" @@ -693,6 +694,7 @@ void SetupItemSlider::apply(std::string eventName) save(); } + SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, int min, int max, @@ -851,3 +853,104 @@ void SetupItemSlider2::setInvertValue(int v) mInvertValue = v; toWidget(); } + + +SetupItemSliderList::SetupItemSliderList(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + int width, bool onTheFly, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mSlider(nullptr), + mModel(model), + mWidth(width), + mOnTheFly(onTheFly) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSliderList::SetupItemSliderList(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + std::string def, int width, + bool onTheFly, bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mSlider(nullptr), + mModel(model), + mWidth(width), + mOnTheFly(onTheFly) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSliderList::~SetupItemSliderList() +{ + mHorizont = nullptr; + mWidget = nullptr; + mSlider = nullptr; + mLabel = nullptr; +} + +void SetupItemSliderList::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mSlider = new SliderList(mModel, mParent, mEventName); + mSlider->setSelectedString(mValue); + mSlider->adjustSize(); + + mWidget = mSlider; + mHorizont->add(mLabel, 5); + mHorizont->add(mSlider); + + mParent->getContainer()->add2(mHorizont, true, 4); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemSliderList::fromWidget() +{ + if (!mSlider) + return; + + mValue = mSlider->getSelectedString(); +} + +void SetupItemSliderList::toWidget() +{ + if (!mSlider) + return; + + mSlider->setSelectedString(mValue); +} + +void SetupItemSliderList::action(const gcn::ActionEvent &event A_UNUSED) +{ + fromWidget(); + if (mOnTheFly) + save(); +} + +void SetupItemSliderList::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 b950d1488..f883a5b94 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -42,6 +42,7 @@ class HorizontContainer; class IntTextField; class Label; class Slider; +class SliderList; class TextField; class SetupItem : public gcn::ActionListener @@ -353,4 +354,40 @@ class SetupItemSlider2 : public SetupItem bool mOnTheFly; }; +class SetupItemSliderList : public SetupItem +{ + public: + SetupItemSliderList(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + int width = 150, bool onTheFly = false, + bool mainConfig = true); + + SetupItemSliderList(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + std::string def, int width = 150, + bool onTheFly = false, bool mainConfig = true); + + ~SetupItemSliderList(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + SliderList *mSlider; + gcn::ListModel *mModel; + int mWidth; + bool mOnTheFly; +}; + #endif |