ManaPlus
setuptouchitem.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
24 
25 #include "gui/widgets/dropdown.h"
27 #include "gui/widgets/label.h"
29 
31 
32 #include "utils/stringutils.h"
33 
34 #include "debug.h"
35 
37  const std::string &restrict
38  description,
39  const std::string &restrict keyName,
40  SetupTabScroll *restrict const parent,
41  const std::string &restrict eventName,
43  const model,
44  const int width,
45  const MainConfig mainConfig) :
46  SetupItem(text, description, keyName, parent, eventName, mainConfig),
47  mHorizont(nullptr),
48  mLabel(nullptr),
49  mModel(model),
50  mDropDown(nullptr),
51  mWidth(width)
52 {
53  mValueType = VSTR;
55 }
56 
58  const std::string &restrict
59  description,
60  const std::string &restrict keyName,
61  SetupTabScroll *restrict const parent,
62  const std::string &restrict eventName,
64  const model,
65  const int width,
66  const std::string &restrict def,
67  const MainConfig mainConfig) :
68  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
70  mLabel(nullptr),
71  mModel(model),
73  mWidth(width)
74 {
75  mValueType = VSTR;
77 }
78 
80 {
81  mHorizont = nullptr;
82  mWidget = nullptr;
83  mModel = nullptr;
84  mDropDown = nullptr;
85  mLabel = nullptr;
86 }
87 
89 {
90  if (mModel == nullptr)
91  return;
92 
93  load();
94  mHorizont = new HorizontContainer(this, 32, 2);
95 
96  mLabel = new Label(this, mText);
98  mDropDown = new DropDown(this,
99  mModel,
100  false,
101  Modal_false,
102  nullptr,
103  std::string());
108  static_cast<InputActionT>(atoi(mValue.c_str()))));
109 
110  mWidget = mDropDown;
112  mHorizont->add(mLabel);
114 
115  mParent->getContainer()->add2(mHorizont, true, 4);
116  mParent->addControl(this);
117  mParent->addActionListener(this);
118  mWidget->addActionListener(this);
119 }
120 
122 {
123  if ((mDropDown == nullptr) || (mModel == nullptr))
124  return;
125 
127  mDropDown->getSelected())));
128 }
129 
131 {
132  if ((mDropDown == nullptr) || (mModel == nullptr))
133  return;
134 
136  static_cast<InputActionT>(atoi(mValue.c_str()))));
137 }
void load()
Definition: setupitem.cpp:112
std::string mEventName
Definition: setupitem.h:136
void addControl(SetupItem *const widget)
void setWidth(const int width)
Definition: widget.cpp:132
std::string mValue
Definition: setupitem.h:138
HorizontContainer * mHorizont
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
std::string mDescription
Definition: setupitem.h:130
TouchActionsModel * mModel
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
int mValueType
Definition: setupitem.h:146
VertContainer * getContainer() const
int getSelectionFromAction(const InputActionT action) const
#define CAST_S32
Definition: cast.h:29
void add2(Widget *const widget, const bool resizable, const int spacing)
Definition: label.h:87
Widget * mWidget
Definition: setupitem.h:142
#define nullptr
Definition: localconsts.h:44
SetupTabScroll * mParent
Definition: setupitem.h:134
void add(Widget *const widget)
void fixFirstItemSize(Widget *const widget)
Definition: setupitem.cpp:197
void setToolTip(const std::string &str)
SetupActionDropDown(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, TouchActionsModel *const model, const int width, const MainConfig mainConfig)
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
InputActionT getActionFromSelection(const int sel) const
#define restrict
Definition: localconsts.h:164
void setSelected(int selected)
Definition: dropdown.cpp:514
int getSelected() const
Definition: dropdown.cpp:509
std::string mText
Definition: setupitem.h:128