ManaPlus
setuptabscroll.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-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 
24 #include "gui/widgets/scrollarea.h"
25 #include "gui/widgets/setupitem.h"
27 
28 #include "utils/delete2.h"
29 
30 #include "debug.h"
31 
33  SetupTab(widget),
34  mContainer(new VertContainer(this, 25, false, 8)),
35  mScroll(new ScrollArea(this, mContainer, Opaque_false, std::string())),
36  mItems(),
37  mAllItems(),
38  mPreferredFirstItemSize(200)
39 {
42  mScroll->setSelectable(false);
43  mContainer->setSelectable(false);
44 }
45 
47 {
48  mScroll = nullptr;
50  removeItems();
51 }
52 
54 {
55  std::set<SetupItem*>::iterator it = mAllItems.begin();
56  const std::set<SetupItem*>::iterator it_end = mAllItems.end();
57  while (it != it_end)
58  {
59  delete *it;
60  ++ it;
61  }
62  mAllItems.clear();
63 
64  mItems.clear();
65 }
66 
68 {
69  removeItems();
71  mContainer->clear();
72 }
73 
75 {
76  if (widget == nullptr)
77  return;
78  const std::string actionId = widget->getActionEventId();
79  if (!actionId.empty())
80  {
81  const std::map<std::string, SetupItem*>::iterator iter
82  = mItems.find(actionId);
83  if (iter != mItems.end())
84  {
85  delete (*iter).second;
86  mItems.erase(iter);
87  }
88  mItems[actionId] = widget;
89  }
90  mAllItems.insert(widget);
91 }
92 
94  const std::string &event)
95 {
96  const std::map<std::string, SetupItem*>::iterator iter
97  = mItems.find(event);
98  if (iter != mItems.end())
99  {
100  delete (*iter).second;
101  mItems.erase(iter);
102  }
103  mItems[event] = widget;
104  mAllItems.insert(widget);
105 }
106 
108 {
109  for (std::map<std::string, SetupItem*>::const_iterator
110  iter = mItems.begin(), iter_end = mItems.end();
111  iter != iter_end; ++ iter)
112  {
113  if ((*iter).second != nullptr)
114  (*iter).second->apply((*iter).first);
115  }
116 }
117 
119 {
120  for (std::map<std::string, SetupItem*>::const_iterator
121  iter = mItems.begin(), iter_end = mItems.end();
122  iter != iter_end; ++ iter)
123  {
124  if ((*iter).second != nullptr)
125  (*iter).second->cancel((*iter).first);
126  }
127 }
128 
130 {
131  for (std::map<std::string, SetupItem*>::const_iterator
132  iter = mItems.begin(), iter_end = mItems.end();
133  iter != iter_end; ++ iter)
134  {
135  SetupItem *const widget = (*iter).second;
136  if ((widget != nullptr) && widget->isMainConfig() == MainConfig_false)
137  widget->externalUpdated((*iter).first);
138  }
139 }
140 
142 {
143  for (std::map<std::string, SetupItem*>::const_iterator
144  iter = mItems.begin(), iter_end = mItems.end();
145  iter != iter_end; ++ iter)
146  {
147  SetupItem *const widget = (*iter).second;
148  if ((widget != nullptr) && widget->isMainConfig() == MainConfig_false)
149  widget->externalUnloaded((*iter).first);
150  }
151 }
152 
154 {
155  mScroll->setWidth(getWidth() - 12);
156  mScroll->setHeight(getHeight() - 12 - 12);
157 }
158 
159 void SetupTabScroll::reread(const std::string &name)
160 {
161  SetupItem *const item = mItems[name + "Event"];
162  if (item != nullptr)
163  item->rereadValue();
164 }
void removeControls()
Definition: container.cpp:43
Definition: event.h:79
void setVerticalScrollPolicy(const ScrollPolicy vPolicy)
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
void setWidth(int width)
void setHeight(int height)
MainConfig isMainConfig() const
Definition: setupitem.h:97
virtual std::string getActionEventId() const
Definition: setupitem.cpp:155
virtual void externalUpdated(const std::string &eventName)
Definition: setupitem.cpp:188
virtual void externalUnloaded(const std::string &eventName)
Definition: setupitem.cpp:194
virtual void rereadValue()
Definition: setupitem.cpp:207
void widgetResized(const Event &event)
std::map< std::string, SetupItem * > mItems
void addControl(SetupItem *const widget)
void reread(const std::string &name)
std::set< SetupItem * > mAllItems
SetupTabScroll(const Widget2 *const widget)
VertContainer * mContainer
ScrollArea * mScroll
void setSelectable(const bool selectable)
Definition: widget.h:948
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
#define new
Definition: debug_new.h:147
#define delete2(var)
Definition: delete2.h:25
#define A_UNUSED
Definition: localconsts.h:160
const bool MainConfig_false
Definition: mainconfig.h:30
const bool Opaque_false
Definition: opaque.h:30