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